mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-17 07:36:23 +08:00
Introduce do_move_bb() to update bitboards after a move
Avoid a clear_bit() + set_bit() sequence but update bitboards with only one xor instructions. This is faster and simplifies the code. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
@@ -741,12 +741,11 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
|
||||
do_capture_move(st->capture, them, to);
|
||||
|
||||
// Move the piece
|
||||
clear_bit(&(byColorBB[us]), from);
|
||||
clear_bit(&(byTypeBB[piece]), from);
|
||||
clear_bit(&(byTypeBB[0]), from); // HACK: byTypeBB[0] == occupied squares
|
||||
set_bit(&(byColorBB[us]), to);
|
||||
set_bit(&(byTypeBB[piece]), to);
|
||||
set_bit(&(byTypeBB[0]), to); // HACK: byTypeBB[0] == occupied squares
|
||||
Bitboard move_bb = make_move_bb(from, to);
|
||||
do_move_bb(&(byColorBB[us]), move_bb);
|
||||
do_move_bb(&(byTypeBB[piece]), move_bb);
|
||||
do_move_bb(&(byTypeBB[0]), move_bb); // HACK: byTypeBB[0] == occupied squares
|
||||
|
||||
board[to] = board[from];
|
||||
board[from] = EMPTY;
|
||||
|
||||
@@ -838,6 +837,7 @@ void Position::do_capture_move(PieceType capture, Color them, Square to) {
|
||||
// Remove captured piece
|
||||
clear_bit(&(byColorBB[them]), to);
|
||||
clear_bit(&(byTypeBB[capture]), to);
|
||||
clear_bit(&(byTypeBB[0]), to);
|
||||
|
||||
// Update hash key
|
||||
st->key ^= zobrist[them][capture][to];
|
||||
@@ -1170,17 +1170,13 @@ void Position::undo_move(Move m) {
|
||||
assert(color_of_piece_on(to) == us);
|
||||
|
||||
// Put the piece back at the source square
|
||||
Bitboard move_bb = make_move_bb(to, from);
|
||||
piece = type_of_piece_on(to);
|
||||
set_bit(&(byColorBB[us]), from);
|
||||
set_bit(&(byTypeBB[piece]), from);
|
||||
set_bit(&(byTypeBB[0]), from); // HACK: byTypeBB[0] == occupied squares
|
||||
do_move_bb(&(byColorBB[us]), move_bb);
|
||||
do_move_bb(&(byTypeBB[piece]), move_bb);
|
||||
do_move_bb(&(byTypeBB[0]), move_bb); // HACK: byTypeBB[0] == occupied squares
|
||||
board[from] = piece_of_color_and_type(us, piece);
|
||||
|
||||
// Clear the destination square
|
||||
clear_bit(&(byColorBB[us]), to);
|
||||
clear_bit(&(byTypeBB[piece]), to);
|
||||
clear_bit(&(byTypeBB[0]), to); // HACK: byTypeBB[0] == occupied squares
|
||||
|
||||
// If the moving piece was a king, update the king square
|
||||
if (piece == KING)
|
||||
kingSquare[us] = from;
|
||||
@@ -1193,7 +1189,7 @@ void Position::undo_move(Move m) {
|
||||
{
|
||||
assert(st->capture != KING);
|
||||
|
||||
// Replace the captured piece
|
||||
// Restore the captured piece
|
||||
set_bit(&(byColorBB[them]), to);
|
||||
set_bit(&(byTypeBB[st->capture]), to);
|
||||
set_bit(&(byTypeBB[0]), to);
|
||||
|
||||
Reference in New Issue
Block a user