introduced TTable class
This commit is contained in:
1 parent
9622a28db5
commit
e9f5a15d6b
6 files changed
+41
-16
No files matched your search
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
void RunBenchmark();
|
||||
+4
-4
@@ -25,7 +25,7 @@ static int ScoreMove(Board &board, Move &move) {
|
||||
|
||||
if (attackerType == nullPieceType || targetType == nullPieceType) return 0;
|
||||
|
||||
TTEntry *current = &TTable[board.hashKey % hashSize];
|
||||
TTEntry *current = TT.GetRawEntry(board.hashKey);
|
||||
if (current->bestMove == move) {
|
||||
return 50000;
|
||||
}
|
||||
@@ -151,7 +151,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) {
|
||||
|
||||
// if NOT PV node then we try to hit the TTable
|
||||
if (beta - alpha == 1) {
|
||||
SearchResults entry = ReadEntry(board.hashKey, depth, alpha, beta);
|
||||
SearchResults entry = TT.ReadEntry(board.hashKey, depth, alpha, beta);
|
||||
if (entry.score != invalidEntry) {
|
||||
return entry;
|
||||
}
|
||||
@@ -236,7 +236,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) {
|
||||
killerMoves[1][ply] = killerMoves[0][ply];
|
||||
killerMoves[0][ply] = board.moveList[i];
|
||||
|
||||
WriteEntry(board.hashKey, depth, score, CutNode, Move());
|
||||
TT.WriteEntry(board.hashKey, depth, score, CutNode, Move());
|
||||
return score;
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) {
|
||||
}
|
||||
}
|
||||
|
||||
WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove);
|
||||
TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove);
|
||||
if (searchStopped) return 0;
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ constexpr int maxDepth = 64;
|
||||
extern U64 nodes;
|
||||
extern bool benchStarted;
|
||||
|
||||
constexpr int invalidEntry = 111111;
|
||||
constexpr int inf = 100000;
|
||||
|
||||
class SearchResults {
|
||||
|
||||
+4
-4
@@ -77,8 +77,8 @@ U64 GetHashKey(Board &board) {
|
||||
return key;
|
||||
}
|
||||
|
||||
SearchResults ReadEntry(U64 &hashKey, int depth, int alpha, int beta) {
|
||||
TTEntry *current = &TTable[hashKey % hashSize];
|
||||
SearchResults TTable::ReadEntry(U64 &hashKey, int depth, int alpha, int beta) {
|
||||
TTEntry *current = &table[hashKey % hashSize];
|
||||
|
||||
if (current->hashKey == hashKey) {
|
||||
if (current->depth >= depth) {
|
||||
@@ -96,8 +96,8 @@ SearchResults ReadEntry(U64 &hashKey, int depth, int alpha, int beta) {
|
||||
return invalidEntry;
|
||||
}
|
||||
|
||||
void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move bestMove) {
|
||||
TTEntry *current = &TTable[hashKey % hashSize];
|
||||
void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move bestMove) {
|
||||
TTEntry *current = &table[hashKey % hashSize];
|
||||
|
||||
current->hashKey = hashKey;
|
||||
current->nodeType = nodeType;
|
||||
|
||||
+30
-5
@@ -18,7 +18,7 @@ void InitZobrist();
|
||||
U64 GetHashKey(Board &board);
|
||||
|
||||
class TTEntry {
|
||||
public:
|
||||
public:
|
||||
U64 hashKey;
|
||||
int depth;
|
||||
int score;
|
||||
@@ -27,8 +27,33 @@ public:
|
||||
};
|
||||
|
||||
// 5 MB
|
||||
inline int hashSize = 5000000 / sizeof(TTEntry);
|
||||
inline std::vector<TTEntry> TTable(hashSize);
|
||||
inline int hashSize = (5 * 1000000) / sizeof(TTEntry);
|
||||
constexpr int invalidEntry = 111111;
|
||||
|
||||
SearchResults ReadEntry(U64 &hashKey, int depth, int alpha, int beta);
|
||||
void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove);
|
||||
class TTable {
|
||||
private:
|
||||
std::vector<TTEntry> table;
|
||||
public:
|
||||
TTable() {
|
||||
table.reserve(hashSize);
|
||||
}
|
||||
|
||||
void Resize(int size) {
|
||||
table.resize(size);
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
table.clear();
|
||||
}
|
||||
|
||||
TTEntry* GetRawEntry(U64 &hashKey) {
|
||||
TTEntry *current = &table[hashKey % hashSize];
|
||||
return current;
|
||||
}
|
||||
|
||||
SearchResults ReadEntry(U64 &hashKey, int depth, int alpha, int beta);
|
||||
|
||||
void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove);
|
||||
};
|
||||
|
||||
inline TTable TT;
|
||||
+2
-2
@@ -160,7 +160,7 @@ void ParseGo(Board &board, std::string &command) {
|
||||
static void SetOption(std::string &command) {
|
||||
if (command.find("Hash") != std::string::npos) {
|
||||
hashSize = (ReadParam("value", command) * 1000000) / sizeof(TTEntry);
|
||||
TTable.resize(hashSize);
|
||||
TT.Resize(hashSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ void UCILoop(Board &board) {
|
||||
// parse UCI "ucinewgame" command
|
||||
if (input.find("ucinewgame") != std::string::npos) {
|
||||
board.SetByFen(StartingFen);
|
||||
TTable.clear();
|
||||
TT.Clear();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user