Repository navigation
Make the world tick: provinces, expansion and time controls - #36
Merged
Merged
Conversation
…vel cost) On 2000 x 2000 worlds a tile-level multi-source Dijkstra takes about 0.45 s; a 20 tile seed spacing gives about 2,100 provinces of a median 460 tiles (p10 320, p90 665); at 30 tiles islands start to go unseeded. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
…el cost
buildProvinces runs one multi-source Dijkstra over land tiles (own heap, total order) from seeds spread on
cheap ground, so every province is connected and borders fall on mountains, rivers and coasts. Every landmass
gets a seed; provinces under minArea merge, smallest first, into the neighbour with the longest shared border;
a speck with no neighbour belongs to nobody. Provinces carry CSR tile lists, area, centroid, mean cost and
neighbours with border lengths. Config gains provinces { spacing 20, minArea 40, costCap 12 }.
Tests on drawn worlds, mutation checked (every mutant killed except a no-op).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
A nation now owns provinces (ids, in the order it claimed them) instead of tiles. The world derives its province layer (the cut and what each province is like) from the terrain on create and on restore; it is never saved. - provinceProfile: per-province partial profiles (sums, plus a bit mask of resource kinds for diversity), and combineProfile, so a nation's profile is a sum over its provinces. Tested equal to measureProfile on the union of tiles, and mutation checked. - territory: starting territories grow over the province graph (centre distance x mean cost), all nations at once, each stopping at the first province that takes it to nations.startArea. Found and fixed a stranded province: when the nation reaching for it filled up, a nation with room beside it was never offered it. - spawner: provinces that are mostly ice are not claimable; two capitals in one province keep the better hub. - World: provinceOwner, ownership written through, validate() checks province ids, double holders, capital, ownership per tile, profile = sum of provinces, stats = deriveStats(profile), expansion points. - Nation gains expansionPoints; snapshots gain provinceCount. - Hash schema 4 (province fingerprint, expansion points, province ids; vectors recomputed with the independent Python reference) and save format 5. Goldens are not regenerated yet: they are pinned once, after expansion lands. Measured at 2000 x 2000: about 2,100 provinces (median 465 tiles), nations start with 2 to 4 provinces (1,200 to 2,000 tiles), creation 7.0 to 7.8 s (was 6.5 s). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
ExpansionSystem runs first in World.step(). Each tick a nation earns expansion points (config expansion.rate, scaled by 0.5 + expansionism and the square root of population/100) and spends them on the free, claimable province beside its land that is the best value for the price (price = costPerTile x area x mean cost). No chance anywhere: ties go to the lower province id and nations are served in a rotating order (start = tick mod count), so who wins a contested province alternates. Claims keep the province lists, the owner of each province and tile, and each nation's profile and stats (re-summed and re-derived) in step. Once every reachable province is taken nothing changes any more (saturated). Province facts now follow resource stocks: a stock change (extract or regrow) marks the province and those beside a changed water tile dirty and they are measured again, so facts always equal a fresh computation from the current state. This fixes a real divergence a restored world showed (facts snapshotted at creation vs. at restore) once nations started to change. claimableProvinces (mostly-ice rule) is shared by the spawner and the expansion system. At 2000 x 2000 (seed 1337, 12 nations): a tick costs 0.006 ms; nations saturate after 20,825 ticks (57 years) holding 89% of the claimable provinces, the rest being on landmasses nobody can reach by land; validate() is clean throughout. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
…nes on the map
The worker answers run { ticks } with the clock, the nations as they are and, when provinces changed hands, the
ownership layer and (only while the political view is on screen) the political overlay. host/tickRunner.ts
throttles the overlay to every 250 ms and flushes held-back updates on pause, on a switch to the political
view and when the borders settle; host/Pacer.ts turns frame time into whole ticks (a stall catches up by at
most 250 ms, a request is capped), one request in flight at a time.
The store keeps paused (a new world starts paused), speed (1, 10, 100, 1000 days a second), the clock and
whether the borders have settled. @sovereign/ui has a transport bar (date in 365-day years, play / pause,
speeds, 'Borders settled') that wraps on narrow screens, and the nation panel shows provinces and area. Space,
+ and - work from the keyboard; a mouse or touch click releases the button's focus so Space still pauses.
politicalRgba draws the lines between a nation's provinces faintly inside it. The snapshot carries the
timestep, IndexedDB is version 6, and the CLI summary reports provinces and whether the borders have settled.
Checked in a real browser (software GL): pnpm --filter @sovereign/web e2e:time (desktop play / pause / speeds
/ keys, a nation growing in its panel until the borders settle; phone portrait and landscape layout and
touch), and the existing e2e and e2e:mobile still pass.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
…ces and grow Hash schema 4. Every entry gains the province sizes of a test-sized map; two entries are new: a world whose nations are still expanding (seed 11, 300 ticks) and one whose borders have settled (seed 7, 2000 ticks), with tests that they are what they say. The depletion golden is re-pinned (the same 7,358 units are taken). Node 22, Chromium 157 and QuickJS reproduce all 27 values (these entries, the depletion golden, a save round-trip of each, and a world saved mid-growth that continues exactly like the original); the full 2000 x 2000 world for seed 1337 after 3,000 ticks hashes to 7641ec2a09f9110eb62ffa6d586f2aac on Node and Chromium. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
…at moved tests/determinism/provinces-expansion.test.ts (in a CI shard) holds three 1000 x 1000 worlds to the design: provinces are connected and sized sensibly; their borders are pulled toward costly ground more than the same seeds cut by plain distance (a control: rivers 1.4 to 1.6 times as common beside a border, against 1.0 to 1.06); the nations settle, and then nothing changes; a replay and a save in the middle give the same hash. ADR 0007 records the design and its honest limits: the pull on borders is modest (provinces are even-sized, a border can slide by half a province; mountain biomes are not enriched), creation and load are about 1.6 s slower (the layer is derived and rebuilt), and nations never fight or cross water. The terrain, nations, save-format, roadmap, development and README docs and the docs index are updated, and the performance table is re-measured. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Roadmap phase 3 core:
World.step()is no longer empty. The land is cut into provinces by travel cost, nations own provinces and grow into free ones beside them (no randomness), and the app has play / pause, four speeds and a date. Exit criterion met: one seed grows borders that settle, and replaying it (or saving in the middle and restoring) gives the same hash. Design, numbers and limits:docs/decisions/0007-provinces-and-expansion.md.Changes
terrain/provinces.ts): seeds on cheap ground aprovinces.spacingapart, one tile-level Dijkstra in travel cost, small provinces merge into the neighbour with the longest border. About 2,100 provinces on 2000 x 2000 (median ~465 tiles). Derived from terrain + config, never saved, rebuilt on create and restore.Nation.provincesis province ids in claim order; a nation's profile is the sum of its provinces' (provinceProfile.ts), stats re-derived on every change. Starting territories grow over the province graph. Fixed a stranded-province bug found by an invariant test.World.saturated).run/tickedprotocol,TickRunner(overlay throttled to 250 ms, flushed on pause / view switch / settle),Pacer, transport bar in@sovereign/ui, Space and +/- keys, province lines in the political overlay, nation panel shows provinces and area. CLI summary reports provinces and whether borders settled.provincesandexpansion.tests/determinism/provinces-expansion.test.ts(in a CI shard), ADR 0007, terrain / nations / save-format / roadmap / development docs, README.Related Issues
None.
Type of Change
Checklist
pnpm build) — not runpnpm lint)pnpm typecheck)pnpm test; andpnpm test:determinismif the engine changed)e2e:timeplus existinge2eande2e:mobile; desktop shell not exercisedCI has not run on this branch yet; everything above was run locally.
Verification and measurements
7641ec2a09f9110eb62ffa6d586f2aacon Node and Chromium.Honest limits
Generated by Claude Code