minor rework in tt | bench 3415609 #75

Merged
rektdie merged 1 commits from SE into main 2025-06-06 09:58:43 +02:00
3 changed files with 18 additions and 11 deletions

No files matched your search

+5 -4
View File
@@ -316,12 +316,13 @@ 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 = 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 NOT PV node then we try to hit the TTable
if constexpr (!isPV) { if constexpr (!isPV) {
SearchResults entry = ctx->TT.ReadEntry(board.hashKey, depth, alpha, beta); if (ttHit)
if (entry.score != invalidEntry) { return SearchResults(entry.score, entry.bestMove);
return entry;
}
} }
if (depth <= 0) return Quiescence<mode>(board, alpha, beta, ply, ctx); if (depth <= 0) return Quiescence<mode>(board, alpha, beta, ply, ctx);
+5 -5
View File
@@ -1,16 +1,16 @@
#include "tt.h" #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()]; TTEntry *current = &table[hashKey % table.size()];
if (current->hashKey == hashKey) { if (current->hashKey == hashKey) {
if (current->depth >= depth) { if (current->depth >= depth) {
if (current->nodeType == PV){ if (current->nodeType == PV){
return {current->score, current->bestMove}; return *current;
} else if (current->nodeType == AllNode && current->score <= alpha) { } else if (current->nodeType == AllNode && current->score <= alpha) {
return current->score; return *current;
} else if (current->nodeType == CutNode && current->score >= beta) { } 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->score = score;
current->depth = depth; current->depth = depth;
current->bestMove = bestMove; current->bestMove = bestMove;
} }
+8 -2
View File
@@ -27,6 +27,12 @@ public:
uint8_t depth = 0; uint8_t depth = 0;
uint8_t nodeType = 0; uint8_t nodeType = 0;
TTEntry() {}
TTEntry(int16_t score) {
this->score = score;
}
operator U64() { operator U64() {
return hashKey; return hashKey;
} }
@@ -37,7 +43,7 @@ constexpr U64 maxHash = (1024 * 1000000) / sizeof(TTEntry);
// 5 MB // 5 MB
constexpr U64 defaultHash = (8 * 1000000) / sizeof(TTEntry); constexpr U64 defaultHash = (8 * 1000000) / sizeof(TTEntry);
constexpr int invalidEntry = 111111; constexpr int16_t invalidEntry = 111111;
class TTable { class TTable {
private: private:
@@ -71,7 +77,7 @@ public:
return count; 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); void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove);
}; };