版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sunyanxiong123/article/details/76222996
static void bfs(int p_x,int p_y,int p_z,int count){
boolean flag = false;
int new_x,new_y,new_z;
for(int i = 0;i < 6;i++){
new_x = p_x + dir[i][0][0];
new_y = p_y + dir[i][0][1];
new_z = p_z + dir[i][0][2];
if(new_x >= 0 && new_x < x
&& new_y >= 0 && new_y < y
&& new_z >= 0 && new_z < z){
if(dungeon[new_z][new_x][new_y] == 1){
dungeon[new_z][new_x][new_y] = 5; // 标记
visit[visitIndex++] = new_x;
visit[visitIndex++] = new_y;
visit[visitIndex++] = new_z;
flag = true;
} else if(dungeon[new_z][new_x][new_y] == 9) {
isSuccess = true;
steps = count;
return;
}
}
}
// bfs(visit[count-1],visit[count],visit[count+1],count = count + 1);
if(flag){
bfs(visit[count-1],visit[count],visit[count+1],count = count + 1);
dungeon[p_z][p_x][p_y] = 1; // 标记
} else {
System.out.println("!!!!");
// bfs(visit[count-1],visit[count],visit[count+1],count);
}
}