mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-22 18:17:02 +08:00
Refactor do_castle()
Not a real functional change, but bench changed due to different piecelist
reordering. To verify it a temporary my canonicalize_rooks function was
written as follows. It just ensures that the rook on the "smaller" square
is listed first.
void Position::canonicalize_rooks(Color c)
{
if (pieceCount[c][ROOK] == 2)
{
Square s0 = pieceList[c][ROOK][0];
Square s1 = pieceList[c][ROOK][1];
if (s0 > s1)
{
pieceList[c][ROOK][0] = s1;
pieceList[c][ROOK][1] = s0;
index[s0] = 1;
index[s1] = 0;
}
}
}
With this both bench and the test on Chess960 positions
./stockfish bench 128 1 8 Chess960.epd file > /dev/null
Gives same result.
bench: 4424151
This commit is contained in:
committed by
Marco Costalba
parent
a16ba5bbd1
commit
f7096ea7ce
@@ -989,25 +989,12 @@ void Position::undo_move(Move m) {
|
||||
|
||||
void Position::do_castle(Square kfrom, Square kto, Square rfrom, Square rto) {
|
||||
|
||||
Color us = sideToMove;
|
||||
Bitboard k_from_to_bb = SquareBB[kfrom] ^ SquareBB[kto];
|
||||
Bitboard r_from_to_bb = SquareBB[rfrom] ^ SquareBB[rto];
|
||||
byTypeBB[KING] ^= k_from_to_bb;
|
||||
byTypeBB[ROOK] ^= r_from_to_bb;
|
||||
byTypeBB[ALL_PIECES] ^= k_from_to_bb ^ r_from_to_bb;
|
||||
byColorBB[us] ^= k_from_to_bb ^ r_from_to_bb;
|
||||
|
||||
// Could be from == to, so first set NO_PIECE then KING and ROOK
|
||||
board[kfrom] = board[rfrom] = NO_PIECE;
|
||||
board[kto] = make_piece(us, KING);
|
||||
board[rto] = make_piece(us, ROOK);
|
||||
|
||||
// Could be kfrom == rto, so use a 'tmp' variable
|
||||
int tmp = index[kfrom];
|
||||
index[rto] = index[rfrom];
|
||||
index[kto] = tmp;
|
||||
pieceList[us][KING][index[kto]] = kto;
|
||||
pieceList[us][ROOK][index[rto]] = rto;
|
||||
// Remove both pieces first since squares could overlap in Chess960
|
||||
remove_piece(kfrom, sideToMove, KING);
|
||||
remove_piece(rfrom, sideToMove, ROOK);
|
||||
board[kfrom] = board[rfrom] = NO_PIECE; // Since remove_piece doesn't do it for us
|
||||
put_piece(kto, sideToMove, KING);
|
||||
put_piece(rto, sideToMove, ROOK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user