0

Recently i'm working on a chess and for the AI i'm using Stockfish with the UCI Protocol. Thanks to this 2 following links ( UCI Protocol : http://wbec-ridderkerk.nl/html/UCIProtocol.html and this post : Using Stockfish Chess AI in Unity ) i have done some progress but i have an issue.

Here is my code :

        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;

When i ask Stockfish an evaluation with this following code : myStreamWriter.WriteLine("go movetime 2000");

He does it but stop it right away when i ask the processus to close : p.Close();

So i would like for the processus to wait until the task is done, is there anyway to do it and how?

Thansk for reading me and have a nice day.

Nico
  • 35
  • 5