]> git.sesse.net Git - stockfish/commitdiff
Fixed an embarassing Chess960 bug found by Alexander Schmidt.
authorTord Romstad <tord@glaurungchess.com>
Mon, 5 Oct 2009 14:46:18 +0000 (16:46 +0200)
committerTord Romstad <tord@glaurungchess.com>
Mon, 5 Oct 2009 14:46:18 +0000 (16:46 +0200)
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.

src/position.cpp

index 00503429242342be2d9f0587fa73b06b2a0ceab7..e0e9aa3a9b37b316dc1b55f02b00755a3305c42b 100644 (file)
@@ -985,17 +985,22 @@ void Position::do_castle_move(Move m) {
       rto = relative_square(us, SQ_D1);
   }
 
-  // Move the pieces
-  Bitboard kmove_bb = make_move_bb(kfrom, kto);
-  do_move_bb(&(byColorBB[us]), kmove_bb);
-  do_move_bb(&(byTypeBB[KING]), kmove_bb);
-  do_move_bb(&(byTypeBB[0]), kmove_bb); // HACK: byTypeBB[0] == occupied squares
-
-  Bitboard rmove_bb = make_move_bb(rfrom, rto);
-  do_move_bb(&(byColorBB[us]), rmove_bb);
-  do_move_bb(&(byTypeBB[ROOK]), rmove_bb);
-  do_move_bb(&(byTypeBB[0]), rmove_bb); // HACK: byTypeBB[0] == occupied squares
-
+  // Remove pieces from source squares:
+  clear_bit(&(byColorBB[us]), kfrom);
+  clear_bit(&(byTypeBB[KING]), kfrom);
+  clear_bit(&(byTypeBB[0]), kfrom); // 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
+
+  // Put pieces on destination squares:
+  set_bit(&(byColorBB[us]), kto);
+  set_bit(&(byTypeBB[KING]), kto);
+  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
   Piece king = piece_of_color_and_type(us, KING);
   Piece rook = piece_of_color_and_type(us, ROOK);
@@ -1106,6 +1111,7 @@ void Position::undo_move(Move m) {
       pieceList[us][PAWN][index[to]] = to;
   }
 
+
   // Put the piece back at the source square
   Bitboard move_bb = make_move_bb(to, from);
   do_move_bb(&(byColorBB[us]), move_bb);
@@ -1183,17 +1189,22 @@ void Position::undo_castle_move(Move m) {
 
   assert(piece_on(kto) == piece_of_color_and_type(us, KING));
   assert(piece_on(rto) == piece_of_color_and_type(us, ROOK));
-
-  // Put the pieces back at the source square
-  Bitboard kmove_bb = make_move_bb(kto, kfrom);
-  do_move_bb(&(byColorBB[us]), kmove_bb);
-  do_move_bb(&(byTypeBB[KING]), kmove_bb);
-  do_move_bb(&(byTypeBB[0]), kmove_bb); // HACK: byTypeBB[0] == occupied squares
-
-  Bitboard rmove_bb = make_move_bb(rto, rfrom);
-  do_move_bb(&(byColorBB[us]), rmove_bb);
-  do_move_bb(&(byTypeBB[ROOK]), rmove_bb);
-  do_move_bb(&(byTypeBB[0]), rmove_bb); // HACK: byTypeBB[0] == occupied squares
+  
+  // Remove pieces from destination squares:
+  clear_bit(&(byColorBB[us]), kto);
+  clear_bit(&(byTypeBB[KING]), kto);
+  clear_bit(&(byTypeBB[0]), kto); // 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
+  // Put pieces on source squares:
+  set_bit(&(byColorBB[us]), kfrom);
+  set_bit(&(byTypeBB[KING]), kfrom);
+  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
   board[rto] = board[kto] = EMPTY;