This commit is contained in:
lrave 2025-05-22 18:13:37 +02:00
parent 4815212520
commit c464c6dede
1 changed files with 12 additions and 12 deletions

View File

@ -168,18 +168,18 @@ public class Board {
}
}
if (valid) {
Piece pieceToMove = board[selectedX][selectedY];
if (valid) { //if the tile we have selected is a highlighted position proceed with move through the following :
Piece pieceToMove = board[selectedX][selectedY]; // The previously selected X and Y coordinates contain a piece which is now the piece we want to move
if (pieceToMove.getType() == PieceType.King && Math.abs(x - selectedX) == 2) {
if (pieceToMove.getType() == PieceType.King && Math.abs(x - selectedX) == 2) { // only case where king can move 2 tiles away is through castling so checks if it is the case.
y = selectedY;
if (x == 6) {
board[5][y] = board[7][y];
board[7][y] = null;
board[5][y].setMoved(true);
board[5][y].setX(5);
if (x == 6) { //King side castling
board[5][y] = board[7][y]; //Final position of rook becomes a rook tile
board[7][y] = null; // Initial position becomes empty
board[5][y].setMoved(true); //Manually change the moved status as the rook is not subject to it since it's technically not the piece to be moved
board[5][y].setX(5); // For same reason, in order to display correctly on the interface
board[5][y].setY(y);
} else if (x == 2) {
} else if (x == 2) { // Queen side castling
board[3][y] = board[0][y];
board[0][y] = null;
board[3][y].setMoved(true);
@ -187,9 +187,9 @@ public class Board {
board[3][y].setY(y);
}
}
if (pieceToMove.getType() == PieceType.Pawn && (y == 0 || y == 7)) {
PieceType promotionType = askPromotionChoice(pieceToMove.isWhite());
board[x][y] = new Piece(x, y, promotionType, pieceToMove.isWhite());
if (pieceToMove.getType() == PieceType.Pawn && (y == 0 || y == 7)) { // When a pawn reaches an end line (no need to check color as they can only move forward so a pawn reaching 0 or 7 necessarly needs promotion)
PieceType promotionType = askPromotionChoice(pieceToMove.isWhite()); // color as input to be able to replace with piece of accurate color.
board[x][y] = new Piece(x, y, promotionType, pieceToMove.isWhite()); // The position of the previous pawn is replaced by the pawn defined in askPromotionChoice
}
// Handle en passant capture