v2026.6.1
All Bundles
Bundle Classic AI algorithms: graph search, adversarial game search, optimization and tabular reinforcement learning (-lib ai)

AStar

A* single-pair shortest path: Dijkstra ordered by f = g + h using a per-node heuristic array. With an admissible heuristic (never overestimating the remaining cost) the result cost equals Dijkstra's while typically expanding fewer nodes.

Example

# heuristic[i] = straight-line estimate from node i to the goal
result := AStar->FindPath(graph, 0, 5, heuristic);

Operations

FindPath # function

Finds the minimum-cost path between two nodes guided by a heuristic.

function : FindPath(graph:Graph, start:Int, goal:Int, heuristic:Float[]) ~ SearchResult

Parameters

NameTypeDescription
graphGraphgraph to search
startIntstart node id
goalIntgoal node id
heuristicFloatestimated remaining cost per node id (length = node count)

Return

TypeDescription
SearchResultsearch result