Utilities · zero-dependency · MIT

larzpathfind

Real A* search over a grid.

An open set ordered by f = g + h, a closed set, and path reconstruction via a came-from map - the real algorithm, built on this stack's own heap for the priority queue. 4-directional by default (Manhattan heuristic) or 8-directional with diagonals (Euclidean), or pass your own heuristic.

larzscript pkg install pathfind
View on GitHub →Learn the stack

What you get

Try it

import "pathfind" as pf
let g = pf.grid_new(5, 5)
pf.grid_block(g, 1, 1); pf.grid_block(g, 2, 1); pf.grid_block(g, 3, 1)
let path = pf.astar(g, {"x": 0, "y": 0}, {"x": 4, "y": 4})
print("steps:", len(path), "cost:", pf.path_cost(path))
for p in path { print(p["x"], p["y"]) }
print("unreachable goal:", pf.astar(g, {"x": 0, "y": 0}, {"x": 100, "y": 100}))
Output
steps: 9 cost: 8
0 0
1 0
2 0
3 0
4 0
4 1
4 2
4 3
4 4
unreachable goal: nil

Why it's in the Larz Stack

larzpathfind is a real Larzscript package (larzscript pkg install pathfind) - money-native, zero dependencies, the same language as the rest of the estate, not a separate Python runtime. It composes with the rest of the Larz Stack and the Larz framework.