From c33b8288b6af509595211c647ee875c0f6734e84 Mon Sep 17 00:00:00 2001 From: rektdie Date: Sun, 1 Jun 2025 04:41:46 +0200 Subject: [PATCH] fixed asp windows | bench 3975258 --- source/benchmark.cpp | 1 - source/search.cpp | 54 ++++++++++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/source/benchmark.cpp b/source/benchmark.cpp index 2ff4618..9b581c5 100644 --- a/source/benchmark.cpp +++ b/source/benchmark.cpp @@ -63,7 +63,6 @@ constexpr std::array fenPositions = { void RunBenchmark() { Board board; int depth = BENCH_DEPTH; - int ply = 0; SearchContext ctx; diff --git a/source/search.cpp b/source/search.cpp index d6cca0d..cfb164d 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -507,6 +507,30 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC return results; } +class AspirationWindow { +public: + int delta = 50; + + int alpha = -inf; + int beta = inf; + + void WidenDown() { + alpha -= delta; + delta *= 2; + } + + void WidenUp() { + beta += delta; + delta *= 2; + } + + void Set(int score) { + delta = 50; + alpha = score - delta; + beta = score + delta; + } +}; + // Iterative deepening template static SearchResults ID(Board &board, SearchParams params, SearchContext& ctx) { @@ -522,12 +546,7 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext& ctx) { toDepth = BENCH_DEPTH; } - int alpha = -inf; - int beta = inf; - - int delta = 50; - - int ply = 0; + AspirationWindow aw; int elapsed = 0; @@ -537,26 +556,21 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext& ctx) { ctx.timeToSearch = std::max((fullTime / 20) + (inc / 2), 4); int softTime = ctx.timeToSearch * 0.65; - SearchResults currentResults = PVS(board, depth, alpha, beta, ply, ctx, false); + SearchResults currentResults = PVS(board, depth, aw.alpha, aw.beta, 0, ctx, false); elapsed = ctx.sw.GetElapsedMS(); - // If we fell outside the window, try again with full width - if ((currentResults.score <= alpha) - || (currentResults.score >= beta)) { - delta *= 2; - - alpha -= delta; - beta += delta; - + if (aw.alpha != -inf && currentResults.score <= aw.alpha) { + aw.WidenDown(); + depth--; + continue; + } + if (aw.beta != inf && currentResults.score >= aw.beta) { + aw.WidenUp(); depth--; - - if (ctx.searchStopped) break; continue; } - alpha = currentResults.score - delta; - beta = currentResults.score + delta; - delta = 50; + aw.Set(currentResults.score); if (ctx.searchStopped) { break;