1. 程式人生 > >三維迷宮 - 演算法

三維迷宮 - 演算法

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