diff --git a/source/search.cpp b/source/search.cpp index 7d35158..d8762c5 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -154,7 +154,7 @@ bool IsDraw(Board &board, SearchContext* ctx) { } template -static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int ply, bool cutnode, bool improving, bool corrplexity, SearchContext* ctx) { +static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int ply, bool cutnode, bool improving, bool corrplexity, bool ttpv, SearchContext* ctx) { int reduction = 0; // Late Move Reduction @@ -173,6 +173,9 @@ static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int if (corrplexity) reduction -= lmrCorrplexity; + if (ttpv) + reduction -= lmrTTPV; + // History LMR int historyReduction = 0; @@ -304,7 +307,7 @@ static bool ShouldStop(SearchContext* ctx) { return false; } -template +template static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, SearchContext* ctx) { if (ShouldStop(ctx)) return 0; @@ -317,13 +320,16 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear int bestScore = AdjustEval(board, ctx, NNUE::net.Evaluate(board)); ctx->ss[ply].eval = bestScore; + TTEntry entry; if (!ctx->excluded) { - TTEntry entry = ctx->TT.GetRawEntry(board.hashKey); + entry = ctx->TT.GetRawEntry(board.hashKey); if (entry.hashKey == board.hashKey) { bestScore = entry.score; } } + const bool ttpv = isPV | entry.ttpv; + if (bestScore >= beta) { return bestScore; @@ -371,11 +377,11 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear ctx->TT.PrefetchEntry(copy.hashKey); - int score = -Quiescence(copy, -beta, -alpha, ply + 1, ctx).score; + int score = -Quiescence(copy, -beta, -alpha, ply + 1, ctx).score; if (score >= beta) { if (!ctx->excluded) { - ctx->TT.WriteEntry(board.hashKey, 0, score, CutNode, board.moveList[i]); + ctx->TT.WriteEntry(board.hashKey, 0, score, CutNode, board.moveList[i], ttpv); } return score; } @@ -392,7 +398,7 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear results.score = bestScore; if (ctx->searchStopped) return 0; if (!ctx->excluded) { - ctx->TT.WriteEntry(board.hashKey, 0, results.score, nodeType, results.bestMove); + ctx->TT.WriteEntry(board.hashKey, 0, results.score, nodeType, results.bestMove, ttpv); } return results; } @@ -417,6 +423,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC entry = ctx->TT.GetRawEntry(board.hashKey); const bool ttHit = entry.hashKey == board.hashKey; + const bool ttpv = isPV | entry.ttpv; if constexpr (!isPV) { if (ttHit) { @@ -430,7 +437,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC } } - if (depth <= 0) return Quiescence(board, alpha, beta, ply, ctx); + if (depth <= 0) return Quiescence(board, alpha, beta, ply, ctx); int rawEval = NNUE::net.Evaluate(board); const int staticEval = AdjustEval(board, ctx, rawEval); @@ -460,7 +467,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC // Razoring if (!isPV && depth <= 3 && staticEval + razoringScalar * depth < alpha) { - return Quiescence(board, alpha, beta, ply, ctx).score; + return Quiescence(board, alpha, beta, ply, ctx).score; } // Null Move Pruning @@ -517,7 +524,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC ctx->positionHistory[copy.positionIndex] = copy.hashKey; ctx->nodes++; - int score = -Quiescence(copy, -probcutBeta, -probcutBeta + 1, ply + 1, ctx).score; + int score = -Quiescence(copy, -probcutBeta, -probcutBeta + 1, ply + 1, ctx).score; if (score >= probcutBeta) { score = -PVS(copy, probcutDepth - 1, -probcutBeta, -probcutBeta + 1, @@ -527,7 +534,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC if (ctx->searchStopped) return 0; if (score >= probcutBeta) { - ctx->TT.WriteEntry(board.hashKey, probcutDepth, score, CutNode, currMove); + ctx->TT.WriteEntry(board.hashKey, probcutDepth, score, CutNode, currMove, ttpv); return score; } @@ -658,7 +665,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC if (ply && depth <= 10 && !SEE(board, currMove, SEEThreshold)) continue; - int reductions = GetReductions(board, currMove, depth, moveSeen, ply, cutnode, improving, corrplexity, ctx); + int reductions = GetReductions(board, currMove, depth, moveSeen, ply, cutnode, improving, corrplexity, ttpv, ctx); int newDepth = depth + (copy.InCheck() && !ctx->excluded) - 1 + extension; @@ -789,7 +796,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC } if (!ctx->excluded) - ctx->TT.WriteEntry(board.hashKey, depth, score, CutNode, currMove); + ctx->TT.WriteEntry(board.hashKey, depth, score, CutNode, currMove, ttpv); return score; } @@ -822,7 +829,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC ctx->corrhist.UpdateAll(board, depth, corrHistBonus); } - ctx->TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove); + ctx->TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove, ttpv); } return results; } diff --git a/source/tt.cpp b/source/tt.cpp index f139e0c..0febbb8 100644 --- a/source/tt.cpp +++ b/source/tt.cpp @@ -1,6 +1,6 @@ #include "tt.h" -void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move bestMove) { +void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move bestMove, bool ttpv) { TTEntry *current = &table[hashKey % table.size()]; current->hashKey = hashKey; @@ -8,4 +8,5 @@ void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move b current->score = score; current->depth = depth; current->bestMove = bestMove; + current->ttpv = ttpv; } diff --git a/source/tt.h b/source/tt.h index e07e74f..811e30a 100644 --- a/source/tt.h +++ b/source/tt.h @@ -26,6 +26,7 @@ public: Move bestMove = Move(); uint8_t depth = 0; uint8_t nodeType = 0; + bool ttpv = false; TTEntry() {} @@ -83,5 +84,5 @@ public: TTEntry ReadEntry(U64 &hashKey, int depth, int alpha, int beta); - void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove); + void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove, bool ttpv); }; diff --git a/source/tunables.h b/source/tunables.h index 4af6b4d..ec9fee4 100644 --- a/source/tunables.h +++ b/source/tunables.h @@ -12,6 +12,7 @@ X_DOUBLE(lmrDivisorNoisy, 3.20, 1.5, 3.5) \ X_INT(lmrCutnode, 2048, 1024, 3072) \ X_INT(lmrIsPV, 1024, 512, 2048) \ + X_INT(lmrTTPV, 1024, 512, 2048) \ X_INT(lmrHistoryDivisor, 8192, 6000, 10000) \ X_INT(lmrImproving, 1024, 6000, 10000) \ X_INT(lmrCorrplexity, 1024, 6000, 10000) \