//[SetUp] public void Setup() { _startup = new UCIEngineStartupArgs(Guid.NewGuid(), "mocked engine", "runMockEngine.exe"); ProcessMock = new Mock <EngineProcess>(new UCIEngineMessageSubscriber(null)); ProcessMock.Setup(x => x.Start()).Callback(() => { IsStarted = true; }).Returns(true); ProcessMock.Setup(x => x.BeginErrorReadLine()).Callback(SetupErrorReadLine); ProcessMock.Setup(x => x.BeginOutputReadLine()).Callback(SetupOutputReadLine); ProcessMock.Setup(x => x.SetPriority(It.IsAny <ProcessPriorityClass>())).Callback <ProcessPriorityClass>(SetupSetPriority); ProcessMock.Setup(x => x.WaitForExit(It.IsAny <int>())).Returns(true); ProcessMock.SetupGet(x => x.ProcessId).Returns(420); Eng = new UCIEngine(_startup, Process); (ProcessMock.Object.MessageSubscriber as UCIEngineMessageSubscriber).EngineResponseCallback = Eng.ResponseReceived; Eng.DebugEventExecuted += (s, arg) => { Console.WriteLine(arg.DebugText); }; ProcessMock.Setup(s => s.Send(It.IsAny <CommandInfo>())).Callback <CommandInfo>(ci => { var txt = ci.CommandText; if (txt == "uci") { ProcessMock.Object.HandleMessageFromEngine("uciok"); } if (txt == "isready") { ProcessMock.Object.HandleMessageFromEngine("readyok"); } if (txt == "quit") { Process.Close(); } LastCommand = txt; }); EngineTask = Eng.StartAsync(); }
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(); } }