早上好。我正在尝试将Stockfish集成到一个Unity国际象棋游戏中,有人告诉我使用Spawn.Process是最好的方法。有人知道我可以参考的现有代码吗?
使用不同的游戏状态是与AI通信的最佳方式吗?
谢谢!
回答:
如果你能用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); // 处理5秒钟 string processString = "go movetime 5000"; // 处理深度20 // string processString = "go depth 20"; p.StandardInput.WriteLine(processString); string bestMoveInAlgebraicNotation = p.StandardOutput.ReadLine(); p.Close(); return bestMoveInAlgebraicNotation;}