Skip to main content
The Deno 2 Release Candidate is here
Learn more
Latest
interface AStarOptions
import { type AStarOptions } from "https://deno.land/x/lazy_pathfinding@v1.1.1/directed/a_star.ts";

Type Parameters

Node
optional
Cost = number

Properties

start: Node

The starting node.

successors: (node: Node) => Iterable<[Node, Cost]>

Returns a list of successors for a given node, along with the cost for moving from the node to the successor.

heuristic: (node: Node) => Cost

Returns an approximation of the cost from a given node to the goal. The approximation must not be greater than the real cost, or a wrong shortest path may be returned.

success: (node: Node) => boolean

Checks whether the goal has been reached. It is not a node as some problems require a dynamic solution instead of a fixed node.

key: (node: Node) => unknown

A function that returns a unique key for a node. Equal nodes must return keys that are equal. If the nodes are primitive values, are represented by persistent unique objects, or are never encountered more than once, then the identity function (x => x) can be used here. Otherwise, a custom function that converts the node to a string is recommended. (JSON.stringify can be used for this.)

In the future, if the Javascript Record and Tuple proposal is implemented, then this option may be changed to be optional with a default value set to the identity function, in order to make Record and Tuple nodes work as simply as possible.

optional
costOptions: CostOptions<Cost>

This option lets custom functions for managing the Cost values be specified. This is not necessary to use if the Cost type is a number. This option is useful if you want a different type of Cost value, such as a tuple of numbers representing separate resource costs where 1 of an earlier index is worth more than any amount in further indexes.

optional
maxCost: Cost

Stop considering paths that have a cost greater than this value.