         playerTurn.invert()
         attackersToKing = attackers
         self.halfmoves = halfmoves
+        self.castlingRights = rights
         return move
     }
 

    public typealias PlayerTurn = Color

    /// All of the conducted moves in the game.
    private var _moveHistory: [(move: Move, piece: Piece, capture: Piece?, kingAttackers: Bitboard, halfmoves: UInt)]

    /// All of the undone moves in the game.
    private var _undoHistory: [(move: Move, promotion: Piece?, kingAttackers: Bitboard)]


    /// Undoes the previous move and returns it, if any.
    private func _undoMove() -> Move? {
        guard let (move, piece, capture, attackers, halfmoves, rights) = _moveHistory.popLast() else {
            return nil
        }
        var captureSquare = move.end
