walkDistance: say which argument is cached, and guard the slow order (#24 item 1)
walkDistance(from, to) in src/engine/grid.ts builds a flood field keyed on to and keeps up to 64 (fields, cleared past 64). A caller that varies to across many cells (e.g. a bot scoring candidate cells as to) thrashes the cache: in skirmish, reversing the arguments took 300 simulated seconds from 8.7s to 0.28s (31×). The doc comment gives no reason to care about order. This is engine code that is copied into the forge's game template, so the next game inherits it.
Do:
Document on walkDistance (and pathStep, which uses the same field) that the field is keyed on to, so callers should keep to fixed and vary from. Distance is symmetric on this grid, so the swap is always safe.
Add a test that makes the cost visible: e.g. counting field builds (expose a small counter or a fieldsBuilt() for tests) and asserting that N distances to one fixed target build 1 field, not N.
Check val's own callers (src/bots.ts, pathStep) and say in the pull whether any vary to per call; fix the order if so.
Acceptance: the test fails if the cache key is moved to from; bun test green; no gameplay change.
walkDistance: say which argument is cached, and guard the slow order (#24 item 1)
walkDistance(from, to)insrc/engine/grid.tsbuilds a flood field keyed ontoand keeps up to 64 (fields, cleared past 64). A caller that variestoacross many cells (e.g. a bot scoring candidate cells asto) thrashes the cache: in skirmish, reversing the arguments took 300 simulated seconds from 8.7s to 0.28s (31×). The doc comment gives no reason to care about order. This is engine code that is copied into the forge'sgametemplate, so the next game inherits it.Do:
walkDistance(andpathStep, which uses the same field) that the field is keyed onto, so callers should keeptofixed and varyfrom. Distance is symmetric on this grid, so the swap is always safe.fieldsBuilt()for tests) and asserting that N distances to one fixed target build 1 field, not N.src/bots.ts,pathStep) and say in the pull whether any varytoper call; fix the order if so.Acceptance: the test fails if the cache key is moved to
from;bun testgreen; no gameplay change.