Skip to content

Instantly share code, notes, and snippets.

@bgrins
Last active April 12, 2024 15:58
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save bgrins/581352 to your computer and use it in GitHub Desktop.
Save bgrins/581352 to your computer and use it in GitHub Desktop.
<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
</script>
@Salmanalfa
Copy link

How can immplement this simple code into html file?

@bgrins
Copy link
Author

bgrins commented May 2, 2012

Check out the demo in the project page: https://github.com/bgrins/javascript-astar/tree/master/demo

@Nashorn
Copy link

Nashorn commented Nov 29, 2020

How can I use with 1D array?

@campbellgalon
Copy link

How can I use with 1D array?

why would you need an A* for a 1D array? To find shortest path from X to Y, just do array.join``.match(/X.*?Y/)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment