Compare commits

...

2 Commits

Author SHA1 Message Date
leahb 2aabc3b0f1 Merge branch 'master' of
https://gitarero.ecam.fr/louise.berteloot/OOP_2A5_Project.git
2025-05-19 21:04:46 +02:00
leahb 22eea2b7e9 en oassant working 2025-05-19 21:03:14 +02:00
2 changed files with 31 additions and 12 deletions

View File

@ -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);
@ -230,15 +255,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;

View File

@ -5,8 +5,10 @@ import java.util.ArrayList;
public class MoveConditions {
private Piece piece;
private Board board;
//private boolean enPassant;
public MoveConditions(Piece piece, Board board) {
public MoveConditions(Piece piece, Board board) {
this.piece = piece;
this.board = board;
}
@ -58,6 +60,7 @@ public class MoveConditions {
sidePawn.isWhite() != isWhite) {
moves.add(new int[]{sideX, y + dir}); // capture en passant square
board.setEnPassant(true);
}
}
}