0.2.4 • Published 2 years ago

@decoy9697/a-star v0.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

A Star

Downloads Size

npm install @decoy9697/a-star

The library presumes you have some kind of linked structure with a start Node and a goal Node. The Node structure can be whatever you like.

Options

You will need to provide an options object to the aStar function, with the following keys:

KeyTypeDescription
startNodeThe starting node
goalNodeThe goal node. The algorithm will attempt to make an array of nodes from the start to the goal.
getNeighboursNode => Array<Node>A function that finds the directly connected nodes for a given node
eqNode(Node, Node) => booleanA function for comparing two nodes (true if they are the same)
heuristic(Node, Node) => numberA function that determines the cost of travelling from one node to the other.

Return type

KeyTypeDescription
pathArray<Node>The path from the start to the goal (if possible)
reachedGoalbooleantrue, given the algorithm found a path from start to goal

Example

import aStar from "@decoy9697/a-star";

const result = aStar({
  start: node0,
  goal: node43,
  getNeighbours: (node) => { ... },
  eqNode: (nodeA, nodeB) => { ... },
  heuristic: (nodeA, nodeB ) => { ... }
});

if (result.reachedGoal) {
  console.log('Path': result.path);
  } else {
  console.log('Did not reach goal');
}