public static int Evaluate(BoardState board, EvaluationStatistics statistics, int openingPhase, int endingPhase) { var entry = PawnHashTable.Get(board.PawnHash); if (entry.IsKeyValid(board.PawnHash)) { #if DEBUG statistics.PHTHits++; #endif return(entry.Score); } #if DEBUG else { statistics.PHTNonHits++; if (entry.Key != 0 || entry.Score != 0) { statistics.PHTReplacements++; } } #endif var result = Evaluate(board, Color.White, openingPhase, endingPhase) - Evaluate(board, Color.Black, openingPhase, endingPhase); PawnHashTable.Add(board.PawnHash, (short)result); #if DEBUG statistics.PHTAddedEntries++; #endif return(result); }
private void IterativeDeepening_OnSearchUpdate(object sender, SearchStatistics statistics) { // Main search result _interactiveConsole.WriteLine($" === Depth: {statistics.Depth}, Score: {statistics.Score}, Best: {statistics.PrincipalVariation[0]}, " + $"Time: {((float) statistics.SearchTime / 1000):F} s"); // Normal search _interactiveConsole.WriteLine($" Normal search: Nodes: {statistics.Nodes}, Leafs: {statistics.Leafs}, " + $"Branching factor: {statistics.BranchingFactor:F}, Beta cutoffs: {statistics.BetaCutoffs}"); // Quiescence search _interactiveConsole.WriteLine($" Q search: Nodes: {statistics.QNodes}, Leafs: {statistics.QLeafs}, " + $"Branching factor: {statistics.QBranchingFactor:F}, Beta cutoffs: {statistics.QBetaCutoffs}"); // Total _interactiveConsole.WriteLine($" Total: Nodes: {statistics.TotalNodes} ({((float)statistics.TotalNodesPerSecond / 1000000):F} MN/s), " + $"Leafs: {statistics.TotalLeafs}, Branching factor: {statistics.TotalBranchingFactor:F}, " + $"Beta cutoffs: {statistics.TotalBetaCutoffs}"); #if DEBUG // Beta cutoffs at first move _interactiveConsole.WriteLine($" Beta cutoffs at first move: {statistics.BetaCutoffsAtFirstMove} ({statistics.BetaCutoffsAtFirstMovePercent:F} %), " + $"Q Beta cutoffs at first move: {statistics.QBetaCutoffsAtFirstMove} ({statistics.QBetaCutoffsAtFirstMovePercent:F} %)"); // Transposition statistics _interactiveConsole.WriteLine($" TT: " + $"Added: {statistics.TTAddedEntries}, " + $"Replacements: {statistics.TTReplacements} ({statistics.TTReplacesPercent:F} %), " + $"Hits: {statistics.TTHits} ({statistics.TTHitsPercent:F} %), " + $"Missed: {statistics.TTNonHits}, " + $"Filled: {TranspositionTable.GetFillLevel():F} %"); // Pawn hash table statistics _interactiveConsole.WriteLine($" PHT: " + $"Added: {statistics.EvaluationStatistics.PHTAddedEntries}, " + $"Replacements: {statistics.EvaluationStatistics.PHTReplacements} ({statistics.EvaluationStatistics.PHTReplacesPercent:F} %), " + $"Hits: {statistics.EvaluationStatistics.PHTHits} ({statistics.EvaluationStatistics.PHTHitsPercent:F} %), " + $"Missed: {statistics.EvaluationStatistics.PHTNonHits}, " + $"Filled: {PawnHashTable.GetFillLevel():F} %"); // Evaluation hash table statistics _interactiveConsole.WriteLine($" EHT: " + $"Added: {statistics.EvaluationStatistics.EHTAddedEntries}, " + $"Replacements: {statistics.EvaluationStatistics.EHTReplacements} ({statistics.EvaluationStatistics.EHTReplacesPercent:F} %), " + $"Hits: {statistics.EvaluationStatistics.EHTHits} ({statistics.EvaluationStatistics.EHTHitsPercent:F} %), " + $"Missed: {statistics.EvaluationStatistics.EHTNonHits}, " + $"Filled: {EvaluationHashTable.GetFillLevel():F} %"); _interactiveConsole.WriteLine($" Valid TT moves: {statistics.TTValidMoves}, Invalid TT moves: {statistics.TTInvalidMoves}, " + $"IID hits: {statistics.IIDHits}, Loud generations: {statistics.LoudMovesGenerated}, " + $"Quiet generations: {statistics.QuietMovesGenerated}"); #endif _interactiveConsole.WriteLine(); }
public void Run(params string[] parameters) { TranspositionTable.Clear(); PawnHashTable.Clear(); EvaluationHashTable.Clear(); KillerHeuristic.Clear(); HistoryHeuristic.Clear(); _uciClient.BoardState.SetDefaultState(); }
private void Test(BoardState boardState, string name, int depth) { _interactiveConsole.WriteLine($" == {name}:"); TranspositionTable.Clear(); PawnHashTable.Clear(); EvaluationHashTable.Clear(); KillerHeuristic.Clear(); HistoryHeuristic.Clear(); var context = new SearchContext(boardState) { MaxDepth = depth }; IterativeDeepening.OnSearchUpdate += IterativeDeepening_OnSearchUpdate; IterativeDeepening.FindBestMove(context); IterativeDeepening.OnSearchUpdate -= IterativeDeepening_OnSearchUpdate; _interactiveConsole.WriteLine(); }
public static int Evaluate(BoardState board, EvaluationStatistics statistics, int openingPhase, int endingPhase) { var entry = PawnHashTable.Get(board.PawnHash); if (entry.IsKeyValid(board.PawnHash)) { #if DEBUG statistics.PHTHits++; #endif return(TaperedEvaluation.AdjustToPhase(entry.OpeningScore, entry.EndingScore, openingPhase, endingPhase)); } #if DEBUG else { statistics.PHTNonHits++; if (entry.Key != 0 || entry.OpeningScore != 0 || entry.EndingScore != 0) { statistics.PHTReplacements++; } } #endif var(openingWhiteScore, endingWhiteScore) = Evaluate(board, Color.White, openingPhase, endingPhase); var(openingBlackScore, endingBlackScore) = Evaluate(board, Color.Black, openingPhase, endingPhase); var openingScore = openingWhiteScore - openingBlackScore; var endingScore = endingWhiteScore - endingBlackScore; var result = TaperedEvaluation.AdjustToPhase(openingScore, endingScore, openingPhase, endingPhase); PawnHashTable.Add(board.PawnHash, (short)openingScore, (short)endingScore); #if DEBUG statistics.PHTAddedEntries++; #endif return(result); }