en oassant working
This commit is contained in:
parent
d3dbd9fdb7
commit
22eea2b7e9
|
|
@ -15,6 +15,7 @@ public class Board {
|
|||
private boolean pawnDoubleStep;
|
||||
private int xCoordinatePawn;
|
||||
private int yCoordinatePawn;
|
||||
private boolean enPassant;
|
||||
|
||||
private ArrayList<Board> previousStates;
|
||||
|
||||
|
|
@ -24,6 +25,7 @@ public class Board {
|
|||
this.turnNumber = 0;
|
||||
this.isWhiteTurn = true; // White starts first
|
||||
this.previousStates = new ArrayList<>(); // Initialize the ArrayList
|
||||
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
|
|
@ -54,6 +56,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;
|
||||
|
|
@ -196,11 +206,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);
|
||||
|
|
@ -224,15 +246,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;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import java.util.ArrayList;
|
|||
public class MoveConditions {
|
||||
private Piece piece;
|
||||
private Board board;
|
||||
//private boolean enPassant;
|
||||
|
||||
|
||||
public MoveConditions(Piece piece, Board board) {
|
||||
this.piece = piece;
|
||||
|
|
@ -58,6 +60,7 @@ public class MoveConditions {
|
|||
sidePawn.isWhite() != isWhite) {
|
||||
|
||||
moves.add(new int[]{sideX, y + dir}); // capture en passant square
|
||||
board.setEnPassant(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue