https://github.com/webbestmaster/a-star-finder
Generic synchronous/asynchronous A* search algorithm.
https://github.com/webbestmaster/a-star-finder
Last synced: about 1 year ago
JSON representation
Generic synchronous/asynchronous A* search algorithm.
- Host: GitHub
- URL: https://github.com/webbestmaster/a-star-finder
- Owner: webbestmaster
- License: mit
- Created: 2017-05-29T18:21:26.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-03-23T17:42:06.000Z (over 8 years ago)
- Last Synced: 2025-05-06T04:23:41.801Z (about 1 year ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# a-star-finder
Generic synchronous/asynchronous A* search algorithm.
### How to use
```javascript
// sync version
const {getPath} = require('a-star-finder');
const map = [
'··S·###···', // S and E - Start and End, not required, here is for example only
'····#·····', // · - available to across square, not required, here is for example only
'····#E##··', // # - NOT AVAILABLE to across square, REQUIRED
'····###···',
'··········'
];
const start = [2, 0]; // x and y coordinates, start of path
const end = [5, 2]; // x and y coordinates, end of path
const path = getPath(map, start, end);
console.log(path); // array of square's coordinates [start, [3, 0], [3, 1], ..., [6, 1], [5, 1], end]
// getPath support options
getPath(map, start, end, {noPath: '#'}); // noPath will used instead of default not across square
// async version
const {getPathAsync} = require('a-star-finder');
// getPathAsync support options: getPathAsync(map, start, end, callback, options)
getPathAsync(map, start, end, path => {
// here your path
console.log(path);
});
```
If end point is unreachable, return null.