2.0.1 • Published 11 months ago

@decoy9697/a-star v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

A Star

Build Coverage 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.
getIdNode => stringA function for that identifies a node using a string
getNeighboursNode => Array<Node>A function that finds the directly connected nodes for a given node. NOTE. The returned nodes will be used as Map keys, so these ought to be references to the nodes in the graph.
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,
  getId: (node) => node.id,
  getNeighbours: (node) => { ... },
  eqNode: (nodeA, nodeB) => { ... },
  heuristic: (nodeA, nodeB ) => { ... }
});

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

12 months ago

1.0.0

12 months ago

2.0.1

11 months ago

2.0.0

12 months ago

0.2.4

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.1.0

5 years ago