Fixed / added positional awareness in pawn movements

This commit is contained in:
Kai S. K. Engelbart 2019-07-02 15:16:18 +02:00
parent b9882b43c6
commit e9105fe9eb
1 changed files with 7 additions and 8 deletions

View File

@ -17,14 +17,13 @@ public class Pawn extends Piece {
@Override
public boolean isValidMove(Move move) {
// TODO: Positioning, en passant
if (getColor() == Color.WHITE)
return ((move.xDist == 0 && move.yDist > 0 && move.yDist <= 2) || (move.xDist == 1 && move.yDist == 1))
&& move.ySign == -1 && isFreePath(move);
else return ((move.xDist == 0 && move.yDist > 0 && move.yDist <= 2) || (move.xDist == 1 && move.yDist == 1))
&& move.ySign == 1
&& isFreePath(move);
// TODO: en passant
boolean step = move.isVertical() && move.yDist == 1;
boolean doubleStep = move.isVertical() && move.yDist == 2;
boolean strafe = move.isDiagonal() && move.xDist == 1;
if (getColor() == Color.WHITE) doubleStep &= move.yPos == 6;
else doubleStep &= move.yPos == 1;
return (step ^ doubleStep ^ strafe) && move.ySign == (getColor() == Color.WHITE ? -1 : 1) && isFreePath(move);
}
@Override