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

Method pinnedToKing

src/main/java/game/Board.java:307–330  ·  view source on GitHub ↗
(Piece king)

Source from the content-addressed store, hash-verified

305 }
306
307 private Map<Piece, Piece> pinnedToKing(Piece king) {
308 final Map<Piece, Piece> blockingChecks = new HashMap<>();
309 final int kingRow = king.position.row, kingCol = king.position.col;
310 final Color color = king.color;
311 for (int rowDiff = -1; rowDiff <= 1; rowDiff++) {
312 for (int colDiff = -1; colDiff <= 1; colDiff++) {
313 if (!(rowDiff == 0 && colDiff == 0)) {
314 final PieceType type = rowDiff == 0 || colDiff == 0 ? PieceType.ROOK : PieceType.BISHOP;
315 final Reference<Piece> blockingPiece = new Reference<>();
316 for (int k = 1; k < 8; k++) {
317 final int row = kingRow + (rowDiff * k), col = kingCol + (colDiff * k);
318 if (Utils.withinBoardLimits(row, col)) {
319 if (stopFindingPin(row, col, color, blockingPiece, blockingChecks, PieceType.QUEEN, type)) {
320 break;
321 }
322 } else {
323 break;
324 }
325 }
326 }
327 }
328 }
329 return blockingChecks;
330 }
331
332 public boolean stopFindingPin(int row, int col, Color color,
333 Reference<Piece> blockingPiece, Map<Piece, Piece> blockingChecks,

Callers 1

getLegalMovesMethod · 0.95

Calls 2

withinBoardLimitsMethod · 0.95
stopFindingPinMethod · 0.95

Tested by

no test coverage detected