             while let targetLocation = Location.ifValid(file: file, rank: rank) {
                 if let occupant = board[targetLocation] {
                     if occupant.player != player {
-                        result.append(.capture(piece: piece,
-                                               from: location,
-                                               to: targetLocation,
-                                               captured: occupant.kind))
+                        moves.append(.capture(piece: piece,
+                                              from: location,
+                                              to: targetLocation,
+                                              captured: occupant.kind))
                     }
                     break
                 }
                 else {
-                    result.append(.move(piece: piece, from: location, to: targetLocation))
+                    moves.append(.move(piece: piece, from: location, to: targetLocation))
                     file = file + h
                     rank = rank + v
                 }
             }
         }
-
-        return result
     }
 
     // MARK:- Pawn


                if to.rank == promotionRank {
                    for kind in PieceKind.promotionKinds {
                        result.append(.promote(player: player,
                                               from: location,
                                               to: to,
                                               promoted: kind))
                    }
                }
                else {
                    result.append(.move(piece: piece, from: location, to: to))

                    let startRank = Position.pawnStartRank(player: player)
                    if rank == startRank {
                        let jumpRank = startRank + 2 * moveDirection
                        if board.isEmpty(file: file, rank: jumpRank) {
                            result.append(.move(piece: piece,
                                                from: location,
                                                to: Location(file, jumpRank)))
                        }
                    }
                }

    /// the player's king in check or that it doesn't result
    /// in a repeated board position.
    private func possibleMoves() -> [Move] {
        let piecesLocations = board.pieces(player: toMove)

        var moves = [Move]()
        moves.reserveCapacity(200)
        for (piece, location) in piecesLocations {
            addMoves(piece: piece, location: location, to: &moves)
        }
        return moves
    }

    /// Add moves for a `Piece` at the given `Location` to an array.
    private func addMoves(piece: Piece, location: Location,
                          to moves: inout [Move]) {
        switch piece.kind {
        case .pawn:   addPawnMoves(piece: piece, location: location, to: &moves)
        case .knight: addKnightMoves(piece: piece, location: location, to: &moves)
        case .rook:   addRookMoves(piece: piece, location: location, to: &moves)
        case .bishop: addBishopMoves(piece: piece, location: location, to: &moves)
        case .queen:  addQueenMoves(piece: piece, location: location, to: &moves)
        case .king:   addKingMoves(piece: piece, location: location, to: &moves)
        }
    }

    private func addSlideMoves(piece: Piece, location: Location, vectors: [(Int, Int)],
                               to moves: inout [Move]) {
        let player = piece.player

        for (h, v) in vectors {
            var file = location.file + h
