encapsulated TT
This commit is contained in:
1 parent
e7079c3c73
commit
8ca878275a
6 files changed
+28
-26
No files matched your search
+19
-6
@@ -9,6 +9,19 @@
|
||||
|
||||
namespace SEARCH {
|
||||
|
||||
SearchContext::SearchContext() {
|
||||
pvLine.Clear();
|
||||
history.Clear();
|
||||
TT = new TTable();
|
||||
sw.Restart();
|
||||
killerMoves = {};
|
||||
positionHistory = {};
|
||||
}
|
||||
|
||||
SearchContext::~SearchContext() {
|
||||
delete TT;
|
||||
}
|
||||
|
||||
void InitLMRTable() {
|
||||
for (int depth = 0; depth <= MAX_DEPTH; depth++) {
|
||||
for (int move = 0; move < MAX_MOVES; move++) {
|
||||
@@ -25,7 +38,7 @@ void InitLMRTable() {
|
||||
}
|
||||
|
||||
static int ScoreMove(Board &board, Move &move, int ply, SearchContext& ctx) {
|
||||
TTEntry *current = TT.GetRawEntry(board.hashKey);
|
||||
TTEntry *current = ctx.TT->GetRawEntry(board.hashKey);
|
||||
if (current->bestMove == move) {
|
||||
return 50000;
|
||||
}
|
||||
@@ -148,7 +161,7 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear
|
||||
|
||||
int bestScore = HCE::Evaluate(board);
|
||||
|
||||
TTEntry *entry = TT.GetRawEntry(board.hashKey);
|
||||
TTEntry *entry = ctx.TT->GetRawEntry(board.hashKey);
|
||||
if (entry->hashKey == board.hashKey) {
|
||||
bestScore = entry->score;
|
||||
}
|
||||
@@ -222,7 +235,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
||||
|
||||
// if NOT PV node then we try to hit the TTable
|
||||
if constexpr (!isPV) {
|
||||
SearchResults entry = TT.ReadEntry(board.hashKey, depth, alpha, beta);
|
||||
SearchResults entry = ctx.TT->ReadEntry(board.hashKey, depth, alpha, beta);
|
||||
if (entry.score != invalidEntry) {
|
||||
return entry;
|
||||
}
|
||||
@@ -340,7 +353,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
||||
}
|
||||
}
|
||||
|
||||
TT.WriteEntry(board.hashKey, depth, score, CutNode, Move());
|
||||
ctx.TT->WriteEntry(board.hashKey, depth, score, CutNode, Move());
|
||||
return score;
|
||||
}
|
||||
|
||||
@@ -363,7 +376,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
||||
}
|
||||
|
||||
if (ctx.searchStopped) return 0;
|
||||
TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove);
|
||||
ctx.TT->WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove);
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -431,7 +444,7 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext& ctx) {
|
||||
std::cout << " time " << elapsed;
|
||||
std::cout << " score cp " << UTILS::ConvertToWhiteRelative(board, safeResults.score);
|
||||
std::cout << " nodes " << ctx.nodes << " nps " << int(ctx.nodes/ctx.sw.GetElapsedSec());
|
||||
std::cout << " hashfull " << TT.GetUsedPercentage();
|
||||
std::cout << " hashfull " << ctx.TT->GetUsedPercentage();
|
||||
std::cout << " pv ";
|
||||
ctx.pvLine.Print(0);
|
||||
std::cout << std::endl;
|
||||
|
||||
Reference in new issue
Block a user