在Unity中使用Stockfish Chess AI

时间:2018-10-17 10:35:12

标签: c# unity3d artificial-intelligence uci

早上好。我被告知最好的方法是使用Spawn.Process,以将Stockfish实施为Unity棋类游戏。 有人知道我可以查看并作为参考的现有代码吗?

不同的游戏状态是与AI通信的最佳方式吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

如果您可以在Forsyth-Edwards Notation中表示游戏状态并阅读Algebraic Notation来提高棋盘状态,则应该可以:

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;
}