Castling is fully functional, i needed to split long and short, idk it

works so thats a win
This commit is contained in:
hugomanipoud2 2025-05-22 21:27:00 +02:00
parent ee44342e4f
commit 248fdbda92
1 changed files with 3 additions and 7 deletions

View File

@ -20,24 +20,20 @@ public class Move {
//helper function to change the coordinates of a piece //helper function to change the coordinates of a piece
public void movePiece(int selectX, int selectY, int toX, int toY) { public void movePiece(int selectX, int selectY, int toX, int toY) {
Piece movingPiece = null ; // initializing variable to work with and store it Piece movingPiece = null ; // initializing variable to work with and store it
PieceType type = null;
boolean color = true;
int turnNb = board.getTurnNumber(); // Increment turn number and change turn color; // Increment turn number and change turn color int turnNb = board.getTurnNumber(); // Increment turn number and change turn color; // Increment turn number and change turn color
for (Piece piece : pieces) { // iterate trough all pieces for (Piece piece : pieces) { // iterate trough all pieces
if(piece.getX() == selectX && piece.getY() == selectY) { // if the coordinates selected and the coordinate of a piece on the board matches, the loop will activate if(piece.getX() == selectX && piece.getY() == selectY) { // if the coordinates selected and the coordinate of a piece on the board matches, the loop will activate
movingPiece = piece; //storing in memory the piece movingPiece = piece; //storing in memory the piece
type = movingPiece.getType();
color = movingPiece.isWhite();
if (board.isHighlighted(toX, toY)) { // only allow the value of cases that are set to true as isHghlighted is a bool function if (board.isHighlighted(toX, toY)) { // only allow the value of cases that are set to true as isHghlighted is a bool function
if (board.isAPieceThere(toX, toY)){//checking if a piece is at the arrival coordinates if (board.isAPieceThere(toX, toY)){//checking if a piece is at the arrival coordinates
needPieceDeletion(toX, toY); //if a piece is at arrival coord, remove the piece needPieceDeletion(toX, toY); //if a piece is at arrival coord, remove the piece
} }
specialMoves.pawnPromotion(movingPiece, toY); specialMoves.pawnPromotion(movingPiece, toY);
specialMoves.castling(movingPiece, toX, toY); specialMoves.castlingShort(movingPiece, toX, toY);
specialMoves.castlingLong(movingPiece, toX, toY);
movingPiece.setX(toX); // change coordinates to the new coordinate movingPiece.setX(toX); // change coordinates to the new coordinate
movingPiece.setY(toY); movingPiece.setY(toY);
board.setTurnNb(turnNb + 1); board.setTurnNb(turnNb + 1);