Repository navigation
Move adults into empty beds when that shortens the total walk - #16
Merged
Merged
Conversation
A pass used to swap adults only between the beds adults already occupied, so an empty home beside a workplace was never used. Each district is now solved over its occupied and empty beds (rectangular Hungarian, n adults by m beds). Moves that end in an empty bed are applied as chains; cycles are unchanged. A home's number of adults can now change. Children still never move, and paused, blocked or automation-off homes still gain nobody. - Snapshot.HomeFree; the adapter lists every usable home with an empty bed in each district through its DistrictBuildingRegistry. - Cycles.SplitChains splits the moves into chains and cycles, each applicable on its own. - A lone adult is no longer skipped: it can move into an empty bed. - PassState version 6: a pass running in an older save starts over once. - Tests: chain splitting, brute-force optimum with empty beds, the empty lodge beside a workplace, and empty beds in the lockstep and reload tests (43 run). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J9E8mdmw7xR61ijmdTWXg8
A chain of moves into an empty bed takes an adult out of its first home and puts one into its last. It is now turned down if that would leave the colony fewer homes with at least two adults and an empty bed, the homes that can have a kit. Cycles keep every head count, so they are unaffected. Counts are carried across the chains a pass applies, so the total never falls. Tests: the lodge beside a workplace is refused when the worker's home would stop breeding, and allowed when it keeps or makes a breeding home; 60 colonies with empty beds over several passes never lose a breeding home (45 run). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J9E8mdmw7xR61ijmdTWXg8
Checked against the decompiled game (Timberborn 1.1.2.4): - Breeding (Folktails' ProcreationHouse): a kit needs two adults, a free bed, and fewer children than the home's child beds (a third of its beds, rounded down) and than half its adults, rounded down. The engine assumed two adults and a free bed, so it counted homes such as 6 beds with 2 adults and a child as breeding, and turned moves out of them down. - Adult beds (Dwelling): only beds - beds/3 are for adults. The game marks a home with more adults than that as overpopulated and moves an adult out, so a chain that put an adult in a child's bed would be undone. The snapshot now carries each home's beds, adults and children from the game; HomeRules.FreeForAdults gives the empty beds an adult may keep and HomeRules.CanBreed the breeding rule. ApplyCycle also refuses a move that would put more adults in a home than its adult beds. The test fake follows the game the same way, with new cases pinning both rules; reverting either one fails the suite. 46 checks pass, including the compiled-adapter check against the installed game. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What changes
A pass used to swap adults only between beds adults already occupied, so an empty home beside a workplace was never used (e.g. an empty Mini Lodge next to a Lumberjack Flag whose worker lives across the map). Now each district is solved over its occupied and empty beds, so a worker moves into the empty lodge when that shortens the colony's total walk.
Hungarian.Steptakes n rows by m ≥ n columns (O(n²m)). A district's columns are its adults' beds, then its empty beds (at most one per adult in each home). The solve budget is n²m/8.HomeFreeper home. Homes now include every usable home with an empty bed in a district with adults. Children count against beds, so they keep theirs.Cycles.SplitChainssplits moves into cycles (head counts kept) and chains (the last move takes an empty bed). Each can be applied on its own.ApplyCycle's existing capacity check turns a chain away as stale if the game filled that bed meanwhile.Capturelists empty-bed homes throughdistrict.GetComponent<DistrictBuildingRegistry>().GetEnabledBuildingsInstant<Dwelling>(), with the sameUsableHomeand district checks as before.PassStateversion 6: a pass running in an older save starts over once, and remembered route costs carry over.Not done here
DistrictBuildingRegistry/GetEnabledBuildingsInstant<Dwelling>()call is unverified. Build locally and run the compiled-adapter check before release.#vacantand#breeding, the index rules, the compare table ("Adults per home"), the#howsteps, troubleshooting "Empty beds aren't used" and the "41 automated checks" status line all need updating with the release. The README has an Unreleased changelog entry.Tests
dotnet run --project OptimizedLocalHousing.Tests -c Release→45 checks passed.That is the 40 existing checks plus:CLAUDE.md now expects
45 checks passed.🤖 Generated with Claude Code
https://claude.ai/code/session_01J9E8mdmw7xR61ijmdTWXg8