2013-02-17 4 views
-3

현재 게임 Othello를 코딩하려는 시도에서 getLegalMoves() 메소드를 코딩하려고합니다. 문제는 명확하게 정의 했음에도 불구하고 getLegalMoves() 메서드에서 기호를 찾을 수 없다는 것을 계속 말합니다.Java - getLegalMoves()에서 심볼을 찾을 수 없습니다.

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

그래서 그 코드가 실패 정상입니다 :

ArrayList<Location> empty 

그리고 목록은 getDirectionTowards(...) 방법이없는 :

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; 
} 
+7

그리고 어떤 오류가 발생합니까? –

+0

나머지 코드는 어디에 있습니까? 당신은'''''''방법에서 이것을 부르시겠습니까? – djhworld

+0

예외를 참조하십시오. – Kal

답변

2

empty가 목록입니다 : 여기 코드입니다 컴파일 (괄호가 불필요한 방식). 어쩌면 당신은 다음과 같이 쓸 것입니다 :

int direction = emptyspot.getDirectionTowards(playeroccupied.get(c)); 
+0

흠, 방금 시도했지만 여전히 같은 오류 메시지가 나타납니다. 그래도 그것을 가져 주셔서 감사합니다. –

+0

@EthanB'getDirectionTowards (Location)'클래스는 어디에 있습니까? 해당 클래스의 인스턴스에서만 호출 할 수 있습니다. – assylias

+0

Location 클래스입니다. –

관련 문제