Ttpv lmr #135

Merged
rektdie merged 2 commits from ttpv-lmr into main 2026-01-08 08:30:35 +01:00
4 changed files with 25 additions and 15 deletions
Showing only changes of commit 6ed9e882f8 - Show all commits

No files matched your search

+20 -13
View File
@@ -154,7 +154,7 @@ bool IsDraw(Board &board, SearchContext* ctx) {
} }
template <bool isPV> template <bool isPV>
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; int reduction = 0;
// Late Move Reduction // Late Move Reduction
@@ -173,6 +173,9 @@ static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int
if (corrplexity) if (corrplexity)
reduction -= lmrCorrplexity; reduction -= lmrCorrplexity;
if (ttpv)
reduction -= lmrTTPV;
// History LMR // History LMR
int historyReduction = 0; int historyReduction = 0;
@@ -304,7 +307,7 @@ static bool ShouldStop(SearchContext* ctx) {
return false; return false;
} }
template <searchMode mode> template <bool isPV, searchMode mode>
static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, SearchContext* ctx) { static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, SearchContext* ctx) {
if (ShouldStop<mode>(ctx)) return 0; if (ShouldStop<mode>(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)); int bestScore = AdjustEval(board, ctx, NNUE::net.Evaluate(board));
ctx->ss[ply].eval = bestScore; ctx->ss[ply].eval = bestScore;
TTEntry entry;
if (!ctx->excluded) { if (!ctx->excluded) {
TTEntry entry = ctx->TT.GetRawEntry(board.hashKey); entry = ctx->TT.GetRawEntry(board.hashKey);
if (entry.hashKey == board.hashKey) { if (entry.hashKey == board.hashKey) {
bestScore = entry.score; bestScore = entry.score;
} }
} }
const bool ttpv = isPV | entry.ttpv;
if (bestScore >= beta) { if (bestScore >= beta) {
return bestScore; return bestScore;
@@ -371,11 +377,11 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear
ctx->TT.PrefetchEntry(copy.hashKey); ctx->TT.PrefetchEntry(copy.hashKey);
int score = -Quiescence<mode>(copy, -beta, -alpha, ply + 1, ctx).score; int score = -Quiescence<isPV, mode>(copy, -beta, -alpha, ply + 1, ctx).score;
if (score >= beta) { if (score >= beta) {
if (!ctx->excluded) { 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; return score;
} }
@@ -392,7 +398,7 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear
results.score = bestScore; results.score = bestScore;
if (ctx->searchStopped) return 0; if (ctx->searchStopped) return 0;
if (!ctx->excluded) { 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; 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); entry = ctx->TT.GetRawEntry(board.hashKey);
const bool ttHit = entry.hashKey == board.hashKey; const bool ttHit = entry.hashKey == board.hashKey;
const bool ttpv = isPV | entry.ttpv;
if constexpr (!isPV) { if constexpr (!isPV) {
if (ttHit) { if (ttHit) {
@@ -430,7 +437,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
} }
} }
if (depth <= 0) return Quiescence<mode>(board, alpha, beta, ply, ctx); if (depth <= 0) return Quiescence<isPV, mode>(board, alpha, beta, ply, ctx);
int rawEval = NNUE::net.Evaluate(board); int rawEval = NNUE::net.Evaluate(board);
const int staticEval = AdjustEval(board, ctx, rawEval); 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 // Razoring
if (!isPV && depth <= 3 && staticEval + razoringScalar * depth < alpha) { if (!isPV && depth <= 3 && staticEval + razoringScalar * depth < alpha) {
return Quiescence<mode>(board, alpha, beta, ply, ctx).score; return Quiescence<isPV, mode>(board, alpha, beta, ply, ctx).score;
} }
// Null Move Pruning // 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->positionHistory[copy.positionIndex] = copy.hashKey;
ctx->nodes++; ctx->nodes++;
int score = -Quiescence<mode>(copy, -probcutBeta, -probcutBeta + 1, ply + 1, ctx).score; int score = -Quiescence<isPV, mode>(copy, -probcutBeta, -probcutBeta + 1, ply + 1, ctx).score;
if (score >= probcutBeta) { if (score >= probcutBeta) {
score = -PVS<isPV, mode>(copy, probcutDepth - 1, -probcutBeta, -probcutBeta + 1, score = -PVS<isPV, mode>(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 (ctx->searchStopped) return 0;
if (score >= probcutBeta) { if (score >= probcutBeta) {
ctx->TT.WriteEntry(board.hashKey, probcutDepth, score, CutNode, currMove); ctx->TT.WriteEntry(board.hashKey, probcutDepth, score, CutNode, currMove, ttpv);
return score; 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)) if (ply && depth <= 10 && !SEE(board, currMove, SEEThreshold))
continue; continue;
int reductions = GetReductions<isPV>(board, currMove, depth, moveSeen, ply, cutnode, improving, corrplexity, ctx); int reductions = GetReductions<isPV>(board, currMove, depth, moveSeen, ply, cutnode, improving, corrplexity, ttpv, ctx);
int newDepth = depth + (copy.InCheck() && !ctx->excluded) - 1 + extension; 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) if (!ctx->excluded)
ctx->TT.WriteEntry(board.hashKey, depth, score, CutNode, currMove); ctx->TT.WriteEntry(board.hashKey, depth, score, CutNode, currMove, ttpv);
return score; 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->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; return results;
} }
+2 -1
View File
@@ -1,6 +1,6 @@
#include "tt.h" #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()]; TTEntry *current = &table[hashKey % table.size()];
current->hashKey = hashKey; current->hashKey = hashKey;
@@ -8,4 +8,5 @@ void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move b
current->score = score; current->score = score;
current->depth = depth; current->depth = depth;
current->bestMove = bestMove; current->bestMove = bestMove;
current->ttpv = ttpv;
} }
+2 -1
View File
@@ -26,6 +26,7 @@ public:
Move bestMove = Move(); Move bestMove = Move();
uint8_t depth = 0; uint8_t depth = 0;
uint8_t nodeType = 0; uint8_t nodeType = 0;
bool ttpv = false;
TTEntry() {} TTEntry() {}
@@ -83,5 +84,5 @@ public:
TTEntry ReadEntry(U64 &hashKey, int depth, int alpha, int beta); 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);
}; };
+1
View File
@@ -12,6 +12,7 @@
X_DOUBLE(lmrDivisorNoisy, 3.20, 1.5, 3.5) \ X_DOUBLE(lmrDivisorNoisy, 3.20, 1.5, 3.5) \
X_INT(lmrCutnode, 2048, 1024, 3072) \ X_INT(lmrCutnode, 2048, 1024, 3072) \
X_INT(lmrIsPV, 1024, 512, 2048) \ X_INT(lmrIsPV, 1024, 512, 2048) \
X_INT(lmrTTPV, 2048, 512, 2048) \
X_INT(lmrHistoryDivisor, 8192, 6000, 10000) \ X_INT(lmrHistoryDivisor, 8192, 6000, 10000) \
X_INT(lmrImproving, 1024, 6000, 10000) \ X_INT(lmrImproving, 1024, 6000, 10000) \
X_INT(lmrCorrplexity, 1024, 6000, 10000) \ X_INT(lmrCorrplexity, 1024, 6000, 10000) \