From acee84c13480e3d2df5ea1f922063abc9450c033 Mon Sep 17 00:00:00 2001 From: rektdie Date: Sat, 1 Nov 2025 02:34:59 +0100 Subject: [PATCH] datagen issues fixed | bench 4317404 --- source/nnue.cpp | 4 ++-- source/search.cpp | 26 +++++++++++++++----------- source/search.h | 11 +++++------ 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/source/nnue.cpp b/source/nnue.cpp index 240d52a..cf9e7d8 100644 --- a/source/nnue.cpp +++ b/source/nnue.cpp @@ -186,8 +186,8 @@ int Forward(const Board& board, const Network& net) { } int16_t Network::Evaluate(const Board& board) { - return std::clamp(Forward(board, *this), (-SEARCH::MATE_SCORE + SEARCH::MAX_PLY), - (SEARCH::MATE_SCORE - SEARCH::MAX_PLY)); + return std::clamp(Forward(board, *this), (-SEARCH::MATE_SCORE + SEARCH::MAX_DEPTH), + (SEARCH::MATE_SCORE - SEARCH::MAX_DEPTH)); } } diff --git a/source/search.cpp b/source/search.cpp index 1cd39bb..49cf6ec 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -41,7 +41,7 @@ int16_t ContHistory::GetNPly(Board& board, Move& move, SearchContext* ctx, int p static int AdjustEval(Board &board, SearchContext* ctx, int eval) { int corrhist = ctx->corrhist.GetAllHist(board); - int mateFound = MATE_SCORE - MAX_PLY; + int mateFound = MATE_SCORE - MAX_DEPTH; return std::clamp(eval + corrhist / CORRHIST_GRAIN, -mateFound + 1, mateFound - 1); } @@ -272,13 +272,11 @@ bool SEE(Board& board, Move& move, int threshold) { template static bool ShouldStop(SearchContext* ctx) { - if constexpr (mode != bench && mode != nodesMode) { + if constexpr (mode == normal) { if (ctx->nodes % 1024 == 0) { - if constexpr (mode == normal) { - if (ctx->sw.GetElapsedMS() >= ctx->timeToSearch) { - ctx->searchStopped = true; - return true; - } + if (ctx->sw.GetElapsedMS() >= ctx->timeToSearch) { + ctx->searchStopped = true; + return true; } } } else if constexpr (mode == nodesMode) { @@ -300,6 +298,9 @@ template static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, SearchContext* ctx) { if (ShouldStop(ctx)) return 0; + if (ply >= MAX_DEPTH) + return NNUE::net.Evaluate(board); + if (ply > ctx->seldepth) ctx->seldepth = ply; @@ -390,6 +391,9 @@ template SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchContext* ctx, bool cutnode) { if (ShouldStop(ctx)) return 0; + if (ply >= MAX_DEPTH) + return NNUE::net.Evaluate(board); + if (ply > ctx->seldepth) ctx->seldepth = ply; @@ -469,7 +473,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC const int probcutBeta = beta + 200; const int probcutDepth = std::max(depth - 3, 1); - if (depth >= 7 && std::abs(beta) < MATE_SCORE - MAX_PLY + if (depth >= 7 && std::abs(beta) < MATE_SCORE - MAX_DEPTH && (!entry.bestMove || !entry.bestMove.IsQuiet()) && !(ttHit && entry.depth >= probcutDepth && entry.score < probcutBeta)) { @@ -535,7 +539,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC if (ctx->excluded == currMove) continue; - bool notMated = results.score > (-MATE_SCORE + MAX_PLY); + bool notMated = results.score > (-MATE_SCORE + MAX_DEPTH); int lmrDepth = depth - lmrTable[currMove.IsQuiet()][depth][moveSeen]; // Late move pruning @@ -954,7 +958,7 @@ void PrintSearchInfo(SearchContext* ctx, SearchResults& results, int depth, int std::cout << " time " << elapsed; std::cout << " score "; - if (std::abs(results.score) + MAX_PLY >= MATE_SCORE) { + if (std::abs(results.score) + MAX_DEPTH >= MATE_SCORE) { int mateIn = (MATE_SCORE - (std::abs(results.score) - 1)) / 2; mateIn = results.score < 0 ? mateIn * -1 : mateIn; @@ -991,7 +995,7 @@ void PrintSearchInfo(SearchContext* ctx, SearchResults& results, int depth, int bool isMate = false; int mateIn = 0; - if (std::abs(results.score) + MAX_PLY >= MATE_SCORE) { + if (std::abs(results.score) + MAX_DEPTH >= MATE_SCORE) { isMate = true; mateIn = (MATE_SCORE - (std::abs(results.score) - 1)) / 2; mateIn = results.score < 0 ? mateIn * -1 : mateIn; diff --git a/source/search.h b/source/search.h index 7d84250..ab0a371 100644 --- a/source/search.h +++ b/source/search.h @@ -21,8 +21,7 @@ enum searchMode { }; constexpr int MATE_SCORE = 32767; -constexpr int MAX_DEPTH = 128; -constexpr int MAX_PLY = 512; +constexpr int MAX_DEPTH = 256; constexpr int MAX_HISTORY = 16384; constexpr int CORRHIST_WEIGHT_SCALE = 256; @@ -125,8 +124,8 @@ public: class PVLine { private: - int length[MAX_PLY] = {}; - Move table[MAX_PLY][MAX_PLY] = {}; + int length[MAX_DEPTH] = {}; + Move table[MAX_DEPTH][MAX_DEPTH] = {}; public: void SetLength(int ply) { length[ply] = ply; @@ -206,13 +205,13 @@ public: ContHistory conthist; CorrHist corrhist; - std::array, 2> killerMoves{}; + std::array, 2> killerMoves{}; std::vector positionHistory; TTable TT; - std::array ss{}; + std::array ss{}; Stopwatch sw;