最近,我正在研究国际象棋,对于人工智能,我正在使用带有UCI协议的Stockfish。多亏了这两个链接( UCI Protocol:http://wbec-ridderkerk.nl/html/UCIProtocol.html和这篇文章:Using Stockfish Chess AI in Unity ),我已经取得了一些进展,但我有一个问题。
下面是我的代码:
var p = new System.Diagnostics.Process();
p.StartInfo.FileName = "C:/stockfish/stockfish-11-win/Windows/stockfish_20011801_32bit";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
StreamWriter myStreamWriter = p.StandardInput;
myStreamWriter.WriteLine("position fen " + fen);
myStreamWriter.WriteLine("go movetime 2000");
myStreamWriter.Close();
Thread.Sleep(2000);
StreamReader reader = p.StandardOutput;
String bestMoveInAlgebraicNotation = reader.ReadToEnd();
reader.Close();
p.Close();
return bestMoveInAlgebraicNotation;
当我要求Stockfish使用以下代码进行评估时:myStreamWriter.WriteLine("go movetime 2000");
他这样做了,但当我要求进程关闭时,他立即停止:p.Close();
所以我想让processus一直等到任务完成,有没有什么办法呢?
谢谢你读我的文章,祝你有愉快的一天。
发布于 2020-06-02 22:47:08
https://stackoverflow.com/questions/62162474
复制相似问题