private static void ReadLine(string line) { var tokens = line.Split(" "); if (tokens[0].Equals("uci")) { UciOut.SendUci(); } else if (tokens[0].Equals("isready")) { Console.WriteLine("readyok"); } else if (tokens[0].Equals("ucinewgame")) { TtUtil.Init(false); TtUtil.ClearValues(); } else if (tokens[0].Equals("position")) { Position(tokens); } else if (tokens[0].Equals("go")) { Go(tokens); } else if (tokens[0].Equals("ponderhit")) { Pondering = false; if (_maxTimeExceeded) { NegamaxUtil.IsRunning = false; } } else if (tokens[0].Equals("eval")) { UciOut.Eval(_cb, _threadData); } else if (tokens[0].Equals("setoption")) { if (tokens.Length > 4) { SetOption(tokens[2], tokens[4]); } } else if (tokens[0].Equals("quit")) { Environment.Exit(0); } else if (tokens[0].Equals("stop")) { NegamaxUtil.IsRunning = false; } else { Console.WriteLine("Unknown command: " + tokens[0]); } }
private static async Task InfoTask(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { await Task.Delay(2000, cancellationToken); UciOut.SendInfo(); } }
public static void Log(ChessBoard cb, Exception e, bool systemExit) { try { // print to Console Console.WriteLine(e); // redirect Console var writer = new StringWriter(); Console.SetOut(writer); // print info Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Chess22kDotNet " + UciOut.GetVersion()); Console.WriteLine(); Console.WriteLine("start fen"); Console.WriteLine(StartFen); Console.WriteLine(); Console.WriteLine("crashed fen"); Console.WriteLine(cb); Console.WriteLine(); // print statistics Statistics.Print(); Console.Out.Flush(); // print exception Serilog.Log.Information(writer.ToString()); Serilog.Log.Error(e, "An exception occurred"); } catch (IOException ex) { Console.WriteLine(ex); } finally { if (systemExit) { Environment.Exit(1); } } }
private static void SearchTask() { try { var source = new CancellationTokenSource(); Task.Run(async() => await MaxTimeTask(source.Token), source.Token); Task.Run(async() => await InfoTask(source.Token), source.Token); _maxTimeExceeded = false; SearchUtil.Start(_cb); // calculation ready source.Cancel(); UciOut.SendBestMove(_threadData); } catch (Exception e) { ErrorLogger.Log(_cb, e, true); } }