- // 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);
-
- // Update hash key
- st->key ^= Zobrist::psq[us][KING][kfrom] ^ Zobrist::psq[us][KING][kto];
- st->key ^= Zobrist::psq[us][ROOK][rfrom] ^ Zobrist::psq[us][ROOK][rto];
-
- // Clear en passant square
- if (st->epSquare != SQ_NONE)
- {
- st->key ^= Zobrist::enpassant[file_of(st->epSquare)];
- st->epSquare = SQ_NONE;
- }
-
- // Update castling rights
- st->key ^= Zobrist::castle[st->castleRights & castleRightsMask[kfrom]];
- st->castleRights &= ~castleRightsMask[kfrom];
-
- // Update checkers BB
- st->checkersBB = attackers_to(king_square(~us)) & pieces(us);
-
- sideToMove = ~sideToMove;
- }
- else
- // Undo: point our state pointer back to the previous state
- st = st->previous;
-
- assert(pos_is_ok());
+ // 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;