Skip to content

Strategic points from a route network; nations derived from their land - #35

Merged
CodeByBryant merged 14 commits into
mainfrom
claude/kind-edison-2locd1-routes-nations
Nov 21, 2026
Merged

CodeByBryant merged 14 commits into
mainfrom
claude/kind-edison-2locd1-routes-nations

Conversation

@CodeByBryant

Copy link
Copy Markdown
Owner

Summary

Two systems read as noise, and this PR fixes both.

Strategic points were four local scans on a grid. Over 10 worlds of 2000 x 2000 they gave about 1,580 points per world, 92% of them river crossings, a median 6.7 tiles apart, and they connected to nothing. Nations were a biome score for the start and then rng.float() for everything else (government, personality, all four stats), on a fixed 25-tile square; their stats correlated with their land at -0.13 to 0.00.

Now strategic points are the places a route network has to go through, and a nation's territory, stats, government and personality are computed from its land. See docs/decisions/0006-routes-and-nations-from-the-land.md.

Changes

  • Route network (terrain/cost.ts, heap.ts, routes.ts, suitability.ts): a movement-cost grid (biome, steepness, height, river width, coastal sea lanes; open ocean closed); hubs at the best places to live; one multi-source Dijkstra (own deterministic heap) joins neighbouring hubs, and traffic is weighted betweenness. Sites near the sea score higher (ports).
  • Strategic points read off the routes (terrain/strategic.ts): a pass where a route crosses a ridge, a ford at the narrowest river tile, a strait where a route crosses water between shores, an isthmus where it runs over a land neck. Value 1 to 10 from the route's traffic and how narrow or high the point is. Peninsulas are removed (a headland is not a chokepoint).
  • Nations from the land up (nations/): capitals on hubs, spread out (capitals.ts); starting territory grown over the cost of the ground, all nations at once, 1,200 tiles by default (territory.ts); measureProfile measures food, metals, luxuries, coast, defence, trade and neighbours (profile.ts); deriveStats, deriveGovernment, derivePersonality are pure functions of the profile (derive.ts). Stats have no randomness; government and personality get a small seeded jitter (at most 0.08 and 0.06).
  • UI: the strategic overlay draws the route lines (brighter with traffic) under the markers; the nation panel has a "Land" section showing the facts the stats follow from.
  • Contracts and config: RouteHub, StrategicRoute, NationProfile, hubs and routes in TerrainFields; new routes section, rebuilt strategic section, nations.startArea.
  • Docs: ADR 0006, terrain and nations references, determinism spec (hash schema 3, vectors recomputed with the independent Python reference), save format 4, README, roadmap, development.

Measured over 10 worlds of 2000 x 2000:

Before After
Strategic points per world about 1,580 (92% river crossings) about 160 (about 50 fords, 50 passes, 50 necks, 10 straits)
Median distance to the next point 6.7 tiles 38 tiles
Hubs / routes none about 190 / about 480
Nation starting territory 25 tiles 1,200 tiles
Population vs food (rank correlation) -0.10 0.77
Economy vs luxuries -0.06 0.87
Military vs metals -0.13 0.47
Governments that occur all 8, at random all 8, from the land
Creation time (2000 x 2000) 6.5 s about 6.5 s

Related Issues

Follows #34 (resources) and #32 (terrain retune).

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

Breaking: every existing world, hash and golden changes (pre-1.0). HASH_SCHEMA_VERSION is 3, SAVE_FORMAT_VERSION is 4 (old saves are refused), the web IndexedDB is version 5 (older saves are dropped), the strategic config was rebuilt, and peninsula is no longer a strategic point type.

Checklist

  • Builds (pnpm build): not run in this session
  • Linting and the dependency rules pass (pnpm lint)
  • Type checking passes (pnpm typecheck)
  • Tests pass (pnpm test: 12 contracts, 146 config, 59 renderer, 13 ui, 843 simulation, 48 web, 37 cli, 9 desktop, 47 tool tests; pnpm test:determinism: 42; Prettier clean)
  • Tested locally in the web app: both Playwright e2e scripts pass (the phone one was adjusted: a nation now holds a large territory, so a tap on the map reopens its panel)
  • If a golden hash moved, it is regenerated in its own commit and the reason is above (test: hash schema 3, save format 4, regenerated goldens and a routes-and-nations guard)
  • Updated documentation / JSDoc where applicable

Determinism: Node 22, Chromium 157 and QuickJS (a non-V8 engine) all reproduce all 19 pinned values (including save round trips and the depletion golden). The full 2000 x 2000 world for seed 1337 hashes to d9dac93160c04dab7721dd564f68f8a2 on Node and on Chromium. The pure code (heap, cost grid, routes, site score, route features, capitals, territory, profile, derive, the route overlay) is unit tested on drawn worlds and mutation checked; tests/determinism/routes-nations.test.ts (three 1000 x 1000 worlds) fails when the points stop lying on routes, one kind swamps the rest, or nation stats stop following from the land.

Not verified

  • CI has not run on this branch. The new guard is in a Linux and Windows determinism shard; Windows is untested.
  • The stat formulas are provisional. No economy exists yet to say what a nation needs; the constants are calibrated only so the distributions are plausible (population 34 to 195, military 18 to 150). What follows from what is the point.
  • Routes are angular (they run on a 4-tile grid and move in 8 directions); only fords are refined to the exact tile.
  • A hub sitting on the mouth of a land neck hides the neck (it becomes the end of a route). Rare on real maps where hubs are 60 tiles apart.
  • Government is tuned for full-size territories; on test-sized maps (150-tile starts) nearly every nation comes out tribal.
  • A nation's profile is measured once, at spawn. When territory changes, the simulation must call measureProfile again; nothing does yet.
  • Real iOS and Android devices are untested (Chromium emulation only).


Generated by Claude Code

Over 10 worlds of 2000 x 2000: 92% of strategic points are river crossings (1455 per world, one per 53
river tiles, median 6.7 tiles from the next point), 12 peninsulas, every nation starts with exactly 25
tiles, and nation stats correlate with the land at -0.13 to 0.00 (they are random).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
A routes section in the world config (cell, hub spacing, per-biome and slope, height, river and sea
costs) and buildCostGrid: land cells cost the base plus the mean biome, steepness and height extra of
their land tiles plus the widest river in them; water is a sea lane within reach of land and closed
beyond it. Mutation-checked.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
Hubs are picked best-first with a spacing; one multi-source Dijkstra over the cost grid gives each cell
its nearest hub, and where two hubs' territories touch the cheapest meeting is the route between them
(the natural-neighbour graph in travel cost: it crosses a strait, never an ocean). Traffic is weighted
betweenness over the hub graph. Mutation-checked; the survivors left are equivalent or tie-break only.

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
Strategic points are no longer local scans. Hubs (the best places to live) are joined by the cheapest
paths over the terrain, and the strategic points are where those routes have to go: a pass where a route
crosses a ridge, a ford where it crosses a river (the narrowest tile), a strait where it crosses water
between two shores, a land neck where it runs over narrow land between wider land. Each point's value
comes from the traffic of the routes through it. Hubs and routes are part of the terrain, the state hash,
the validation and the save header. Peninsulas are gone (they were not chokepoints); isthmus replaces them.

On 3 worlds of 2000 x 2000: 183 points per world (was 1579, 92% of them river crossings), median distance
to the next point 37 tiles (was 6.7), 192 hubs and 473 routes; creation 7.3 s (was 6.5 s).

The hash schema and save format versions are bumped, and the goldens regenerated, with the nation work.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
All nations grow at once from their capitals, each step taking the cheapest tile any of them can reach, so
territories follow open ground and stop at mountains, rivers and coasts; between equals on open ground the
border is halfway. A nation that has its area stops and the others go on. Mutation-checked.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
A pure measurement of a territory: food (fertility, rivers, coast, grain, pasture, fisheries), timber, stone,
horses, metals, luxuries, resource diversity, coast, river and high-ground tiles, the value of the strategic
points inside it, its share of route traffic and how many neighbours it has. Resource amounts are the stock
left, so a mined-out seam stops counting. Mutation-checked.

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

deriveStats is a pure function of the profile with no chance in it: population from food, military from
people, metals, horses, timber, stone and defensible ground, economy from variety, luxuries, ports and trade,
diplomacy from neighbours and trade. Government is the best-scoring of eight, personality follows
circumstance, each with a small seeded jitter so identical lands are not clones. Mutation-checked.

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

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
Nations start on hubs, spread out; their starting territory grows over the cost of the ground (1200 tiles
by default, nations.startArea); a profile measures what that land is like, and stats, government and
personality follow from it by pure functions. Stats have no randomness; government and personality get a
small seeded jitter so identical lands are not clones. Sites near the sea score higher (ports). The
nation panel shows the land the stats follow from. The profile is hashed, saved and validated.

On 8 worlds of 2000 x 2000: every nation starts with 1200 tiles (was 25), all eight governments occur,
population follows food at rank correlation 0.78 (was -0.10) and economy follows luxuries at 0.86 (was -0.06).

Goldens, hash and save versions are updated in the next commits.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
Routes are drawn as lines two tiles wide, brighter by the square root of their share of the busiest route's
traffic, under the strategic point markers. Each tile of a route is blended once however the line steps over
it. The worker builds the overlay with the routes of the world.

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

HASH_SCHEMA_VERSION is 3 (hubs, routes and each nation's profile are hashed; vectors recomputed with the
independent Python reference), SAVE_FORMAT_VERSION is 4, the web database is version 5. World, terrain and
depletion goldens regenerated (the golden worlds now use a 24 tile hub spacing and a 150 tile starting area).

tests/determinism/routes-nations.test.ts (three 1000 x 1000 worlds, in a CI shard) fails if the strategic
points stop lying on routes, one kind swamps the rest, they crowd together, or nation stats stop following
from the land (it fails when population is made to ignore food).

Node 22, Chromium 157 and QuickJS all reproduce the 19 pinned values; the full 2000 x 2000 world for
seed 1337 hashes to d9dac93160c04dab7721dd564f68f8a2 on Node and Chromium.

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

ADR 0006 (routes and nations from the land), the terrain and nations references, save format 4, README,
roadmap and development notes with the measured numbers. The phone e2e closes the nation panel before it
looks at the resource legend (a nation now holds a large territory, so a tap on the map reopens its panel)
and hides the tile inspector for the tap on the capital, which in landscape the sheet would cover.

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 21, 2026 01:48

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 merged commit dbdf247 into main Nov 21, 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