1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 19:49:14 +00:00

Microptimize castling in undo_move()

We don't need to set 'captured' and 'pt' after we
castle back.

No functional change.
This commit is contained in:
Marco Costalba 2014-03-15 11:21:47 +01:00
parent 36c381154b
commit 142874b058

View file

@ -863,7 +863,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
// Update the key with the final value // Update the key with the final value
st->key = k; st->key = k;
// Update checkers bitboard: piece must be already moved // Update checkers bitboard: piece must be already moved due to attacks_from()
st->checkersBB = 0; st->checkersBB = 0;
if (moveIsCheck) if (moveIsCheck)
@ -877,7 +877,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
st->checkersBB |= to; st->checkersBB |= to;
// Discovered checks // Discovered checks
if (ci.dcCandidates && (ci.dcCandidates & from)) if (unlikely(ci.dcCandidates) && (ci.dcCandidates & from))
{ {
if (pt != ROOK) if (pt != ROOK)
st->checkersBB |= attacks_from<ROOK>(king_square(them)) & pieces(us, QUEEN, ROOK); st->checkersBB |= attacks_from<ROOK>(king_square(them)) & pieces(us, QUEEN, ROOK);
@ -904,24 +904,20 @@ void Position::undo_move(Move m) {
sideToMove = ~sideToMove; sideToMove = ~sideToMove;
Color us = sideToMove; Color us = sideToMove;
Color them = ~us;
Square from = from_sq(m); Square from = from_sq(m);
Square to = to_sq(m); Square to = to_sq(m);
PieceType pt = type_of(piece_on(to)); PieceType pt = type_of(piece_on(to));
PieceType captured = st->capturedType;
assert(empty(from) || type_of(m) == CASTLING); assert(empty(from) || type_of(m) == CASTLING);
assert(captured != KING); assert(st->capturedType != KING);
if (type_of(m) == PROMOTION) if (type_of(m) == PROMOTION)
{ {
PieceType promotion = promotion_type(m); assert(pt == promotion_type(m));
assert(promotion == pt);
assert(relative_rank(us, to) == RANK_8); assert(relative_rank(us, to) == RANK_8);
assert(promotion >= KNIGHT && promotion <= QUEEN); assert(promotion_type(m) >= KNIGHT && promotion_type(m) <= QUEEN);
remove_piece(to, us, promotion); remove_piece(to, us, promotion_type(m));
put_piece(to, us, PAWN); put_piece(to, us, PAWN);
pt = PAWN; pt = PAWN;
} }
@ -930,28 +926,27 @@ void Position::undo_move(Move m) {
{ {
Square rfrom, rto; Square rfrom, rto;
do_castling<false>(from, to, rfrom, rto); do_castling<false>(from, to, rfrom, rto);
captured = NO_PIECE_TYPE;
pt = KING;
} }
else else
{
move_piece(to, from, us, pt); // Put the piece back at the source square move_piece(to, from, us, pt); // Put the piece back at the source square
if (captured) if (st->capturedType)
{
Square capsq = to;
if (type_of(m) == ENPASSANT)
{ {
capsq -= pawn_push(us); Square capsq = to;
assert(pt == PAWN); if (type_of(m) == ENPASSANT)
assert(to == st->previous->epSquare); {
assert(relative_rank(us, to) == RANK_6); capsq -= pawn_push(us);
assert(piece_on(capsq) == NO_PIECE);
assert(pt == PAWN);
assert(to == st->previous->epSquare);
assert(relative_rank(us, to) == RANK_6);
assert(piece_on(capsq) == NO_PIECE);
}
put_piece(capsq, ~us, st->capturedType); // Restore the captured piece
} }
put_piece(capsq, them, captured); // Restore the captured piece
} }
// Finally point our state pointer back to the previous state // Finally point our state pointer back to the previous state