Tt read fix #89

Merged
rektdie merged 2 commits from tt-read-fix into main 2025-08-22 14:31:24 +02:00
2 changed files with 18 additions and 19 deletions
Showing only changes of commit ec46fddfe5 - Show all commits

No files matched your search

+16 -17
View File
@@ -43,8 +43,8 @@ int16_t ContHistory::GetTwoPly(Board& board, Move& move, SearchContext* ctx, int
} }
static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) { static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) {
TTEntry *current = ctx->TT.GetRawEntry(board.hashKey); TTEntry current = ctx->TT.GetRawEntry(board.hashKey);
if (current->hashKey == board.hashKey && current->bestMove == move) { if (current.hashKey == board.hashKey && current.bestMove == move) {
return 100000; return 100000;
} }
@@ -271,9 +271,9 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear
ctx->ss[ply].eval = bestScore; ctx->ss[ply].eval = bestScore;
if (!ctx->excluded) { if (!ctx->excluded) {
TTEntry *entry = ctx->TT.GetRawEntry(board.hashKey); TTEntry entry = ctx->TT.GetRawEntry(board.hashKey);
if (entry->hashKey == board.hashKey) { if (entry.hashKey == board.hashKey) {
bestScore = entry->score; bestScore = entry.score;
} }
} }
@@ -359,21 +359,20 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
if (ply && (IsDraw(board, ctx))) return 0; if (ply && (IsDraw(board, ctx))) return 0;
TTEntry* entry = nullptr; TTEntry entry;
if (!ctx->excluded) if (!ctx->excluded)
entry = ctx->TT.GetRawEntry(board.hashKey); entry = ctx->TT.GetRawEntry(board.hashKey);
const bool ttHit = entry != nullptr const bool ttHit = entry.hashKey == board.hashKey;
&& entry->hashKey == board.hashKey;
if constexpr (!isPV) { if constexpr (!isPV) {
if (ttHit) { if (ttHit) {
if (entry->depth >= depth && if (entry.depth >= depth &&
((entry->nodeType == PV) || ((entry.nodeType == PV) ||
(entry->nodeType == AllNode && entry->score <= alpha) || (entry.nodeType == AllNode && entry.score <= alpha) ||
(entry->nodeType == CutNode && entry->score >= beta))) { (entry.nodeType == CutNode && entry.score >= beta))) {
return SearchResults(entry->score, entry->bestMove); return SearchResults(entry.score, entry.bestMove);
} }
} }
} }
@@ -488,12 +487,12 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
if (ply if (ply
&& depth >= 8 && depth >= 8
&& ttHit && ttHit
&& currMove == entry->bestMove && currMove == entry.bestMove
&& ctx->excluded == 0 && ctx->excluded == 0
&& entry->depth >= depth - 3 && entry.depth >= depth - 3
&& entry->nodeType != AllNode) && 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; const int sDepth = (depth - 1) / 2;
ctx->excluded = currMove; ctx->excluded = currMove;
+2 -2
View File
@@ -61,9 +61,9 @@ public:
table.resize(size); table.resize(size);
} }
TTEntry* GetRawEntry(U64 &hashKey) { TTEntry GetRawEntry(U64 &hashKey) {
TTEntry *current = &table[hashKey % table.size()]; TTEntry *current = &table[hashKey % table.size()];
return current; return *current;
} }
// returns used space per mill // returns used space per mill