diff --git a/src/chess/Pawn.java b/src/chess/Pawn.java index 4c210f1..0509c71 100644 --- a/src/chess/Pawn.java +++ b/src/chess/Pawn.java @@ -25,10 +25,14 @@ public class Pawn extends ChessPiece { ArrayList moves = new ArrayList(); if (isWhite) { moves.add(b.checkIfMoveValid(pawnForwardMoveValid(new Move(x, y + 1)), isWhite)); + moves.add(pawnAttack(new Move(x + 1, y + 1))); + moves.add(pawnAttack(new Move(x - 1, y + 1))); if (isFirstMove()) moves.add(b.checkIfMoveValid(new Move(x, y + 2), isWhite)); } else { moves.add(b.checkIfMoveValid(pawnForwardMoveValid(new Move(x, y - 1)), isWhite)); + moves.add(pawnAttack(new Move(x + 1, y - 1))); + moves.add(pawnAttack(new Move(x - 1, y - 1))); if (isFirstMove()) moves.add(b.checkIfMoveValid(new Move(x, y - 2), isWhite)); } @@ -54,6 +58,12 @@ public class Pawn extends ChessPiece { return prune(moves); } + private Move pawnAttack(Move m){ + if (b.get(m) != null && b.get(m).isWhite != isWhite) + return m; + return null; + } + private Move pawnForwardMoveValid(Move m){ // basically prevent a pawn from moving into the enemy head on. if (b.get(m) != null)