<script type='text/javascript' src='astar.js'></script><script type='text/javascript'> var graph = new Graph([ [1,1,1,1], [0,1,1,0], [0,0,1,1] ]); var start = graph.grid[0][0]; var end = graph.grid[1][2]; var result = astar.search(graph, start, end); // result is an array containing the shortest path var graphDiagonal = new Graph([ [1,1,1,1], [0,1,1,0], [0,0,1,1] ], { diagonal: true }); var start = graphDiagonal.grid[0][0]; var end = graphDiagonal.grid[1][2]; var resultWithDiagonals = astar.search(graphDiagonal, start, end, { heuristic: astar.heuristics.diagonal }); // Weight can easily be added by increasing the values within the graph, and where 0 is infinite (a wall)
A few notes about weight values:
A weight of 0 denotes a wall.
A weight cannot be negative.
A weight cannot be between 0 and 1 (exclusive).
A weight can contain decimal values (greater than 1).