-/// Position::do_castle_move() is a private method used to do/undo a castling
-/// move. Note that castling moves are encoded as "king captures friendly rook"
-/// moves, for instance white short castling in a non-Chess960 game is encoded
-/// as e1h1.
-template<bool Do>
-void Position::do_castle_move(Move m) {
-
- assert(is_ok(m));
- assert(type_of(m) == CASTLE);
-
- Color us = sideToMove;
- Square kfrom, kto, rfrom, rto;
-
- bool kingSide = to_sq(m) > from_sq(m);
- kfrom = kto = from_sq(m);
- rfrom = rto = to_sq(m);
-
- if (Do)
- {
- kto = relative_square(us, kingSide ? SQ_G1 : SQ_C1);
- rto = relative_square(us, kingSide ? SQ_F1 : SQ_D1);
- }
- else
- {
- kfrom = relative_square(us, kingSide ? SQ_G1 : SQ_C1);
- rfrom = relative_square(us, kingSide ? SQ_F1 : SQ_D1);
- }
-
- assert(piece_on(kfrom) == make_piece(us, KING));
- assert(piece_on(rfrom) == make_piece(us, ROOK));
-
- // Move the pieces, with some care; in chess960 could be kto == rfrom
- 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;
-
- // Update board
- board[kfrom] = board[rfrom] = NO_PIECE;
- board[kto] = make_piece(us, KING);
- board[rto] = make_piece(us, ROOK);
-
- // Update piece lists
- pieceList[us][KING][index[kfrom]] = kto;
- pieceList[us][ROOK][index[rfrom]] = rto;
- int tmp = index[rfrom]; // In Chess960 could be kto == rfrom
- index[kto] = index[kfrom];
- index[rto] = tmp;
-
- if (Do)
- {
- // Reset capture field
- st->capturedType = NO_PIECE_TYPE;
-
- // Update incremental scores
- st->psqScore += psq_delta(make_piece(us, KING), kfrom, kto);
- st->psqScore += psq_delta(make_piece(us, ROOK), rfrom, rto);