를 사용하여 AWT-EventQueue-0 ", java.lang.ArrayIndexOutOfBoundsException : -1 at java.util.ArrayList.elementData (ArrayList.java:371) at java.util.ArrayList.get (ArrayList.java:384) at KnightTour. processKnightTour (KnightTour.java:82)나이트 투어 내가 DFS를 사용하여 프로그램 기사 투어를 만들기 위해 노력하고있어하지만 난 항상 곁에 스레드에서이</p> <p>예외 "와 같은 메시지 오류가 있기 때문에 내가 ..이 프로그램을 해결할 수없는 깊이 우선-검색 알고리즘
나는 누군가가 나를 도울 수 있기를 바랍니다..
public void processKnightTour(int indexX, int indexY){
System.out.println(indexX);
System.out.println(indexY);
int[] x={2,2,-2,-2,1,1,-1,-1};
int[] y={1,-1,1,-1,2,-2,2,-2};
int countPath=0;
workList = new ArrayList();
node[indexX][indexY] = 1;
workList.add(new Coordinate(indexX, indexY));
current =(Coordinate) workList.get(workList.size()-1);
boolean statusChild;
while(node[current.row][current.column] != 64){
statusChild = false;
for(int loop=0; loop<8; loop++){
if(current.row+x[loop]>=0 && current.row+x[loop]<=7 && current.column+y[loop]>=0 && current.column+y[loop]<=7){
if(node[(current.row+x[loop])][(current.column+y[loop])]==0){
workList.add(new Coordinate(current.row+x[loop], current.column+y[loop], current));
statusChild = true;
}
}
}
if(statusChild == true){
workList.remove(workList.indexOf(current));
}else{
if(workList.size()-2 >= 0){
after = (Coordinate) workList.get(workList.size()-2);
if(current.nodeParent.equals(after.nodeParent)){
}else{
node[current.nodeParent.row][current.nodeParent.column] = 0;
}
}
node[current.row][current.column] = 0;
workList.remove(workList.size()-1);
}
current = (Coordinate) workList.get(workList.size()-1);
node[current.row][current.column] = (node[current.getParent().row][current.getParent().column])+1;
countPath++;
//System.out.println(countPath+", "+workList.size()+", "+node[current.column][current.row]);
}
}
012 이 조각에서
82 번 줄은 어느 것입니까? –