en passant but it pass juste il bouffe pas
This commit is contained in:
parent
4b260b4866
commit
a7edd56e68
|
|
@ -12,6 +12,8 @@ public class Board {
|
||||||
private int selectedY = -1;
|
private int selectedY = -1;
|
||||||
private boolean[][] highlightedSquares;
|
private boolean[][] highlightedSquares;
|
||||||
private Stack<String[]> undoStack = new Stack<>();
|
private Stack<String[]> undoStack = new Stack<>();
|
||||||
|
private int enPassantCol = -1;
|
||||||
|
private int enPassantRow = -1;
|
||||||
|
|
||||||
public Board(int colNum, int lineNum) {
|
public Board(int colNum, int lineNum) {
|
||||||
this.width = colNum; // col move x
|
this.width = colNum; // col move x
|
||||||
|
|
@ -289,6 +291,21 @@ public class Board {
|
||||||
// Captures
|
// Captures
|
||||||
checkPawnCapture(moves, pawn, x, y, direction, -1);
|
checkPawnCapture(moves, pawn, x, y, direction, -1);
|
||||||
checkPawnCapture(moves, pawn, x, y, direction, 1);
|
checkPawnCapture(moves, pawn, x, y, direction, 1);
|
||||||
|
|
||||||
|
// En passant captures
|
||||||
|
if ((pawn.isWhite() && y == 3) || (!pawn.isWhite() && y == 4)) {
|
||||||
|
// Check both sides
|
||||||
|
for (int dx : new int[]{-1, 1}) {
|
||||||
|
int captureX = x + dx;
|
||||||
|
// If there's a valid en passant opportunity
|
||||||
|
if (captureX == enPassantCol && y + direction == enPassantRow) {
|
||||||
|
Move enPassantMove = new Move(x, y, captureX, y + direction);
|
||||||
|
// Set the captured piece (the pawn that just moved)
|
||||||
|
enPassantMove.setCapturedPiece(board[captureX][y]);
|
||||||
|
moves.add(enPassantMove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkPawnCapture(ArrayList<Move> moves, Piece pawn, int x, int y, int dir, int dx) {
|
private void checkPawnCapture(ArrayList<Move> moves, Piece pawn, int x, int y, int dir, int dx) {
|
||||||
|
|
@ -403,7 +420,7 @@ public class Board {
|
||||||
public Board(Board board) {
|
public Board(Board board) {
|
||||||
//TODO
|
//TODO
|
||||||
|
|
||||||
}// test
|
}
|
||||||
|
|
||||||
public void playMove(Move move) {
|
public void playMove(Move move) {
|
||||||
// Save current state before move for undo
|
// Save current state before move for undo
|
||||||
|
|
@ -416,11 +433,36 @@ public class Board {
|
||||||
piece.x = move.getToX();
|
piece.x = move.getToX();
|
||||||
piece.y = move.getToY();
|
piece.y = move.getToY();
|
||||||
|
|
||||||
|
// Reset en passant tracking at the start of each move
|
||||||
|
enPassantCol = -1;
|
||||||
|
enPassantRow = -1;
|
||||||
|
|
||||||
|
// Check if this is a pawn making a double move
|
||||||
|
if (piece.getType() == PieceType.Pawn &&
|
||||||
|
Math.abs(move.getFromY() - move.getToY()) == 2) {
|
||||||
|
enPassantCol = move.getToX();
|
||||||
|
enPassantRow = (move.getFromY() + move.getToY()) / 2; // Middle square
|
||||||
|
}
|
||||||
|
|
||||||
if (piece.getType() == PieceType.Pawn &&
|
if (piece.getType() == PieceType.Pawn &&
|
||||||
(piece.getY() == 0 || piece.getY() == height - 1)) {
|
(piece.getY() == 0 || piece.getY() == height - 1)) {
|
||||||
board[piece.getX()][piece.getY()] = promotePawn(piece.isWhite(), piece.getX(), piece.getY());
|
board[piece.getX()][piece.getY()] = promotePawn(piece.isWhite(), piece.getX(), piece.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle en passant capture
|
||||||
|
if (piece.getType() == PieceType.Pawn &&
|
||||||
|
move.getToX() != move.getFromX() &&
|
||||||
|
board[move.getToX()][move.getToY()] == null) {
|
||||||
|
// This is a diagonal pawn move to an empty square - must be en passant
|
||||||
|
|
||||||
|
// Capture the pawn
|
||||||
|
Piece capturedPawn = board[move.getToX()][move.getFromY()];
|
||||||
|
move.setCapturedPiece(capturedPawn);
|
||||||
|
|
||||||
|
// Remove the captured pawn
|
||||||
|
board[move.getToX()][move.getFromY()] = null;
|
||||||
|
}
|
||||||
|
|
||||||
turn++;
|
turn++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue