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

Method castlingAllowance

src/main/java/game/Board.java:732–768  ·  view source on GitHub ↗
(Move move)

Source from the content-addressed store, hash-verified

730 }
731
732 private void castlingAllowance(Move move) {
733 if (move.piece.sameType(PieceType.KING)) {
734 final int color = move.piece.color.ordinal();
735 if (canCastle[color][0]) {
736 zobristHash ^= zobristCastle[color * 2];
737 }
738 if (canCastle[color][1]) {
739 zobristHash ^= zobristCastle[color * 2 + 1];
740 }
741 canCastle[color][1] = canCastle[color][0] = false;
742 //take castling into account
743 if (move.target.row == move.piece.position.row && Math.abs(move.piece.position.col - move.target.col) == 2) {
744 final int row = color * 7;
745 if (move.target.col == 6) {
746 makeMove(Move.get(getPiece(row, 7), Cell.get(row, 5), false));
747 } else {
748 makeMove(Move.get(getPiece(row, 0), Cell.get(row, 3), false));
749 }
750 }
751 } else {
752 for (int i = 0; i <= 1; i++) {
753 for (int j = 0; j <= 1; j++) {
754 final Cell corner = Cell.get(i * 7, j * 7);
755 if (move.piece.position.equals(corner) || (move.captureMove && move.captureCell.equals(corner))) {
756 if (canCastle[i][j]) {
757 if (move.piece.position.equals(Cell.get(i * 7, j * 7))) {
758 if (canCastle[i][j]) {
759 zobristHash ^= zobristCastle[i * 2 + j];
760 }
761 canCastle[i][j] = false;
762 }
763 }
764 }
765 }
766 }
767 }
768 }
769
770 private void markDraw(Move move) {
771 positions[positionIndex % positions.length] = zobristHash;

Callers 1

postMoveUpdatesMethod · 0.95

Calls 6

makeMoveMethod · 0.95
getMethod · 0.95
getPieceMethod · 0.95
getMethod · 0.95
sameTypeMethod · 0.80
equalsMethod · 0.45

Tested by

no test coverage detected