minor rework in tt | bench 3415609
This commit is contained in:
1 parent
dec219e4d7
commit
4564d10bcf
3 files changed
+17
-10
No files matched your search
+5
-4
@@ -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);
|
||||||
|
|||||||
+4
-4
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-2
@@ -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);
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user