Advertisement
Guest User

Untitled

a guest
Aug 17th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. for (let i = 0; i < queue.length; i++) {
  2. const neighbors = new Array();
  3. const cur_x = queue[i].x;
  4. const cur_y = queue[i].y;
  5.  
  6. if (is_location_valid(cur_x + 1, cur_y))
  7. neighbors.push(map[cur_x + 1][cur_y]);
  8.  
  9. if (is_location_valid(cur_x - 1, cur_y))
  10. neighbors.push(map[cur_x - 1][cur_y]);
  11.  
  12. if (is_location_valid(cur_x, cur_y + 1))
  13. neighbors.push(map[cur_x][cur_y + 1]);
  14.  
  15. if (is_location_valid(cur_x, cur_y - 1))
  16. neighbors.push(map[cur_x][cur_y - 1]);
  17.  
  18. for (let j = 0; j < neighbors.length; j++) {
  19. const tile = neighbors[j];
  20.  
  21. if (!tile.blocked && tile.actual_cost == Number.MAX_VALUE) {
  22. tile.actual_cost = queue[i].actual_cost + 1;
  23. queue.push(tile);
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement