私は現在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;
}