Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global weights = [];
- for (var cell = 0; cell <= 612; cell++)
- weights[cell] = 0;
- global open_list = [];
- global closed_list = [];
- function dijkstra(cell1, cell2)
- {
- push(open_list, getCell());
- while (count(open_list) > 0)
- {
- var current = shift(open_list);
- push(closed_list, current);
- var cellsToAdd = getNearestCells(current);
- for (var cell in cellsToAdd)
- {
- if (!inArray(closed_list, cell))
- {
- push(open_list, cell);
- }
- if (cell == cell2)
- {
- //... :D
- }
- }
- }
- }
- function getNearestCells(cell)
- {
- var x = getCellX(cell);
- var y = getCellY(cell);
- var cells = [getCellFromXY(x + 1, y + 1),
- getCellFromXY(x + 1, y - 1),
- getCellFromXY(x - 1, y + 1),
- getCellFromXY(x - 1, y - 1)];
- while (inArray(cells, null))
- removeElement(cells, null);
- return cells;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement