From 4da9654e536de595d27ec1078eb24f9a32064ffe Mon Sep 17 00:00:00 2001 From: rektdie Date: Thu, 6 Mar 2025 20:17:21 +0100 Subject: [PATCH] implemented aspiration windows --- source/search.cpp | 20 +++++++++++++++++++- source/search.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/source/search.cpp b/source/search.cpp index a1b47be..fb8d9b8 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -252,10 +252,28 @@ static SearchResults ID(Board &board, SearchParams params) { SearchResults safeResults; safeResults.score = -inf; + int alpha = -inf; + int beta = inf; + for (int depth = 1; depth <= 99; depth++) { timeToSearch = (fullTime / 20) + (inc / 2); - SearchResults currentResults = PVS(board, depth, -inf, inf); + SearchResults currentResults = PVS(board, depth, alpha, beta); + + // If we fell outside the window, try again with full width + if ((currentResults.score <= alpha) + || (currentResults.score >= beta)) { + alpha = -inf; + beta = inf; + depth--; + + if (searchStopped) break; + continue; + } + + alpha = currentResults.score - aspWinConst; + beta = currentResults.score + aspWinConst; + if (currentResults.bestMove) { safeResults = currentResults; } diff --git a/source/search.h b/source/search.h index 64f8d0e..defa8c3 100644 --- a/source/search.h +++ b/source/search.h @@ -8,6 +8,7 @@ extern bool benchStarted; constexpr int invalidEntry = 111111; constexpr int inf = 100000; +constexpr int aspWinConst = 50; class SearchResults { public: