public static void Main() { var cb = ChessBoardInstances.Get(0); MainEngine.MaxDepth = MaxPly; UciOut.NoOutput = true; EngineConstants.Power2TtEntries = 2; TtUtil.Init(false); long totalNodesSearched = 0; var epdStrings = BestMoveTest.GetEpdStrings("Resources/WAC-201.epd"); for (var index = 0; index < NumberOfPositions; index++) { Console.WriteLine(index); var epdString = epdStrings[index + 20]; Statistics.Reset(); var epd = new Epd(epdString); ChessBoardUtil.SetFen(epd.GetFen(), cb); SearchUtil.Start(cb); totalNodesSearched += ChessBoardUtil.CalculateTotalMoveCount(); } Console.WriteLine("Total " + totalNodesSearched); Console.WriteLine("Average " + totalNodesSearched / NumberOfPositions); }
public static void Set(ChessBoard cb, int[] moves, int bestMove) { Array.Fill(moves, 0); moves[0] = bestMove; cb.DoMove(bestMove); for (var i = 1; i < moves.Length; i++) { var ttEntry = TtUtil.GetEntry(cb.ZobristKey); if (ttEntry.Key == 0) { break; } var move = ttEntry.Move; if (move == 0) { break; } moves[i] = move; cb.DoMove(move); } for (var i = moves.Length - 1; i >= 0; i--) { if (moves[i] == 0) { continue; } cb.UndoMove(moves[i]); } }
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]); } }
public static void Main() { var cb = ChessBoardInstances.Get(0); ChessBoardUtil.SetFen(FenStandardMiddlegame, cb); TimeUtil.SetSimpleTimeWindow(5000); TtUtil.Init(false); SearchUtil.Start(cb); Statistics.Print(); }
public static void Main() { UciOut.NoOutput = true; TtUtil.Init(false); DoTest(GetEpdStrings("Resources/WAC-201.epd")); // DoTest(GetEpdStrings("Resources/EigenmannEndgame.epd")); Console.WriteLine(""); Console.WriteLine("Total: " + _positionTestOk + "/" + (_positionTestOk + _positionTestNok)); }
public static void Main() { var cb = ChessBoardInstances.Get(0); // read all fens, including score var fens = Tuner.LoadFens("d:\\backup\\chess\\epds\\violent.epd", false, true); Console.WriteLine("Fens found : " + fens.Count); // NegamaxUtil.isRunning = true; EngineConstants.Power2TtEntries = 1; TtUtil.Init(false); double totalPositions = 0; double sameScore = 0; long totalError = 0; var watch = new Stopwatch(); watch.Start(); foreach (var entry in fens) { ChessBoardUtil.SetFen(entry.Key, cb); if (cb.CheckingPieces == 0) { continue; } totalPositions++; var searchScore = NegamaxUtil.CalculateBestMove(cb, ThreadData, 0, 1, Util.ShortMin, Util.ShortMax, 0); TtUtil.ClearValues(); var qScore = QuiescenceUtil.CalculateBestMove(cb, ThreadData, Util.ShortMin, Util.ShortMax); if (searchScore == qScore) { sameScore++; } else { var error = searchScore - qScore; // if (error > 500) { // System.out.println(searchScore + " " + qScore); // QuiescenceUtil.calculateBestMove(cb, threadData, Util.SHORT_MIN, Util.SHORT_MAX); // } totalError += error; } } var averageError = (int)(totalError / (totalPositions - sameScore)); Console.WriteLine($"{sameScore / totalPositions:f4} {averageError}"); Console.WriteLine("msec: " + watch.ElapsedMilliseconds); }
public static void SendInfo() { if (NoOutput) { return; } if (Stopwatch.IsRunning && Stopwatch.ElapsedMilliseconds < 2000) { return; } var totalMoveCount = ChessBoardUtil.CalculateTotalMoveCount(); Console.WriteLine("info nodes " + totalMoveCount + " nps " + CalculateNps(totalMoveCount) + " hashfull " + TtUtil.GetUsagePercentage()); }
public static void SendPlyInfo(ThreadData threadData) { if (NoOutput) { return; } Stopwatch.Restart(); var totalMoveCount = ChessBoardUtil.CalculateTotalMoveCount(); // info depth 1 seldepth 2 score cp 50 pv d2d4 d7d5 e2e3 hashfull 0 nps 1000 nodes 22 // info depth 4 seldepth 10 score cp 40 upperbound pv d2d4 d7d5 e2e3 hashfull 0 nps 30000 nodes 1422 Console.WriteLine("info depth " + threadData.Depth + " time " + TimeUtil.GetPassedTimeMs() + " score cp " + threadData.BestScore + threadData.ScoreType.ToFriendlyName() + "nps " + CalculateNps(totalMoveCount) + " nodes " + totalMoveCount + " hashfull " + TtUtil.GetUsagePercentage() + " pv " + PvUtil.AsString(threadData.Pv)); }
private static void SetOption(string optionName, string optionValue) { // setoption name Hash value 128 if (optionName.ToLower().Equals("hash")) { var value = int.Parse(optionValue); TtUtil.SetSizeMb(value); } else if (optionName.ToLower().Equals("threads")) { UciOptions.SetThreadCount(int.Parse(optionValue)); _cb = ChessBoardInstances.Get(0); _threadData = ThreadData.GetInstance(0); } else if (optionName.ToLower().Equals("ponder")) { UciOptions.SetPonder(bool.Parse(optionValue)); } else { Console.WriteLine("Unknown option: " + optionName); } }
public static void Print() { if (!Enabled) { return; } var totalMoveCount = ChessBoardUtil.CalculateTotalMoveCount(); Console.WriteLine("AB-nodes " + AbNodes); Console.WriteLine("PV-nodes " + _pvNodes + " = 1/" + (_pvNodes + _cutNodes + _allNodes) / _pvNodes); Console.WriteLine("Cut-nodes " + _cutNodes); PrintPercentage("Cut 1 ", FailHigh[0], _cutNodes - FailHigh[0]); PrintPercentage("Cut 2 ", FailHigh[1], _cutNodes - FailHigh[1]); PrintPercentage("Cut 3 ", FailHigh[2], _cutNodes - FailHigh[2]); Console.WriteLine("All-nodes " + _allNodes); Console.WriteLine("Q-nodes " + QNodes); Console.WriteLine("See-nodes " + SeeNodes); Console.WriteLine("Evaluated " + EvalNodes); Console.WriteLine("Moves " + totalMoveCount); var threadData = ThreadData.GetInstance(0); Console.WriteLine("### Caches #######"); PrintPercentage("TT ", TtHits, TtMisses); Console.WriteLine("usage " + TtUtil.GetUsagePercentage() / 10 + "%"); PrintPercentage("Eval ", EvalCacheHits, EvalCacheMisses); Console.WriteLine("usage " + Util.GetUsagePercentage(threadData.EvalCache) + "%"); PrintPercentage("Pawn eval ", PawnEvalCacheHits, PawnEvalCacheMisses); Console.WriteLine("usage " + Util.GetUsagePercentage(threadData.PawnCache) + "%"); PrintPercentage("Material ", MaterialCacheHits, MaterialCacheMisses); Console.WriteLine("usage " + Util.GetUsagePercentage(threadData.MaterialCache) + "%"); Console.WriteLine("## Best moves #####"); Console.WriteLine("TT " + _bestMoveTt); Console.WriteLine("TT-upper " + _bestMoveTtUpper); Console.WriteLine("TT-lower " + _bestMoveTtLower); Console.WriteLine("Win-cap " + _bestMoveWinningCapture); Console.WriteLine("Los-cap " + _bestMoveLosingCapture); Console.WriteLine("Promo " + _bestMovePromotion); Console.WriteLine("Killer1 " + _bestMoveKiller1); Console.WriteLine("Killer2 " + _bestMoveKiller2); Console.WriteLine("Killer1 evasi " + _bestMoveKillerEvasive1); Console.WriteLine("Killer2 evasi " + _bestMoveKillerEvasive2); Console.WriteLine("Counter " + _bestMoveCounter); Console.WriteLine("Other " + _bestMoveOther); Console.WriteLine("### Outcome #####"); Console.WriteLine("Checkmate " + MateCount); Console.WriteLine("Stalemate " + StaleMateCount); Console.WriteLine("Repetitions " + Repetitions + "(" + _repetitionTests + ")"); Console.WriteLine("### Extensions #####"); Console.WriteLine("Check " + CheckExtensions); Console.WriteLine("### Pruning #####"); PrintPercentage("Null-move ", NullMoveHit, NullMoveMiss); PrintDepthTotals("Static nmp ", StaticNullMoved, false); PrintDepthTotals("Razored ", Razored, false); PrintDepthTotals("Futile ", Futile, false); PrintDepthTotals("LMP ", Lmped, false); }
private static void Go(string[] goCommandTokens) { // go movestogo 30 wtime 3600000 btime 3600000 // go wtime 40847 btime 48019 winc 0 binc 0 movestogo 20 Statistics.Reset(); TimeUtil.Reset(); TimeUtil.SetMoveCount(_cb.MoveCounter); MaxDepth = EngineConstants.MaxPlies; Pondering = false; TtUtil.Init(false); var ttEntry = TtUtil.GetEntry(_cb.ZobristKey); if (ttEntry.Key != 0 && ttEntry.Flag == TtUtil.FlagExact) { TimeUtil.SetTtHit(); } // go // go infinite // go ponder if (goCommandTokens.Length != 1) { for (var i = 1; i < goCommandTokens.Length; i++) { if (goCommandTokens[i].Equals("infinite")) { // TODO are we clearing the values again? TtUtil.ClearValues(); } else if (goCommandTokens[i].Equals("ponder")) { Pondering = true; } else if (goCommandTokens[i].Equals("movetime")) { var s = goCommandTokens[i + 1]; TimeUtil.SetExactMoveTime(int.Parse(s)); } else if (goCommandTokens[i].Equals("movestogo")) { var s = goCommandTokens[i + 1]; TimeUtil.SetMovesToGo(int.Parse(s)); } else if (goCommandTokens[i].Equals("depth")) { var s = goCommandTokens[i + 1]; MaxDepth = int.Parse(s); } else if (goCommandTokens[i].Equals("wtime")) { if (_cb.ColorToMove != ChessConstants.White) { continue; } var s = goCommandTokens[i + 1]; TimeUtil.SetTotalTimeLeft(int.Parse(s)); } else if (goCommandTokens[i].Equals("btime")) { if (_cb.ColorToMove != ChessConstants.Black) { continue; } var s = goCommandTokens[i + 1]; TimeUtil.SetTotalTimeLeft(int.Parse(s)); } else if (goCommandTokens[i].Equals("winc") || goCommandTokens[i].Equals("binc")) { var s = goCommandTokens[i + 1]; TimeUtil.SetIncrement(int.Parse(s)); } } } TimeUtil.Start(); Task.Run(SearchTask); }