This commit is contained in:
lrave 2025-05-22 18:27:31 +02:00
parent c464c6dede
commit 3c9da5de45
1 changed files with 8 additions and 8 deletions

View File

@ -193,16 +193,16 @@ public class Board {
}
// Handle en passant capture
if (pieceToMove.getType() == PieceType.Pawn && board[x][y] == null && x != selectedX) {
board[x][selectedY] = null;
if (pieceToMove.getType() == PieceType.Pawn && board[x][y] == null && x != selectedX) { // only case where a pawn can change an x while going towards an empty tile is if en passant is happening
board[x][selectedY] = null; //deletes the pawn subject to the en passant (previous Y coordinate current X coordinate)
}
board[x][y] = new Piece(x, y, pieceToMove.getType(), pieceToMove.isWhite());
board[x][y] = new Piece(x, y, pieceToMove.getType(), pieceToMove.isWhite()); //Re-create the piece to move at the move end location and delete it at initial position
board[selectedX][selectedY] = null;
board[x][y].setMoved(true);
board[x][y].setMoved(true); // Set tile coordinates as has moved (if later on another piece gets to that spot it would mean that it would have moved anyway)
if (pieceToMove.getType() == PieceType.Pawn && Math.abs(y - selectedY) == 2) {
lastDoubleStepPawn = new int[]{x, y};
lastDoubleStepPawn = new int[]{x, y};
} else {
lastDoubleStepPawn = null;
}
@ -210,7 +210,7 @@ public class Board {
incrementTurn();
}
selectedX = -1;
selectedX = -1; //reset selected as impossible coordinates (unselect)
selectedY = -1;
highlightedPositions.clear();
clearConsole();
@ -232,11 +232,11 @@ public class Board {
return false;
}
public boolean isInBounds(int x, int y) {
public boolean isInBounds(int x, int y) { // set boundaries of piece moves
return x >= 0 && x < width && y >= 0 && y < height;
}
private ArrayList<int[]> getValidMoves(Piece piece) {
private ArrayList<int[]> getValidMoves(Piece piece) { //lists all moves available for selected piece (list of moves is set in Piece class)
return piece.getValidMoves(this);
}