Revert "encapsulated TT"

This reverts commit 8ca878275a.
This commit is contained in:
rektdie committed 2025-04-12 00:52:52 +02:00
1 parent 0242eec87d
commit 43dc63cdf3
6 files changed
+26 -28

No files matched your search

+6
View File
@@ -4,6 +4,7 @@
#include "benchmark.h" #include "benchmark.h"
#include "search.h" #include "search.h"
#include "stopwatch.h" #include "stopwatch.h"
#include "tt.h"
using namespace SEARCH; using namespace SEARCH;
@@ -65,8 +66,12 @@ void RunBenchmark() {
int depth = BENCH_DEPTH; int depth = BENCH_DEPTH;
int ply = 0; int ply = 0;
// Clearing
TT.Clear();
SearchContext ctx; SearchContext ctx;
Stopwatch sw; Stopwatch sw;
for (int i = 0; i < fenPositions.size(); i++) { for (int i = 0; i < fenPositions.size(); i++) {
board.SetByFen(fenPositions[i]); board.SetByFen(fenPositions[i]);
@@ -74,4 +79,5 @@ void RunBenchmark() {
} }
std::cout << ctx.nodes << " nodes " << int(ctx.nodes/sw.GetElapsedSec()) << " nps" << std::endl; std::cout << ctx.nodes << " nodes " << int(ctx.nodes/sw.GetElapsedSec()) << " nps" << std::endl;
TT.Clear();
} }
+1
View File
@@ -1,5 +1,6 @@
#include "board.h" #include "board.h"
#include "movegen.h" #include "movegen.h"
#include "tt.h"
#include <iostream> #include <iostream>
#include <ranges> #include <ranges>
#include <string_view> #include <string_view>
+6 -19
View File
@@ -9,19 +9,6 @@
namespace SEARCH { namespace SEARCH {
SearchContext::SearchContext() {
pvLine.Clear();
history.Clear();
TT = new TTable();
sw.Restart();
killerMoves = {};
positionHistory = {};
}
SearchContext::~SearchContext() {
delete TT;
}
void InitLMRTable() { void InitLMRTable() {
for (int depth = 0; depth <= MAX_DEPTH; depth++) { for (int depth = 0; depth <= MAX_DEPTH; depth++) {
for (int move = 0; move < MAX_MOVES; move++) { for (int move = 0; move < MAX_MOVES; move++) {
@@ -38,7 +25,7 @@ void InitLMRTable() {
} }
static int ScoreMove(Board &board, Move &move, int ply, SearchContext& ctx) { static int ScoreMove(Board &board, Move &move, int ply, SearchContext& ctx) {
TTEntry *current = ctx.TT->GetRawEntry(board.hashKey); TTEntry *current = TT.GetRawEntry(board.hashKey);
if (current->bestMove == move) { if (current->bestMove == move) {
return 50000; return 50000;
} }
@@ -161,7 +148,7 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear
int bestScore = HCE::Evaluate(board); int bestScore = HCE::Evaluate(board);
TTEntry *entry = ctx.TT->GetRawEntry(board.hashKey); TTEntry *entry = TT.GetRawEntry(board.hashKey);
if (entry->hashKey == board.hashKey) { if (entry->hashKey == board.hashKey) {
bestScore = entry->score; bestScore = entry->score;
} }
@@ -235,7 +222,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 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); SearchResults entry = TT.ReadEntry(board.hashKey, depth, alpha, beta);
if (entry.score != invalidEntry) { if (entry.score != invalidEntry) {
return entry; return entry;
} }
@@ -353,7 +340,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
} }
} }
ctx.TT->WriteEntry(board.hashKey, depth, score, CutNode, Move()); TT.WriteEntry(board.hashKey, depth, score, CutNode, Move());
return score; return score;
} }
@@ -376,7 +363,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
} }
if (ctx.searchStopped) return 0; if (ctx.searchStopped) return 0;
ctx.TT->WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove); TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove);
return results; return results;
} }
@@ -444,7 +431,7 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext& ctx) {
std::cout << " time " << elapsed; std::cout << " time " << elapsed;
std::cout << " score cp " << UTILS::ConvertToWhiteRelative(board, safeResults.score); std::cout << " score cp " << UTILS::ConvertToWhiteRelative(board, safeResults.score);
std::cout << " nodes " << ctx.nodes << " nps " << int(ctx.nodes/ctx.sw.GetElapsedSec()); std::cout << " nodes " << ctx.nodes << " nps " << int(ctx.nodes/ctx.sw.GetElapsedSec());
std::cout << " hashfull " << ctx.TT->GetUsedPercentage(); std::cout << " hashfull " << TT.GetUsedPercentage();
std::cout << " pv "; std::cout << " pv ";
ctx.pvLine.Print(0); ctx.pvLine.Print(0);
std::cout << std::endl; std::cout << std::endl;
+7 -5
View File
@@ -6,8 +6,6 @@
#include <algorithm> #include <algorithm>
#include "stopwatch.h" #include "stopwatch.h"
class TTable;
namespace SEARCH { namespace SEARCH {
enum searchMode { enum searchMode {
@@ -113,15 +111,19 @@ public:
PVLine pvLine; PVLine pvLine;
History history; History history;
TTable* TT;
std::array<std::array<int, MAX_PLY>, 2> killerMoves{}; std::array<std::array<int, MAX_PLY>, 2> killerMoves{};
std::array<U64, 1000> positionHistory; std::array<U64, 1000> positionHistory;
Stopwatch sw; Stopwatch sw;
SearchContext(); SearchContext(){
~SearchContext(); pvLine.Clear();
history.Clear();
sw.Restart();
killerMoves = {};
positionHistory = {};
}
}; };
template <bool isPV, searchMode mode> template <bool isPV, searchMode mode>
+2
View File
@@ -60,3 +60,5 @@ public:
void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove); void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove);
}; };
inline TTable TT;
+4 -4
View File
@@ -92,10 +92,10 @@ static void ParseGo(Board &board, std::string &command, SEARCH::SearchContext& c
} }
} }
static void SetOption(std::string &command, SEARCH::SearchContext& ctx) { static void SetOption(std::string &command) {
if (command.find("Hash") != std::string::npos) { if (command.find("Hash") != std::string::npos) {
hashSize = (ReadParam("value", command) * 1000000) / sizeof(TTEntry); hashSize = (ReadParam("value", command) * 1000000) / sizeof(TTEntry);
ctx.TT->Resize(hashSize); TT.Resize(hashSize);
} }
} }
@@ -134,7 +134,7 @@ void UCILoop(Board &board) {
board.SetByFen(StartingFen); board.SetByFen(StartingFen);
// Clearing // Clearing
ctx.TT->Clear(); TT.Clear();
ctx.killerMoves = {}; ctx.killerMoves = {};
ctx.history.Clear(); ctx.history.Clear();
@@ -169,7 +169,7 @@ void UCILoop(Board &board) {
} }
if (input.find("setoption") != std::string::npos) { if (input.find("setoption") != std::string::npos) {
SetOption(input, ctx); SetOption(input);
continue; continue;
} }