walkDistance: say which argument is cached, and guard the slow order (#24 ite… #39
shipped production is serving it deploy b42aa0d
merged this
Sign in to join this conversation.
shipped production is serving it deploy b42aa0d
walkDistanceandpathStepinsrc/engine/grid.tsnow say that the walk field is cached byto. Callers should keeptofixed and varyfrom. Distance is symmetric on this grid, so swapping the arguments never changes the answer. There is no gameplay change: the only code added is a build counter.Changes
Gridtype, and the doc comments onwalkDistanceandpathStepnow explain the argument order.fieldsBuilt()is added toGrid. It counts how many walk fields have been built and exists only so tests can see the cache.src/engine/grid.test.ts:- Asking every floor cell's distance to one target builds 1 field. - Varying the target builds one field per target. -
pathStepreuses the field thatwalkDistancebuilt for the same goal. - Distance is the same in both directions for every pair of cells, which is why the swap is safe. -clearPaths()forces the next request to build again.fromby hand and three tests failed, then put it back. The fullbun testrun passes (310 tests). There is notsconfig.json, so there was no type check to run.Val's own callers (none needed a change)
src/bots.ts:112:walkDistance(bot, loose)already variesfrom(the bot) against a fixedto(the dropped spike).src/bots.ts:122:pathStep(bot, goal)hastofixed per goal. One exception: once the spike is planted, attacking bots pick a new random goal within ±110 units of the spike every tick. That does varyto, but with 80-unit tiles it can only land on a few tiles around the spike, well under the 64-field limit, so the cache doesn't thrash. I left it alone because the fix would be to keep each bot's jitter steady, which changes how bots behave. That's out of scope here and could be its own issue.grid.ts,pathStepcallswalkDistance(from, to)with the sameto, so it reads the same field.Preview: there is nothing new to see in it, because this is engine documentation and a test. To check the work, run
bun test src/engine/grid.test.ts.🤖 Generated with Claude Code
Closes #38