Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ PR → merge.

- **Tests (what CI runs, `.github/workflows/tests.yml`, SDK 8):** `dotnet run --project OptimizedLocalHousing.Tests -c Release`
must end with `40 checks passed.` (41 exist; the compiled-adapter check needs the built mod and the game, so it runs
only locally with two extra arguments; see README "Build and test").
- **Build and package** (needs a local Timberborn install; never done in CI): see README "Build and test", then `./package.ps1`.
only locally with two extra arguments; see `DEVELOPING.md`).
- **Build and package** (needs a local Timberborn install; never done in CI): see `DEVELOPING.md`, then `./package.ps1`.

## Standing rules

Expand All @@ -18,6 +18,24 @@ PR → merge.
- Compare fairly with Bobingabout's Housing Optimize and Commute Balancer, by what their Workshop pages say. Never
"the best housing mod". The 25.6 vs 24.1 figure is a model with straight-line distances, not a benchmark.

## Writing README and website text

Kyler, 2026-09-24: "simplicity and elegance is effective and desirable." Every change to the README, the website
text and the player docs follows these rules.

- **Write for a Timberborn player** who wants to download, install and use the mod. Developer detail goes in
`DEVELOPING.md` or the changelog; link to it rather than repeating it.
- **Short.** One idea per sentence, most under about 20 words. A paragraph or FAQ answer is one to three sentences,
a troubleshooting answer a few numbered steps.
- **Lead with the action.** Menu paths as arrow chains; on-screen labels in bold, exactly as in game.
- **Say each thing once**, where a player would look for it; link to it elsewhere.
- **Plain words.** No internals (class names, ids, formats) unless the player needs them to act.
- **Cut** filler, repeated caveats, edge cases a player won't meet, and history ("since …", "no longer", older
builds). Describe the mod as it is now.
- **Check every fact against the code** before writing it; changelogs lag.
- **Keep, briefly:** credits, the unofficial line, the status, and safety facts.
- **Reread as a new player before publishing.** Every step works as written, and nothing is said twice.

## Website

- **Where:** `docs/`: `index.html`, `install.html`, `troubleshooting.html`, `faq.html`, `404.html`, `style.css`,
Expand Down Expand Up @@ -93,6 +111,7 @@ PR → merge.

### Content rules

- Every text change follows *Writing README and website text* above.
- Describe the mod as it is now. No "New in <version>", "added in …" or version history on player pages; that belongs
in the README changelog and the GitHub release notes. Upgrade steps players need are the only exception.
- The played and not-played status matches the README exactly: the 1.0 code (released as 1.0.0) ran 16 passes in a
Expand All @@ -104,12 +123,13 @@ PR → merge.
- Terminology: pass; move cycle; route cost / route-cost unit (the game's own, not straight-line); commute; adults,
children, homes, workplaces, districts; the 32 nearest homes; rejected, stale; Hungarian algorithm.
- `docs/release.js` is shared across timbermods sites and byte-identical: replace it, never edit it. Check:
`git hash-object docs/release.js` equals `gh api repos/timbermods/MixedStorage/contents/site/assets/release.js -q .sha`.
`git hash-object docs/release.js` equals `gh api repos/timbermods/MixedStorage/contents/docs/assets/release.js -q .sha`.
- `404.html` uses absolute `/OptimizedLocalHousing/` paths and loads no scripts (unstyled on the local preview; that's expected).

### Update the website for a new release

When asked to "update the website for the latest release, consistent with the design":
When asked to "update the website for the latest release, consistent with the design" (write every change by
*Writing README and website text* above):
1. Read the release and the docs: `gh release list -R timbermods/OptimizedLocalHousing -L 5`,
`gh release view <tag> -R timbermods/OptimizedLocalHousing`, README (incl. Changelog and "What has not been
measured"), PRODUCT.md. List every player-facing change.
Expand All @@ -125,7 +145,7 @@ When asked to "update the website for the latest release, consistent with the de
- Requirements and game version (built against 1.1.2.4, minimum 1.1.0.0): install `#requirements`, FAQ
`#which-game-versions-operating-systems`, troubleshooting `#update`, index hero lead and meta description.
- Behaviour: index `#features` (six rules; the head says "Six rules"), `#how` steps, `#rules` always / never,
`#compare` table, `#results`; FAQ `#does-it-have-settings` (tuning constants); log messages in troubleshooting
`#compare` table, `#results`; FAQ `#does-it-have-settings` (links the tuning constants in `DEVELOPING.md`); log messages in troubleshooting
`#log` table and symptoms; install `#layout` (the `version-1.1` folder tree), `#update`, `#uninstall`.
- `<meta name="description">` / `og:description` on every page, and PRODUCT.md's Operating Context.
3. Put new content into the existing components: a rule → `ul.rules-key` item (h3 + p); always / never → `ul.checks` /
Expand Down
88 changes: 88 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Developing Optimized Local Housing

For people who build, test or change the mod. Players want the [README](README.md) and the
[website](https://timbermods.github.io/OptimizedLocalHousing/). The website's own rules are in `CLAUDE.md`.

## Build and test

Requires .NET SDK 8. Building the mod also needs a local Timberborn installation; no game DLLs are redistributed.
The tests compile only the game-independent engine and restore Newtonsoft.Json from nuget.org (13.0.4, the same
release the game ships), so they run without the game. CI (`.github/workflows/tests.yml`) runs them that way on
every push to main and every pull request, without the two arguments below: the compiled-adapter check needs the
built mod and the game, so it runs only locally.

```powershell
dotnet build OptimizedLocalHousing/OptimizedLocalHousing.csproj -c Release -p:GameManaged="C:\path\Timberborn_Data\Managed"
dotnet run --project OptimizedLocalHousing.Tests -c Release -- OptimizedLocalHousing/bin/Release/netstandard2.1/OptimizedLocalHousing.dll "C:\path\Timberborn_Data\Managed"
./package.ps1
```

The tests cover the solver against brute force, pause/resume at every row, cycle splitting, optimality on
random colonies with one to three districts, route queries that stay inside a district, each district solved on
its own (the same homes as a colony of that district alone, in no more ticks), the safety rules in the README,
stale-world handling, route costs carried from one pass to the next and priced again when they come due,
determinism between peers, save/reload at every tick of three passes (the first, the next, and the one where the
first pass's remembered costs come due; with one district and with several), per-tick work bounds (route
queries, and solver operations with one budget across districts), large colonies whose passes end within the
daytime with budgets set from the colony (in lockstep across a reload mid-pass), and the compiled adapter against
the installed game's component blacklist. Omitting the two arguments skips the compiled-adapter check.

## How a pass works

`GameAdapter.cs` is the thin bridge to the game; `PassEngine.cs` and `Assignment.cs` hold everything else. Each pass:

1. **Capture.** Every housed adult beaver, its home, and its assigned workplace.
2. **Price.** For every workplace, real route costs (`Accessible.FindRoadPath`, so ziplines and stairs count)
from the 32 nearest homes in its district. Homes in other districts are never queried, because the game's
route search never leaves a district. Homes farther away are estimated, and any move to one is re-checked
with a real route before it is allowed.
3. **Solve.** The optimal way to reassign the adults to the beds that adults occupy today (the Hungarian
algorithm). Nobody moves between districts, so each district is solved on its own, one after another. In a
colony with several districts that takes far fewer ticks and far less memory than solving them as one (47 solve
ticks instead of 157 for four districts of 300 adults), and reaches the same optimum.
4. **Verify.** Every proposed move is re-priced with fresh routes. A whole cycle of moves is dropped if it would
leave a beaver who can reach work today unable to, and each cycle must save at least half a route-cost unit in
total. The fresh costs of homes beyond the 32 nearest are remembered in place of estimates, so a move that was
turned down is not proposed again every day (anything proposed is still re-priced first). A remembered cost is
used for seven passes. The seventh prices it again, and keeps it, if one of that workplace's workers lives in
the home or if there was no route (so a road that comes back is noticed); otherwise it lapses to the estimate.
5. **Apply.** Moves are applied as whole cycles (A takes B's bed, B takes C's, C takes A's), in one game tick.

Each beaver gets a one-route-cost-unit bonus for staying put (`StayBonus`), so a rearrangement must save at least one
unit for every beaver it moves.

## Cost

- Work is spread over ticks with budgets per tick: **32 route queries** and about 250,000 solver operations on a
colony of a few hundred adults. A pass takes roughly a fifth of a game day (147 ticks on a 266-beaver colony),
never one long stall.
- A larger colony's pass takes larger budgets, set from the colony when the pass starts and saved with it, so
that it still ends within the day's 512 daytime ticks: at most **128 route queries** and about 1,000,000 solver
operations per tick (plus the solver row it started last). On test colonies of 1,600 adults in one district a
pass takes 480 ticks on randomly housed adults (1,118 with the smallest budgets), and about 216 (740) once they
are settled. The route-query budget stops growing at about 770 staffed workplaces, and the solver budget at about
1,150 adults in one district (about 920 in each of two, or 800 in each of three), so a still larger colony's
pass takes longer instead (609 ticks on 2,000 randomly housed adults in one district).
- The replay of the real 266-beaver colony took 147 ticks, 4,388 route queries and about 22 ms of total CPU.
- Not measured: frame-time impact. The per-tick work is bounded, but the cost of a real path query has not been
timed, nor the larger solver budget that large districts get: more than about 730 adults in one district, about
580 in each of two, or about 500 in each of three.

## Multiplayer and saved state

- All decisions use integer arithmetic and sorted IDs, and the whole pass state (snapshot, prices, solver rows,
verification results, and the route costs kept from earlier passes) is saved with the game. Reloading mid-pass,
or a peer that loads a save taken mid-pass while another peer keeps running, continues exactly where the pass
was and does the same work on every following tick, so every peer applies the same moves on the same tick.
There is no wall-clock or frame-time rule anywhere.
- For Timber Together: the mod only ticks inside the simulation, draws no random numbers, never moves a beaver
between districts (so colonies stay separate), and nothing it touches is patched by BeaverBuddies.
- The saved state is a few hundred bytes when idle on a settled colony, and a few KB (about 20 KB at 1,300
adults) where beavers keep changing jobs. For seven days after a pass that moved many beavers it also holds the
route costs that pass checked, capped at 1,024 (about 11 KB for 240 adults, about 85 KB at the cap). During a
pass it grows with the colony: about 70 KB for 240 adults, 100 KB for 350 to 400, 380 KB for 1,300.

## Tuning constants

There are no settings. The tuning constants are in the source: `NearHomes`, `QueriesPerTick` and the other
per-tick budgets in `PassEngine.cs`, and `StayBonus` in `Assignment.cs`.
4 changes: 3 additions & 1 deletion PRODUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ Success, in order:
## Brand Commitments

- **Voice:** a fellow player explaining a useful mod: clear, exact, a little proud of the math, never hype. "Straight
answers, including the ones that aren't flattering." Numbers are given with their caveats.
answers, including the ones that aren't flattering." Numbers are given with their caveats. Short and plain: one
idea per sentence, each thing said once, no internals and no history (see CLAUDE.md, *Writing README and website
text*).
- **No official Timberborn logos or key art.** The game's own item icons are allowed where used (none are used today).
The site's marks are its own: `favicon.svg` (a house linked to a workplace) and simple line icons.
- **License:** MIT, copyright Timbermods, for the code, docs and site.
Expand Down
Loading