Skip to content

M2: villagers gather (deposits as rows, halls and stockpiles, sparse resources) - #41

Open
CodeByBryant wants to merge 12 commits into
claude/kind-edison-2locd1-m1-entitiesfrom
claude/kind-edison-2locd1-m2-gather
Open

CodeByBryant wants to merge 12 commits into
claude/kind-edison-2locd1-m1-entitiesfrom
claude/kind-edison-2locd1-m2-gather

Conversation

@CodeByBryant

Copy link
Copy Markdown
Owner

Summary

Milestone M2 of the units plan (ADR 0008, ADR 0009). Stacked on #39 (M1): the base is the M1 branch, so this diff is M2 only. Retarget to main once #38 and #39 merge.

Villagers now do something: each one walks to the nearest deposit of a resource it picked, works it, carries what it took home and drops it in its hall's stockpile, and you can watch the deposit shrink and regrow. Along the way the resources got thinned: the first screenshots were a solid wall of icons (74% of land tiles near a capital held a surface resource), so placement now leaves room between objects (about 15% now).

Changes

  • Deposits as rows: NodeStore (kind, tile, stock, richness; about 960k nodes, 6.7 MB), NodeIndex ("the nearest tree"), ResourceStocks rewritten on node ids. The tile slot arrays stay as write-through views, so the renderer, inspector and nation profiles are unchanged. Hash 6, save 7 (binary node block; the 24 MB of resource layers are gone), web DB 8.
  • Halls and stockpiles: EntityKind.Hall rows at each capital, 22 counters each (saved and hashed), four new villager columns (hall, goal, carriedType, carriedCount).
  • The gather cycle (UnitSystem, the old WanderSystem): pick a kind, walk, work (water deposits from the shore), take what the deposit, the trip and the carry limit allow, haul home, deposit. Config: units.carryCapacity, searchRadius and a per-resource gather table.
  • The page keeps up by deltas: World.drainStockChanges(), ticked.stock, applyStockChanges; halls and unit state/carried resource in the protocol; working poses and carried bundles in the sprite layer.
  • Sparse placement: an optional spacing per resource rule (best tiles first, skipping any too close to one of the same kind) and lower default shares. Guards now check objects are grouped and that spaced ones never touch.
  • Docs: ADR 0009 (design, measured cost, limits), determinism.md Version 6, save-format.md version 7, terrain.md, roadmap, development; new e2e:gather.

Why the goldens moved (twice, each in its own commit)

Hash 6 hashes nodes instead of six layers, plus new columns and stockpiles, and villagers now gather, which moves stocks and nation profiles (8766aa8); then sparse placement changes every world's resources (324173f). Python reference vectors were recomputed for the new writeUint32Array. All 22 golden values and their save round trips match on Node 22, Chromium 157 and QuickJS after each.

Verification

  • pnpm typecheck, pnpm lint, prettier --check, pnpm test (all packages) and test:determinism pass.
  • Mutation checks on NodeStore, NodeIndex, Stockpiles, the gather cycle, validate rules, placement spacing and the delta code; survivors were equivalent or got a test.
  • e2e:gather and e2e:units pass; screenshots checked by eye (villagers working, carrying, deposits drawn down).

Limits (honest)

  • Cost: gathering costs about 3.5 ms/tick at the default 288 villagers and about 8 ms at 1,200. Gathering itself is cheap (1.6 ms); the rest is re-measuring provinces whose stock changed, which goes away in M4 when stats come from stockpiles.
  • Gathering moves nation stats forever: the determinism guard now says borders and claims hold still once settled, not stats.
  • Balance is not tuned; nothing eats what is stored; halls have no UI readout yet.
  • Resources are still static in the lifecycle sense: they regrow in place on a timer. WorldBox-style seeds spreading, trees burning and animals eating plants are not done.
  • Software-GL e2e cannot judge frame rate.

Type of Change

  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change): every world, hash and save changes (pre-1.0)

Checklist

  • Builds (pnpm build)
  • Linting and the dependency rules pass (pnpm lint)
  • Type checking passes (pnpm typecheck)
  • Tests pass (pnpm test; and pnpm test:determinism since the engine changed)
  • Tested locally in the web app
  • Golden hashes regenerated in their own commits, reasons above
  • Updated documentation / JSDoc where applicable

Generated by Claude Code

Every deposit is a row (kind, tile, stock, richness) in tile order, found by binary search, with
the tile slot arrays kept as write-through views. A bytes form for the save, a changed list for
the app, and an immutable grid index for 'the nearest tree'.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
Stocks now live in the NodeStore and write through to the tile slot arrays, so the renderer,
inspector and nation profiles are untouched. ResourceStocks works on node ids (extractNode for
gatherers). The state hash covers the node block (with a new uint32 array writer and Python
reference vectors) instead of six tile layers; the save ends with a binary node block and the
resource layers are rebuilt on load. World.validate checks the views against the nodes.
Goldens are stale until the regeneration commit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
A hall is an entity row at each capital; its stockpile (22 counters) is saved in the header and
hashed. Villagers gain hall, goal, carriedType and carriedCount columns and the Work and Haul
states exist (nothing uses them yet). unitPositions lists villagers only; validate checks hall
references, carried stacks, goals and that every hall has a stockpile and the reverse.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
UnitSystem (the old WanderSystem) now runs a gather cycle for villagers that belong to a hall:
pick a kind (a counter-based draw, three tries), walk to the nearest deposit in reach (NodeIndex),
work there for the rule's ticks (water deposits are worked from the shore), take what the deposit,
the trip and the carry limit allow through ResourceStocks, haul it home and drop it in the hall's
stockpile. Villagers with no hall or nothing in reach still wander. New states Work and Haul are
validated. Config: units.carryCapacity, searchRadius and a per-resource gather table.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
…ather

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
Every world changes again: the resource layers are hashed as node rows, villagers and halls carry
the new columns, stockpiles are hashed, and villagers now gather, which moves stocks, province
facts and so nation profiles. One new entry runs 800 ticks so halls fill and deposits regrow.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
ticked carries the deposits that changed in a run (applyStockChanges writes them into the app's slot
arrays, which the sprites, inspector and overlays all read); ready carries the halls and starts from a
clean slate of changes. Unit snapshots gain state and carried resource. Spec: hash 6 entity columns and
the stockpile section.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
…rld; e2e:gather; ADR 0009

Working villagers swing, haulers show what they carry, halls come from the new halls list, the
resource overlay is redrawn (throttled) as stock deltas arrive, and the canvas publishes working,
carrying and drawn-down counts for the e2e. ADR 0009, roadmap and development docs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
A rule can ask for spacing: tiles are still taken best first, but one is skipped if an object of the
same kind is closer than that, so a patch is a scatter with open ground between instead of a solid
block. The default rules drop their shares and ask for room (timber 3.5% of land at spacing 2, etc.):
around the first capital 15% of land tiles hold a surface resource instead of 74%. Guards now check
that objects are grouped, not speckled, and that spaced ones never touch.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
Every world's resources change (spacing and lower shares), so every golden hash, the terrain
goldens and the depletion golden move.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
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 25, 2026 18:56

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.

This branch has not been deployed

No deployments
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