astar-algorithm
v0.1.2
Published
An almost universal implementation of A* search algorithm in JavaScript
Downloads
6
Maintainers
Readme
astar-algorithm
An almost universal implementation of A* search algorithm in JavaScript.
Requirements
- ECMAScript 2015+
Usage
// 1)
const astar = require('astar-algorithm')
// 2)
let callbacks = {
// It should return id / key / hash for a node
id(node) {
// return {String} or what you want
},
// It should check: is a node is the goal?
isGoal(node) {
// return {Boolean}
},
// It should return an array of successors / neighbors / children
getSuccessors(node) {
// return {Array} of nodes
},
// g(x). It should return the cost of path between two nodes
distance(nodeA, nodeB) {
// return {Number}
},
// h(x). It should return the cost of path from a node to the goal
estimate(node, goal) {
// return {Number}
}
}
// 3)
let path = astar(start, goal, callbacks)
See more examples there.