Fixed / added positional awareness in pawn movements
This commit is contained in:
parent
32446d4652
commit
616ed129a1
@ -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
|
||||||
|
Reference in New Issue
Block a user