Datagen #46

Merged
rektdie merged 27 commits from datagen into main 2025-04-03 03:54:14 +02:00
4 changed files with 43 additions and 16 deletions
Showing only changes of commit a6459dda00 - Show all commits

No files matched your search

+32 -13
View File
@@ -11,6 +11,7 @@
namespace SEARCH { namespace SEARCH {
U64 nodes = 0; U64 nodes = 0;
U64 nodesToGo = 0;
bool benchStarted = false; bool benchStarted = false;
static inline int timeToSearch = 0; static inline int timeToSearch = 0;
@@ -139,9 +140,17 @@ static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int
return reduction; return reduction;
} }
template <searchMode mode>
static SearchResults Quiescence(Board board, int alpha, int beta, int ply) { static SearchResults Quiescence(Board board, int alpha, int beta, int ply) {
if (!benchStarted && nodes % 1024 == 0) { if constexpr (mode != nodesMode) {
if (sw.GetElapsedMS() >= timeToSearch) { if (!benchStarted && nodes % 1024 == 0) {
if (sw.GetElapsedMS() >= timeToSearch) {
StopSearch();
return 0;
}
}
} else {
if (nodes >= nodesToGo) {
StopSearch(); StopSearch();
return 0; return 0;
} }
@@ -173,7 +182,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply) {
Board copy = board; Board copy = board;
int isLegal = copy.MakeMove(board.moveList[i]); int isLegal = copy.MakeMove(board.moveList[i]);
if (!isLegal) continue; if (!isLegal) continue;
int score = -Quiescence(copy, -beta, -alpha, ply + 1).score; int score = -Quiescence<mode>(copy, -beta, -alpha, ply + 1).score;
positionIndex--; positionIndex--;
if (score >= beta) { if (score >= beta) {
@@ -195,20 +204,25 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply) {
template <bool isPV, searchMode mode> template <bool isPV, searchMode mode>
SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) { SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
if constexpr (mode != bench) { if constexpr (mode != bench || mode != nodesMode) {
if (nodes % 1024 == 0) { if (nodes % 1024 == 0) {
if constexpr (mode == normal) { if constexpr (mode == normal) {
if (sw.GetElapsedMS() >= timeToSearch) { if (sw.GetElapsedMS() >= timeToSearch) {
StopSearch(); StopSearch();
return 0; return 0;
} }
} else { } else if constexpr (mode == datagen) {
if (nodes >= DATAGEN::HARD_NODES) { if (nodes >= DATAGEN::HARD_NODES) {
StopSearch(); StopSearch();
return 0; return 0;
} }
} }
} }
} else if constexpr (mode == nodesMode) {
if (nodes >= nodesToGo) {
StopSearch();
return 0;
}
} }
pvLine.SetLength(ply); pvLine.SetLength(ply);
@@ -223,7 +237,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
} }
} }
if (depth <= 0) return Quiescence(board, alpha, beta, ply); if (depth <= 0) return Quiescence<mode>(board, alpha, beta, ply);
const int staticEval = HCE::Evaluate(board); const int staticEval = HCE::Evaluate(board);
@@ -385,9 +399,7 @@ static SearchResults ID(Board &board, SearchParams params) {
int elapsed = 0; int elapsed = 0;
if constexpr (mode == normal) { sw.Restart();
sw.Restart();
}
for (int depth = 1; depth <= toDepth; depth++) { for (int depth = 1; depth <= toDepth; depth++) {
timeToSearch = std::max((fullTime / 20) + (inc / 2), 4); timeToSearch = std::max((fullTime / 20) + (inc / 2), 4);
@@ -421,7 +433,7 @@ static SearchResults ID(Board &board, SearchParams params) {
safeResults = currentResults; safeResults = currentResults;
} }
if constexpr (mode == normal) { if constexpr (mode == normal || mode == nodesMode) {
std::cout << "info "; std::cout << "info ";
std::cout << "depth " << depth; std::cout << "depth " << depth;
std::cout << " time " << elapsed; std::cout << " time " << elapsed;
@@ -432,9 +444,11 @@ static SearchResults ID(Board &board, SearchParams params) {
pvLine.Print(0); pvLine.Print(0);
std::cout << std::endl; std::cout << std::endl;
if (sw.GetElapsedMS() >= softTime) { if constexpr (mode == normal) {
StopSearch(); if (sw.GetElapsedMS() >= softTime) {
break; StopSearch();
break;
}
} }
} else if constexpr (mode == datagen) { } else if constexpr (mode == datagen) {
if (nodes >= DATAGEN::SOFT_NODES) { if (nodes >= DATAGEN::SOFT_NODES) {
@@ -453,6 +467,10 @@ SearchResults SearchPosition(Board &board, SearchParams params) {
searchStopped = false; searchStopped = false;
if constexpr (mode != bench) { if constexpr (mode != bench) {
nodes = 0; nodes = 0;
if constexpr (mode == nodesMode) {
nodesToGo = params.nodes;
}
} }
pvLine.Clear(); pvLine.Clear();
@@ -481,5 +499,6 @@ template SearchResults PVS<false, searchMode::datagen>(Board, int, int, int, int
template SearchResults SearchPosition<normal>(Board &board, SearchParams params); template SearchResults SearchPosition<normal>(Board &board, SearchParams params);
template SearchResults SearchPosition<bench>(Board &board, SearchParams params); template SearchResults SearchPosition<bench>(Board &board, SearchParams params);
template SearchResults SearchPosition<datagen>(Board &board, SearchParams params); template SearchResults SearchPosition<datagen>(Board &board, SearchParams params);
template SearchResults SearchPosition<nodesMode>(Board &board, SearchParams params);
} }
+2 -1
View File
@@ -10,7 +10,8 @@ namespace SEARCH {
enum searchMode { enum searchMode {
normal, normal,
bench, bench,
datagen datagen,
nodesMode
}; };
constexpr int MATE_SCORE = -99000; constexpr int MATE_SCORE = -99000;
+8 -2
View File
@@ -76,14 +76,20 @@ static void ParseGo(Board &board, std::string &command) {
params.winc = ReadParam("winc", command); params.winc = ReadParam("winc", command);
params.binc = ReadParam("binc", command); params.binc = ReadParam("binc", command);
params.movesToGo = ReadParam("movestogo", command); params.movesToGo = ReadParam("movestogo", command);
params.nodes = ReadParam("nodes", command);
if (command.find("movetime") != std::string::npos) { if (command.find("movetime") != std::string::npos) {
params.wtime = ReadParam("movetime", command); params.wtime = ReadParam("movetime", command);
params.btime = ReadParam("movetime", command); params.btime = ReadParam("movetime", command);
} }
auto worker = std::thread(SEARCH::SearchPosition<SEARCH::normal>, std::ref(board), params); if (params.nodes) {
worker.detach(); auto worker = std::thread(SEARCH::SearchPosition<SEARCH::nodesMode>, std::ref(board), params);
worker.detach();
} else {
auto worker = std::thread(SEARCH::SearchPosition<SEARCH::normal>, std::ref(board), params);
worker.detach();
}
} }
static void SetOption(std::string &command) { static void SetOption(std::string &command) {
+1
View File
@@ -9,6 +9,7 @@ public:
int winc = 0; int winc = 0;
int binc = 0; int binc = 0;
int movesToGo = 0; int movesToGo = 0;
int nodes = 0;
SearchParams(){} SearchParams(){}
}; };