-3

我目前正在尝试编写一种getLegalMoves()方法来编写奥赛罗游戏。问题是,在getLegalMoves()方法中它一直说它找不到符号,即使我明确定义了它。这是代码:

public ArrayList <Location> getLegalMoves(String curColor)
{
    ArrayList<Location> legalmoves = new ArrayList<Location>();
    int i = 0;
        ArrayList<Location> occupied = board.getOccupiedLocations();
        ArrayList<Location> playeroccupied = new ArrayList<Location>();
        ArrayList<Location> occupiedopposite = new ArrayList<Location>();
        int b = 0;
        while(b < occupied.size())
        {
            if(board.get(occupied.get(b)).equals(curColor) == false)
                occupiedopposite.add(occupied.get(b));
            else
                playeroccupied.add(occupied.get(b));
            b++;
        }       

        int a = 0;
        while(occupiedopposite.size() > i)
        {
            Location location = occupiedopposite.get(i);
            while(board.getEmptyAdjacentLocations(location).size() > a)
            {
                ArrayList<Location> empty = (board.getEmptyAdjacentLocations(location));
                Location emptyspot = empty.get(a);
                int c = 0;
                while(playeroccupied.size() > c)
                {
                    int direction = (empty).getDirectionTowards(playeroccupied.get(c)); //this is the problem line, it can't find playerOccupied.get(c), I think
                    int d = 0;
                    Location checking = emptyspot.getAdjacentLocation(direction);
                    while(board.isValid(checking) && d != -1)
                    {
                        if(d == 0 && checking.equals("W"))
                            d = -1;
                        else if(checking.equals(null) || checking.equals("B"))
                        {
                            d++;
                            checking = checking.getAdjacentLocation(direction);
                        }
                        else if(checking.equals("W") && d != 0)
                            legalmoves.add(emptyspot);
                    }
                    c++;    
                }
                a++;
            }
            i++;
        }
    return legalmoves;
}
4

1 回答 1

2

empty是一个列表:

ArrayList<Location> empty

而且列表没有getDirectionTowards(...)方法:

int direction = (empty).getDirectionTowards(playeroccupied.get(c));

因此,该代码无法编译是正常的(括号是不必要的)。也许你的意思是写:

int direction = emptyspot.getDirectionTowards(playeroccupied.get(c));
于 2013-02-17T16:16:43.127 回答