SHOW:
|
|
- or go back to the newest paste.
| 1 | GUESS: this is an java implementation of aStar (at least a part of it) | |
| 2 | ||
| 3 | static int bfs(int i,int j,int k ,int count) | |
| 4 | {
| |
| 5 | ||
| 6 | ||
| 7 | node node = new node(i,j,k,count); | |
| 8 | node.d= 0; //distance to the source node is initialized to zero | |
| 9 | Queue<node> q = new LinkedList<node>(); | |
| 10 | q.add(node); //add the first node to the queue | |
| 11 | ||
| 12 | while(!q.isEmpty()){
| |
| 13 | node u = q.poll(); | |
| 14 | for(int v = 0 ; v < 6 ; v++) | |
| 15 | { //check all the neighbours of u, if one of them is not visited, add it to the queue and mark it as visited
| |
| 16 | ||
| 17 | ||
| 18 | int xx = u.x + dx[v]; | |
| 19 | int yy = u.y + dy[v]; | |
| 20 | int zz = u.z + dz[v]; | |
| 21 | ||
| 22 | ||
| 23 | if(xx >= 0 && xx < l && yy >= 0 && yy < r && zz >= 0 && zz < c && !visited[xx][yy][zz] && maze[xx][yy][zz] != '#') | |
| 24 | {
| |
| 25 | ||
| 26 | visited[xx][yy][zz] = true; | |
| 27 | ||
| 28 | node newNode= new node(xx,yy,zz,u.d+1); | |
| 29 | //v is not visited yet | |
| 30 | ||
| 31 | q.add(newNode); | |
| 32 | ||
| 33 | if(eX == xx && eY == yy && eZ == zz) | |
| 34 | {
| |
| 35 | flag = true; | |
| 36 | return count; | |
| 37 | } | |
| 38 | } | |
| 39 | } | |
| 40 | } | |
| 41 | return count; | |
| 42 | } |