diff --git a/source/benchmark.cpp b/source/benchmark.cpp index 9dcf0fa..72e702c 100644 --- a/source/benchmark.cpp +++ b/source/benchmark.cpp @@ -65,7 +65,6 @@ void RunBenchmark() { Board board; int depth = BENCH_DEPTH; int ply = 0; - searchStopped = false; positionIndex = 0; // Clearing diff --git a/source/search.cpp b/source/search.cpp index 3239318..f065a9e 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -134,14 +134,14 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply, Searc if constexpr (mode != bench) { if (ctx.nodes % 1024 == 0) { if (ctx.sw.GetElapsedMS() >= ctx.timeToSearch) { - StopSearch(); + ctx.searchStopped = true; return 0; } } } } else { if (ctx.nodes > ctx.nodesToGo) { - StopSearch(); + ctx.searchStopped = true; return 0; } } @@ -189,7 +189,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply, Searc } results.score = bestScore; - if (searchStopped) return 0; + if (ctx.searchStopped) return 0; return results; } @@ -199,19 +199,19 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo if (ctx.nodes % 1024 == 0) { if constexpr (mode == normal) { if (ctx.sw.GetElapsedMS() >= ctx.timeToSearch) { - StopSearch(); + ctx.searchStopped = true; return 0; } } else if constexpr (mode == datagen) { if (ctx.nodes >= DATAGEN::HARD_NODES) { - StopSearch(); + ctx.searchStopped = true; return 0; } } } } else if constexpr (mode == nodesMode) { if (ctx.nodes > ctx.nodesToGo) { - StopSearch(); + ctx.searchStopped = true; return 0; } } @@ -251,7 +251,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo int score = -PVS(copy, depth - 3, -beta, -beta + 1, ply + 1, ctx).score; ctx.doingNullMove = false; - if (searchStopped) return 0; + if (ctx.searchStopped) return 0; if (score >= beta) return score; } } @@ -318,7 +318,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo moveSeen++; positionIndex--; - if (searchStopped) return 0; + if (ctx.searchStopped) return 0; if (currMove.IsQuiet()) { seenQuiets[seenQuietsCount] = currMove; @@ -362,7 +362,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo } } - if (searchStopped) return 0; + if (ctx.searchStopped) return 0; TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove); return results; } @@ -410,7 +410,7 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext& ctx) { depth--; - if (searchStopped) break; + if (ctx.searchStopped) break; continue; } @@ -418,7 +418,7 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext& ctx) { beta = currentResults.score + delta; delta = 50; - if (searchStopped) { + if (ctx.searchStopped) { break; } else { if (currentResults.bestMove) { @@ -438,13 +438,13 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext& ctx) { if constexpr (mode == normal) { if (ctx.sw.GetElapsedMS() >= softTime) { - StopSearch(); + ctx.searchStopped = true; break; } } } else if constexpr (mode == datagen) { if (ctx.nodes >= DATAGEN::SOFT_NODES) { - StopSearch(); + ctx.searchStopped = true; break; } } @@ -456,7 +456,7 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext& ctx) { template SearchResults SearchPosition(Board &board, SearchParams params, SearchContext& ctx) { - searchStopped = false; + ctx.searchStopped = false; if constexpr (mode != bench) { ctx.nodes = 0; @@ -477,10 +477,6 @@ SearchResults SearchPosition(Board &board, SearchParams params, SearchContext& c return results; } -void StopSearch() { - searchStopped = true; -} - template SearchResults PVS(Board, int, int, int, int, SearchContext& ctx); template SearchResults PVS(Board, int, int, int, int, SearchContext& ctx); template SearchResults PVS(Board, int, int, int, int, SearchContext& ctx); diff --git a/source/search.h b/source/search.h index 98d4c47..e897898 100644 --- a/source/search.h +++ b/source/search.h @@ -22,8 +22,6 @@ constexpr int MAX_HISTORY = 16384; constexpr int inf = 100000; -inline bool searchStopped = false; - // [id][ply] inline int killerMoves[2][MAX_PLY]; @@ -112,6 +110,7 @@ public: int timeToSearch = 0; bool doingNullMove = false; + bool searchStopped = false; PVLine pvLine; History history; @@ -130,7 +129,6 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo template SearchResults SearchPosition(Board &board, SearchParams params, SearchContext& ctx); -void StopSearch(); bool IsDraw(Board &board); diff --git a/source/uci.cpp b/source/uci.cpp index ad676b6..3097a92 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -159,7 +159,7 @@ void UCILoop(Board &board) { // parse UCI "stop" command if (input.find("stop") != std::string::npos) { // stop the loop - SEARCH::StopSearch(); + ctx.searchStopped = true; continue; }