|
|
|
|
@ -15,7 +15,11 @@ public class Board {
|
|
|
|
|
private boolean pawnDoubleStep;
|
|
|
|
|
private int xCoordinatePawn;
|
|
|
|
|
private int yCoordinatePawn;
|
|
|
|
|
//<<<<<<< HEAD
|
|
|
|
|
private boolean enPassant;
|
|
|
|
|
//=======
|
|
|
|
|
private boolean isGameOver = false;//flag for when a king is checkmate and no moves can be made anymore
|
|
|
|
|
//>>>>>>> branch 'master' of https://gitarero.ecam.fr/louise.berteloot/OOP_2A5_Project.git
|
|
|
|
|
|
|
|
|
|
private ArrayList<Board> previousStates;
|
|
|
|
|
|
|
|
|
|
@ -25,6 +29,7 @@ public class Board {
|
|
|
|
|
this.turnNumber = 0;
|
|
|
|
|
this.isWhiteTurn = true; // White starts first
|
|
|
|
|
this.previousStates = new ArrayList<>(); // Initialize the ArrayList
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getWidth() {
|
|
|
|
|
@ -55,6 +60,14 @@ public class Board {
|
|
|
|
|
return this.isWhiteTurn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isEnPassant() {
|
|
|
|
|
return this.enPassant;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setEnPassant(boolean enPassant) {
|
|
|
|
|
this.enPassant = enPassant;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void resetTurn() {
|
|
|
|
|
this.turnNumber = 0;
|
|
|
|
|
this.isWhiteTurn = true;
|
|
|
|
|
@ -202,11 +215,23 @@ public class Board {
|
|
|
|
|
// detects castling (piece is castling only if piecetype is king and distance between king and its move is of 2)
|
|
|
|
|
boolean isCastling = selectedPiece.getType() == PieceType.King && Math.abs(x - originalX) == 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (clickedPiece != null) {
|
|
|
|
|
System.out.println("Capturing piece at: " + x + ", " + y);
|
|
|
|
|
pieces.remove(clickedPiece);
|
|
|
|
|
} else {
|
|
|
|
|
if (enPassant == true && y == Math.abs(yCoordinatePawn-1) && x == xCoordinatePawn) {
|
|
|
|
|
pieces.remove(getPieceAt(xCoordinatePawn, yCoordinatePawn));
|
|
|
|
|
enPassant = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (selectedPiece.getType() == PieceType.Pawn && Math.abs(y - selectedY) == 2) {
|
|
|
|
|
pawnDoubleStep = true; //boolean to check if pawn has been moved 2 at start
|
|
|
|
|
xCoordinatePawn = x; //get its coordinates
|
|
|
|
|
yCoordinatePawn = y;
|
|
|
|
|
System.out.println("Pawn moved two squares to (" + xCoordinatePawn + ", " + yCoordinatePawn + ")");
|
|
|
|
|
} else {
|
|
|
|
|
pawnDoubleStep = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("Moving piece to: " + x + ", " + y);
|
|
|
|
|
@ -231,15 +256,6 @@ public class Board {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (selectedPiece.getType() == PieceType.Pawn && Math.abs(y - selectedY) == 2) {
|
|
|
|
|
pawnDoubleStep = true; //boolean to check if pawn has been moved 2 at start
|
|
|
|
|
xCoordinatePawn = x; //get its coordinates
|
|
|
|
|
yCoordinatePawn = y;
|
|
|
|
|
System.out.println("Pawn moved two squares to (" + xCoordinatePawn + ", " + yCoordinatePawn + ")");
|
|
|
|
|
} else {
|
|
|
|
|
pawnDoubleStep = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
turnNumber++;
|
|
|
|
|
isWhiteTurn = !isWhiteTurn;
|
|
|
|
|
|
|
|
|
|
|