【发布时间】:2020-01-09 19:38:40
【问题描述】:
这是我目前的寻路算法:
public void AAlg(int a, int b){
boolean bool=true;
while(bool) {
bool = false;
for (int i = 0; i <map.length; i++) {
for (int j = 0; j < map.length; j++) {
if(ifObj(i, j)) {
bool=true;
}
}
}
int smallest=N;
int[] coords = new int[2];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if((i==1&&j==0)||(i==2&&j==1)||(i==1&&j==2)||(i==0&&j==1)) {
findFGH(i+a,j+b);
if(f<smallest) {
smallest=f;
coords[0]=i+a;
coords[1]=j+b;
}
}
}
}
if(coords[0]==N-1&&coords[1]==.N-1) {
System.out.println("The distance travelled is "+cnt);
}
AAlg(coords[0], coords[1]);
cnt++;
}
N 是网格的宽度和高度的长度,地图很好,地图。它是一个布尔值[][],除了有障碍物之外,一切都是假的。我设想我的代码有点只是从一个正方形到另一个正方形,迭代并找到最有效的正方形去下一个。怎么了?它只是无限循环。
【问题讨论】:
-
您在自身内部调用
AAlg- 递归地 - 但您没有递归结束的返回条件。那么为什么你期望它呢?
标签: java loops infinite-loop path-finding