c# - 在 Unity 中使用 Stockfish Chess AI

标签 c# unity-game-engine artificial-intelligence uci

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

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

谢谢!

最佳答案

如果你能在 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;
}

关于c# - 在 Unity 中使用 Stockfish Chess AI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52852843/

相关文章:

c# - 如何在这种情况下使用更少的代码

c# - Unity 游戏不适合 Android 屏幕

unity-game-engine - Unity3D - 发射值参数未显示

machine-learning - tensorflow 图像形状错误

artificial-intelligence - 最佳优先 Vs。广度优先

c# - 在 UWP 的 gridview 中检索 JSON 数据

c# - “IBM437”不是 ZipFile 读取方法支持的编码名称

java - 编写可永久修改的字段或类(Java、ASM),无需数据库/文件

C# 参数化方法数组或参数化方法列表

unity-game-engine - 我可以使用 Unity 3D 导航网格进行第一人称导航吗?