@@ -864,47 +864,54 @@ Value Search::Worker::search(
864864 Piece captured;
865865
866866 while ((move = mp.next_move ()) != Move::none ())
867- if (move != excludedMove && pos.legal (move))
868- {
869- assert (pos.capture_stage (move));
867+ {
868+ assert (move.is_ok ());
870869
871- movedPiece = pos. moved_piece (move);
872- captured = pos. piece_on (move. to_sq ()) ;
870+ if (move == excludedMove)
871+ continue ;
873872
873+ // Check for legality
874+ if (!pos.legal (move))
875+ continue ;
874876
875- // Prefetch the TT entry for the resulting position
876- prefetch (tt.first_entry (pos.key_after (move)));
877+ assert (pos.capture_stage (move));
877878
878- ss->currentMove = move;
879- ss->continuationHistory =
880- &this
881- ->continuationHistory [ss->inCheck ][true ][pos.moved_piece (move)][move.to_sq ()];
879+ movedPiece = pos.moved_piece (move);
880+ captured = pos.piece_on (move.to_sq ());
882881
883- thisThread->nodes .fetch_add (1 , std::memory_order_relaxed);
884- pos.do_move (move, st);
885882
886- // Perform a preliminary qsearch to verify that the move holds
887- value = -qsearch<NonPV>( pos, ss + 1 , -probCutBeta, -probCutBeta + 1 );
883+ // Prefetch the TT entry for the resulting position
884+ prefetch (tt. first_entry ( pos. key_after (move)) );
888885
889- // If the qsearch held, perform the regular search
890- if (value >= probCutBeta)
891- value = -search<NonPV>(pos, ss + 1 , -probCutBeta, -probCutBeta + 1 , depth - 4 ,
892- !cutNode);
886+ ss->currentMove = move;
887+ ss->continuationHistory =
888+ &this ->continuationHistory [ss->inCheck ][true ][pos.moved_piece (move)][move.to_sq ()];
893889
894- pos.undo_move (move);
890+ thisThread->nodes .fetch_add (1 , std::memory_order_relaxed);
891+ pos.do_move (move, st);
895892
896- if (value >= probCutBeta)
897- {
898- thisThread->captureHistory [movedPiece][move.to_sq ()][type_of (captured)]
899- << stat_bonus (depth - 2 );
900-
901- // Save ProbCut data into transposition table
902- ttWriter.write (posKey, value_to_tt (value, ss->ply ), ss->ttPv , BOUND_LOWER,
903- depth - 3 , move, unadjustedStaticEval, tt.generation ());
904- return std::abs (value) < VALUE_TB_WIN_IN_MAX_PLY ? value - (probCutBeta - beta)
905- : value;
906- }
893+ // Perform a preliminary qsearch to verify that the move holds
894+ value = -qsearch<NonPV>(pos, ss + 1 , -probCutBeta, -probCutBeta + 1 );
895+
896+ // If the qsearch held, perform the regular search
897+ if (value >= probCutBeta)
898+ value =
899+ -search<NonPV>(pos, ss + 1 , -probCutBeta, -probCutBeta + 1 , depth - 4 , !cutNode);
900+
901+ pos.undo_move (move);
902+
903+ if (value >= probCutBeta)
904+ {
905+ thisThread->captureHistory [movedPiece][move.to_sq ()][type_of (captured)]
906+ << stat_bonus (depth - 2 );
907+
908+ // Save ProbCut data into transposition table
909+ ttWriter.write (posKey, value_to_tt (value, ss->ply ), ss->ttPv , BOUND_LOWER,
910+ depth - 3 , move, unadjustedStaticEval, tt.generation ());
911+ return std::abs (value) < VALUE_TB_WIN_IN_MAX_PLY ? value - (probCutBeta - beta)
912+ : value;
907913 }
914+ }
908915
909916 Eval::NNUE::hint_common_parent_position (pos, networks[numaAccessToken], refreshTable);
910917 }
0 commit comments