首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Unity中使用Stockfish国际象棋AI

在Unity中使用Stockfish国际象棋AI
EN

Stack Overflow用户
提问于 2018-10-17 18:35:12
回答 1查看 2.4K关注 0票数 1

早上好。我正在尝试将Stockfish实现到Unity国际象棋游戏中,我被告知最好的方法是使用Spawn.Process。有人知道我可以查看和参考的现有代码吗?

不同的游戏庄园是与AI沟通的最佳方式吗?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-18 03:49:03

如果你可以用Forsyth-Edwards Notation表示你的游戏状态,并读取Algebraic Notation来提升你的棋盘状态,这应该是可行的:

代码语言:javascript
复制
string GetBestMove(string forsythEdwardsNotationString){
    var p = new System.Diagnostics.Process();
    p.StartInfo.FileName = "stockfishExecutable";
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardInput = true;
    p.StartInfo.RedirectStandardOutput = true;
    p.Start();  
    string setupString = "position fen "+forsythEdwardsNotationString;
    p.StandardInput.WriteLine(setupString);
    
    // Process for 5 seconds
    string processString = "go movetime 5000";
    
    // Process 20 deep
    // string processString = "go depth 20";

    p.StandardInput.WriteLine(processString);
    
    string bestMoveInAlgebraicNotation = p.StandardOutput.ReadLine();

    p.Close();

    return bestMoveInAlgebraicNotation;
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52852843

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档