diff --git a/src/backend/Board.java b/src/backend/Board.java index e56e970..9a6ce07 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -14,6 +14,8 @@ public class Board { private boolean enPassant; private int pawnX; private int pawnY; + private int enPassantX; + private int enPassantY; private boolean whiteRookLeft; private boolean whiteRookRight; private boolean blackRookLeft; @@ -36,6 +38,8 @@ public class Board { enPassant = false; pawnX = -1; pawnY = -1; + enPassantX = -1; + enPassantY = -1; whiteRookLeft = false; whiteRookRight = false; blackRookLeft = false; @@ -73,6 +77,8 @@ public class Board { enPassant = false; pawnX = -1; pawnY = -1; + enPassantX = -1; + enPassantY = -1; whiteRookLeft = false; whiteRookRight = false; blackRookLeft = false; @@ -182,7 +188,6 @@ public class Board { // a piece is already selected (so the new click is where the user wants to move the piece) else { Move move = new Move(this.x,this.y,x,y); - MoveCalculator legalMoves = new MoveCalculator(this.board); // if the new location is the same as before, de-selects the piece and no move happens if (this.x == x && this.y == y || board[this.y][this.x] == null) { this.x = -1; @@ -191,9 +196,9 @@ public class Board { // the new location is highlighted, meaning it is a legal displacement else if (isHighlighted(x,y)) { // handling en passant - if (enPassant == true && board[this.y][this.x].getType() == PieceType.Pawn && x == legalMoves.getEnPassantX() && y == legalMoves.getEnPassantY()) { - playMove(move); + if (this.enPassant == true && board[this.y][this.x].getType() == PieceType.Pawn && x == enPassantX && y == enPassantY) { board[pawnY][pawnX] = null; + playMove(move); } // castling to the left @@ -228,10 +233,15 @@ public class Board { else { // verify if the pawn goes two steps forward (to know if en passant will be possible for the opponent) if (board[this.y][this.x].getType() == PieceType.Pawn && (y == this.y+2 || y == this.y-2)) { - enPassant =true; + enPassant = true; pawnX = x; pawnY = y; } + else { + enPassant = false; + pawnX = -1; + pawnX = -1; + } // check if rooks or kings are beeing moved to enable (or not) castling later if (board[this.y][this.x].getType() == PieceType.Rook) { @@ -336,6 +346,8 @@ public class Board { ArrayList moves = legalMoves.getMove(board[this.y][this.x].getType(), board[this.y][this.x].isWhite(), this.x, this.y, king, rookRight, rookLeft, enPassant, pawnX, pawnY); this.castlingLeft = legalMoves.getCastlingLeft(); this.castlingRight = legalMoves.getCastlingRight(); + this.enPassantX = legalMoves.getEnPassantX(); + this.enPassantY = legalMoves.getEnPassantY(); for (int i = 0; i < moves.size(); i++) { if (x == moves.get(i)[0] && y == moves.get(i)[1]) { return true;