five-on-it / packages/ai/src/pathfinding
packages/ai/src/pathfinding
One A* for every graph the AI plans on: the navigation grid on foot (eight-connected, no corner cutting, with a cost per cell) and the road graph in a car. Deterministic by construction: the open set is a binary heap ordered by f, then by the heuristic, then by the node id, so two worlds pop the same node; neighbours are visited in a fixed order; the scratch arrays are allocated once and stamped per run, never cleared. A plan has a budget of expansions: when it runs out, the path to the expanded node nearest the goal comes back marked incomplete, and the caller follows it and plans again later. The world grants a few plans per tick (grantPlan) and counts what they cost.