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

Method longRangeUpdate

src/main/java/game/Board.java:489–537  ·  view source on GitHub ↗
(final Cell affectedCell,
                                 final Consumer<Piece> initialOperation,
                                 final BiConsumer<Move, Cell> moveUpdateOperation,
                                 final BiConsumer<Move, Cell> guardUpdateOperation)

Source from the content-addressed store, hash-verified

487 }
488
489 private void longRangeUpdate(final Cell affectedCell,
490 final Consumer<Piece> initialOperation,
491 final BiConsumer<Move, Cell> moveUpdateOperation,
492 final BiConsumer<Move, Cell> guardUpdateOperation) {
493 for (int i = -1; i <= 1; i++) {
494 for (int j = -1; j <= 1; j++) {
495 final PieceType type = (i == 0 || j == 0) ? PieceType.ROOK : PieceType.BISHOP;
496 if (i != 0 || j != 0) {
497 for (int k = 0; k < 8; k++) {
498 final int row = affectedCell.row + i * k;
499 final int col = affectedCell.col + j * k;
500 if (Utils.withinBoardLimits(row, col)) {
501 if (!isEmpty(row, col)) {
502 final Piece piece = getPiece(row, col);
503 if (piece.sameType(PieceType.QUEEN) || piece.sameType(type)) {
504 if (moves.get(piece.position) != null) {
505 initialOperation.accept(piece);
506 for (int l = 1; l < 8 - k; l++) {
507 final int clearedRow = affectedCell.row - i * l;
508 final int clearedCol = affectedCell.col - j * l;
509 if (Utils.withinBoardLimits(clearedRow, clearedCol)) {
510 final Cell visibleCell = Cell.get(clearedRow, clearedCol);
511 if (isEmpty(clearedRow, clearedCol)) {
512 moveUpdateOperation.accept(Move.get(piece, visibleCell, false), piece.position);
513 } else {
514 final Piece nowVisiblePiece = getPiece(clearedRow, clearedCol);
515 if (nowVisiblePiece.color.equals(piece.color)) {
516 guardUpdateOperation.accept(Move.get(piece, visibleCell, false), piece.position);
517 } else {
518 moveUpdateOperation.accept(Move.get(piece, visibleCell, true), piece.position);
519 }
520 break;
521 }
522 } else {
523 break;
524 }
525 }
526 }
527 }
528 break;
529 }
530 } else {
531 break;
532 }
533 }
534 }
535 }
536 }
537 }
538
539 private void updateForBlockedCell(final Move move) {
540 final Cell affectedCell = move.target;

Callers 2

updateForClearCellMethod · 0.95
updateForBlockedCellMethod · 0.95

Calls 7

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

Tested by

no test coverage detected