Alv*_*gas 2 c# artificial-intelligence unity-game-engine uci
早上好。我正在尝试将 Stockfish 实现到 Unity 国际象棋游戏中,有人告诉我最好的方法是使用 Spawn.Process 有谁知道我可以查看并作为参考的现有代码吗?
不同的游戏状态是与人工智能沟通的最佳方式吗?
谢谢!
如果您可以用 Forsyth-Edwards 表示法表示您的游戏状态并阅读代数表示法来推进您的棋盘状态,那么这应该可行:
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;
}
Run Code Online (Sandbox Code Playgroud)