public List<Position> findPossibleMoves(Position position){
    // UP
    Position posUp = new Position(position.getRow() - 1, position.getCol());
    // Down
    Position posDown = new Position(position.getRow() + 1, position.getCol());
    // Left
    Position posLeft = new Position(position.getRow(), position.getCol() - 1);
    // Right
    Position posRight = new Position(position.getRow(), position.getCol() + 1);
    ArrayList<Position> res = new ArrayList<>();
    processPositionLegalMoves(posUp, res);
    processPositionLegalMoves(posDown, res);
    processPositionLegalMoves(posLeft, res);
    processPositionLegalMoves(posRight, res);
    return res;
}

public List<Position> findPossibleMoves(){
    return findPossibleMoves(this.pacmanPosition);
}

private void processPositionLegalMoves(Position position, ArrayList<Position> res) {
    boolean add = isLegalMove(position);
    if (add) res.add(position);
}

public boolean isLegalMove(Position position) {
    boolean add = false;
    if (isInside(position) && get(position) != '%'){
        add = true;
    }
    return add;
}

private boolean isInside(Position position){
    return position.getRow() >= 0 && position.getCol() >= 0 && position.getRow() < getHeight() && position.getCol() < getWidth();
}
