Advertisement
pierrotdu18

Untitled

Aug 28th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global open_list = [];
  2. global closed_list = [];
  3. function dijkstra(cell1, cell2)
  4. {
  5.     push(open_list, getCell());
  6.     while (count(open_list) > 0)
  7.     {
  8.         var current = shift(open_list);
  9.         if (!inArray(closed_list, current))
  10.         {
  11.             push(closed_list, current);
  12.             pushAll(open_list, getNearestCells(current));
  13.         }
  14.     }
  15. }
  16.  
  17. function getNearestCells(cell)
  18. {
  19.     var x = getCellX(cell);
  20.     var y = getCellY(cell);
  21.     return [getCellFromXY(x + 1, y + 1),
  22.             getCellFromXY(x + 1, y - 1),
  23.             getCellFromXY(x - 1, y + 1),
  24.             getCellFromXY(x - 1, y - 1)];
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement