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 1f371ad006
commit 43437d7b7b
Signed by: kske
GPG Key ID: 8BEB13EC5DF7EF13

View File

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