From 4564d10bcffcd7ad53c203803a3440474d8c31b1 Mon Sep 17 00:00:00 2001 From: rektdie Date: Fri, 6 Jun 2025 09:58:24 +0200 Subject: [PATCH] minor rework in tt | bench 3415609 --- source/search.cpp | 9 +++++---- source/tt.cpp | 10 +++++----- source/tt.h | 10 ++++++++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index f2bbff6..b08413a 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -316,12 +316,13 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC if (ply && (IsDraw(board, ctx))) return 0; + TTEntry entry = ctx->TT.ReadEntry(board.hashKey, depth, alpha, beta); + const bool ttHit = entry.score != invalidEntry; + // if NOT PV node then we try to hit the TTable if constexpr (!isPV) { - SearchResults entry = ctx->TT.ReadEntry(board.hashKey, depth, alpha, beta); - if (entry.score != invalidEntry) { - return entry; - } + if (ttHit) + return SearchResults(entry.score, entry.bestMove); } if (depth <= 0) return Quiescence(board, alpha, beta, ply, ctx); diff --git a/source/tt.cpp b/source/tt.cpp index 6f6b638..72c4e79 100644 --- a/source/tt.cpp +++ b/source/tt.cpp @@ -1,16 +1,16 @@ #include "tt.h" -SearchResults TTable::ReadEntry(U64 &hashKey, int depth, int alpha, int beta) { +TTEntry TTable::ReadEntry(U64 &hashKey, int depth, int alpha, int beta) { TTEntry *current = &table[hashKey % table.size()]; if (current->hashKey == hashKey) { if (current->depth >= depth) { if (current->nodeType == PV){ - return {current->score, current->bestMove}; + return *current; } else if (current->nodeType == AllNode && current->score <= alpha) { - return current->score; + return *current; } else if (current->nodeType == CutNode && current->score >= beta) { - return current->score; + return *current; } } } @@ -27,4 +27,4 @@ void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move b current->score = score; current->depth = depth; current->bestMove = bestMove; -} \ No newline at end of file +} diff --git a/source/tt.h b/source/tt.h index ef47185..6372e2c 100644 --- a/source/tt.h +++ b/source/tt.h @@ -27,6 +27,12 @@ public: uint8_t depth = 0; uint8_t nodeType = 0; + TTEntry() {} + + TTEntry(int16_t score) { + this->score = score; + } + operator U64() { return hashKey; } @@ -37,7 +43,7 @@ constexpr U64 maxHash = (1024 * 1000000) / sizeof(TTEntry); // 5 MB constexpr U64 defaultHash = (8 * 1000000) / sizeof(TTEntry); -constexpr int invalidEntry = 111111; +constexpr int16_t invalidEntry = 111111; class TTable { private: @@ -71,7 +77,7 @@ public: return count; } - SearchResults 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); };