(final Board board, final Piece king, final Set<Move> kingMoves)
| 135 | } |
| 136 | |
| 137 | private static Move[] castlingMoves(final Board board, final Piece king, final Set<Move> kingMoves) { |
| 138 | final Move[] castleMoves = new Move[2]; |
| 139 | int castles = 0; |
| 140 | final int row = king.color.ordinal() * 7; |
| 141 | if (king.position.row == row) { |
| 142 | for (int i = 0; i <= 1; i++) { |
| 143 | if (board.canCastle[king.color.ordinal()][i]) { |
| 144 | final Piece rook = board.getPiece(row, i * 7); |
| 145 | if (rook != null && rook.sameType(PieceType.ROOK)) { |
| 146 | final int colDiff = i == 0 ? -1 : 1; |
| 147 | final int col = 4 + colDiff; |
| 148 | final boolean clear = board.isEmpty(row, col) |
| 149 | && kingMoves.stream() |
| 150 | .map(move -> move.target) |
| 151 | .anyMatch(cell -> Cell.get(row, col).equals(cell)); |
| 152 | final Cell kingCastleCell = Cell.get(row, col + colDiff); |
| 153 | if (clear && board.isEmpty(row, col + colDiff) && !getIllegalSquares(board, Color.opponent(king.color), Collections.singleton(kingCastleCell), kingCastleCell).contains(kingCastleCell)) { |
| 154 | if (i == 1 || board.isEmpty(row, 1)) { |
| 155 | castleMoves[castles++] = Move.get(king, Cell.get(row, 4 + 2 * colDiff), false); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | return castleMoves; |
| 163 | } |
| 164 | |
| 165 | private static boolean xRay(Move move, Board board, Piece king) { |
| 166 | final Line line = new Line(move.piece.position, move.target); |
no test coverage detected