public void UciCommands_Should_Return_ExpectedOutput()
        {
            //	Arrange
            List <UCIResponseToken> response;

            //	Act
            _engine.SendCommand(UCIQuery.Uci());
            response = _engine.GetResponse();

            Assert.IsTrue(response[0] is Id);
            Assert.IsTrue(response[1] is Id);
            Assert.AreEqual("Stockfish 12", (response[0] as Id).EngineName);
            Assert.AreEqual("the Stockfish developers (see AUTHORS file)", (response[1] as Id).EngineAuthor);

            _engine.SendCommand(UCIQuery.IsReady());
            response = _engine.GetResponse();
            Assert.IsTrue(response[0] is ReadyOk);

            _engine.SendCommand(UCIQuery.UciNewGame());
            response = _engine.GetResponse();
            Assert.AreEqual(0, response.Count);

            _engine.SendCommand(UCIQuery.Position(new List <string>()
            {
                "e2e4", "e7e5"
            }));
            response = _engine.GetResponse();
            Assert.AreEqual(0, response.Count);

            _engine.SendCommand(UCIQuery.Go());
            System.Threading.Thread.Sleep(2500);
            _engine.SendCommand(UCIQuery.Stop());
            System.Threading.Thread.Sleep(250); //  Gives the engine enough time to finish.
            response = _engine.GetResponse();
            Assert.IsTrue(response[response.Count - 1] is BestMove);
            Assert.IsFalse(string.IsNullOrEmpty((response[response.Count - 1] as BestMove).BestMoveValue));
            Assert.IsFalse(string.IsNullOrEmpty((response[response.Count - 1] as BestMove).PonderValue));

            _engine.SendCommand(UCIQuery.Quit());
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            using (var stockfish = new UCIEngine(enginePath, false))
            {
                Console.WriteLine("Starting Stockfish engine");
                //  Get welcome response
                PrintResponse(stockfish.GetResponse());

                //  Send UCI command
                Console.WriteLine($"-> {stockfish.SendCommand(UCIQuery.Uci())}");
                PrintResponse(stockfish.GetResponse());

                //  Send IsReady command
                Console.WriteLine($"-> {stockfish.SendCommand(UCIQuery.IsReady())}");
                PrintResponse(stockfish.GetResponse());

                //  Send Position command
                Console.WriteLine($"-> {stockfish.SendCommand(UCIQuery.Position(new List<string>() { "e2e4", "e7e5" }))}");

                //  Send Go command
                Console.WriteLine($"-> {stockfish.SendCommand(UCIQuery.Go(5000))}");

                //  Display Stockfish’s thinks
                while (true)
                {
                    var tokens = stockfish.GetResponse();
                    if (tokens.Count > 0)
                    {
                        PrintResponse(tokens);
                        if (tokens[tokens.Count - 1] is BestMove)
                        {
                            break;
                        }
                    }
                }
            }
            Console.WriteLine("End of the demo.");
            Console.Read();
        }