You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<scripttype='text/javascript'src='astar.js'></script><scripttype='text/javascript'>vargraph=newGraph([[1,1,1,1],[0,1,1,0],[0,0,1,1]]);varstart=graph.grid[0][0];varend=graph.grid[1][2];varresult=astar.search(graph,start,end);// result is an array containing the shortest pathvargraphDiagonal=newGraph([[1,1,1,1],[0,1,1,0],[0,0,1,1]],{diagonal: true});varstart=graphDiagonal.grid[0][0];varend=graphDiagonal.grid[1][2];varresultWithDiagonals=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)vargraphWithWeight=newGraph([[1,1,2,30],[0,4,1.3,0],[0,0,5,1]]);varstartWithWeight=graphWithWeight.grid[0][0];varendWithWeight=graphWithWeight.grid[1][2];varresultWithWeight=astar.search(graphWithWeight,startWithWeight,endWithWeight);// resultWithWeight is an array containing the shortest path taking into account the weight of a node</script>
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).