en passant OK
This commit is contained in:
parent
4000184705
commit
0cf7e16c45
|
|
@ -11,6 +11,10 @@ public class Board {
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
private int turnNumber;
|
private int turnNumber;
|
||||||
|
private boolean lastTurnPawnTwo = false;//for en passant
|
||||||
|
private int xTwo;
|
||||||
|
private int yTwo;
|
||||||
|
private boolean enPassant = false;
|
||||||
|
|
||||||
public Board(int colNum, int lineNum) {
|
public Board(int colNum, int lineNum) {
|
||||||
this.colNum = colNum;
|
this.colNum = colNum;
|
||||||
|
|
@ -162,9 +166,25 @@ public class Board {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(((this.positionOccupied(x, y) == false || pieces.get(whatPiece(x,y)).isWhite() != pieces.get(whatPiece(this.x,this.y)).isWhite())) && (highlights)) {//moves the piece only if the position selected is not occupied by a piece of the same color
|
if(((this.positionOccupied(x, y) == false || pieces.get(whatPiece(x,y)).isWhite() != pieces.get(whatPiece(this.x,this.y)).isWhite())) && (highlights)) {//moves the piece only if the position selected is not occupied by a piece of the same color
|
||||||
|
if (enPassant) {
|
||||||
|
this.pieces.remove(whatPiece(xTwo,yTwo));
|
||||||
|
enPassant = false;
|
||||||
|
}
|
||||||
|
|
||||||
int indexPiece = this.whatPiece(this.x, this.y);
|
int indexPiece = this.whatPiece(this.x, this.y);
|
||||||
|
|
||||||
|
if (pieces.get(indexPiece).getType() == PieceType.Pawn && Math.abs(this.y-y)==2) {//save the number of the turn at which a pawn moved by two
|
||||||
|
lastTurnPawnTwo = true;
|
||||||
|
xTwo = x;
|
||||||
|
yTwo = y;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lastTurnPawnTwo = false;
|
||||||
|
}
|
||||||
|
|
||||||
pieces.get(indexPiece).setX(x);
|
pieces.get(indexPiece).setX(x);
|
||||||
pieces.get(indexPiece).setY(y);
|
pieces.get(indexPiece).setY(y);
|
||||||
|
|
||||||
this.turnNumber +=1;
|
this.turnNumber +=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -352,13 +372,24 @@ public class Board {
|
||||||
boolean highlight = false;
|
boolean highlight = false;
|
||||||
if (positionOccupied(this.x,this.y)) { //check if we have selected a position with a piece
|
if (positionOccupied(this.x,this.y)) { //check if we have selected a position with a piece
|
||||||
int indexPieceSelect = whatPiece(this.x,this.y);
|
int indexPieceSelect = whatPiece(this.x,this.y);
|
||||||
|
|
||||||
if (pieces.get(indexPieceSelect).getType() == PieceType.Pawn) {//highlight for pawns
|
if (pieces.get(indexPieceSelect).getType() == PieceType.Pawn) {//highlight for pawns
|
||||||
|
|
||||||
if (pieces.get(indexPieceSelect).isWhite()) {//white pawns
|
if (pieces.get(indexPieceSelect).isWhite()) {//white pawns
|
||||||
|
|
||||||
|
if (lastTurnPawnTwo) {//en passant
|
||||||
|
if(yTwo == this.y && Math.abs(xTwo - this.x) == 1 && x == xTwo && y == this.y - 1) {
|
||||||
|
highlight = true;
|
||||||
|
enPassant = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(y == this.y-1) {
|
if(y == this.y-1) {
|
||||||
if((x == this.x) && (positionOccupied(x,y)==false)) {//advance one case
|
if((x == this.x) && (positionOccupied(x,y)==false)) {//advance one case
|
||||||
highlight = true;
|
highlight = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if((Math.abs(x-this.x) == 1) && (positionOccupied(x,y)) && pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()) {//highlight the piece in diagonal, if existing and of another color
|
if((Math.abs(x-this.x) == 1) && (positionOccupied(x,y)) && pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()) {//highlight the piece in diagonal, if existing and of another color
|
||||||
highlight = true;
|
highlight = true;
|
||||||
}
|
}
|
||||||
|
|
@ -370,9 +401,18 @@ public class Board {
|
||||||
|
|
||||||
if (pieces.get(indexPieceSelect).isWhite() == false) {//black pawns
|
if (pieces.get(indexPieceSelect).isWhite() == false) {//black pawns
|
||||||
if(y == this.y+1) {
|
if(y == this.y+1) {
|
||||||
|
|
||||||
|
if (lastTurnPawnTwo) {//en passant
|
||||||
|
if(yTwo == this.y && Math.abs(xTwo - this.x) == 1 && x == xTwo && y == this.y+1) {
|
||||||
|
highlight = true;
|
||||||
|
enPassant = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if((x == this.x) && (positionOccupied(x,y)==false)) {
|
if((x == this.x) && (positionOccupied(x,y)==false)) {
|
||||||
highlight = true;
|
highlight = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((Math.abs(x-this.x) == 1) && (positionOccupied(x,y)) && pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()) {
|
if((Math.abs(x-this.x) == 1) && (positionOccupied(x,y)) && pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()) {
|
||||||
highlight = true;
|
highlight = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue