From 2fd3cf0d2a05889d0b9073ab10553f05144dd80a Mon Sep 17 00:00:00 2001 From: rektdie Date: Mon, 22 Dec 2025 01:50:48 +0100 Subject: [PATCH 1/5] tt adjusted rfp | bench 4065988 --- source/search.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index d8762c5..95ac6d0 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -443,6 +443,16 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC const int staticEval = AdjustEval(board, ctx, rawEval); ctx->ss[ply].eval = staticEval; + int ttAdjustedEval = staticEval; + + if (!ctx->excluded && !board.InCheck() && entry.bestMove && + ((entry.nodeType == PV) || + (entry.nodeType == AllNode && entry.score <= staticEval) || + (entry.nodeType == CutNode && entry.score >= staticEval))) { + + ttAdjustedEval = entry.score; + } + bool corrplexity = std::abs(rawEval - staticEval) > 70; const bool improving = [&] @@ -461,8 +471,8 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC if (ply) { // Reverse Futility Pruning int margin = rfpBase + rfpMargin * (depth - improving); - if (!ttHit && staticEval - margin >= beta && depth < 7) { - return (beta + (staticEval - beta) / 3); + if (!ttHit && ttAdjustedEval - margin >= beta && depth < 7) { + return (beta + (ttAdjustedEval - beta) / 3); } // Razoring -- 2.47.3 From 1f0b36764dac8aec3eec877e21720bc457bb28ee Mon Sep 17 00:00:00 2001 From: rektdie Date: Sat, 14 Feb 2026 20:34:21 +0100 Subject: [PATCH 2/5] returning staticeval | bench 1795203 --- source/search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/search.cpp b/source/search.cpp index 95ac6d0..f02ac60 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -472,7 +472,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC // Reverse Futility Pruning int margin = rfpBase + rfpMargin * (depth - improving); if (!ttHit && ttAdjustedEval - margin >= beta && depth < 7) { - return (beta + (ttAdjustedEval - beta) / 3); + return (beta + (staticEval - beta) / 3); } // Razoring -- 2.47.3 From 7cf8b381cee7341860374ce5f70645532e04da5e Mon Sep 17 00:00:00 2001 From: rektdie Date: Sat, 14 Feb 2026 20:38:16 +0100 Subject: [PATCH 3/5] removed no tthit condition | bench 1997703 --- source/search.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index f02ac60..31df2e8 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -471,8 +471,8 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC if (ply) { // Reverse Futility Pruning int margin = rfpBase + rfpMargin * (depth - improving); - if (!ttHit && ttAdjustedEval - margin >= beta && depth < 7) { - return (beta + (staticEval - beta) / 3); + if (ttAdjustedEval - margin >= beta && depth < 7) { + return (beta + (ttAdjustedEval - beta) / 3); } // Razoring -- 2.47.3 From f114a6d0bbf89fed131657650d097a8b2d515299 Mon Sep 17 00:00:00 2001 From: rektdie Date: Sat, 14 Feb 2026 21:15:33 +0100 Subject: [PATCH 4/5] tthit condition | bench 1774202 --- source/search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/search.cpp b/source/search.cpp index 31df2e8..17b97d5 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -445,7 +445,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC int ttAdjustedEval = staticEval; - if (!ctx->excluded && !board.InCheck() && entry.bestMove && + if (!ctx->excluded && !board.InCheck() && ttHit && ((entry.nodeType == PV) || (entry.nodeType == AllNode && entry.score <= staticEval) || (entry.nodeType == CutNode && entry.score >= staticEval))) { -- 2.47.3 From 41dabc215082fa7ac2438e075a23ada703f58ac0 Mon Sep 17 00:00:00 2001 From: rektdie Date: Sat, 14 Feb 2026 23:27:51 +0100 Subject: [PATCH 5/5] tt buckets | bench 1783856 --- source/search.cpp | 6 +++--- source/tt.cpp | 15 ++++++++++++++- source/tt.h | 30 ++++++++++++++++++++---------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index d8762c5..ae6d650 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -47,7 +47,7 @@ static int AdjustEval(Board &board, SearchContext* ctx, int eval) { } static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) { - TTEntry current = ctx->TT.GetRawEntry(board.hashKey); + TTEntry current = ctx->TT.GetEntry(board.hashKey); if (current.hashKey == board.hashKey && current.bestMove == move) { return 100000; } @@ -322,7 +322,7 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear TTEntry entry; if (!ctx->excluded) { - entry = ctx->TT.GetRawEntry(board.hashKey); + entry = ctx->TT.GetEntry(board.hashKey); if (entry.hashKey == board.hashKey) { bestScore = entry.score; } @@ -420,7 +420,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC TTEntry entry; if (!ctx->excluded) - entry = ctx->TT.GetRawEntry(board.hashKey); + entry = ctx->TT.GetEntry(board.hashKey); const bool ttHit = entry.hashKey == board.hashKey; const bool ttpv = isPV | entry.ttpv; diff --git a/source/tt.cpp b/source/tt.cpp index 0febbb8..0468905 100644 --- a/source/tt.cpp +++ b/source/tt.cpp @@ -1,7 +1,20 @@ #include "tt.h" void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move bestMove, bool ttpv) { - TTEntry *current = &table[hashKey % table.size()]; + TTBucket *bucket = &table[hashKey % table.size()]; + TTEntry *current = nullptr; + + if (bucket->depthPreferred && bucket->depthPreferred.hashKey == hashKey) { + current = &bucket->depthPreferred; + } else if (bucket->alwaysReplace && bucket->alwaysReplace.hashKey == hashKey) { + current = &bucket->alwaysReplace; + } else if (ttpv) { + current = &bucket->depthPreferred; + } else if (!bucket->depthPreferred || bucket->depthPreferred.depth <= depth) { + current = &bucket->depthPreferred; + } else { + current = &bucket->alwaysReplace; + } current->hashKey = hashKey; current->nodeType = nodeType; diff --git a/source/tt.h b/source/tt.h index 811e30a..83a227b 100644 --- a/source/tt.h +++ b/source/tt.h @@ -39,16 +39,22 @@ public: } }; +class TTBucket { +public: + TTEntry depthPreferred; + TTEntry alwaysReplace; +}; + // 1024 MB -constexpr U64 maxHash = (1024 * 1000000) / sizeof(TTEntry); +constexpr U64 maxHash = (1024 * 1000000) / sizeof(TTBucket); // 8 MB -constexpr U64 defaultHash = (8 * 1000000) / sizeof(TTEntry); +constexpr U64 defaultHash = (8 * 1000000) / sizeof(TTBucket); constexpr int16_t invalidEntry = 11111; class TTable { private: - std::vector table; + std::vector table; public: TTable() : table(defaultHash) {}; @@ -66,9 +72,15 @@ public: __builtin_prefetch(&table[hashKey % table.size()]); } - TTEntry GetRawEntry(U64 &hashKey) { - TTEntry *current = &table[hashKey % table.size()]; - return *current; + TTEntry GetEntry(U64 &hashKey) { + TTBucket *current = &table[hashKey % table.size()]; + if (current->depthPreferred.hashKey == hashKey) { + return current->depthPreferred; + } else if (current->alwaysReplace.hashKey == hashKey) { + return current->alwaysReplace; + } + + return TTEntry(); } // returns used space per mill @@ -76,13 +88,11 @@ public: int count = 0; for (int i = 0; i < 1000; i++) { - if (table[i]) count++; + if (table[i].depthPreferred || table[i].alwaysReplace) count++; } return count; } - TTEntry ReadEntry(U64 &hashKey, int depth, int alpha, int beta); - - void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove, bool ttpv); + void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move bestMove, bool ttpv); }; -- 2.47.3