Rook bugfix

This commit is contained in:
Filip Znachor 2023-04-22 12:28:57 +02:00
parent 642d4e718b
commit 2476e1c6d3
3 changed files with 9 additions and 11 deletions

View file

@ -84,9 +84,9 @@ public class ChessboardMouseAdapter extends MouseAdapter {
if (piece != null) {
double totalScale = c.pieceScale * c.boardScale;
c.getRootPane().repaint(getRepaintRectangle(piece.getOverrideX(), piece.getOverrideY(), totalScale));
double pieceX = me.getX();
double pieceY = me.getY();
piece.setOverride(pieceX - 50 * totalScale, pieceY - 50 * totalScale);
double pieceX = me.getX() - 50 * totalScale;
double pieceY = me.getY() - 50 * totalScale;
piece.setOverride(pieceX, pieceY);
c.getRootPane().repaint(getRepaintRectangle(pieceX, pieceY, totalScale));
}
}

View file

@ -45,8 +45,8 @@ public class King extends AbstractPiece {
if(!chessboard.isEndangered(player, i, j)) setPossibleMove(moves, i, j);
}
}
if(checkCastling(-1)) setPossibleMove(moves, 1, y);
if(checkCastling(1)) setPossibleMove(moves, 6, y);
if(!attack && checkCastling(-1)) setPossibleMove(moves, 1, y);
if(!attack && checkCastling(1)) setPossibleMove(moves, 6, y);
return moves;
}

View file

@ -32,12 +32,10 @@ public class Rook extends AbstractPiece {
@Override
public boolean[][] getPossibleMoves(boolean attack) {
boolean[][] moves = new boolean[chessboard.SQUARE_COUNT][chessboard.SQUARE_COUNT];
int[] directions = new int[]{-1, 0, 1};
for (int xDirection : directions) {
for (int yDirection : directions) {
if((xDirection == 1 || xDirection == -1) && (yDirection == 1 || yDirection == -1)) continue;
tracePath(moves, xDirection, yDirection);
}
int[] xDirections = new int[]{1, 0, -1, 0};
int[] yDirections = new int[]{0, 1, 0, -1};
for (int i = 0; i < xDirections.length; i++) {
tracePath(moves, xDirections[i], yDirections[i]);
}
return moves;
}