Skip to content

docs: add comprehensive REFERENCE.md for pipeline, formulas, and config - #25

Merged
countercheck merged 4 commits into
masterfrom
claude/determined-grothendieck-a55663
May 11, 2026
Merged

docs: add comprehensive REFERENCE.md for pipeline, formulas, and config#25
countercheck merged 4 commits into
masterfrom
claude/determined-grothendieck-a55663

Conversation

@countercheck

Copy link
Copy Markdown
Owner

Summary

  • New docs/REFERENCE.md (~1,400 lines) — a single reference covering the 15-stage pipeline, every calculation, and all ~70 WorldConfig parameters with defaults, ranges, and effects
  • Includes a colour-coded mermaid flowchart of the pipeline in §1
  • Every formula is tagged with a file:line link into the source
  • README gets a one-line pointer near the top
  • Bundled separately: a small style: apply ruff format commit fixing pre-existing formatter drift in 3 unrelated files (line-wrap normalisation, no behavioural change)

What's in the doc

  1. Overview — scale, axial coordinates, reproducibility, pipeline diagram
  2. Data Model — WorldState, Hex (every field with range and writer), enums, tag vocabulary
  3. Pipeline & Algorithms — one section per stage with reads/writes, plain-English algorithm, key formulas, and source links. Heavy detail on the meatier stages (Erosion's particle hydraulics, Hydrology's 8-phase Priority-Flood / lake drainage / confluence splitting, Climate's orographic precipitation, Roads' gravity model + pheromone + slope cost)
  4. Configuration Reference — 16 grouped tables of every WorldConfig parameter, cross-linked to the §3 stages that consume them
  5. In-Code Constants — magic numbers outside WorldConfig (erosion _MAX_STEPS, mountain elev cap >0.8, habitability weights, dense-forest threshold (wet_moist+1)/2, hardcoded village separation 3, etc.)
  6. Outputs — what worldgen generate writes
  7. Glossary — fBm, domain warp, lapse rate, orographic precipitation, Priority-Flood, gravity model, Gumbel-max, etc.

Why

README.md covers usage and worldgen_plan.md is the original spec, but neither answers "how does this number in config.py actually affect the map?" or "what's the formula behind orographic moisture / road slope cost / lake spillway routing?" — anyone tuning a world or extending a stage today has to read source. This doc closes that gap, and is structured so a config-tuner can land in §4 and skip the math while a code-extender can read §3 top-to-bottom.

Test plan

  • python3 -m ruff check . — passes
  • python3 -m ruff format --check . — passes (52 files clean)
  • python3 -m pytest — 210 passed
  • Spot-checked defaults in §4 against worldgen/core/config.py
  • Spot-checked formulas in §3 against cited source lines (climate temperature, hydrology Dijkstra penalty, road grade-percent)
  • Pipeline order in §1 matches cli.py:58–74
  • Reviewer: open docs/REFERENCE.md on GitHub and verify the mermaid flowchart renders

🤖 Generated with Claude Code

countercheck and others added 3 commits May 10, 2026 14:02
Three files had drifted out of ruff format compliance on master. Pure
formatting changes (line-wrap normalization in error messages and
comments); no behavioural change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
A single reference doc that explains every calculation in the 15-stage
pipeline — with file:line links to source for every formula — and
documents all ~70 WorldConfig parameters plus the in-code constants that
shape map output. Includes a colour-coded mermaid flowchart of the
pipeline. README gets a one-line pointer.

Closes the gap between user-facing setup docs (README.md) and the
original spec (worldgen_plan.md): neither covers "how does this number
in config.py actually affect the map" or "what's the formula behind
orographic moisture / road slope cost / lake spillway routing".

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The original 'config.py:42-113' range endpoint was off-by-one against
unmerged origin/master (which has it at line 114) due to a one-line
formatter shift. Dropping the endpoint makes the citation correct in
both states; the link target #L42 is stable either way.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@countercheck
countercheck requested a review from Copilot May 10, 2026 19:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a consolidated reference document intended to explain the full worldgen pipeline, formulas, and WorldConfig parameters, and links it from the README. Includes a small ruff-format-only cleanup in a few existing files.

Changes:

  • Add docs/REFERENCE.md covering pipeline stages, algorithms/formulas, config parameters, constants, outputs, and glossary.
  • Add a short README pointer to the new reference doc.
  • Apply ruff format normalization to a few existing Python/test files (no behavioral changes intended).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
worldgen/core/config.py Formatting-only changes (line wrap/indent normalization in config + validation error message).
tests/test_settlements.py Formatting-only changes (assert line wrapping).
tests/test_road_cost.py Formatting-only changes (assert message wrap).
README.md Adds a link near the top pointing readers to docs/REFERENCE.md.
docs/REFERENCE.md New comprehensive reference doc for the pipeline, formulas, and configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/REFERENCE.md Outdated

**Algorithm**

Eight phases, top to bottom in
Comment thread docs/REFERENCE.md Outdated
incoming = mean(atm[upwind neighbours]) or 1.0 if none upwind
lift = max(0, hex.elevation - sea_level)
fraction = min(1, lift * orographic_strength)
hex.moisture = incoming * fraction
Comment thread docs/REFERENCE.md Outdated
Comment on lines +622 to +624
river-tagged neighbour at `≤` its own elevation. This builds a wider
moisture corridor along big rivers, especially in valleys, but never
uphill. Re-normalised after the passes.
Comment thread docs/REFERENCE.md Outdated
Comment on lines +1042 to +1049
**Stochastic placement** uses the **Gumbel-max trick**
([village_placement.py:80–81](../worldgen/stages/village_placement.py#L80)):
```
u = uniform_random per candidate
order = sort by -u^(1/weight) descending
```
This is equivalent to drawing weighted samples without replacement. Then
the stage walks `order` and accepts a candidate iff it is `>= 3` hexes
Comment thread docs/REFERENCE.md Outdated
- **Coordinates:** axial `(q, r)`, flat-top hexagons.
Neighbours, distance, ranges, and pixel conversion live in
[worldgen/core/hex_grid.py](../worldgen/core/hex_grid.py).
Hex distance is the standard cube-distance halved:
@countercheck

Copy link
Copy Markdown
Owner Author

@copilot apply changes based on the comments in this thread

Agent-Logs-Url: https://github.com/countercheck/worldgen/sessions/3ecf7792-6de2-483d-b3a5-90137dd234bc

Co-authored-by: countercheck <4325443+countercheck@users.noreply.github.com>

Copilot AI commented May 11, 2026

Copy link
Copy Markdown
Contributor

@copilot apply changes based on the comments in this thread

Implemented all requested review-thread fixes in docs/REFERENCE.md and pushed in commit 7d6bd48: corrected hex-distance wording, hydrology count text, defined precip in climate pseudocode, fixed moisture-bleed elevation gating direction, and renamed the village sampling algorithm reference (plus glossary) to Efraimidis–Spirakis.

@countercheck
countercheck merged commit a517acf into master May 11, 2026
3 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