diff --git a/src/search.cpp b/src/search.cpp index 41177b81c..cd84eb240 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -516,14 +516,21 @@ void Search::Worker::iterative_deepening() { } -void Search::Worker::do_move(Position& pos, const Move move, StateInfo& st) { - do_move(pos, move, st, pos.gives_check(move)); +void Search::Worker::do_move(Position& pos, const Move move, StateInfo& st, Stack* const ss) { + do_move(pos, move, st, pos.gives_check(move), ss); } -void Search::Worker::do_move(Position& pos, const Move move, StateInfo& st, const bool givesCheck) { +void Search::Worker::do_move(Position& pos, const Move move, StateInfo& st, const bool givesCheck, Stack* const ss) { + bool capture = pos.capture_stage(move); DirtyPiece dp = pos.do_move(move, st, givesCheck, &tt); nodes.fetch_add(1, std::memory_order_relaxed); accumulatorStack.push(dp); + if (ss != nullptr) + { + ss->currentMove = move; + ss->continuationHistory = &continuationHistory[ss->inCheck][capture][dp.pc][move.to_sq()]; + ss->continuationCorrectionHistory = &continuationCorrectionHistory[dp.pc][move.to_sq()]; + } } void Search::Worker::do_null_move(Position& pos, StateInfo& st) { pos.do_null_move(st, tt); } @@ -695,7 +702,7 @@ Value Search::Worker::search( if (depth >= 8 && ttData.move && pos.pseudo_legal(ttData.move) && pos.legal(ttData.move) && !is_decisive(ttData.value)) { - do_move(pos, ttData.move, st); + do_move(pos, ttData.move, st, nullptr); Key nextPosKey = pos.key(); auto [ttHitNext, ttDataNext, ttWriterNext] = tt.probe(nextPosKey); undo_move(pos, ttData.move); @@ -920,13 +927,7 @@ Value Search::Worker::search( movedPiece = pos.moved_piece(move); - do_move(pos, move, st); - - ss->currentMove = move; - ss->continuationHistory = - &continuationHistory[ss->inCheck][true][movedPiece][move.to_sq()]; - ss->continuationCorrectionHistory = - &continuationCorrectionHistory[movedPiece][move.to_sq()]; + do_move(pos, move, st, ss); // Perform a preliminary qsearch to verify that the move holds value = -qsearch(pos, ss + 1, -probCutBeta, -probCutBeta + 1); @@ -1161,17 +1162,10 @@ moves_loop: // When in check, search starts here } // Step 16. Make the move - do_move(pos, move, st, givesCheck); + do_move(pos, move, st, givesCheck, ss); // Add extension to new depth newDepth += extension; - - // Update the current move (this must be done after singular extension search) - ss->currentMove = move; - ss->continuationHistory = - &continuationHistory[ss->inCheck][capture][movedPiece][move.to_sq()]; - ss->continuationCorrectionHistory = - &continuationCorrectionHistory[movedPiece][move.to_sq()]; uint64_t nodeCount = rootNode ? uint64_t(nodes) : 0; // Decrease reduction for PvNodes (*Scaler) @@ -1658,16 +1652,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta) } // Step 7. Make and search the move - Piece movedPiece = pos.moved_piece(move); - - do_move(pos, move, st, givesCheck); - - // Update the current move - ss->currentMove = move; - ss->continuationHistory = - &continuationHistory[ss->inCheck][capture][movedPiece][move.to_sq()]; - ss->continuationCorrectionHistory = - &continuationCorrectionHistory[movedPiece][move.to_sq()]; + do_move(pos, move, st, givesCheck, ss); value = -qsearch(pos, ss + 1, -beta, -alpha); undo_move(pos, move); diff --git a/src/search.h b/src/search.h index e0b57e30b..a43649e94 100644 --- a/src/search.h +++ b/src/search.h @@ -297,8 +297,8 @@ class Worker { private: void iterative_deepening(); - void do_move(Position& pos, const Move move, StateInfo& st); - void do_move(Position& pos, const Move move, StateInfo& st, const bool givesCheck); + void do_move(Position& pos, const Move move, StateInfo& st, Stack* const ss); + void do_move(Position& pos, const Move move, StateInfo& st, const bool givesCheck, Stack* const ss); void do_null_move(Position& pos, StateInfo& st); void undo_move(Position& pos, const Move move); void undo_null_move(Position& pos);