Ich weis nicht wieso das nicht klappt
Main()
[CODE lang="java" title="Main" highlight="3"]System.out.println("Vor dem Durchlauf:");
print();
BFSearch(3,1);
System.out.println();
System.out.println("Nach dem Durchlauf");
print();[/CODE]
BFSearch()
[CODE lang="java" title="BFSearch()"]public static void BFSearch(int px, int py){
ArrayList<Integer> nextX = new ArrayList<Integer>();
ArrayList<Integer> nextY = new ArrayList<Integer>();
nextX.add(px);
nextY.add(py);
int x = nextX.get(0);
int y = nextY.get(0);
while(y!=0 || y!=9 || x!=0 || x!=9 || (nextX.size()!=0 && nextY.size()!=9))
{
if(labyrinth[y-1][x] == 0){
labyrinth[y-1][x] = 8;
nextX.add(x);
nextY.add(y-1);
}
if(labyrinth[y][x+1] == 0){
labyrinth[y][x+1] = 7;
nextX.add(x+1);
nextY.add(y);
}
if(labyrinth[y+1][x] == 0){
labyrinth[y+1][x] = 5;
nextX.add(x);
nextY.add(y+1);
}
if(labyrinth[y][x-1] == 0){
labyrinth[y][x-1] = 6;
nextX.add(x-1);
nextY.add(y);
}
nextX.remove(0);
nextY.remove(0);
x = nextX.get(0);
y = nextY.get(0);
}
}[/CODE]
Das ist die Fehlermeldung
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10
at labyrinth.Main.BFSearch(Main.java:103)
at labyrinth.Main.main(Main.java:34)
Habt ihr ne Idee?
Main()
[CODE lang="java" title="Main" highlight="3"]System.out.println("Vor dem Durchlauf:");
print();
BFSearch(3,1);
System.out.println();
System.out.println("Nach dem Durchlauf");
print();[/CODE]
BFSearch()
[CODE lang="java" title="BFSearch()"]public static void BFSearch(int px, int py){
ArrayList<Integer> nextX = new ArrayList<Integer>();
ArrayList<Integer> nextY = new ArrayList<Integer>();
nextX.add(px);
nextY.add(py);
int x = nextX.get(0);
int y = nextY.get(0);
while(y!=0 || y!=9 || x!=0 || x!=9 || (nextX.size()!=0 && nextY.size()!=9))
{
if(labyrinth[y-1][x] == 0){
labyrinth[y-1][x] = 8;
nextX.add(x);
nextY.add(y-1);
}
if(labyrinth[y][x+1] == 0){
labyrinth[y][x+1] = 7;
nextX.add(x+1);
nextY.add(y);
}
if(labyrinth[y+1][x] == 0){
labyrinth[y+1][x] = 5;
nextX.add(x);
nextY.add(y+1);
}
if(labyrinth[y][x-1] == 0){
labyrinth[y][x-1] = 6;
nextX.add(x-1);
nextY.add(y);
}
nextX.remove(0);
nextY.remove(0);
x = nextX.get(0);
y = nextY.get(0);
}
}[/CODE]
Das ist die Fehlermeldung
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10
at labyrinth.Main.BFSearch(Main.java:103)
at labyrinth.Main.main(Main.java:34)
Habt ihr ne Idee?