No globals #50

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

No files matched your search

+6 -9
View File
@@ -4,7 +4,6 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include "tt.h" #include "tt.h"
#include "stopwatch.h"
#include "datagen.h" #include "datagen.h"
#include "benchmark.h" #include "benchmark.h"
@@ -12,8 +11,6 @@ namespace SEARCH {
static inline int timeToSearch = 0; static inline int timeToSearch = 0;
Stopwatch sw;
void InitLMRTable() { void InitLMRTable() {
for (int depth = 0; depth <= MAX_DEPTH; depth++) { for (int depth = 0; depth <= MAX_DEPTH; depth++) {
for (int move = 0; move < MAX_MOVES; move++) { for (int move = 0; move < MAX_MOVES; move++) {
@@ -138,7 +135,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply, Searc
if constexpr (mode != nodesMode) { if constexpr (mode != nodesMode) {
if constexpr (mode != bench) { if constexpr (mode != bench) {
if (ctx.nodes % 1024 == 0) { if (ctx.nodes % 1024 == 0) {
if (sw.GetElapsedMS() >= timeToSearch) { if (ctx.sw.GetElapsedMS() >= timeToSearch) {
StopSearch(); StopSearch();
return 0; return 0;
} }
@@ -203,7 +200,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo
if constexpr (mode != bench || mode != nodesMode) { if constexpr (mode != bench || mode != nodesMode) {
if (ctx.nodes % 1024 == 0) { if (ctx.nodes % 1024 == 0) {
if constexpr (mode == normal) { if constexpr (mode == normal) {
if (sw.GetElapsedMS() >= timeToSearch) { if (ctx.sw.GetElapsedMS() >= timeToSearch) {
StopSearch(); StopSearch();
return 0; return 0;
} }
@@ -396,14 +393,14 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext& ctx) {
int elapsed = 0; int elapsed = 0;
sw.Restart(); ctx.sw.Restart();
for (int depth = 1; depth <= toDepth; depth++) { for (int depth = 1; depth <= toDepth; depth++) {
timeToSearch = std::max((fullTime / 20) + (inc / 2), 4); timeToSearch = std::max((fullTime / 20) + (inc / 2), 4);
int softTime = timeToSearch * 0.65; int softTime = timeToSearch * 0.65;
SearchResults currentResults = PVS<true, mode>(board, depth, alpha, beta, ply, ctx); SearchResults currentResults = PVS<true, mode>(board, depth, alpha, beta, ply, ctx);
elapsed = sw.GetElapsedMS(); elapsed = ctx.sw.GetElapsedMS();
// If we fell outside the window, try again with full width // If we fell outside the window, try again with full width
if ((currentResults.score <= alpha) if ((currentResults.score <= alpha)
@@ -435,14 +432,14 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext& ctx) {
std::cout << "depth " << depth; std::cout << "depth " << depth;
std::cout << " time " << elapsed; std::cout << " time " << elapsed;
std::cout << " score cp " << UTILS::ConvertToWhiteRelative(board, safeResults.score); std::cout << " score cp " << UTILS::ConvertToWhiteRelative(board, safeResults.score);
std::cout << " nodes " << ctx.nodes << " nps " << int(ctx.nodes/sw.GetElapsedSec()); std::cout << " nodes " << ctx.nodes << " nps " << int(ctx.nodes/ctx.sw.GetElapsedSec());
std::cout << " hashfull " << TT.GetUsedPercentage(); std::cout << " hashfull " << TT.GetUsedPercentage();
std::cout << " pv "; std::cout << " pv ";
ctx.pvLine.Print(0); ctx.pvLine.Print(0);
std::cout << std::endl; std::cout << std::endl;
if constexpr (mode == normal) { if constexpr (mode == normal) {
if (sw.GetElapsedMS() >= softTime) { if (ctx.sw.GetElapsedMS() >= softTime) {
StopSearch(); StopSearch();
break; break;
} }
+4
View File
@@ -4,6 +4,7 @@
#include <vector> #include <vector>
#include "move.h" #include "move.h"
#include <algorithm> #include <algorithm>
#include "stopwatch.h"
namespace SEARCH { namespace SEARCH {
@@ -114,9 +115,12 @@ public:
PVLine pvLine; PVLine pvLine;
History history; History history;
Stopwatch sw;
SearchContext(){ SearchContext(){
pvLine.Clear(); pvLine.Clear();
history.Clear(); history.Clear();
sw.Restart();
} }
}; };