MCPcopy Index your code
hub / github.com/coding-parrot/chess-engine / illegalEnPassant

Method illegalEnPassant

src/main/java/game/Board.java:262–283  ·  view source on GitHub ↗
(final Move move, final Piece king)

Source from the content-addressed store, hash-verified

260 }
261
262 private boolean illegalEnPassant(final Move move, final Piece king) {
263 if (move.piece.sameType(PieceType.PAWN) && move.captureMove && move.captureCell != move.target) {
264 //does not expose an attack on the king.
265 //The king is not discovered with the capture
266 //ignore the captured and capturing pawn, and then check if the ray is a check.
267 final Set<Piece> ignorePawns = new HashSet<>();
268 ignorePawns.add(move.piece);
269 ignorePawns.add(getPiece(move.captureCell.row, move.captureCell.col));
270 final Line line = new Line(move.captureCell, king.position);
271 if (line.isStraight) {
272 for (int row = king.position.row + line.rowDiff, col = king.position.col + line.colDiff; Utils.withinBoardLimits(row, col); row = row + line.rowDiff, col = col + line.colDiff) {
273 if (!isEmpty(row, col) && !ignorePawns.contains(getPiece(row, col))) {
274 final Piece piece = getPiece(row, col);
275 return piece.color != king.color && (piece.sameType(line.minorPieceType) || piece.sameType(PieceType.QUEEN));
276 } else if (move.target.equals(Cell.get(row, col))) {
277 break;
278 }
279 }
280 }
281 }
282 return false;
283 }
284
285 private Set<Cell> rayOfCheck(Piece king, Piece attacker) {
286 final Set<Cell> stopCheck = new HashSet<>();

Callers 1

getLegalMovesMethod · 0.95

Calls 6

sameTypeMethod · 0.95
getPieceMethod · 0.95
withinBoardLimitsMethod · 0.95
isEmptyMethod · 0.95
getMethod · 0.95
equalsMethod · 0.45

Tested by

no test coverage detected