Skip to content

M0: ADR 0008, units and a living world (and what units and resource nodes cost) - #38

Merged
CodeByBryant merged 1 commit into
mainfrom
claude/kind-edison-2locd1-units
Nov 24, 2026
Merged

CodeByBryant merged 1 commit into
mainfrom
claude/kind-edison-2locd1-units

Conversation

@CodeByBryant

Copy link
Copy Markdown
Owner

Summary

First stage of replacing the points-and-provinces expansion (ADR 0007) with simulated units: villagers and settlers who walk, gather, carry, build and spread, with resource nodes as entities and territory from buildings, drawn as zoom-gated pixel sprites. This PR is M0 only: two probes that fix the budget, and ADR 0008. No engine behaviour changes. Later stages stack on this branch (M1 entities and a world you can see, M2 gather loop, M3 settle and build, M4 live, M5 spread, M6 crowds and god powers).

Changes

  • tests/probe/units.probe.ts: a gatherer loop (idle, pick a spot, A* over the 4-tile cost grid, walk, work, walk home, deposit) for 2,000 / 10,000 / 30,000 units, every walker stepped each tick vs units that sleep until they arrive vs routes shared between units.
  • tests/probe/nodes.probe.ts: the two resource slots as passive rows: count, memory, build time, a spatial index, nearest-node query time, hash and save size against the six tile layers.
  • docs/decisions/0008-units-and-a-living-world.md: the decisions and what the probes measured; roadmap, docs index and development docs updated.
  • tests/heap.test.ts: a test for the existing MinHeap.clear() (a heap serving many searches).

Findings (2000 x 2000, seed 1337, Node 22, one machine)

  • Movement is nearly free; pathfinding is the whole cost (about 48 microseconds a leg). With every unit computing its own route, 30,000 units cost 42 ms a tick. With routes shared and reversible, 30,000 units cost 1.2 ms a tick, 10,000 cost 0.7 ms (35x cheaper). Hence the budget of about 10,000 simulated units, hard cap 30,000.
  • Resource nodes as entities are cheap: 960,000 rows (not the 2M I first guessed), 9.6 MB, built in 23 ms; spatial index 30 ms and 9.6 MB; nearest tree 26 us; hashing half the time of the tile layers; save 9.6 MB instead of 24 MB. The tile-data fallback is not needed.
  • One tick stays one in-game day; travel time comes from route cost over walking speed; speed is a request, so a heavy world runs slower than asked instead of freezing the page.

Related Issues

None.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactor / cleanup (no functional changes)
  • Documentation update (plus two probes and one test; no functional change)

Checklist

  • Builds (pnpm build) — not run locally; CI runs it
  • Linting and the dependency rules pass (pnpm lint) — ESLint and Prettier on the touched packages, run locally
  • Type checking passes (pnpm typecheck) — simulation package, run locally
  • Tests pass (pnpm test; and pnpm test:determinism if the engine changed) — heap tests run locally; engine unchanged, so determinism suite not re-run
  • Tested locally in the web app (and the desktop shell if it changed) — not applicable, no app change
  • If a golden hash moved, it is regenerated in its own commit and the reason is above — no golden moved
  • Updated documentation / JSDoc where applicable

Honest limits

  • The unit probe measures walking and searching only. Hunger, building, births, hunting, claiming and sprites will each add cost, and balance will take more effort than code.
  • Route sharing assumes workers revisit places; a world where the ground changes every day lowers the hit rate, so invalidation must be cheap and local.
  • About 10,000 units at a thousand days a second is not sustainable; the top speed will run below its request.
  • Rendering at scale is unmeasured (software-GL e2e cannot judge frame rate).

Generated by Claude Code

…esource nodes cost

M0 of the pivot from abstract expansion to simulated units. Two probes on a 2000 x 2000 world:

- tests/probe/units.probe.ts: a gatherer loop for 2,000 / 10,000 / 30,000 units. Movement is nearly free (a
  stepped walker and a sleeping one cost the same); pathfinding is the whole cost, about 48 us a leg. With routes
  shared between units 30,000 units cost 1.2 ms a tick instead of 42 ms, 10,000 cost 0.7 ms.
- tests/probe/nodes.probe.ts: resource nodes as rows. There are 960,000 (not 2M): 9.6 MB, built in 23 ms, a
  spatial index in 30 ms and 9.6 MB, nearest-tree in 26 us, hashing half the time of the tile layers and a
  save of 9.6 MB instead of 24 MB. Nodes as entities is confirmed; the tile-data fallback is not needed.

ADR 0008 records the decisions (event-driven units, shared routes, nodes as passive rows, territory from
buildings, provinces leave the engine path, zoom-gated sprites, one tick stays a day, about 10,000 units as
the budget) and the stages M1 to M6, with the limits. The roadmap and docs index are updated. No engine
behaviour changes; MinHeap.clear gains a test.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
Copilot AI balanced review requested due to automatic review settings November 24, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@CodeByBryant
CodeByBryant added this pull request to stack #40 November 24, 2026 23:49
@CodeByBryant
CodeByBryant merged commit fcb43f6 into main Nov 24, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants