From 7543a0d23120e97e90355d2e42c022404f7e474d Mon Sep 17 00:00:00 2001 From: rektdie Date: Fri, 11 Apr 2025 03:12:41 +0200 Subject: [PATCH] encapsulated timeToSearch --- source/search.cpp | 10 ++++------ source/search.h | 1 + 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index 590fd3c..3239318 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -9,8 +9,6 @@ namespace SEARCH { -static inline int timeToSearch = 0; - void InitLMRTable() { for (int depth = 0; depth <= MAX_DEPTH; depth++) { for (int move = 0; move < MAX_MOVES; move++) { @@ -135,7 +133,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply, Searc if constexpr (mode != nodesMode) { if constexpr (mode != bench) { if (ctx.nodes % 1024 == 0) { - if (ctx.sw.GetElapsedMS() >= timeToSearch) { + if (ctx.sw.GetElapsedMS() >= ctx.timeToSearch) { StopSearch(); return 0; } @@ -200,7 +198,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo if constexpr (mode != bench || mode != nodesMode) { if (ctx.nodes % 1024 == 0) { if constexpr (mode == normal) { - if (ctx.sw.GetElapsedMS() >= timeToSearch) { + if (ctx.sw.GetElapsedMS() >= ctx.timeToSearch) { StopSearch(); return 0; } @@ -396,8 +394,8 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext& ctx) { ctx.sw.Restart(); for (int depth = 1; depth <= toDepth; depth++) { - timeToSearch = std::max((fullTime / 20) + (inc / 2), 4); - int softTime = timeToSearch * 0.65; + ctx.timeToSearch = std::max((fullTime / 20) + (inc / 2), 4); + int softTime = ctx.timeToSearch * 0.65; SearchResults currentResults = PVS(board, depth, alpha, beta, ply, ctx); elapsed = ctx.sw.GetElapsedMS(); diff --git a/source/search.h b/source/search.h index dbc2ba2..98d4c47 100644 --- a/source/search.h +++ b/source/search.h @@ -109,6 +109,7 @@ class SearchContext { public: U64 nodes = 0; U64 nodesToGo = 0; + int timeToSearch = 0; bool doingNullMove = false;