コード例 #1
0
ファイル: EngineTests.cs プロジェクト: wesIdeal/ChessLib
        public void TestStopDuringCalculationsOfRealEngine()
        {
            var startupArgs = new UCIEngineStartupArgs(Guid.NewGuid(), "StockFish", "stockfish_10_x64.exe");

            using (var engine = new UCIEngine(startupArgs))
            {
                //engine.DebugEventExecuted += (s, o) => { Console.WriteLine(o.ToString()); };
                EngineTask = engine.StartAsync();
                engine.SetOption("Debug Log File", "c:\\temp\\sf.log.txt");
                engine.DebugEventExecuted += (o, d) =>
                {
                    Console.WriteLine($"{d.ToString()}");
                };
                engine.EngineCalculationReceived += (s, o) =>
                {
                    var message = "";
                    if (o.ResponseObject == null)
                    {
                        Debug.WriteLine("****Calc Result Was Null****");
                    }
                    else if (o.ResponseObject.ResponseType == CalculationResponseTypes.BestMove)
                    {
                        var bm = o.ResponseObject as BestMoveResponse;
                        message = ($"Bestmove found: {bm.BestMove}. Pondering: {bm.PonderMove}");
                        engine.SendQuit();
                    }
                    else if (o.ResponseObject.ResponseType == CalculationResponseTypes.PrincipalVariation)
                    {
                        var pv = o.ResponseObject as PrincipalVariationResponse;
                        message = ($"Principal variation {pv.PVOrdinal} found, starting with {pv.Variation[0].SAN}.");
                    }
                    //Console.WriteLine(message);
                };
                engine.SetOption("MultiPV", "3");
                engine.SendPosition("rnbqkbnr/pppppppp/8/8/2P5/8/PP1PPPPP/RNBQKBNR b KQkq - 0 1");
                RunEngineCalculationForGivenTime(engine, TimeSpan.FromSeconds(10));
                EngineTask.Wait();
            }
        }