fix error of en passant
This commit is contained in:
parent
45144b42e7
commit
e7a64f69a7
|
|
@ -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
|
||||
|
|
@ -232,6 +237,11 @@ public class Board {
|
|||
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<int[]> 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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue