Skip to content

Retune terrain so all 26 biomes generate (ocean unchanged); touch and phone controls; remove Dependabot - #32

Merged
CodeByBryant merged 11 commits into
mainfrom
claude/kind-edison-2locd1-biome-probe
Nov 20, 2026
Merged

CodeByBryant merged 11 commits into
mainfrom
claude/kind-edison-2locd1-biome-probe

Conversation

@CodeByBryant

Copy link
Copy Markdown
Owner

Summary

A probe over 10 full-size worlds found that only 22 of the 26 biomes ever generated: no mountains, highland, alpine or glacier, and deserts, jungles and wetlands under 0.01% of tiles. The original app had the same limits. This PR fixes that without touching the ocean (it is now pinned to exactly what it was), adds touch and phone controls, and removes the Dependabot config. 11 commits, each independently reviewable; the goldens are regenerated in their own commit, per the determinism policy.

Cause. Every terrain field was a narrow bell curve around 0.5 while the biome table assumed a broad 0 to 1 spread (elevation peaked at 0.37 to 0.59 against mountain/alpine/highland thresholds of 0.85/0.78/0.74; temperature almost never reached the 0.7 "tropical" band). Tuning noise knobs cannot fix that across seeds, so each field is now reshaped by rank into a designed distribution (monotone, so coastlines and ridges do not move), and the climate table was fitted to agreed target shares. See docs/decisions/0004-distribution-aware-terrain.md.

Changes

Terrain (10 seeds, 2000 x 2000, none used for fitting)

Before After
Biomes that generate 22 of 26 26 of 26, in 10 of 10 worlds
Ocean (19% deep, 55.5% ocean, 3% shore) about right, one seed off exact on every seed
Land amount 25.2 to 25.6%, one seed 42.6% 25.5% on every seed
Mountain / alpine / highland, % of land 0 / 0 / 0 4 / 2.4 / 7.6
Desert, % of land 0.003 about 6
River coverage, % of land 7.4 7.6
Mountain passes per world 0 about 48
Gold / iron / stone, % of land 0 / 0.009 / 0.12 0.055 / 2.7 / 13.6
Time per 2000 x 2000 world 5.8 s 5.8 s

20 of 23 climate biomes are within +/-30% of their target share; the rest (polar desert, glacier, mangrove) are within 0.5x to 2x.

  • remapByProfile / scaleToUnit (math/quantile.ts): the rank remap, deterministic by construction (integer histogram and + - * /). Matches an independent Python reference bit for bit; mutation-checked.
  • Config: elevation.profile, temperature.profile, humidity.profile, the classifier as data (biomes.bands, biomes.lowlandBand), strategic.mountainPassRise / mountainPassMinRatio; validation for all of it; redistributionPower removed.
  • glacier was unreachable code; it is the polar table's top row. The old decision tree is kept in the tests as an oracle that the table reproduces it everywhere except that one change.
  • Rivers re-tuned (thresholds x0.72), and the mountain-pass detector made configurable (it found none before, with or without mountains).
  • tests/probe/biome-coverage.probe.ts (10-world measurement) and fit-climate.probe.ts (refits the climate table); pnpm probe printed nothing after the vitest 5 bump (my earlier regression) and now does.
  • tests/determinism/biome-coverage.test.ts: a guard that runs in CI on Linux and Windows. It fails when I put the original bugs back (glacier unreachable, no mountains, deserts removed, ocean moved).

Touch and phone controls (1c8a3f0)

  • GestureTracker (pure, 24 tests): one finger pans, two fingers pinch (with midpoint pan), a quick release is a tap. A mouse behaves exactly as before.
  • A tap selects a nation and fills the tile inspector (a phone has no hover). Zoom -/+ in the toolbar.
  • Layout: touch-action: none, 44 px tap targets, a toolbar that wraps instead of spilling off a 390 px screen, side panels become bottom sheets on narrow or short screens, safe-area insets, viewport-fit=cover, Fullscreen hidden where unsupported.
  • A mobile e2e (Chromium touch emulation, 390x844 and 844x390) and extra mouse checks in the desktop e2e. Both read the camera from data-camera-* attributes: screenshots of a WebGL canvas alternate between frames on software GL, which made my first version of the check unreliable.

Other: Dependabot configuration removed (its alerts and security updates are repository settings and are unaffected). Docs: ADR 0004, determinism spec section 6.2, terrain.md, development.md, README controls.

Related Issues

Follows the restructure stack (#17 to #24). Supersedes the closed Dependabot PRs (#26 to #31).

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 for users: every existing world changes (pre-1.0), the same seed gives a different world than before, and old saves are refused (save format 2). The web app drops its stored saves on upgrade (IndexedDB version 3).

Checklist

  • Builds (pnpm build)
  • Linting and the dependency rules pass (pnpm lint)
  • Type checking passes (pnpm typecheck)
  • Tests pass (pnpm test: 464 simulation, 82 config, 45 web, 47 tool tests and others; pnpm test:determinism: 26)
  • Tested locally in the web app: both e2e scripts pass; real-browser IndexedDB upgrade and save round trip pass
  • If a golden hash moved, it is regenerated in its own commit and the reason is above (c6f3cc4; 16 hashes, each taken from the failing test's own output; one scenario's premise re-pointed, explained in the commit)
  • Updated documentation / JSDoc where applicable

Determinism, verified against the new goldens: Node 22, Chromium 157 and QuickJS (a non-V8 engine) all reproduce all 16 golden values (including a save round trip of each). The full 2000 x 2000 world for seed 1337 hashes to 5f5c15c6742f3492f52fca8920c92532 in Node, in Chromium and in the CLI. HASH_SCHEMA_VERSION is unchanged; SAVE_FORMAT_VERSION is 2.

Not verified

  • CI has not run on this branch yet; the first run on this PR is its first. It adds the biome-coverage guard to the Linux/Windows determinism shard and the mobile e2e to the e2e job.
  • Real iOS and Android devices were not tested: the mobile checks are Chromium's touch emulation. Memory for the 2000 x 2000 world on low-end phones is unmeasured; the map size is deliberately left as is so a seed is the same world on every device.
  • The web app's Worker hash was not recomputed this round (it runs the same engine code as the CLI, which was).
  • The rare polar and wet biomes depend on small, seed-specific regions, so their shares vary most between seeds.

Generated by Claude Code

… vitest 5

Adds tests/probe/biome-coverage.probe.ts, a measurement (never part of a suite) that generates
10 full-size worlds, reports each biome's share of all tiles and of land, and sweeps the
classifier over every input to separate "can never be emitted" from "rare in real worlds".

Finding: only 22 of 26 biomes generate. glacier, alpine, highland and mountain never appear.
Elevation tops out around 0.37-0.59 while highland starts at 0.74, alpine at 0.78 and mountain at
0.85; glacier is also dead code (every tile high enough was already classed highland/alpine/
mountain). The original app's generator has the same ceiling (0.36-0.44), so this predates the
restructure. Desert, rainforest, wetland and mangrove are under 0.01% of tiles.

vitest.probe.config.ts now uses the verbose reporter: vitest 5's default reporter hides the
console output of passing tests, which silently emptied `pnpm probe` after the toolchain bump.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
Version-update pull requests are not wanted. Nothing else in the repository referenced the file.
GitHub's own Dependabot security alerts and updates are repository settings, not this file, and
are unaffected; they can be switched off in Settings > Code security if wanted.

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

Extends the biome coverage probe so a retune can be compared with the code it replaces. Baseline
on today's generator, 10 seeds at 2000 x 2000 (percent of land tiles, mean): river tiles 7.4
(4.9 to 9.7), timber 26.3, fertile 20.8, fur 17.0, fish 0.87, stone 0.12, iron 0.009, gold 0.000;
strategic points per world: river crossings about 1456, straits 66, peninsulas 13, mountain
passes 0; 12 nations spawned on every seed.

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

remapByProfile ranks each tile of a field among the others (optionally only among masked tiles,
such as land) and gives it the value a piecewise-linear profile assigns to that rank. The map is
monotone, so coastlines, ridges and latitude bands stay where they are; only the values move.

It is deterministic by construction: a 65 536-bin integer histogram, a running sum and within-bin
interpolation using only + - * / and Math.floor; no sort, no transcendental, no iteration-order
dependence. Equal values share the rank of the first of them. Out-of-range values clamp to the end
bins; non-finite values, a mask of the wrong length and an invalid profile are RangeErrors.

Tested against an independent reference written from the spec in Python: two 200 000-value hashes
match bit for bit, plus small vectors and properties (monotone, exact quantiles, masks, plateaus,
clamping). Mutation-checked: every non-equivalent mutant is killed. QuantileProfile is a new type in
@sovereign/contracts. Nothing calls it yet, so no world changes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
…e table; save format 2

WorldConfig gains what the retuned pipeline needs, with no change to any world yet:

- elevation.profile, temperature.profile, humidity.profile: monotone rank-to-value maps. The
  default elevation profile pins today's ocean exactly (19% deep ocean, water 74.5% of tiles at sea
  level 0.37, shore 3%) and puts 14% of land above the highland threshold, 7.5% above alpine
  and 4% above mountain. Temperature and humidity start as even spreads over land; they are tuned
  against the probe next.
- biomes.bands and biomes.lowlandBand: the temperature x humidity table that was hard-coded in the
  classifier, as data, with glacier now the polar table's top row (it was unreachable code).
- validateWorldConfig checks all of it (profile shape and range, band and row order, known
  biomes); mutation-checked. resolveWorldConfig copies array-valued fields so a resolved config never
  aliases the defaults.

SAVE_FORMAT_VERSION is 2 because the saved config's shape changed; a version 1 file is refused as an
unsupported version. The web app's IndexedDB moves to version 3 and drops older records, as it did
for version 2. redistributionPower is removed together with its only reader in the next commit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
…nfig; glacier is reachable

determineBiome now looks land up in `config.bands` (first band whose maxTemperature is above the
tile's temperature, then the first row whose maxHumidity is above its humidity) instead of a
hard-coded decision tree, so tuning the climate is a change to data. Water, shore and the
highland/alpine/mountain elevation gates still come first.

The old tree is kept in the tests as an oracle, run on its own thresholds written out as a table:
over 1.9 million input combinations the table agrees with it everywhere except one place, the
intended change. Wet polar land is now glacier; the tree's glacier branch could never be reached
because every tile high enough was already highland, alpine or mountain. A second test proves all 26
biomes are reachable, and nine mutants of the lookup are all killed.

Determinism goldens are stale from here until they are regenerated at the end of this series.

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

The biome probe found only 22 of 26 biomes generating (no mountains, highland, alpine or glacier;
deserts, jungles and wetlands under 0.01%). Cause: every field was a narrow bell around 0.5 while the
biome table assumed a broad 0 to 1 spread (elevation peaked at 0.37 to 0.59 against thresholds of
0.74/0.78/0.85; temperature almost never reached the 0.7 tropical band). The original app had the
same ceiling.

Elevation, temperature and humidity are now reshaped by rank (remapByProfile) into the
distributions in `elevation.profile`, `temperature.profile` and `humidity.profile`, so the
thresholds mean what they say on every seed. The map is monotone, so coastlines, ridges and latitude
bands are untouched. The ocean is pinned to exactly what it was: 19% deep, 55.5% ocean, 3% shore,
25.5% land on every seed (it was 25.2 to 25.6% on nine seeds and 42.6% on the tenth). The
power curve (redistributionPower) is gone, the generators no longer clamp (a clamp makes masses of
identical tiles that no ranking can separate; scaleToUnit feeds the remap instead), and the rivers'
humidity boost now comes after the humidity reshaping, in the units it was written for.

Tuned with the probe (10 seeds, 2000 x 2000, none of them used for fitting):
- climate: the temperature knots and every humidity threshold are fitted by
  tests/probe/fit-climate.probe.ts so each biome covers a target share of land. All 26 biomes appear
  in 10 of 10 worlds; 20 of 23 climate biomes are within +/-30% of target, the rest (polar desert,
  glacier, mangrove) within 0.5x to 2x.
- elevated land: mountain 4%, alpine 2.4%, highland 7.6% of land (there was none).
- rivers: thresholds x0.72, 7.6% of land (baseline 7.4%; it would have been 10.5%).
- mountain passes: the detector's two constants are now strategic.mountainPassRise / MinRatio
  (0.02 / 0.35); 48 per world (it found none before, with or without mountains).
- other layers: stone 13.6% (was 0.1), iron 2.7% (0.009), gold 0.055% (0); 12 nations on every seed.
Creation time is unchanged at about 5.8 s per 2000 x 2000 world.

Fast-suite tests that relied on the compressed field are adapted: the land-ratio rescue still works
but only fires for a custom sea level now, so those tests force it with sea level 0.9. The pinned
nations golden and the determinism goldens are stale until regenerated in the next commit.

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

Every pinned world moves, on purpose: the terrain pipeline now reshapes elevation, temperature and
humidity by rank (previous commit), so every biome, river, resource and strategic point changes.
The hash layout is unchanged (HASH_SCHEMA_VERSION stays 1). 16 hashes updated: the 8 world
entries in world-hashes.json, the 7 terrain goldens and the nations golden. Each new value was
taken from the failing test's own output, not computed by hand.

One scenario's premise is re-pointed. "land-ratio rescue (default sea level 0.37)" no longer
exercises the rescue, because the default sea level now leaves 25.5% land on every seed; it is
renamed to "sea level 0.9 leaves too little land" and uses sea level 0.9, which does.

Verified against the new values: Node 22, Chromium 157 and QuickJS (a non-V8 engine) all reproduce
all 16 golden values, including a save round trip of each; the full 2000 x 2000 world for seed 1337
hashes to 5f5c15c6742f3492f52fca8920c92532 in Node, in Chromium and in the CLI.

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

A probe once found that four of the 26 biomes never generated and that the amount of land depended
on the seed, and nothing in the test suite noticed. tests/determinism/biome-coverage.test.ts
generates three 1000 x 1000 worlds (about 5 s) and fails if a biome is missing, the deep ocean, ocean
or shore share moves off what the elevation profile pins, any biome leaves a 4x band around its
target share of inland land, or the elevated land drifts from about 4% mountain and 14% highland
or above.

It is not decorative. Reintroducing the original bugs makes it fail: glacier made unreachable
again, mountains removed from the elevation profile, deserts removed from the climate table, and
the ocean amount moved. It runs in CI on Linux and Windows (added to the world-goldens shard;
tools/determinism-shards.test.mjs requires every determinism file to be in exactly one shard).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
…e, measured results)

- ADR 0004: why terrain fields are reshaped by rank, the alternatives, consequences and guards.
- determinism.md section 6.2 specifies the rank remap (histogram, rank, profile evaluation,
  scaleToUnit) with the two reference hashes, and the enforcement table gains the remap and the
  biome-coverage guard.
- terrain.md: the distribution stage with the ocean-pinning table, unclamped temperature and
  humidity, the table-driven classifier, the fitted climate with target vs measured shares for
  all 23 climate biomes, new river thresholds, mountain pass settings and the profile config.
- development.md: the coverage and climate-fit probes, and the new determinism-suite guard.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
The map was built for a mouse. On a phone, touch panning was unreliable (the canvas had no
touch-action, so the browser could claim the touch and cancel the stream), there was no pinch zoom,
a tile could not be inspected (the inspector updated on hover), and the layout did not fit 390 px:
the toolbar spilled 30 px off screen, the two side panels covered the map and each other, every button
was 38 px, and there was no safe-area handling.

Input: GestureTracker (apps/web/src/input) is pure logic that turns pointer events into pan, pinch
(scale about the midpoint, plus the midpoint's movement) and tap, with no jump when a finger lands or
lifts. A tap is a quick release that never strayed from where it went down, so a drag that ends where
it began is not a selection. 24 tests, mutation-checked (the two dead-code survivors found were
removed). MapView uses it: one finger pans, two fingers pinch, a tap selects a nation and fills the
tile inspector. A mouse behaves exactly as before (hover inspects, click selects, wheel zooms).

Layout: touch-action none on the canvas; zoom -/+ buttons in the toolbar (also useful with a
trackpad); 44 px tap targets on touch; on narrow or short screens the toolbar wraps and the panels
become bottom sheets (dvh heights, one at a time, above the toolbar); safe-area insets and
viewport-fit=cover; the Fullscreen button is hidden where the API is missing (iPhone); the
inspector hint reads "Tap or hover over a tile".

Tests: a mobile e2e in Chromium's touch emulation (390x844 and 844x390) checks that the layout fits and
nothing overlaps, and that a drag pans, a pinch zooms, the toolbar zooms, a tap on a nation's
capital opens its panel as a sheet and closes again, and a tap fills the inspector. It failed on the
old layout for the right reasons and fails if the tap handler is broken. The desktop e2e now also
checks hover, wheel, drag and click-to-select. Both read the camera from data-camera-* attributes
on the map shell: screenshots of a WebGL canvas alternate between frames on software GL, which made
the first version of the check unreliable. CI runs both.

Not covered: real iOS and Android devices (this is Chromium's emulation), and memory on low-end
phones with the 2000 x 2000 world, which is left as is on purpose so a seed is the same world on
every device.

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 20, 2026 17:30

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 f1c4cd0 into main Nov 20, 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