From 57c285dfdc4279863a78dec83525b618cc1df8d9 Mon Sep 17 00:00:00 2001 From: PikaCat Date: Thu, 11 Jul 2024 13:15:10 +0800 Subject: [PATCH] Move Loop Consistency in Probcut In probcut move loop, everything is enclosed within a large if statement. I've changed it to guard clauses to stay consistent with other move loops. No functional change --- src/search.cpp | 68 +++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index f350a7df..468fcea0 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -748,47 +748,53 @@ Value Search::Worker::search( Piece captured; while ((move = mp.next_move()) != Move::none()) - if (move != excludedMove && pos.legal(move)) - { - assert(pos.capture(move)); + { + assert(move.is_ok()); - movedPiece = pos.moved_piece(move); - captured = pos.piece_on(move.to_sq()); + if (move == excludedMove) + continue; + // Check for legality + if (!pos.legal(move)) + continue; - // Prefetch the TT entry for the resulting position - prefetch(tt.first_entry(pos.key_after(move))); + assert(pos.capture(move)); - ss->currentMove = move; - ss->continuationHistory = - &this - ->continuationHistory[ss->inCheck][true][pos.moved_piece(move)][move.to_sq()]; + movedPiece = pos.moved_piece(move); + captured = pos.piece_on(move.to_sq()); - thisThread->nodes.fetch_add(1, std::memory_order_relaxed); - pos.do_move(move, st); + // Prefetch the TT entry for the resulting position + prefetch(tt.first_entry(pos.key_after(move))); - // Perform a preliminary qsearch to verify that the move holds - value = -qsearch(pos, ss + 1, -probCutBeta, -probCutBeta + 1); + ss->currentMove = move; + ss->continuationHistory = + &this->continuationHistory[ss->inCheck][true][pos.moved_piece(move)][move.to_sq()]; - // If the qsearch held, perform the regular search - if (value >= probCutBeta) - value = -search(pos, ss + 1, -probCutBeta, -probCutBeta + 1, depth - 4, - !cutNode); + thisThread->nodes.fetch_add(1, std::memory_order_relaxed); + pos.do_move(move, st); - pos.undo_move(move); + // Perform a preliminary qsearch to verify that the move holds + value = -qsearch(pos, ss + 1, -probCutBeta, -probCutBeta + 1); - if (value >= probCutBeta) - { - thisThread->captureHistory[movedPiece][move.to_sq()][type_of(captured)] - << stat_bonus(depth - 2); - - // Save ProbCut data into transposition table - ttWriter.write(posKey, value_to_tt(value, ss->ply), ss->ttPv, BOUND_LOWER, - depth - 3, move, unadjustedStaticEval, tt.generation()); - return std::abs(value) < VALUE_MATE_IN_MAX_PLY ? value - (probCutBeta - beta) - : value; - } + // If the qsearch held, perform the regular search + if (value >= probCutBeta) + value = + -search(pos, ss + 1, -probCutBeta, -probCutBeta + 1, depth - 4, !cutNode); + + pos.undo_move(move); + + if (value >= probCutBeta) + { + thisThread->captureHistory[movedPiece][move.to_sq()][type_of(captured)] + << stat_bonus(depth - 2); + + // Save ProbCut data into transposition table + ttWriter.write(posKey, value_to_tt(value, ss->ply), ss->ttPv, BOUND_LOWER, + depth - 3, move, unadjustedStaticEval, tt.generation()); + return std::abs(value) < VALUE_MATE_IN_MAX_PLY ? value - (probCutBeta - beta) + : value; } + } Eval::NNUE::hint_common_parent_position(pos, network[numaAccessToken], refreshTable); }