From 43437d7b7b7a554c77abdfc650e8d41bb1f4b6c4 Mon Sep 17 00:00:00 2001 From: kske 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