From 311fc28c1c2438c9b6508343837ec546bf366a41 Mon Sep 17 00:00:00 2001 From: rektdie Date: Wed, 6 Aug 2025 01:54:04 +0200 Subject: [PATCH] removed ReadEntry function | bench 10412097 --- source/search.cpp | 27 +++++++++++++++++---------- source/tt.cpp | 19 ------------------- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index 3f768c9..8dfeb9b 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -359,16 +359,22 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC if (ply && (IsDraw(board, ctx))) return 0; - TTEntry entry = TTEntry(invalidEntry); + TTEntry* entry = nullptr; if (!ctx->excluded) - entry = ctx->TT.ReadEntry(board.hashKey, depth, alpha, beta); + entry = ctx->TT.GetRawEntry(board.hashKey); - const bool ttHit = entry.score != invalidEntry; + const bool ttHit = entry != nullptr && entry->score != invalidEntry; - // if NOT PV node then we try to hit the TTable if constexpr (!isPV) { - if (ttHit) - return SearchResults(entry.score, entry.bestMove); + if (ttHit) { + if ((entry->hashKey == board.hashKey && entry->depth >= depth) && + ((entry->nodeType == PV) || + (entry->nodeType == AllNode && entry->score <= alpha) || + (entry->nodeType == CutNode && entry->score >= beta))) { + + return SearchResults(entry->score, entry->bestMove); + } + } } if (depth <= 0) return Quiescence(board, alpha, beta, ply, ctx); @@ -480,12 +486,13 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC if (ply && depth >= 8 - && currMove == entry.bestMove + && ttHit + && currMove == entry->bestMove && ctx->excluded == 0 - && entry.depth >= depth - 3 - && entry.nodeType != AllNode) + && entry->depth >= depth - 3 + && entry->nodeType != AllNode) { - const int sBeta = std::max(-inf + 1, entry.score - depth * 2); + const int sBeta = std::max(-inf + 1, entry->score - depth * 2); const int sDepth = (depth - 1) / 2; ctx->excluded = currMove; diff --git a/source/tt.cpp b/source/tt.cpp index 72c4e79..f139e0c 100644 --- a/source/tt.cpp +++ b/source/tt.cpp @@ -1,24 +1,5 @@ #include "tt.h" -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; - } else if (current->nodeType == AllNode && current->score <= alpha) { - return *current; - } else if (current->nodeType == CutNode && current->score >= beta) { - return *current; - } - } - } - - // returning invalid value - return invalidEntry; -} - void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move bestMove) { TTEntry *current = &table[hashKey % table.size()];