Improved Pawn possible moves and added change

This commit is contained in:
Filip Znachor 2023-04-17 11:19:13 +02:00
parent 6b20f36d15
commit c5a3eca894

View file

@ -31,9 +31,19 @@ public class Pawn extends AbstractPiece {
public boolean[][] getPossibleMoves() {
boolean[][] moves = new boolean[chessboard.SQUARE_COUNT][chessboard.SQUARE_COUNT];
int directionY = color == PieceColor.BLACK ? 1 : -1;
setPossibleMove(moves, x, y + directionY);
for(int i=-1; i<=1; i++) {
IPiece piece = chessboard.getPiece(new PiecePosition(x+i, y+directionY));
if((i != 0 && piece != null) || (i == 0 && piece == null)) setPossibleMove(moves, x+i, y+directionY);
}
if(moveCount == 0 && chessboard.getPiece(new PiecePosition(x, y+directionY)) == null) setPossibleMove(moves, x, y + directionY*2);
return moves;
}
@Override
public boolean move(PiecePosition pos) {
boolean result = super.move(pos);
int changeY = color == PieceColor.WHITE ? 0 : chessboard.SQUARE_COUNT-1;
if(y == changeY) new Queen(chessboard, x, y, color);
return result;
}
}