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

Method getMovesWithinPin

src/main/java/game/Board.java:244–260  ·  view source on GitHub ↗
(Map.Entry<Piece, Piece> pinnedEntry)

Source from the content-addressed store, hash-verified

242 }
243
244 private List<Move> getMovesWithinPin(Map.Entry<Piece, Piece> pinnedEntry) {
245 final Piece pinnedPiece = pinnedEntry.getKey();
246 final Piece attacker = pinnedEntry.getValue();
247 final Piece king = getKing(pinnedPiece.color);
248 final Set<Move> moves = getMoveList(pinnedPiece);
249 final Line line = new Line(pinnedPiece.position, attacker.position);
250 final Line inverse = new Line(pinnedPiece.position, king.position);
251 if (line.isStraight) {
252 return moves.stream().filter(move -> {
253 final Line otherLine = new Line(move.piece.position, move.target);
254 final boolean towardsAttacker = otherLine.isStraight && otherLine.rowDiff == line.rowDiff && otherLine.colDiff == line.colDiff;
255 final boolean towardsKing = otherLine.isStraight && otherLine.rowDiff == inverse.rowDiff && otherLine.colDiff == inverse.colDiff;
256 return towardsAttacker || towardsKing;
257 }).collect(Collectors.toList());
258 }
259 return new ArrayList<>();
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) {

Callers

nothing calls this directly

Calls 2

getKingMethod · 0.95
getMoveListMethod · 0.95

Tested by

no test coverage detected