Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50ceac43a7 | ||
|
|
56b00e290d |
No files matched your search
+3
-4
@@ -300,7 +300,7 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear
|
|||||||
bool ttHit = false;
|
bool ttHit = false;
|
||||||
entry = ctx->TT->GetEntry(board.hashKey);
|
entry = ctx->TT->GetEntry(board.hashKey);
|
||||||
|
|
||||||
if (entry.hashKey == board.hashKey) {
|
if (entry.hashKey == PackHashKey(board.hashKey) && entry.depth > 0) {
|
||||||
ttHit = true;
|
ttHit = true;
|
||||||
|
|
||||||
switch (entry.nodeType) {
|
switch (entry.nodeType) {
|
||||||
@@ -423,13 +423,12 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
|||||||
if (!ctx->excluded)
|
if (!ctx->excluded)
|
||||||
entry = ctx->TT->GetEntry(board.hashKey);
|
entry = ctx->TT->GetEntry(board.hashKey);
|
||||||
|
|
||||||
const bool ttHit = entry.hashKey == board.hashKey;
|
const bool ttHit = entry.hashKey == PackHashKey(board.hashKey) && entry.depth >= depth;
|
||||||
const bool ttpv = isPV | entry.ttpv;
|
const bool ttpv = isPV | entry.ttpv;
|
||||||
|
|
||||||
if constexpr (!isPV) {
|
if constexpr (!isPV) {
|
||||||
if (ttHit) {
|
if (ttHit) {
|
||||||
if (entry.depth >= depth &&
|
if (((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))) {
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -4,11 +4,12 @@ TTable SharedTT;
|
|||||||
|
|
||||||
void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move bestMove, bool ttpv) {
|
void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move bestMove, bool ttpv) {
|
||||||
TTBucket *bucket = &table[hashKey % table.size()];
|
TTBucket *bucket = &table[hashKey % table.size()];
|
||||||
|
const uint16_t packedKey = PackHashKey(hashKey);
|
||||||
TTEntry *current = nullptr;
|
TTEntry *current = nullptr;
|
||||||
|
|
||||||
if (bucket->depthPreferred && bucket->depthPreferred.hashKey == hashKey) {
|
if (bucket->depthPreferred && bucket->depthPreferred.hashKey == packedKey) {
|
||||||
current = &bucket->depthPreferred;
|
current = &bucket->depthPreferred;
|
||||||
} else if (bucket->alwaysReplace && bucket->alwaysReplace.hashKey == hashKey) {
|
} else if (bucket->alwaysReplace && bucket->alwaysReplace.hashKey == packedKey) {
|
||||||
current = &bucket->alwaysReplace;
|
current = &bucket->alwaysReplace;
|
||||||
} else if (!bucket->alwaysReplace) {
|
} else if (!bucket->alwaysReplace) {
|
||||||
current = &bucket->alwaysReplace;
|
current = &bucket->alwaysReplace;
|
||||||
@@ -27,7 +28,7 @@ void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move b
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool samePosition = current->hashKey == hashKey;
|
const bool samePosition = current->hashKey == packedKey;
|
||||||
const bool exactBound = nodeType == PV;
|
const bool exactBound = nodeType == PV;
|
||||||
const bool entryFromCurrentAge = current->age == age;
|
const bool entryFromCurrentAge = current->age == age;
|
||||||
const int writeDepth = depth + 4 + ttpv * 2;
|
const int writeDepth = depth + 4 + ttpv * 2;
|
||||||
@@ -36,7 +37,7 @@ void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move b
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
current->hashKey = hashKey;
|
current->hashKey = packedKey;
|
||||||
current->nodeType = nodeType;
|
current->nodeType = nodeType;
|
||||||
current->score = score;
|
current->score = score;
|
||||||
current->depth = depth;
|
current->depth = depth;
|
||||||
|
|||||||
+14
-3
@@ -19,9 +19,16 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr U64 hashKeyMask = 0xFFFF;
|
||||||
|
|
||||||
|
// only the lowest bits of the hashkey are stored, the rest is only used for indexing
|
||||||
|
inline uint16_t PackHashKey(U64 &hashKey) {
|
||||||
|
return uint16_t(hashKey & hashKeyMask);
|
||||||
|
}
|
||||||
|
|
||||||
class TTEntry {
|
class TTEntry {
|
||||||
public:
|
public:
|
||||||
U64 hashKey = 0;
|
uint16_t hashKey = 0;
|
||||||
int16_t score = 0;
|
int16_t score = 0;
|
||||||
Move bestMove = Move();
|
Move bestMove = Move();
|
||||||
uint8_t depth = 0;
|
uint8_t depth = 0;
|
||||||
@@ -46,6 +53,8 @@ public:
|
|||||||
TTEntry alwaysReplace;
|
TTEntry alwaysReplace;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(TTEntry) == 10);
|
||||||
|
|
||||||
// 1024 MB
|
// 1024 MB
|
||||||
constexpr U64 maxHash = (1024 * 1000000) / sizeof(TTBucket);
|
constexpr U64 maxHash = (1024 * 1000000) / sizeof(TTBucket);
|
||||||
// 8 MB
|
// 8 MB
|
||||||
@@ -84,9 +93,11 @@ public:
|
|||||||
|
|
||||||
TTEntry GetEntry(U64 &hashKey) {
|
TTEntry GetEntry(U64 &hashKey) {
|
||||||
TTBucket *current = &table[hashKey % table.size()];
|
TTBucket *current = &table[hashKey % table.size()];
|
||||||
if (current->depthPreferred.hashKey == hashKey) {
|
const uint16_t packedKey = PackHashKey(hashKey);
|
||||||
|
|
||||||
|
if (current->depthPreferred.hashKey == packedKey) {
|
||||||
return current->depthPreferred;
|
return current->depthPreferred;
|
||||||
} else if (current->alwaysReplace.hashKey == hashKey) {
|
} else if (current->alwaysReplace.hashKey == packedKey) {
|
||||||
return current->alwaysReplace;
|
return current->alwaysReplace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user