package com.nullprogram.chess.pieces;

import java.util.ArrayList;

import com.nullprogram.chess.Position;
import com.nullprogram.chess.Piece;
import com.nullprogram.chess.Board;

public class Pawn extends Piece {
    public Pawn(Side side) {
        super(side);
    }

    public ArrayList<Position> getMoves() {
        ArrayList<Position> list = new ArrayList<Position>();
        Board b = getBoard();
        Position pos = getPosition();
        int dir = direction();
        Position first = new Position(pos.x, pos.y + 1 * dir);
        if (b.isEmpty(first) && b.inRange(first)) {
            list.add(first);
        }
        Position second = new Position(pos.x, pos.y + 2 * dir);
        if (!moved() && b.isEmpty(first) && b.inRange(first)) {
            list.add(first);
        }
        return list;
    }

    private Boolean moved() {
        Side side = getSide();
        Position pos = getPosition();
        return !((side == Side.WHITE && pos.x == 1) ||
                 (side == Side.BLACK && pos.y == 6));
    }

    private int direction() {
        if (getSide() == Side.WHITE) {
            return 1;
        } else {
            return -1;
        }
    }
}

@@ -764,37 +764,38 @@
        list.add(
-first
+second
 );%0A        %7D%0A   
@@ -962,17 +962,17 @@
  && pos.
-x
+y
  == 1) %7C

Fix move bug in Pawn.