Advertisement
pierrotdu18

Untitled

Aug 28th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global weights = [];
  2. for (var cell = 0; cell <= 612; cell++)
  3.     weights[cell] = 0;
  4. global open_list = [];
  5. global closed_list = [];
  6. function dijkstra(cell1, cell2)
  7. {
  8.     push(open_list, getCell());
  9.     while (count(open_list) > 0)
  10.     {
  11.         var current = shift(open_list);
  12.         push(closed_list, current);
  13.         var cellsToAdd = getNearestCells(current);
  14.         for (var cell in cellsToAdd)
  15.         {
  16.             if (!inArray(closed_list, cell))
  17.             {
  18.                 push(open_list, cell);         
  19.             }
  20.             if (cell == cell2)
  21.             {
  22.                 //... :D           
  23.             }
  24.         }
  25.     }
  26. }
  27.  
  28. function getNearestCells(cell)
  29. {
  30.     var x = getCellX(cell);
  31.     var y = getCellY(cell);
  32.     var cells = [getCellFromXY(x + 1, y + 1),
  33.                  getCellFromXY(x + 1, y - 1),
  34.                  getCellFromXY(x - 1, y + 1),
  35.                  getCellFromXY(x - 1, y - 1)];
  36.     while (inArray(cells, null))
  37.         removeElement(cells, null);
  38.     return cells;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement