1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Fixed an embarassing Chess960 bug found by Alexander Schmidt.

It turned out that we used do_move_bb to update the king and rook
bitboards when making and unmaking castling moves, which obviously
doesn't work in Chess960, where the source and destination squares
for the king or rook could be identical.

No functional change in normal chess.
This commit is contained in:
Tord Romstad 2009-10-05 16:46:18 +02:00
parent 3701a8e57d
commit 32dfaa56b0

View file

@ -985,16 +985,21 @@ void Position::do_castle_move(Move m) {
rto = relative_square(us, SQ_D1); rto = relative_square(us, SQ_D1);
} }
// Move the pieces // Remove pieces from source squares:
Bitboard kmove_bb = make_move_bb(kfrom, kto); clear_bit(&(byColorBB[us]), kfrom);
do_move_bb(&(byColorBB[us]), kmove_bb); clear_bit(&(byTypeBB[KING]), kfrom);
do_move_bb(&(byTypeBB[KING]), kmove_bb); clear_bit(&(byTypeBB[0]), kfrom); // HACK: byTypeBB[0] == occupied squares
do_move_bb(&(byTypeBB[0]), kmove_bb); // HACK: byTypeBB[0] == occupied squares clear_bit(&(byColorBB[us]), rfrom);
clear_bit(&(byTypeBB[ROOK]), rfrom);
clear_bit(&(byTypeBB[0]), rfrom); // HACK: byTypeBB[0] == occupied squares
Bitboard rmove_bb = make_move_bb(rfrom, rto); // Put pieces on destination squares:
do_move_bb(&(byColorBB[us]), rmove_bb); set_bit(&(byColorBB[us]), kto);
do_move_bb(&(byTypeBB[ROOK]), rmove_bb); set_bit(&(byTypeBB[KING]), kto);
do_move_bb(&(byTypeBB[0]), rmove_bb); // HACK: byTypeBB[0] == occupied squares set_bit(&(byTypeBB[0]), kto); // HACK: byTypeBB[0] == occupied squares
set_bit(&(byColorBB[us]), rto);
set_bit(&(byTypeBB[ROOK]), rto);
set_bit(&(byTypeBB[0]), rto); // HACK: byTypeBB[0] == occupied squares
// Update board array // Update board array
Piece king = piece_of_color_and_type(us, KING); Piece king = piece_of_color_and_type(us, KING);
@ -1106,6 +1111,7 @@ void Position::undo_move(Move m) {
pieceList[us][PAWN][index[to]] = to; pieceList[us][PAWN][index[to]] = to;
} }
// Put the piece back at the source square // Put the piece back at the source square
Bitboard move_bb = make_move_bb(to, from); Bitboard move_bb = make_move_bb(to, from);
do_move_bb(&(byColorBB[us]), move_bb); do_move_bb(&(byColorBB[us]), move_bb);
@ -1184,16 +1190,21 @@ void Position::undo_castle_move(Move m) {
assert(piece_on(kto) == piece_of_color_and_type(us, KING)); assert(piece_on(kto) == piece_of_color_and_type(us, KING));
assert(piece_on(rto) == piece_of_color_and_type(us, ROOK)); assert(piece_on(rto) == piece_of_color_and_type(us, ROOK));
// Put the pieces back at the source square // Remove pieces from destination squares:
Bitboard kmove_bb = make_move_bb(kto, kfrom); clear_bit(&(byColorBB[us]), kto);
do_move_bb(&(byColorBB[us]), kmove_bb); clear_bit(&(byTypeBB[KING]), kto);
do_move_bb(&(byTypeBB[KING]), kmove_bb); clear_bit(&(byTypeBB[0]), kto); // HACK: byTypeBB[0] == occupied squares
do_move_bb(&(byTypeBB[0]), kmove_bb); // HACK: byTypeBB[0] == occupied squares clear_bit(&(byColorBB[us]), rto);
clear_bit(&(byTypeBB[ROOK]), rto);
clear_bit(&(byTypeBB[0]), rto); // HACK: byTypeBB[0] == occupied squares
Bitboard rmove_bb = make_move_bb(rto, rfrom); // Put pieces on source squares:
do_move_bb(&(byColorBB[us]), rmove_bb); set_bit(&(byColorBB[us]), kfrom);
do_move_bb(&(byTypeBB[ROOK]), rmove_bb); set_bit(&(byTypeBB[KING]), kfrom);
do_move_bb(&(byTypeBB[0]), rmove_bb); // HACK: byTypeBB[0] == occupied squares set_bit(&(byTypeBB[0]), kfrom); // HACK: byTypeBB[0] == occupied squares
set_bit(&(byColorBB[us]), rfrom);
set_bit(&(byTypeBB[ROOK]), rfrom);
set_bit(&(byTypeBB[0]), rfrom); // HACK: byTypeBB[0] == occupied squares
// Update board // Update board
board[rto] = board[kto] = EMPTY; board[rto] = board[kto] = EMPTY;