52 lines
1.8 KiB
Java
52 lines
1.8 KiB
Java
package backend;
|
|
|
|
public class MovementCapabilities {
|
|
public boolean enPassant(Piece piece, int x, int y, Board board) {
|
|
if (piece.getType() != PieceType.Pawn) {
|
|
return false;
|
|
}
|
|
|
|
int currentX = piece.getX();
|
|
int currentY = piece.getY();
|
|
boolean isWhite = piece.isWhite();
|
|
int direction = isWhite ? -1:1;
|
|
|
|
System.out.println("Checking en passant for pawn at " + currentX + "," + currentY + " to " + x + "," + y);
|
|
|
|
|
|
if (Math.abs(x - currentX) == 1 && y == currentY + direction && board.getPiece(x, y)== null) {
|
|
Move last = board.getLastMove();
|
|
|
|
System.out.println("Last move is " + last);
|
|
|
|
if (last != null) {
|
|
Piece lastMoved = last.getPieceMoved();
|
|
System.out.println("Last moved: " + lastMoved.getType() + " at " + last.getOldX() + "," + last.getOldY() + " to " + last.getNewX() + "," + last.getNewY());
|
|
|
|
boolean isPawn = lastMoved != null && lastMoved.getType()== PieceType.Pawn ;
|
|
boolean isOpp = lastMoved.isWhite() != isWhite ;
|
|
boolean movedTwo = Math.abs(last.getOldY() - last.getNewY()) == 2;
|
|
boolean sameX = last.getNewX()== x;
|
|
boolean sameY = last.getNewY()== currentY;
|
|
|
|
System.out.println("🔍 isPawn: " + isPawn);
|
|
System.out.println("🔍 isEnemy: " + isOpp);
|
|
System.out.println("🔍 movedTwo: " + movedTwo);
|
|
System.out.println("🔍 sameY: " + sameY);
|
|
System.out.println("🔍 sameX: " + sameX);
|
|
|
|
if (isPawn && isOpp && movedTwo && sameX && sameY) {
|
|
System.out.println("✨ En passant conditions met!");
|
|
board.movePiece(currentX, currentY, x, y);
|
|
//board.setPiece(false, null, x, currentY);
|
|
board.removePiece(x, currentY);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|