astar-algorithm

0.1.2 • Public • Published

astar-algorithm

An almost universal implementation of A* search algorithm in JavaScript.

NPM version Build status Test coverage

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.

Package Sidebar

Install

npm i astar-algorithm

Weekly Downloads

1

Version

0.1.2

License

MIT

Last publish

Collaborators

  • nerv