Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabienjuif/astar
an A* algorithm in javascript
https://github.com/fabienjuif/astar
a algorithm astar game path shortest shortest-path
Last synced: 25 days ago
JSON representation
an A* algorithm in javascript
- Host: GitHub
- URL: https://github.com/fabienjuif/astar
- Owner: fabienjuif
- License: mit
- Created: 2020-03-28T13:08:02.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T17:33:54.000Z (almost 2 years ago)
- Last Synced: 2024-10-04T10:18:47.422Z (about 1 month ago)
- Topics: a, algorithm, astar, game, path, shortest, shortest-path
- Language: JavaScript
- Size: 1.26 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @fabienjuif/astar
> an A\* algorithm in javascript
## Installation
`npm install --save @fabienjuif/astar`
## Usage
```js
const getClosestPath = require('@fabienjuif/astar')getClosestPath(
// array of rows that contains cells
graph,
// starting cell { x, y }
start,
// ending cell { x, y }
end,
// all the rest of parameters are **not required**
// but you can use them to tweak the engine
({
// function to test two node are the same
sameNode = defaultSameNode,
// function that map the given graph to the one that the engine needs
mapGraph = identity,
// function to get neighbours of a cell (default works with squared cells)
getNeighbours = defaultGetNeighbours,
// function to get distance between 2 cells, default use pythagore (without the square root)
distance = defaultDistance,
// your heuristic
heuristic = () => 1,
// max loops before stoping the engine
maxLoops = Infinity,
} = {}),
)
```- Node are representated in object `x, y`
- Graph is an array of cells```js
const graph = [
// first line (x === 0)
[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5],
// second line (x === 1)
[1, 0], [1, 1], [1, 2],
// third line (x === 2)
[2, 0], [2, 1], [2, 2], [2, 3],[2, 4],[2, 5],
]console.log(graph[2][3])
```