From 84e2f3851d5465a5dfd08a65bde72d555832a2a1 Mon Sep 17 00:00:00 2001 From: "Robert Nurnberg @ elitebook" Date: Thu, 26 Jun 2025 17:19:09 +0200 Subject: [PATCH] Introduce a constant for ValueList size in search() Having the size of these lists in two separate places likely contributed to the crashes seen during the recent tuning attempt https://tests.stockfishchess.org/tests/view/685c413343ce022d15794536. Thanks to @MinetaS for spotting this. closes https://github.com/official-stockfish/Stockfish/pull/6142 No functional change --- src/search.cpp | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index cdbc9531..4d0e64b3 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -63,6 +63,9 @@ using namespace Search; namespace { +constexpr int SEARCHEDLIST_CAPACITY = 32; +using SearchedList = ValueList; + // (*Scalers): // The values with Scaler asterisks have proven non-linear scaling. // They are optimized to time controls of 180 + 1.8 and longer, @@ -119,16 +122,16 @@ void update_pv(Move* pv, Move move, const Move* childPv); void update_continuation_histories(Stack* ss, Piece pc, Square to, int bonus); void update_quiet_histories( const Position& pos, Stack* ss, Search::Worker& workerThread, Move move, int bonus); -void update_all_stats(const Position& pos, - Stack* ss, - Search::Worker& workerThread, - Move bestMove, - Square prevSq, - ValueList& quietsSearched, - ValueList& capturesSearched, - Depth depth, - Move TTMove, - int moveCount); +void update_all_stats(const Position& pos, + Stack* ss, + Search::Worker& workerThread, + Move bestMove, + Square prevSq, + SearchedList& quietsSearched, + SearchedList& capturesSearched, + Depth depth, + Move TTMove, + int moveCount); } // namespace @@ -605,8 +608,8 @@ Value Search::Worker::search( int priorReduction; Piece movedPiece; - ValueList capturesSearched; - ValueList quietsSearched; + SearchedList capturesSearched; + SearchedList quietsSearched; // Step 1. Initialize node Worker* thisThread = this; @@ -1390,7 +1393,7 @@ moves_loop: // When in check, search starts here // If the move is worse than some previously searched move, // remember it, to update its stats later. - if (move != bestMove && moveCount <= 32) + if (move != bestMove && moveCount <= SEARCHEDLIST_CAPACITY) { if (capture) capturesSearched.push_back(move); @@ -1833,16 +1836,16 @@ void update_pv(Move* pv, Move move, const Move* childPv) { // Updates stats at the end of search() when a bestMove is found -void update_all_stats(const Position& pos, - Stack* ss, - Search::Worker& workerThread, - Move bestMove, - Square prevSq, - ValueList& quietsSearched, - ValueList& capturesSearched, - Depth depth, - Move ttMove, - int moveCount) { +void update_all_stats(const Position& pos, + Stack* ss, + Search::Worker& workerThread, + Move bestMove, + Square prevSq, + SearchedList& quietsSearched, + SearchedList& capturesSearched, + Depth depth, + Move ttMove, + int moveCount) { CapturePieceToHistory& captureHistory = workerThread.captureHistory; Piece movedPiece = pos.moved_piece(bestMove);