From e9105fe9eb8511ed25f4fb86878c69cd1709b6e4 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 2 Jul 2019 15:16:18 +0200 Subject: [PATCH] Fixed / added positional awareness in pawn movements --- src/dev/kske/chess/piece/Pawn.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/dev/kske/chess/piece/Pawn.java b/src/dev/kske/chess/piece/Pawn.java index a66fc89..b35ff59 100644 --- a/src/dev/kske/chess/piece/Pawn.java +++ b/src/dev/kske/chess/piece/Pawn.java @@ -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