No globals #50

Merged
rektdie merged 23 commits from no_globals into main 2025-04-12 13:52:41 +02:00
4 changed files with 16 additions and 23 deletions
Showing only changes of commit ac7325f295 - Show all commits

No files matched your search

-1
View File
@@ -65,7 +65,6 @@ void RunBenchmark() {
Board board;
int depth = BENCH_DEPTH;
int ply = 0;
searchStopped = false;
positionIndex = 0;
// Clearing
+14 -18
View File
@@ -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<false, mode>(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 <searchMode mode>
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<true, searchMode::bench>(Board, int, int, int, int, SearchContext& ctx);
template SearchResults PVS<false, searchMode::bench>(Board, int, int, int, int, SearchContext& ctx);
template SearchResults PVS<true, searchMode::normal>(Board, int, int, int, int, SearchContext& ctx);
+1 -3
View File
@@ -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 <searchMode mode>
SearchResults SearchPosition(Board &board, SearchParams params, SearchContext& ctx);
void StopSearch();
bool IsDraw(Board &board);
+1 -1
View File
@@ -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;
}