From 271ec4dc2a6de8c422210374fb79c5dba412dd1b Mon Sep 17 00:00:00 2001 From: rektdie Date: Sun, 14 Sep 2025 01:06:26 +0200 Subject: [PATCH 1/3] added node tm scaling | bench 6813804 --- source/search.cpp | 21 ++++++++++++++++++++- source/search.h | 2 ++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/source/search.cpp b/source/search.cpp index 6023378..0ba25ea 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -552,6 +552,8 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC int newDepth = depth + copy.InCheck() - 1 + extension; + U64 nodesBeforeSearch = ctx->nodes; + // First move (suspected PV node) if (!moveSeen) { // Full search @@ -580,6 +582,11 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC moveSeen++; + // Root + if (!ply) { + ctx->nodesTable[currMove & 4095] += ctx->nodes - nodesBeforeSearch; + } + if (ctx->searchStopped) return 0; if (currMove != 0 && currMove.IsQuiet()) { @@ -702,6 +709,14 @@ public: } }; +static double ScaleTime(SearchContext *ctx, Move &move) { + double notBmNodesFraction = + ctx->nodesTable[move & 4095] / ctx->nodes; + double nodeScalingFactor = (1.5f - notBmNodesFraction) * 1.35f; + + return nodeScalingFactor; +} + // Iterative deepening template static SearchResults ID(Board &board, SearchParams params, SearchContext* ctx) { @@ -722,14 +737,17 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext* ctx) { int elapsed = 0; + double nodeScaling = 1; + ctx->sw.Restart(); for (int depth = 1; depth <= toDepth; depth++) { ctx->timeToSearch = std::max((fullTime / movesToGo) + (inc / 2), 4); - int softTime = ctx->timeToSearch * 0.65; + int softTime = ctx->timeToSearch * 0.65 * nodeScaling; ctx->seldepth = 0; SearchResults currentResults = PVS(board, depth, aw.alpha, aw.beta, 0, ctx, false); + nodeScaling = ScaleTime(ctx, currentResults.bestMove); elapsed = ctx->sw.GetElapsedMS(); if (aw.alpha != -inf && currentResults.score <= aw.alpha) { @@ -786,6 +804,7 @@ template SearchResults SearchPosition(Board &board, SearchParams params, SearchContext* ctx) { ctx->searchStopped = false; ctx->seldepth = 0; + ctx->nodesTable = {}; if constexpr (mode != bench) { ctx->nodes = 0; diff --git a/source/search.h b/source/search.h index b4d4380..58ae35b 100644 --- a/source/search.h +++ b/source/search.h @@ -168,6 +168,8 @@ public: U64 nodesToGo = 0; int timeToSearch = 0; + std::array nodesTable{}; + int seldepth = 0; Move excluded = Move(); From c108bfa786b29b71d321b930f41078df0f019726 Mon Sep 17 00:00:00 2001 From: rektdie Date: Sun, 14 Sep 2025 01:29:35 +0200 Subject: [PATCH 2/3] bugfix in division | bench 6813804 --- source/search.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index 0ba25ea..87dbf54 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -584,7 +584,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC // Root if (!ply) { - ctx->nodesTable[currMove & 4095] += ctx->nodes - nodesBeforeSearch; + ctx->nodesTable[currMove % 4096] += ctx->nodes - nodesBeforeSearch; } if (ctx->searchStopped) return 0; @@ -711,7 +711,7 @@ public: static double ScaleTime(SearchContext *ctx, Move &move) { double notBmNodesFraction = - ctx->nodesTable[move & 4095] / ctx->nodes; + ctx->nodesTable[move % 4096] / double(ctx->nodes); double nodeScalingFactor = (1.5f - notBmNodesFraction) * 1.35f; return nodeScalingFactor; From 861a3542155b659fae9920ecc47b04bb121953dd Mon Sep 17 00:00:00 2001 From: rektdie Date: Sun, 14 Sep 2025 12:03:30 +0200 Subject: [PATCH 3/3] depth condition for node tm | bench 6813804 --- source/search.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/search.cpp b/source/search.cpp index 87dbf54..43aaf1f 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -747,9 +747,13 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext* ctx) { ctx->seldepth = 0; SearchResults currentResults = PVS(board, depth, aw.alpha, aw.beta, 0, ctx, false); - nodeScaling = ScaleTime(ctx, currentResults.bestMove); + elapsed = ctx->sw.GetElapsedMS(); + if (depth > 6) { + nodeScaling = ScaleTime(ctx, currentResults.bestMove); + } + if (aw.alpha != -inf && currentResults.score <= aw.alpha) { aw.WidenDown(); depth--;