diff --git a/src/position.cpp b/src/position.cpp index 4744d5102..e87091783 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -946,27 +946,6 @@ void Position::do_move(Move m, st->castlingRights &= ~(castlingRightsMask[from] | castlingRightsMask[to]); k ^= Zobrist::castling[st->castlingRights]; - // Move the piece. The tricky Chess960 castling is handled earlier - if (m.type_of() != CASTLING) - { - Piece toPc = pc; - if (m.type_of() == PROMOTION) - toPc = make_piece(us, m.promotion_type()); - - if (captured && m.type_of() != EN_PASSANT) - { - remove_piece(from, &dts); - swap_piece(to, toPc, &dts); - } - else if (pc == toPc) - move_piece(from, to, &dts); - else - { - remove_piece(from, &dts); - put_piece(toPc, to, &dts); - } - } - // If the moving piece is a pawn do some special extra work if (type_of(pc) == PAWN) { @@ -1036,10 +1015,10 @@ void Position::do_move(Move m, st->minorPieceKey ^= Zobrist::psq[pc][from] ^ Zobrist::psq[pc][to]; } + if (tt) + prefetch(tt->first_entry(adjust_key50(k))); // Update the key with the final value st->key = k; - if (tt) - prefetch(tt->first_entry(key())); if (history) { @@ -1050,6 +1029,27 @@ void Position::do_move(Move m, prefetch(&history->nonpawn_correction_entry(*this)); } + // Move the piece. The tricky Chess960 castling is handled earlier + if (m.type_of() != CASTLING) + { + Piece toPc = pc; + if (m.type_of() == PROMOTION) + toPc = make_piece(us, m.promotion_type()); + + if (captured && m.type_of() != EN_PASSANT) + { + remove_piece(from, &dts); + swap_piece(to, toPc, &dts); + } + else if (pc == toPc) + move_piece(from, to, &dts); + else + { + remove_piece(from, &dts); + put_piece(toPc, to, &dts); + } + } + // Set capture piece st->capturedPiece = captured;