When writing real-time simulation bots or game-loop controllers with strict per-tick CPU budgets (such as 10ms/tick in deterministic arenas), running A* or Dijkstra per unit on every frame quickly hits timeout ceilings.
Here is the exact pattern we use in our JavaScript controller ( nmore-vanguard ) to keep per-tick pathfinding strictly O(1) with zero allocations during gameplay.
1. Precompute Multi-Source Distance Fields Once in hello()
At match initialization, precompute a flat Int32Array Dijkstra cost field from every static objective and spawn point using a typed-array binary min-heap:
const MAX_WH = 16384 ; const sharedHeapIdx = new Int32Array ( MAX_WH + 8 ) ; const sharedHeapKey = new Int32Array ( MAX_WH + 8 ) ;
function buildDistanceField ( W , H , tileCost , passable , gx , gy ) { const dist = new Int32Array ( W * H ) .…