From 960b32e6bda18e51e1bec2681c7d732492100f99 Mon Sep 17 00:00:00 2001 From: rektdie Date: Thu, 27 Mar 2025 19:53:49 +0100 Subject: [PATCH 1/4] checking for time only every 1024 nodes | bench 684523 --- source/search.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index b542487..8324a48 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -117,7 +117,7 @@ static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int } static SearchResults Quiescence(Board board, int alpha, int beta, int ply) { - if (!benchStarted) { + if (!benchStarted && nodes % 1024 == 0) { if (sw.GetElapsedMS() >= timeToSearch) { StopSearch(); return 0; @@ -166,7 +166,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply) { template SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) { - if (!benchStarted) { + if (!benchStarted && nodes % 1024 == 0) { if (sw.GetElapsedMS() >= timeToSearch) { StopSearch(); return 0; -- 2.47.3 From 789503ceb2ced68e61b86a3be2e7800c27bac6dc Mon Sep 17 00:00:00 2001 From: rektdie Date: Thu, 27 Mar 2025 20:27:50 +0100 Subject: [PATCH 2/4] handling negative time input | bench 684523 --- source/uci.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/source/uci.cpp b/source/uci.cpp index bd80bd6..d1ae052 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -40,18 +40,29 @@ static void ParsePosition(Board &board, std::string_view command) { } static int ReadParam(std::string param, std::string &command) { - size_t pos = -1; - pos = command.find(param); - + size_t pos = command.find(param); if (pos != std::string::npos) { - std::string result = ""; pos += param.length() + 1; + bool isNegative = false; + std::string result = ""; - while(pos < command.length() && std::isdigit(command[pos])){ + // Check for negative sign + if (pos < command.length() && command[pos] == '-') { + isNegative = true; + pos++; + } + + // Extract digits + while (pos < command.length() && std::isdigit(command[pos])) { result += command[pos]; pos++; } - return stoi(result); + + // Ensure result is not empty before calling stoi + if (!result.empty()) { + int value = std::stoi(result); + return isNegative ? -value : value; + } } return 0; -- 2.47.3 From f7a055ae5275a10a28b649aeeefdf4f9e9d39e46 Mon Sep 17 00:00:00 2001 From: rektdie Date: Thu, 27 Mar 2025 20:39:24 +0100 Subject: [PATCH 3/4] small change | bench 684523 --- source/search.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/search.cpp b/source/search.cpp index 8324a48..d8a8e24 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -269,12 +269,13 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) { score = -PVS(copy, depth - 1, -beta, -alpha, ply + 1).score; } + if (searchStopped) return 0; + moveSeen++; positionIndex--; // Fail high (beta cutoff) if (score >= beta) { - if (searchStopped) return 0; if (!currMove.IsCapture()) { killerMoves[1][ply] = killerMoves[0][ply]; killerMoves[0][ply] = currMove; -- 2.47.3 From d46d5953a7458a1159ba2cb283feb89c8101f241 Mon Sep 17 00:00:00 2001 From: rektdie Date: Thu, 27 Mar 2025 21:46:00 +0100 Subject: [PATCH 4/4] minimum search time is 4ms | bench 684523 --- source/search.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index d8a8e24..9b9fafb 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -313,8 +313,6 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) { // Iterative deepening static SearchResults ID(Board &board, SearchParams params) { - sw.Restart(); - int fullTime = board.sideToMove ? params.btime : params.wtime; int inc = board.sideToMove ? params.binc : params.winc; @@ -328,11 +326,15 @@ static SearchResults ID(Board &board, SearchParams params) { int ply = 0; + int elapsed = 0; + sw.Restart(); + for (int depth = 1; depth <= 99; depth++) { - timeToSearch = (fullTime / 20) + (inc / 2); + timeToSearch = std::max((fullTime / 20) + (inc / 2), 4); int softTime = timeToSearch * 0.65; SearchResults currentResults = PVS(board, depth, alpha, beta, ply); + elapsed = sw.GetElapsedMS(); // If we fell outside the window, try again with full width if ((currentResults.score <= alpha) @@ -361,6 +363,7 @@ static SearchResults ID(Board &board, SearchParams params) { std::cout << "info "; std::cout << "depth " << depth; + std::cout << " time " << elapsed; std::cout << " score cp " << safeResults.score; std::cout << " nodes " << nodes << " nps " << int(nodes/sw.GetElapsedSec()); std::cout << " hashfull " << TT.GetUsedPercentage(); -- 2.47.3