A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: GDD Phase 3 PR 3, housing condition, overflow and the national housing level (refs #734, #383) (#855)
Eyal Golan9e2215a161e9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c8a789f06..28a7d2e15 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -81,6 +81,13 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB- Refusing the reparations claim (`reparations_claim.refuse`) now costs $4 million of Foreign currency, so neither answer is free (owner, 17 Oct 2026, "A cost for refusing too", #938). The amount is a labelled design value, not a historical figure, and waits for the owner's sign-off on the PR. The reference runs send the claim, so no golden moves.- Refusing Egypt's armistice (`armistice_egypt.hold_out`) now sets the war to rung 4, like refusing Jordan's, Lebanon's or Syria's (owner, 17 Oct 2026, "Yes, match the others", #937). The reference runs sign every armistice, so no golden moves.- The desktop players' bundle ID is `io.github.eyalgolan.statecraftisrael` (decision O6, owner, 17 Oct 2026, #879; refs #905). Only the Standalone identifier changes; the WebGL build does not read it.+- The GDD game's cities house every arriving immigrant, with no hard cap, and each city has a housing condition from 0+ to 1 (GDD Phase 3 PR 3, refs #734, #383; R-CITY-004, R-HOUSE-001 to R-HOUSE-004). People beyond a city's housing are+ its overflow, still counted in the city; people in training and recruits take housing, halutz units do not. Each turn+ a city with overflow loses 0.15 times its overflow share of its condition, from a start of 0.35 (design values in+ `rules.yaml`, `mvp.housing_start_condition` and `mvp.overflow_condition_loss`). The national Housing level's base+ is now the cities' people-weighted mean condition (R-HOUSE-004), with policy, map actions and events still on top, so+ a shortage shows on the Housing meter and lowers morale. Every golden is re-pinned.- The 50 people names in Hebrew are flagged agent-checked until a native speaker reads them (owner, #882).- The 3D-model credits in code comments and one test's failure message now name MATKOT, as the owner asked on 17 October 2026; credit text only, with no behaviour change.- People audit batch 1 (#457): shazar's name_he now cites the Knesset's member page instead of en.wiki; thediff --git a/content/rules.yaml b/content/rules.yamlindex 508a0720f..1bf7dc03a 100644--- a/content/rules.yaml+++ b/content/rules.yaml@@ -63,6 +63,13 @@ mvp:# completed yishuv makes a veteran pioneer.veteran_halutz_service: 6 # DESIGN VALUE: owner-set balance, not a historical figure (D-D9, Q-VET-1: turns of work to become a veteran)veteran_progress: 2 # DESIGN VALUE: owner-set balance, not a historical figure (D-D9, Q-VET-2: a veteran's turns of progress a turn)+ # Housing condition (R-HOUSE-001, R-HOUSE-002; D-D1, D-D2): each city's average condition, 0 to 1. Every city starts at+ # model.yaml's housing base, so the cities start where the national level does (Q-START-3), and each turn a city loses+ # overflow_condition_loss times its overflow share (people beyond its housing over its people). 0.15 is model.yaml's+ # homes_lift_morale k, borrowed: no closer comparable exists (Q-HOUSE-1). Agents proposed both numbers ("Agents propose+ # design values", owner, 15 October 2026, #375); the owner may override them. Neither is a historical figure.+ housing_start_condition: 0.35 # DESIGN VALUE: owner-set balance, not a historical figure (D-D2, Q-START-3: every city's start condition)+ overflow_condition_loss: 0.15 # DESIGN VALUE: owner-set balance, not a historical figure (D-D1, Q-HOUSE-1: condition lost a turn at a full overflow share)# Coalition stability lost by replacing a minister (Cabinet.Appoint): a seat taken from the minister's party, or a# reshuffle within it.appoint_stability_cost_other_party: 0.06diff --git a/docs/RELEASING.md b/docs/RELEASING.mdindex 479adef2d..64ad72e8b 100644--- a/docs/RELEASING.md+++ b/docs/RELEASING.md@@ -19,9 +19,9 @@ GitHub Releases page (and, from M4, on itch.io). Steps 1–3 are a normal pull r"$UNITY" -batchmode -CI false -GITHUB_ACTIONS false -TF_BUILD false -quit -projectPath unity -buildTarget WebGL -executeMethod Statecraft.Game.EditorTools.Build.Web -compression gzip -shareable -logFile "$PWD/unity-build-web-gz.log"git checkout -- unity/Assets/Settings unity/ProjectSettings/ProjectSettings.assetuv run tools/web_check.py unity/Builds/Web-gzip --query "golden&smoke=5" \- --expect "GOLDEN OK 1950 e4ebff9b317a02b908434cedb18674608ae820e5e60769ef78272493884590c4" \- --expect "GOLDEN OK 1952 e0d8212a1f6ea8af9211166aa52b76c741c739807d4326b6b6664a5c5d26857f" \- --expect "SMOKE OK 5 turns 1948-10-15 2436927c8b24f28c42be0e7b5a6fe30900f2f6c6a3ba77e4be943c1f50db57cc"+ --expect "GOLDEN OK 1950 7cf678b6b2b3d55dc0fee7b2efdee9ec7688cdf18964dcaa6e5a7c0018e34a51" \+ --expect "GOLDEN OK 1952 9496947232f0c97ed21c0a0b98e6727e7d59c892f9aff12049b5d7e5ee2230e8" \+ --expect "SMOKE OK 5 turns 1948-10-15 3005405d64abc6e7418fa1f0d35c36ce5f64ed3af7c5a4c24a73d5dfdb16121f"bash scripts/oss/package_web.sh unity/Builds/Web-gzip unity/Builds/statecraft-israel-vX.Y.Z-web.zip```diff --git a/docs/determinism.md b/docs/determinism.mdindex e9cad7697..b9cb04ee3 100644--- a/docs/determinism.md+++ b/docs/determinism.md@@ -28,9 +28,9 @@ final `GameState.Hash()` is pinned:| Run | Ends | Hash ||---|---|---|-| to 1950-01-01 (`Hash1950`) | 1950-01-15, turn 20 | `e4ebff9b317a02b908434cedb18674608ae820e5e60769ef78272493884590c4` |-| to 1952-01-01 (`Hash1952`) | 1952-01-15, turn 44 (the game's end) | `e0d8212a1f6ea8af9211166aa52b76c741c739807d4326b6b6664a5c5d26857f` |-| to the game's end (`mvp-end`) | 1952-01-15, turn 44 | `e0d8212a1f6ea8af9211166aa52b76c741c739807d4326b6b6664a5c5d26857f` |+| to 1950-01-01 (`Hash1950`) | 1950-01-15, turn 20 | `7cf678b6b2b3d55dc0fee7b2efdee9ec7688cdf18964dcaa6e5a7c0018e34a51` |+| to 1952-01-01 (`Hash1952`) | 1952-01-15, turn 44 (the game's end) | `9496947232f0c97ed21c0a0b98e6727e7d59c892f9aff12049b5d7e5ee2230e8` |+| to the game's end (`mvp-end`) | 1952-01-15, turn 44 | `9496947232f0c97ed21c0a0b98e6727e7d59c892f9aff12049b5d7e5ee2230e8` |`hash1952` stops at the first turn on or after 1 January 1952, which is the game's last turn, so it is the same run as`mvp-end` (`DeterminismTests.TheWholeGameToItsEndIsFixed`). Both names are kept (spec 2026-10-12 section 3 step 6): a@@ -39,15 +39,15 @@ check `hash1950` and `hash1952`.A further value is pinned for the browser smoke run (`?smoke=5`: the golden seed, five turns played through the UI's ownbuttons, answering each event with its first option while the turn's Attention pays for it, the rest left to their-ministers): `SMOKE OK 5 turns 1948-10-15 2436927c8b24f28c42be0e7b5a6fe30900f2f6c6a3ba77e4be943c1f50db57cc`.+ministers): `SMOKE OK 5 turns 1948-10-15 3005405d64abc6e7418fa1f0d35c36ce5f64ed3af7c5a4c24a73d5dfdb16121f`.It depends on the UI path as well as the sim (which option is first, the turn grid), so re-record it when either changes.Check every build with:```uv run tools/web_check.py unity/Builds/Web-<compression> --query "golden&smoke=5" \- --expect "GOLDEN OK 1950 e4ebff9b317a02b908434cedb18674608ae820e5e60769ef78272493884590c4" \- --expect "GOLDEN OK 1952 e0d8212a1f6ea8af9211166aa52b76c741c739807d4326b6b6664a5c5d26857f" \- --expect "SMOKE OK 5 turns 1948-10-15 2436927c8b24f28c42be0e7b5a6fe30900f2f6c6a3ba77e4be943c1f50db57cc"+ --expect "GOLDEN OK 1950 7cf678b6b2b3d55dc0fee7b2efdee9ec7688cdf18964dcaa6e5a7c0018e34a51" \+ --expect "GOLDEN OK 1952 9496947232f0c97ed21c0a0b98e6727e7d59c892f9aff12049b5d7e5ee2230e8" \+ --expect "SMOKE OK 5 turns 1948-10-15 3005405d64abc6e7418fa1f0d35c36ce5f64ed3af7c5a4c24a73d5dfdb16121f"```**When a golden moves.** The test fails with the lines that changed, grouped by section (`[ind]`, `[pol]`, `[bud]`,@@ -264,3 +264,10 @@ The hash reads the state keys, so it never sees a record outside its window. An| GDD Phase 4 PR 4 | 1950 | `e4ebff9b` | plow fields (R-FIELD-001, R-FIELD-002, #788), rebased on the training camps (#927): once the four yishuv sites are taken, the reference player's veteran group plows their fields in ordinal id order, before any camp. At the end of the 1950 run (1950-01-15) Beit Kama's field is still being plowed (`beit_kama_field=b,1,1`) instead of Camp 80 being built, and the debt is IL 1.5m lower (IL 0.5m for the field instead of IL 2m for the camp) (was `38c8a484`) || GDD Phase 4 PR 4 | 1952 | `e0d8212a` | same; at 2 turns of progress a turn (R-VET-002) the fields are plowed on 1950-02-15 (Beit Kama), 1950-04-15 (Gilat), 1950-06-15 (Mefalsim) and 1950-08-15 (Re'im), so Camp 80 is built on 1950-11-15 (was 1950-03-15) and Tzrifin on 1951-02-15 (was 1950-06-15). The debt is IL 2m higher (4 x IL 0.5m), and the Food stock ends 4 units higher (2736, was 2732), which lifts food_supply and stability in the fourth decimal (was `1e21fcd3`) || GDD Phase 4 PR 4 | mvp-end | `e0d8212a` | same; the same run as hash1952 (was `1e21fcd3`) |+| GDD Phase 3 PR 3 | 1950 | `7cf678b6` | GDD Phase 3 PR 3's housing (R-CITY-004, R-HOUSE-001 to R-HOUSE-004; Q-HOUSE-1, Q-HOUSE-2, Q-HOUSE-5, Q-START-3; owner, 17 October 2026, Q-PR3-A (a)), re-pinned on main after #927 and #871: no hard cap, so every refugee is housed on the next housing step (18 refugees waiting on 1 January 1950, the last turn's arrivals, was 269), the people beyond a city's housing are its overflow, and each city's housing condition (start 0.35) falls by 0.15 times its overflow share a turn; 11 of the 12 cities are at condition 0 by then (Rosh Pinna, with no overflow, keeps 0.35). The condition joins each `city{}` record. The national `housing` indicator's base is now the cities' people-weighted mean condition, so `housing` falls to 0.0850 (was 0.4345) and `housing_crisis` is on; through `homes_lift_morale`, Social cohesion (`morale`) falls to 0.4990 (was 0.5545), with `work_lifts_cohesion` lower too because more civilians share the same jobs; stability 0.4970 (was 0.5612). The national head count, the Treasury, the debt, Food, the camp and field builds and the reference player's orders do not move (was `e4ebff9b`) |+| GDD Phase 3 PR 3 | 1952 | `94969472` | same; 8 refugees waiting at the end (was 608), every city at condition 0; `housing` 0.0850 (was 0.4350), `housing_crisis` on, `morale` 0.4946 (was 0.5691), stability 0.4487 (was 0.5683); the `housing` shift reads -1.4e-17 (was 0), IEEE rounding of the level minus the moving inner value (was `e0d8212a`) |+| GDD Phase 3 PR 3 | mvp-end | `94969472` | same; the same run as hash1952 (was `e0d8212a`) |+| GDD Phase 3 PR 3 | smoke5 | `3005405d` | the condition joins each `city{}` record; the first five turns have no overflow, so `housing` and `morale` are unchanged (was `2436927c`) |+| GDD Phase 3 PR 3 | scenario-cautious | `6507ddc3` | the housing rules: `city{}`, `housing`, `morale`, its two links and stability (was `28fd1405`) |+| GDD Phase 3 PR 3 | scenario-reckless | `8041988a` | same (was `af7b2abd`) |+| GDD Phase 3 PR 3 | scenario-mvp-absorb-first | `a77a8f20` | same (was `b16a8740`) |diff --git a/docs/gdd/one-city.md b/docs/gdd/one-city.mdindex ad2d094a2..4c6b77eba 100644--- a/docs/gdd/one-city.md+++ b/docs/gdd/one-city.md@@ -11,7 +11,7 @@ As a player of the MVP, I want to put Tel Aviv's people to work and house the im- Each turn resolves in the order the owner approved for the plan's resolution phase (D-A6, #456 [S2][S3]): production, then housing and Social cohesion, then arrivals. A turn's arrivals are housed on the next turn.- Production: each employed unit earns `income_per_job_per_year` IL millions a year, for the turn's share of a year (R-CITY-002).- Arrivals: the CBS series in `content/aliyah.yaml` arrives as refugees, in whole units, counted cumulatively so that no unit is lost or counted twice (R-CITY-003, D-A5 [S2]). With twelve cities they are spread over all of them: see `cities.md`.-- Housing: refugees become civilians, without a job, up to the city's housing capacity. The cap is a placeholder while D-D1 is open (R-CITY-004).+- Housing: every refugee becomes a civilian, without a job, on the housing step, with no hard cap; the people beyond the city's housing capacity are its overflow and lower its housing condition (R-CITY-004, R-HOUSE-001 to R-HOUSE-004, D-D1 decided 15 October 2026 [S2]). With twelve cities: see `cities.md`.- Social cohesion: a share from 0% to 100%, the weighted housed share and employed share over all cities (R-CITY-005). At first no other system read it; the top bar shows it as a resource meter, in the GDD loop only (the owner's ruling of 15 October 2026 [S4]). It is now the `morale` indicator (R-NAT-001), which approval and the `low_cohesion` situation read; the employed share is one of its effect-web sources and housing reaches it through the `housing` indicator.## Data toucheddiff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex a722510a9..238d578ef 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -46,7 +46,7 @@ R-CITY-003: Arrivals from the CBS series (`aliyah.yaml`) become refugees in theR-CITY-008: `GameState.Population` is the one record of the nation's people: it takes every arrival from 15 May 1948 and is the count the CBS anchors check. The cities are the part of it placed in towns, so their people (civilians, refugees, recruits and the groups in training, times `people_per_unit`) never exceed it (Q-ARRV-2, owner, 15 October 2026). No person is counted twice.-R-CITY-004: Each turn, `min(refugees, max(0, housing_capacity - civilians))` of a city's refugees become civilians without a job. The cap is a placeholder while overflow (D-D1) is open.+R-CITY-004: Each turn, on the housing step, all of a city's refugees become civilians without a job. There is no hard cap (D-D1, Q-HOUSE-1, owner, 15 October 2026): the people beyond the city's housing stay in the city as its overflow (R-HOUSE-002), and residents are housed automatically (Q-HOUSE-4).R-CITY-005: The cities' employed share (employed over civilians, summed over all cities; 1 with no civilians) is an effect-web source of `morale`, Social cohesion (`work_lifts_cohesion`, source id `employed_share`), read after the turn's housing. The legacy loop has no cities, so there it reads 0 and adds nothing. Housing reaches Social cohesion through the existing `housing` link (`homes_lift_morale`) until Phase 3 makes it the cities' aggregate (Q-NAT-2, decided 15 October 2026). Phase 1's separate cohesion value and its two weights are gone (D-C1, Reading 2).@@ -54,6 +54,14 @@ R-CITY-006: The cities are the `city` and `town` rows of `map/settlements_1948.yR-CITY-007: A city starts with `civilians` = `people / people_per_unit` to the nearest unit (a half rounds up), and at least 1 when `people` is above 0 (Q-START-2, owner, 15 October 2026); `employed` = `people * employed_share / people_per_unit` to the nearest unit; `housing_capacity` and `job_slots` as written, in units. The loader refuses a city whose start employed is above its job slots. The arithmetic is decimal, so it is exact on every runtime.+R-HOUSE-001: Each city has a housing condition from 0 to 1, an average over the city (D-D2, Q-HOUSE-2, owner, 15 October 2026). Every city starts at `mvp.housing_start_condition` (Q-START-3: one design value for all the cities, 0.35, `model.yaml`'s `housing` base). The condition is per city: one city's counts never change another's. It is in the state hash (R-LOOP-002).++R-HOUSE-002: A city's overflow is `max(0, housed - housing_capacity)`, one capacity point housing one population unit (D-D1, Q-HOUSE-1, owner, 15 October 2026). On the housing step, after R-CITY-004 and before Social cohesion (D-A6), a city with overflow loses `overflow_condition_loss * overflow / housed` of its condition, never below 0; a city without overflow keeps its condition. `overflow_condition_loss` is 0.15, a design value. The loader requires both values, from 0 to 1. Overflow reaches Social cohesion through R-HOUSE-004 (a lower condition lowers the base of the national `housing` indicator) and the existing `homes_lift_morale` link (k 0.15) from `housing` into `morale`, which is Social cohesion (R-NAT-001); there is no direct overflow term (Q-HOUSE-1, decided by the owner 15 October 2026, plan:165 of `docs/superpowers/plans/2026-10-15-gdd-phase-3.md`: cohesion follows through the existing `housing` to `morale` link, "so it needs no number of its own"; the cohesion half was built after #728, merged as #857, owner 17 October 2026).++R-HOUSE-003: The people who take a city's housing (`housed`) are its civilians, its recruits and its groups in training, a halutz group included until it becomes a movable unit. Halutz units do not (Q-HOUSE-5, owner, 15 October 2026). Refugees wait for housing and are not in it.++R-HOUSE-004: In the GDD loop the base of the national `housing` indicator is the people-weighted mean of the cities' housing condition, each city weighed by its housed people (R-HOUSE-003): `sum(condition * housed) / sum(housed)`. Policy effects, map actions and events still act on top, as on any indicator. Decided (owner, 17 Oct 2026, option (a) of Q-PR3-A, relayed on [#855 at 06:33Z](https://github.com/eyalgolan/statecraft-israel/pull/855#issuecomment-6230731177)): the national housing base is the people-weighted mean of city condition, with policy, map actions and events still applied on top. When no city houses anybody the mean is undefined, and the base is `model.yaml`'s. Capacity reaches the level through overflow and condition (R-HOUSE-002).+## TrainingTraining is step 4 of the turn in the approved order (§2.3, D-A6): it runs before production. One military camp and one Hakhshara exist in Tel Aviv at the start, a labelled design assumption (D-D5); pioneers build more at camp sites (R-CAMP-001).diff --git a/sim/Statecraft.Sim.Tests/CitiesTests.cs b/sim/Statecraft.Sim.Tests/CitiesTests.csindex f174e8f26..dbddb45ff 100644--- a/sim/Statecraft.Sim.Tests/CitiesTests.cs+++ b/sim/Statecraft.Sim.Tests/CitiesTests.cs@@ -96,31 +96,31 @@ public class CitiesTestsAssert.Equal(6 * 1.2 * SimTime.YearFraction(TurnLength.Week), paid, 9); // the fixture's first turn is a week}- // R-CITY-004+ // R-CITY-004 (Q-HOUSE-1: no hard cap; the 3 beyond the housing for 12 are the city's overflow, HousingTests)[Fact]- public void RefugeesAreHousedOnlyUpToCapacity()+ public void EveryRefugeeIsHousedWithNoHardCap(){var c = Town();var s = With(Simulation.NewGame(c, 1, Mode.Historical), "town_a", 10, 6, 5);var city = Step(c, s).State.Cities["town_a"]; // the first week brings under one unit of arrivals- Assert.Equal((12, 6, 3), (city.Civilians, city.Employed, city.Refugees));+ Assert.Equal((15, 6, 0), (city.Civilians, city.Employed, city.Refugees));}// R-CITY-003, R-CITY-004 (D-A6: arrivals come after housing, so they are housed on the next turn)[Fact]public void ATurnsArrivalsAreHousedOnTheNextTurn(){- // Tel Aviv starts full (Q-START-1: housing equals the start people), so 20 of its people are moved out to free room.// The cities take arrivals from the census day, 8 November 1948 (Q-ARRV-3), so the turn from 15 November has some.+ // Tel Aviv's civilians are set to 228 so the test reads them apart from the start count.var s = Simulation.NewGame(Mvp, GoldenRun.Seed, Mode.Historical);while (s.Date < new DateTime(1948, 11, 15)) s = Step(Mvp, s).State;s = With(s, "tel_aviv", 228, 106, 0);var one = Step(Mvp, s).State;var arrived = one.Cities["tel_aviv"].Refugees;Assert.True(arrived > 0);- Assert.Equal(228, one.Cities["tel_aviv"].Civilians); // housing for 20 more was free, but it ran before they came+ Assert.Equal(228, one.Cities["tel_aviv"].Civilians); // the housing step ran before they camevar two = Step(Mvp, one).State.Cities["tel_aviv"];- Assert.Equal(228 + Math.Min(arrived, 20), two.Civilians);+ Assert.Equal(228 + arrived, two.Civilians); // no hard cap (Q-HOUSE-1): all of them, on the next turn}/// <summary>D-A6: housing comes before Social cohesion in the turn. The effects web reads the cities' employed share after@@ -136,10 +136,10 @@ public class CitiesTests["model.yaml"] = Fixture.Files["model.yaml"].Replace("effects:\n", "effects:\n - { id: work, source: employed_share, target: morale, k: 1, inertia: 1, name: Work }\n"),})));var s = With(Simulation.NewGame(c, 1, Mode.Historical), "town_a", 10, 6, 10);- var after = Step(c, s).State; // 2 housed: 6 of 12 employed- Assert.Equal((12, 8), (after.Cities["town_a"].Civilians, after.Cities["town_a"].Refugees));- Assert.Equal(6.0 / 12, Cities.EmployedShare(after), 12);- Assert.Equal(6.0 / 12, after.EffectContributions["work"], 12);+ var after = Step(c, s).State; // all 10 housed (no hard cap): 6 of 20 employed+ Assert.Equal((20, 0), (after.Cities["town_a"].Civilians, after.Cities["town_a"].Refugees));+ Assert.Equal(6.0 / 20, Cities.EmployedShare(after), 12);+ Assert.Equal(6.0 / 20, after.EffectContributions["work"], 12);}[Fact]diff --git a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs b/sim/Statecraft.Sim.Tests/DesignValuesTests.csindex 979059b8f..3044cde7c 100644--- a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs+++ b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs@@ -38,6 +38,8 @@ public class DesignValuesTests("rules.yaml", "mvp.cover_months"),("rules.yaml", "mvp.veteran_halutz_service"),("rules.yaml", "mvp.veteran_progress"),+ ("rules.yaml", "mvp.housing_start_condition"),+ ("rules.yaml", "mvp.overflow_condition_loss"),// Q-START-1 (owner, 15 October 2026, #375): no city has a sourced housing stock or job count, so every city's// housing is its start people and its job slots its start employed; seven towns with no CBS working share take// the national one. The census people and the five CBS shares are sourced, not design values (R-CITY-006).@@ -166,6 +168,7 @@ public class DesignValuesTestsAssert.Equal((0.0, 0.0), (c.Rules.AttentionCost["pioneer_work"], c.Rules.AttentionCost["stop_work"])); // D-A6: unit orders are freeAssert.Equal((6, 2.0), (m.BuildYishuvTurns, m.BuildYishuvCost));Assert.Equal((100, 5, 60), (m.ObjectivePoints, m.ObjectiveBonusPerMonth, m.ObjectiveBonusCap)); // D-B6, D-B2+ Assert.Equal((0.35, 0.15), (m.HousingStartCondition, m.OverflowConditionLoss)); // Q-START-3, Q-HOUSE-1 (D-D1)Assert.Equal(12, c.Cities.Count);foreach (var x in c.Cities) // the listed housing and job values are the ones Cities.Init starts fromAssert.Equal(((int)x.Housing!.Value, (int)x.Jobs!.Value), (x.HousingCapacity, x.JobSlots));diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.csindex 6536725d0..b7c62568b 100644--- a/sim/Statecraft.Sim.Tests/Fixture.cs+++ b/sim/Statecraft.Sim.Tests/Fixture.cs@@ -234,6 +234,8 @@ mvp:cover_months: 3veteran_halutz_service: 4veteran_progress: 2+ housing_start_condition: 0.5+ overflow_condition_loss: 0.2";public static readonly string GddCities = "\ncities:\n" + City("town_a", 12, 8, 10, 6, "[military_camp, hakhshara]");diff --git a/sim/Statecraft.Sim.Tests/HousingTests.cs b/sim/Statecraft.Sim.Tests/HousingTests.csnew file mode 100644index 000000000..f16a69f2d--- /dev/null+++ b/sim/Statecraft.Sim.Tests/HousingTests.cs@@ -0,0 +1,301 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>GDD Phase 3 PR 3 (#734): housing capacity, condition and overflow in step 8 of the turn (D-D1, D-D2; Q-HOUSE-1,+/// Q-HOUSE-2, Q-HOUSE-4, Q-HOUSE-5, Q-START-3, owner, 15 October 2026, "Take all recommendations", #375). The fixture's+/// values (start condition 0.5, a loss of 0.2 at a full overflow share) are fixture values, not the game's.</summary>+public class HousingTests+{+ static readonly Content Mvp = ContentLoader.Load(RealContentTests.ContentRoot());++ /// <summary>The GDD fixture with the given cities.yaml rows (default: town_a, housing for 12, 20 jobs, 10 civilians, 6 employed).</summary>+ static Content Town(params string[] rows) =>+ ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>+ {+ ["cities.yaml"] = "cities:\n" + (rows.Length == 0 ? Fixture.City("town_a", 12, 20, 10, 6, "[military_camp, hakhshara]") : string.Concat(rows)),+ })));++ static GameState With(GameState s, string city, int civilians, int employed, int refugees)+ {+ var x = s.Clone();+ x.Cities[city] = x.Cities[city].WithCounts(civilians, employed, refugees);+ return x;+ }++ static GameState Step(Content c, GameState s, params Command[] commands) => Simulation.Step(c, s, commands).State;++ /// <summary>Everyone the city holds: civilians, refugees, recruits and the groups in training there.</summary>+ static int People(GameState s, string city) =>+ s.Cities[city].Civilians + s.Cities[city].Refugees + s.Cities[city].Recruits + s.Cohorts.Values.Where(k => k.City == city).Sum(k => k.Count);++ // R-HOUSE-001+ [Fact]+ public void EveryCityStartsAtTheOneStartCondition()+ {+ var s = Simulation.NewGame(Mvp, GoldenRun.Seed, Mode.Historical);+ var start = Mvp.Rules.Mvp!.HousingStartCondition!.Value;+ Assert.Equal(0.35, start);+ Assert.Equal(12, s.Cities.Count);+ Assert.All(s.Cities.Values, x => Assert.Equal(start, x.Condition));+ // Q-START-3: the start is model.yaml's housing base, so the cities start where the national level does.+ Assert.Equal(Mvp.Indicators.Single(i => i.Id == "housing").Base, start);+ }++ // R-CITY-004, R-HOUSE-002 (review focus 4: overflow that makes people vanish or appear)+ [Fact]+ public void OverflowIsCountedNotLost()+ {+ var c = Town();+ var s = With(Simulation.NewGame(c, 1, Mode.Historical), "town_a", 10, 6, 5);+ var after = Step(c, s); // the fixture's first week brings no unit of arrivals+ var x = after.Cities["town_a"];+ Assert.Equal((15, 6, 0), (x.Civilians, x.Employed, x.Refugees)); // no hard cap: every refugee is housed+ Assert.Equal(People(s, "town_a"), People(after, "town_a"));+ Assert.Equal(15, Cities.Housed(after, x));+ Assert.Equal(3, Cities.Overflow(after, x)); // 15 people in housing for 12+ Assert.Contains(Simulation.Step(c, s, Array.Empty<Command>()).Why, w => w.System == "city" && w.Target == "town_a" && w.Message == "Town A: 3 groups more than its homes hold");+ }++ // R-HOUSE-002+ [Fact]+ public void OverflowLowersCondition()+ {+ var c = Town();+ var s = With(Simulation.NewGame(c, 1, Mode.Historical), "town_a", 10, 6, 5);+ Assert.Equal(0.5, s.Cities["town_a"].Condition);+ var after = Step(c, s);+ Assert.Equal(0.5 - 0.2 * 3 / 15.0, after.Cities["town_a"].Condition!.Value, 12); // the loss times 3 over 15 people+ Assert.Equal(after.Cities["town_a"].Condition, Step(c, With(after, "town_a", 12, 6, 0)).Cities["town_a"].Condition); // no overflow, no change+ }++ // R-HOUSE-002: a city record without a condition still reports its overflow, and gains no condition.+ [Fact]+ public void OverflowIsReportedWhenACityHasNoCondition()+ {+ var c = Town();+ var s = With(Simulation.NewGame(c, 1, Mode.Historical), "town_a", 10, 6, 5);+ var x = s.Cities["town_a"];+ s.Cities["town_a"] = new City(x.Id, x.HousingCapacity, x.JobSlots, x.Civilians, x.Employed, x.Refugees);+ var r = Simulation.Step(c, s, Array.Empty<Command>());+ Assert.Null(r.State.Cities["town_a"].Condition);+ Assert.Contains(r.Why, w => w.System == "city" && w.Target == "town_a" && w.Message == "Town A: 3 groups more than its homes hold");+ }++ // R-HOUSE-002+ [Fact]+ public void ConditionNeverFallsBelowZero()+ {+ var c = Town(Fixture.City("town_a", 0, 20, 10, 6)); // no housing: all of the people are overflow+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ var seen = new List<double>();+ for (int i = 0; i < 4; i++) { s = Step(c, s); seen.Add(s.Cities["town_a"].Condition!.Value); }+ Assert.Equal(0.3, seen[0], 12);+ Assert.Equal(0.1, seen[1], 12);+ Assert.Equal(new[] { 0.0, 0.0 }, seen.Skip(2));+ }++ /// <summary>D-A6: the condition reads the counts after this turn's housing. Read before it, the 10 civilians fit the+ /// housing for 12 and the condition would not move.</summary>+ // R-HOUSE-002, R-CITY-004+ [Fact]+ public void ConditionReadsTheCountsAfterThisTurnsHousing()+ {+ var c = Town();+ var s = With(Simulation.NewGame(c, 1, Mode.Historical), "town_a", 10, 6, 5);+ Assert.True(Step(c, s).Cities["town_a"].Condition < 0.5);+ }++ // R-HOUSE-001+ [Fact]+ public void ConditionIsPerCity()+ {+ var c = ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>+ {+ ["map/settlement_hexes.yaml"] = "settlements:\n - { id: town_a, q: 1, r: 0 }\n - { id: town_b, q: 2, r: 1 }\n",+ ["map/settlements_1948.yaml"] = Fixture.Files["map/settlements_1948.yaml"]+ + " - { id: town_b, name: Town B, lon: 34.42, lat: 33.28, type: town, founded: 1900, pre_modern: false }\n",+ ["cities.yaml"] = "cities:\n" + Fixture.City("town_a", 12, 20, 10, 6) + Fixture.City("town_b", 12, 20, 10, 6),+ })));+ var s = With(Simulation.NewGame(c, 1, Mode.Historical), "town_a", 10, 6, 5);+ var after = Step(c, s);+ Assert.True(after.Cities["town_a"].Condition < 0.5);+ Assert.Equal(0.5, after.Cities["town_b"].Condition);+ }++ // R-HOUSE-003 (Q-HOUSE-5): people in training count against their city's housing.+ [Fact]+ public void TraineesTakeHousing()+ {+ var c = Town();+ var s = With(Simulation.NewGame(c, 1, Mode.Historical), "town_a", 10, 6, 4);+ var after = Step(c, s, new Train("town_a", "recruit", 2)); // 8 civilians and 2 in training, then 4 housed+ var x = after.Cities["town_a"];+ Assert.Equal((12, 0), (x.Civilians, x.Refugees));+ Assert.Equal(2, after.Cohorts.Values.Single().Count);+ Assert.Equal(14, Cities.Housed(after, x));+ Assert.Equal(2, Cities.Overflow(after, x));+ }++ // R-HOUSE-003 (Q-HOUSE-5): recruits count against the city they trained in.+ [Fact]+ public void RecruitsTakeHousing()+ {+ var c = Town();+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ s.Cities["town_a"] = s.Cities["town_a"].WithRecruits(3);+ var after = Step(c, s);+ var x = after.Cities["town_a"];+ Assert.Equal(13, Cities.Housed(after, x)); // 10 civilians and 3 recruits in housing for 12+ Assert.Equal(1, Cities.Overflow(after, x));+ Assert.Equal(0.5 - 0.2 * 1 / 13.0, x.Condition!.Value, 12);+ }++ // R-HOUSE-003 (Q-HOUSE-5): halutz units are movable (D-A2) and leave the city's housing when their training ends.+ [Fact]+ public void HalutzUnitsDoNotTakeHousing()+ {+ var c = Town(Fixture.City("town_a", 9, 20, 10, 6, "[military_camp, hakhshara]"));+ var s = Step(c, Simulation.NewGame(c, 1, Mode.Historical), new Train("town_a", "halutz", 2));+ Assert.Equal(10, Cities.Housed(s, s.Cities["town_a"])); // 8 civilians and 2 in training+ while (s.Cohorts.Count > 0) s = Step(c, s);+ Assert.Equal(2, s.Units.Count);+ Assert.Equal(0, s.Cities["town_a"].Recruits);+ Assert.Equal(s.Cities["town_a"].Civilians, Cities.Housed(s, s.Cities["town_a"])); // the two units hold no housing+ }++ /// <summary>Two towns, A and B, with housing for 100 each (no overflow) and the given civilians. Fixture values.</summary>+ static Content TwoTowns(int a, int b, int capacityA = 100) => ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>+ {+ ["map/settlement_hexes.yaml"] = "settlements:\n - { id: town_a, q: 1, r: 0 }\n - { id: town_b, q: 2, r: 1 }\n",+ ["map/settlements_1948.yaml"] = Fixture.Files["map/settlements_1948.yaml"]+ + " - { id: town_b, name: Town B, lon: 34.42, lat: 33.28, type: town, founded: 1900, pre_modern: false }\n",+ ["cities.yaml"] = "cities:\n" + Fixture.City("town_a", capacityA, 20, a, 0) + Fixture.City("town_b", 100, 20, b, 0),+ })));++ static Indicator Housing(Content c) => c.Indicators.Single(i => i.Id == "housing");++ /// <summary>Decided (owner, 17 Oct 2026, option (a) of Q-PR3-A, relayed on #855 at 06:33Z,+ /// https://github.com/eyalgolan/statecraft-israel/pull/855#issuecomment-6230731177): the national housing base is the+ /// people-weighted mean of city condition. Town A houses 10 at condition 0.5, town B 30 at 0.2:+ /// (0.5 * 10 + 0.2 * 30) / 40 = 0.275. The plain mean would be 0.35, and the fixture's base is 0.3. The fixture has no+ /// effect on housing, so the inner level is the mean itself.</summary>+ // R-HOUSE-004+ [Fact]+ public void TheNationalHousingLevelIsThePeopleWeightedMeanCondition()+ {+ var c = TwoTowns(10, 30);+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ s.Cities["town_b"] = s.Cities["town_b"].WithCondition(0.2);+ Assert.Equal(0.275, Cities.HousingLevel(s)!.Value, 12);+ Assert.Equal(0.275, EffectsSystem.Inner(c, s, Housing(c)), 12);+ s.Cohorts.Add(99, new Cohort(99, "recruit", "town_a", 10, 1)); // people in training weigh as housed people (R-HOUSE-003)+ Assert.Equal((0.5 * 20 + 0.2 * 30) / 50, EffectsSystem.Inner(c, s, Housing(c)), 12);+ }++ // R-HOUSE-004: policy, map actions and events still act on top of the cities' mean.+ [Fact]+ public void ShiftsStillActOnTopOfTheCitiesMean()+ {+ var c = TwoTowns(10, 30);+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ s.Cities["town_b"] = s.Cities["town_b"].WithCondition(0.2);+ Assert.Equal(0.1, EffectsSystem.Shift(c, s, "housing", 0.1), 12);+ Assert.Equal(0.375, EffectsSystem.Level(c, s, Housing(c)), 12);+ s.Cities["town_b"] = s.Cities["town_b"].WithCondition(0.0); // the cities move under a standing shift+ Assert.Equal(0.5 * 10 / 40 + 0.1, EffectsSystem.Level(c, s, Housing(c)), 12);+ }++ // R-HOUSE-004: with nobody in the cities' housing the mean is undefined, and the level reads model.yaml's base.+ [Fact]+ public void WithNobodyHousedTheLevelReadsTheBase()+ {+ var c = TwoTowns(0, 0);+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ Assert.Null(Cities.HousingLevel(s));+ Assert.Equal(0.3, EffectsSystem.Inner(c, s, Housing(c)), 12);+ }++ /// <summary>Plan:303: two states differing only in one city's capacity give `housing` in the stated order. Under the+ /// owner's option (a) capacity reaches the level through overflow and condition, so the smaller capacity, with more+ /// overflow, gives the lower level after a turn.</summary>+ // R-HOUSE-004, R-HOUSE-002+ [Fact]+ public void TheNationalHousingLevelFollowsTheCities()+ {+ double After(int capacityA) { var c = TwoTowns(30, 30, capacityA); return Simulation.Step(c, Simulation.NewGame(c, 1, Mode.Historical), Array.Empty<Command>()).State.Indicators["housing"]; }+ Assert.True(After(20) < After(25));+ Assert.True(After(25) < After(30));+ Assert.Equal(After(30), After(40)); // no overflow either way: the same level+ Assert.Equal(0.5, After(30), 12);+ }++ /// <summary>The chain the owner set (17 October 2026; R-HOUSE-002 through R-HOUSE-004 and homes_lift_morale): two+ /// states that differ only in town A's capacity, with model.yaml's link from housing to morale (k 0.15, inertia 2, as in+ /// the real content). More overflow gives a lower condition, a lower housing level and a lower morale, which is Social+ /// cohesion (R-NAT-001). Everything else, the employed share included, is the same in both.</summary>+ // R-HOUSE-002, R-HOUSE-004+ [Fact]+ public void OverflowLowersSocialCohesionThroughTheHousingLevel()+ {+ Content Chain(int capacityA) => ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>+ {+ ["map/settlement_hexes.yaml"] = "settlements:\n - { id: town_a, q: 1, r: 0 }\n - { id: town_b, q: 2, r: 1 }\n",+ ["map/settlements_1948.yaml"] = Fixture.Files["map/settlements_1948.yaml"]+ + " - { id: town_b, name: Town B, lon: 34.42, lat: 33.28, type: town, founded: 1900, pre_modern: false }\n",+ ["cities.yaml"] = "cities:\n" + Fixture.City("town_a", capacityA, 20, 30, 10) + Fixture.City("town_b", 100, 20, 30, 10),+ ["model.yaml"] = Fixture.Files["model.yaml"].Replace("effects:\n", "effects:\n - { id: homes_lift_morale, source: housing, target: morale, k: 0.15, inertia: 2, name: Homes lift morale }\n"),+ })));+ GameState Play(Content c) { var s = Simulation.NewGame(c, 1, Mode.Historical); for (int i = 0; i < 3; i++) s = Simulation.Step(c, s, Array.Empty<Command>()).State; return s; }+ var crowded = Play(Chain(20)); // 10 of town A's 30 beyond its housing+ var housed = Play(Chain(30)); // the same people, all housed+ Assert.Equal(Cities.EmployedShare(housed), Cities.EmployedShare(crowded));+ Assert.True(crowded.Cities["town_a"].Condition < housed.Cities["town_a"].Condition);+ Assert.Equal(housed.Cities["town_b"].Condition, crowded.Cities["town_b"].Condition);+ Assert.True(crowded.Indicators["housing"] < housed.Indicators["housing"]);+ Assert.True(crowded.Indicators["morale"] < housed.Indicators["morale"]);+ }++ // R-HOUSE-004 (Q-START-3): the real cities start where the national level did, so the first day's housing is unchanged.+ [Fact]+ public void TheRealGameStartsAtTheSameHousingLevel()+ {+ var s = Simulation.NewGame(Mvp, GoldenRun.Seed, Mode.Historical);+ Assert.Equal(0.35, Cities.HousingLevel(s)!.Value, 12);+ Assert.Equal(0.35, s.Indicators["housing"], 12);+ }++ // R-LOOP-002, R-HOUSE-001: the condition reaches the hash, and a city record made without one hashes as before.+ [Fact]+ public void TheConditionReachesTheHash()+ {+ var none = new City("a", 1, 2, 3, 1, 0);+ Assert.Equal("a=1,2,3,1,0", none.Canonical());+ Assert.Equal("a=1,2,3,1,0,c3FD6666666666666", none.WithCondition(0.35).Canonical());+ Assert.Equal("a=1,2,3,1,0,4,c3FE0000000000000", none.WithRecruits(4).WithCondition(0.5).Canonical());+ Assert.Equal("a=1,2,3,1,0,c0.35 [3FD6666666666666]", none.WithCondition(0.35).Canonical(true));+ Assert.Equal(0.35, none.WithCondition(0.35).WithCounts(5, 1, 0).WithRecruits(2).Condition); // other changes keep it+ var a = new GameState(); a.Cities["a"] = none.WithCondition(0.35);+ var b = new GameState(); b.Cities["a"] = none.WithCondition(0.36);+ Assert.NotEqual(a.Hash(), b.Hash());+ }++ // R-HOUSE-001, R-HOUSE-002: both values are required, from 0 to 1, so a missing key is never read as 0.+ [Theory]+ [InlineData(" housing_start_condition: 0.5\n", "", "mvp.housing_start_condition", "required")]+ [InlineData(" overflow_condition_loss: 0.2\n", "", "mvp.overflow_condition_loss", "required")]+ [InlineData(" housing_start_condition: 0.5\n", " housing_start_condition: 1.5\n", "mvp.housing_start_condition", "from 0 to 1")]+ [InlineData(" overflow_condition_loss: 0.2\n", " overflow_condition_loss: -0.1\n", "mvp.overflow_condition_loss", "from 0 to 1")]+ [InlineData(" housing_start_condition: 0.5\n", " housing_start_condition: -0.1\n", "mvp.housing_start_condition", "from 0 to 1")]+ [InlineData(" overflow_condition_loss: 0.2\n", " overflow_condition_loss: 1.5\n", "mvp.overflow_condition_loss", "from 0 to 1")]+ public void TheHousingValuesAreRequiredAndInRange(string line, string replacement, string field, string reason)+ {+ var files = Fixture.Gdd();+ Assert.Contains(line, files["rules.yaml"]);+ files["rules.yaml"] = files["rules.yaml"].Replace(line, replacement);+ var e = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(files)));+ Assert.Contains(field, e.Message);+ Assert.Contains(reason, e.Message);+ }+}diff --git a/sim/Statecraft.Sim.Tests/golden/hash1950.txt b/sim/Statecraft.Sim.Tests/golden/hash1950.txtindex fc301b8ca..101f250fd 100644--- a/sim/Statecraft.Sim.Tests/golden/hash1950.txt+++ b/sim/Statecraft.Sim.Tests/golden/hash1950.txt@@ -1,9 +1,9 @@1950-01-15;1948;Historical;20;ind{food_supply=0.8886718750000001 [3FEC700000000001]- housing=0.43452919104400284 [3FDBCF53862C3EB9]+ housing=0.08498850862930471 [3FB5C1CE911942EE]intl_standing=0.8100000000000003 [3FE9EB851EB851EE]- morale=0.5545072916128947 [3FE1BE86135BDE8F]+ morale=0.4990244920977924 [3FDFF0046C5DA244]security=0.5042220244102726 [3FE022963A187B2A]pol{border_settlement=0.2 [3FC999999999999A]@@ -14,11 +14,11 @@ eff{border_villages_secure=0.03922202441027243 [3FA414E8C040046D]building_houses=0.08452919104400287 [3FB5A3B47F17614D]food_lifts_cohesion=0.08774605560302737 [3FB67686872B020E]- homes_lift_morale=0.06510191087455454 [3FB0AA84D21D0271]+ homes_lift_morale=0.022428056459524053 [3F96F7616406A73E]rationing_feeds=0.33867187500000007 [3FD5ACCCCCCCCCCE]rationing_grates=-0.15 [BFC3333333333333]safety_lifts_morale=0.050367774522404846 [3FA9C9CE10B12AF4]- work_lifts_cohesion=0.041291550612907985 [3FA5242A86F7964C]+ work_lifts_cohesion=0.028482605512836157 [3F9D2A8B4CBAE170]shift{food_supply=0.15000000000000002 [3FC3333333333334]housing=0 [0000000000000000]@@ -42,12 +42,13 @@ pop{unknown=18021.68780893306 [40D1996C050FC259]veterans=667938.2378207468 [4124624479C3A414]sit[+ housing_crisistreasury=0 [0000000000000000]debt=78.00032828298673 [4053800560EB2C47]fx=94.52989672613671 [4057A1E9D3F540F0]rung=2;cf=0;mob=0.05 [3FA999999999999A]-stab=0.5612480202322593 [3FE1F5BE687AF41F]+stab=0.49698450107475844 [3FDFCE9814AF09A8]att=4 [4010000000000000]fired[altalena@@ -102,18 +103,18 @@ map[mapturn=0001-01-01:0;over=city{- hadera=12,5,12,5,6- haifa=99,42,99,42,52- jerusalem=84,29,84,29,44- netanya=12,5,12,5,6- petah_tikva=22,10,22,10,12- rehovot=13,5,13,5,7- rishon_lezion=10,5,10,5,6- rosh_pinna=1,0,1,0,0- safed=2,1,2,1,1- tel_aviv=248,106,248,106,131- tiberias=6,2,6,2,3- zikhron_yaakov=2,1,2,1,1+ hadera=12,5,18,5,0,c0 [0000000000000000]+ haifa=99,42,148,42,3,c0 [0000000000000000]+ jerusalem=84,29,125,29,3,c0 [0000000000000000]+ netanya=12,5,18,5,0,c0 [0000000000000000]+ petah_tikva=22,10,33,10,1,c0 [0000000000000000]+ rehovot=13,5,19,5,1,c0 [0000000000000000]+ rishon_lezion=10,5,15,5,1,c0 [0000000000000000]+ rosh_pinna=1,0,1,0,0,c0.35 [3FD6666666666666]+ safed=2,1,3,1,0,c0 [0000000000000000]+ tel_aviv=248,106,370,106,9,c0 [0000000000000000]+ tiberias=6,2,9,2,0,c0 [0000000000000000]+ zikhron_yaakov=2,1,3,1,0,c0 [0000000000000000]units[1:veteran_halutz@-3,19/6site{diff --git a/sim/Statecraft.Sim.Tests/golden/hash1952.txt b/sim/Statecraft.Sim.Tests/golden/hash1952.txtindex fa584b988..d4b884f02 100644--- a/sim/Statecraft.Sim.Tests/golden/hash1952.txt+++ b/sim/Statecraft.Sim.Tests/golden/hash1952.txt@@ -1,9 +1,9 @@1952-01-15;1948;Historical;44;ind{food_supply=0.8556115107122045 [3FEB612B6412E1DF]- housing=0.43504947742483624 [3FDBD7D9C36B9EB6]+ housing=0.08504947742483628 [3FB5C5CD7414E141]intl_standing=0.7800000000000002 [3FE8F5C28F5C28F8]- morale=0.5690955554429493 [3FE23607E1DDA540]+ morale=0.4945578468038132 [3FDFA6D5F48029E0]security=0.5361322526321604 [3FE127FED36C599C]pol{border_settlement=0.2 [3FC999999999999A]@@ -14,14 +14,14 @@ eff{border_villages_secure=0.04113225263216018 [3FA50F495FBB5C36]building_houses=0.08504947742483629 [3FB5C5CD7414E142]food_lifts_cohesion=0.08899999973526929 [3FB6C8B43834FD50]- homes_lift_morale=0.06526319974146688 [3FB0B516CC859C48]+ homes_lift_morale=0.012767196348836194 [3F8A25B0163D2852]rationing_feeds=0.3399999999208376 [3FD5C28F5C133334]rationing_grates=-0.15 [BFC3333333333333]safety_lifts_morale=0.05354077083901369 [3FAB69B227832BE6]- work_lifts_cohesion=0.04129158512719951 [3FA5242BAF71511A]+ work_lifts_cohesion=0.019249879880694112 [3F93B63D92287534]shift{food_supply=0.15000000000000002 [3FC3333333333334]- housing=0 [0000000000000000]+ housing=-1.3877787807814457E-17 [BC70000000000000]intl_standing=0.28000000000000025 [3FD1EB851EB851F0]morale=-0.08000000000000007 [BFB47AE147AE1480]security=0.19500000000000017 [3FC8F5C28F5C28FC]@@ -43,12 +43,13 @@ pop{veterans=690883.9968027371 [41251587FE5CEDA9]sit[fx_crisis+ housing_crisistreasury=0 [0000000000000000]debt=182.89012071283815 [4066DC7BDE6EE43A]fx=-12.990431328096559 [C029FB19D0A63796]rung=2;cf=0;mob=0.05 [3FA999999999999A]-stab=0.5682985020179316 [3FE22F8057110CC0]+stab=0.448654481936148 [3FDCB6C149C7A72C]att=4 [4010000000000000]fired[altalena@@ -123,18 +124,18 @@ map[mapturn=0001-01-01:0;over=mvp_endedcity{- hadera=12,5,12,5,14- haifa=99,42,99,42,118- jerusalem=84,29,84,29,100- netanya=12,5,12,5,14- petah_tikva=22,10,22,10,26- rehovot=13,5,13,5,15- rishon_lezion=10,5,10,5,12- rosh_pinna=1,0,1,0,1- safed=2,1,2,1,3- tel_aviv=248,106,248,106,296- tiberias=6,2,6,2,7- zikhron_yaakov=2,1,2,1,2+ hadera=12,5,26,5,0,c0 [0000000000000000]+ haifa=99,42,215,42,2,c0 [0000000000000000]+ jerusalem=84,29,183,29,1,c0 [0000000000000000]+ netanya=12,5,25,5,1,c0 [0000000000000000]+ petah_tikva=22,10,48,10,0,c0 [0000000000000000]+ rehovot=13,5,28,5,0,c0 [0000000000000000]+ rishon_lezion=10,5,22,5,0,c0 [0000000000000000]+ rosh_pinna=1,0,2,0,0,c0 [0000000000000000]+ safed=2,1,5,1,0,c0 [0000000000000000]+ tel_aviv=248,106,540,106,4,c0 [0000000000000000]+ tiberias=6,2,13,2,0,c0 [0000000000000000]+ zikhron_yaakov=2,1,4,1,0,c0 [0000000000000000]units[1:veteran_halutz@-3,19/6site{diff --git a/sim/Statecraft.Sim.Tests/golden/manifest.txt b/sim/Statecraft.Sim.Tests/golden/manifest.txtindex 0015c7378..372c4e16e 100644--- a/sim/Statecraft.Sim.Tests/golden/manifest.txt+++ b/sim/Statecraft.Sim.Tests/golden/manifest.txt@@ -2,10 +2,10 @@# Tests read this file. To accept a deliberate change: STATECRAFT_UPDATE_GOLDEN=1 dotnet test sim/Statecraft.sln# rewrites this file, the snapshots and the GoldenRun.cs constants; then update docs/determinism.md and tools/web_check.py# (GoldenManifestTests names any place that is out of date) and add a row to the rebaseline history.-hash1950 e4ebff9b317a02b908434cedb18674608ae820e5e60769ef78272493884590c4-hash1952 e0d8212a1f6ea8af9211166aa52b76c741c739807d4326b6b6664a5c5d26857f-smoke5 2436927c8b24f28c42be0e7b5a6fe30900f2f6c6a3ba77e4be943c1f50db57cc-scenario-reckless af7b2abd4c6e477cc78555700b09822030773e9fc6b856ffc0a7109bedc1e7dd-scenario-cautious 28fd140536e326922fadf21571b64bdaae5125f97f2609b44b4baa5ca9bceda3-scenario-mvp-absorb-first b16a87402c03324f6260b57b915a0b7767f12cc166420ace257a21b54b341dd4-mvp-end e0d8212a1f6ea8af9211166aa52b76c741c739807d4326b6b6664a5c5d26857f+hash1950 7cf678b6b2b3d55dc0fee7b2efdee9ec7688cdf18964dcaa6e5a7c0018e34a51+hash1952 9496947232f0c97ed21c0a0b98e6727e7d59c892f9aff12049b5d7e5ee2230e8+smoke5 3005405d64abc6e7418fa1f0d35c36ce5f64ed3af7c5a4c24a73d5dfdb16121f+scenario-reckless 8041988a2c6b5b72a8351fd79ab07c2afca0672f686586cc8b7f9777c2061038+scenario-cautious 6507ddc31437eaf8b0a8858a84c539860dcd7a6febacb0f1d142cb59489e2a9f+scenario-mvp-absorb-first a77a8f20063c741a680a964e3824946dfee27b5675b9cead5e23bbf4bd146183+mvp-end 9496947232f0c97ed21c0a0b98e6727e7d59c892f9aff12049b5d7e5ee2230e8diff --git a/sim/Statecraft.Sim.Tests/golden/mvp-end.txt b/sim/Statecraft.Sim.Tests/golden/mvp-end.txtindex fa584b988..d4b884f02 100644--- a/sim/Statecraft.Sim.Tests/golden/mvp-end.txt+++ b/sim/Statecraft.Sim.Tests/golden/mvp-end.txt@@ -1,9 +1,9 @@1952-01-15;1948;Historical;44;ind{food_supply=0.8556115107122045 [3FEB612B6412E1DF]- housing=0.43504947742483624 [3FDBD7D9C36B9EB6]+ housing=0.08504947742483628 [3FB5C5CD7414E141]intl_standing=0.7800000000000002 [3FE8F5C28F5C28F8]- morale=0.5690955554429493 [3FE23607E1DDA540]+ morale=0.4945578468038132 [3FDFA6D5F48029E0]security=0.5361322526321604 [3FE127FED36C599C]pol{border_settlement=0.2 [3FC999999999999A]@@ -14,14 +14,14 @@ eff{border_villages_secure=0.04113225263216018 [3FA50F495FBB5C36]building_houses=0.08504947742483629 [3FB5C5CD7414E142]food_lifts_cohesion=0.08899999973526929 [3FB6C8B43834FD50]- homes_lift_morale=0.06526319974146688 [3FB0B516CC859C48]+ homes_lift_morale=0.012767196348836194 [3F8A25B0163D2852]rationing_feeds=0.3399999999208376 [3FD5C28F5C133334]rationing_grates=-0.15 [BFC3333333333333]safety_lifts_morale=0.05354077083901369 [3FAB69B227832BE6]- work_lifts_cohesion=0.04129158512719951 [3FA5242BAF71511A]+ work_lifts_cohesion=0.019249879880694112 [3F93B63D92287534]shift{food_supply=0.15000000000000002 [3FC3333333333334]- housing=0 [0000000000000000]+ housing=-1.3877787807814457E-17 [BC70000000000000]intl_standing=0.28000000000000025 [3FD1EB851EB851F0]morale=-0.08000000000000007 [BFB47AE147AE1480]security=0.19500000000000017 [3FC8F5C28F5C28FC]@@ -43,12 +43,13 @@ pop{veterans=690883.9968027371 [41251587FE5CEDA9]sit[fx_crisis+ housing_crisistreasury=0 [0000000000000000]debt=182.89012071283815 [4066DC7BDE6EE43A]fx=-12.990431328096559 [C029FB19D0A63796]rung=2;cf=0;mob=0.05 [3FA999999999999A]-stab=0.5682985020179316 [3FE22F8057110CC0]+stab=0.448654481936148 [3FDCB6C149C7A72C]att=4 [4010000000000000]fired[altalena@@ -123,18 +124,18 @@ map[mapturn=0001-01-01:0;over=mvp_endedcity{- hadera=12,5,12,5,14- haifa=99,42,99,42,118- jerusalem=84,29,84,29,100- netanya=12,5,12,5,14- petah_tikva=22,10,22,10,26- rehovot=13,5,13,5,15- rishon_lezion=10,5,10,5,12- rosh_pinna=1,0,1,0,1- safed=2,1,2,1,3- tel_aviv=248,106,248,106,296- tiberias=6,2,6,2,7- zikhron_yaakov=2,1,2,1,2+ hadera=12,5,26,5,0,c0 [0000000000000000]+ haifa=99,42,215,42,2,c0 [0000000000000000]+ jerusalem=84,29,183,29,1,c0 [0000000000000000]+ netanya=12,5,25,5,1,c0 [0000000000000000]+ petah_tikva=22,10,48,10,0,c0 [0000000000000000]+ rehovot=13,5,28,5,0,c0 [0000000000000000]+ rishon_lezion=10,5,22,5,0,c0 [0000000000000000]+ rosh_pinna=1,0,2,0,0,c0 [0000000000000000]+ safed=2,1,5,1,0,c0 [0000000000000000]+ tel_aviv=248,106,540,106,4,c0 [0000000000000000]+ tiberias=6,2,13,2,0,c0 [0000000000000000]+ zikhron_yaakov=2,1,4,1,0,c0 [0000000000000000]units[1:veteran_halutz@-3,19/6site{diff --git a/sim/Statecraft.Sim.Tests/golden/scenario-cautious.txt b/sim/Statecraft.Sim.Tests/golden/scenario-cautious.txtindex a471bec1f..25f8c1bc5 100644--- a/sim/Statecraft.Sim.Tests/golden/scenario-cautious.txt+++ b/sim/Statecraft.Sim.Tests/golden/scenario-cautious.txt@@ -1,9 +1,9 @@1949-01-15;11400714819323200433;Historical;8;ind{food_supply=0.47968750000000004 [3FDEB33333333334]- housing=0.42228343009948727 [3FDB06B1147AE147]+ housing=0.41685506903832104 [3FDAADC0E22C4014]intl_standing=0.5 [3FE0000000000000]- morale=0.6182874575745196 [3FE3C902C739E7D4]+ morale=0.6175347284969844 [3FE3C2D830E13DBF]security=0.5086917724609377 [3FE04733F7CED918]pol{border_settlement=0.2 [3FC999999999999A]@@ -14,11 +14,11 @@ eff{border_villages_secure=0.033691772460937505 [3FA1400C49BA5E36]building_houses=0.0722834300994873 [3FB2812AB851EB85]food_lifts_cohesion=0.04756250000000001 [3FA85A1CAC083128]- homes_lift_morale=0.06197826633453369 [3FAFBB9D85F06F69]+ homes_lift_morale=0.06191260485593446 [3FAFB3024A220066]rationing_feeds=0.07968750000000002 [3FB4666666666668]rationing_grates=-0.06 [BFAEB851EB851EB8]safety_lifts_morale=0.04761640136718752 [3FA8612D4D4024B6]- work_lifts_cohesion=0.04113028987279843 [3FA50F0783C1E0F0]+ work_lifts_cohesion=0.04044322227386246 [3FA4B4F95A05AEA4]shift{food_supply=0 [0000000000000000]housing=0 [0000000000000000]@@ -47,7 +47,7 @@ debt=26.960591926047705 [403AF5E95A3B2D32]fx=80.85238326859616 [4054368D728D91CC]rung=5;cf=40;mob=0.8 [3FE999999999999A]-stab=0.6256903459725325 [3FE405A7C2ABFF9C]+stab=0.6253697794522252 [3FE403077BD4EDE5]att=4 [4010000000000000]fired[altalena@@ -88,16 +88,16 @@ map[mapturn=0001-01-01:0;over=city{- hadera=12,5,12,5,1- haifa=99,42,99,42,6- jerusalem=84,29,84,29,6- netanya=12,5,12,5,1- petah_tikva=22,10,22,10,1- rehovot=13,5,13,5,1- rishon_lezion=10,5,10,5,1- rosh_pinna=1,0,1,0,0- safed=2,1,2,1,0- tel_aviv=248,106,248,106,16- tiberias=6,2,6,2,0- zikhron_yaakov=2,1,2,1,0+ hadera=12,5,12,5,1,c0.35 [3FD6666666666666]+ haifa=99,42,102,42,3,c0.34408823529411764 [3FD6058AA961B39F]+ jerusalem=84,29,87,29,3,c0.3430628803245436 [3FD5F4BE02DDCA5E]+ netanya=12,5,12,5,1,c0.35 [3FD6666666666666]+ petah_tikva=22,10,23,10,0,c0.3434782608695652 [3FD5FB8C3E54975F]+ rehovot=13,5,14,5,0,c0.33928571428571425 [3FD5B6DB6DB6DB6D]+ rishon_lezion=10,5,10,5,1,c0.35 [3FD6666666666666]+ rosh_pinna=1,0,1,0,0,c0.35 [3FD6666666666666]+ safed=2,1,2,1,0,c0.35 [3FD6666666666666]+ tel_aviv=248,106,256,106,8,c0.34471009036144573 [3FD60FBAE92D0804]+ tiberias=6,2,6,2,0,c0.35 [3FD6666666666666]+ zikhron_yaakov=2,1,2,1,0,c0.35 [3FD6666666666666]food=2253,751,0\ No newline at end of filediff --git a/sim/Statecraft.Sim.Tests/golden/scenario-mvp-absorb-first.txt b/sim/Statecraft.Sim.Tests/golden/scenario-mvp-absorb-first.txtindex b5d49ca2a..8298b90ab 100644--- a/sim/Statecraft.Sim.Tests/golden/scenario-mvp-absorb-first.txt+++ b/sim/Statecraft.Sim.Tests/golden/scenario-mvp-absorb-first.txt@@ -1,9 +1,9 @@1949-06-15;11400714819323200433;Historical;13;ind{food_supply=0.7200000000000001 [3FE70A3D70A3D70B]- housing=0.4311483383927494 [3FDB97EF3347C84B]+ housing=0.33477730272214257 [3FD56CFDC7A89ED4]intl_standing=0.7600000000000002 [3FE851EB851EB854]- morale=0.5096388805373344 [3FE04EF63295B160]+ morale=0.4961955804901623 [3FDFC1AB1BA7FFB8]security=0.500599903035164 [3FE004EA167D566E]pol{border_settlement=0.2 [3FC999999999999A]@@ -14,11 +14,11 @@ eff{border_villages_secure=0.03559990303516388 [3FA23A26868DB8BB]building_houses=0.08114833839274943 [3FB4C62333858794]food_lifts_cohesion=0.047495117187500005 [3FA85147AE147AE2]- homes_lift_morale=0.06417065737109631 [3FB06D7CFAC58CD2]+ homes_lift_morale=0.05648611356478082 [3FACEBBF74E0B44D]rationing_feeds=0.17 [3FC5C28F5C28F5C3]rationing_grates=-0.15 [BFC3333333333333]safety_lifts_morale=0.049817294571876544 [3FA981A705EC3DAE]- work_lifts_cohesion=0.03815581140686154 [3FA38928944A2512]+ work_lifts_cohesion=0.03239705516600502 [3FA09658C8D97234]shift{food_supply=0.15000000000000002 [3FC3333333333334]housing=0 [0000000000000000]@@ -47,7 +47,7 @@ debt=59.72606782031707 [404DDCEFCA53784C]fx=94.29191537516759 [405792AEBDD362D7]rung=2;cf=0;mob=0.8 [3FE999999999999A]-stab=0.5829253189830537 [3FE2A752FFA15CD8]+stab=0.5718469643325106 [3FE24C9201440018]att=4 [4010000000000000]fired[altalena@@ -96,16 +96,16 @@ map[mapturn=0001-01-01:0;over=city{- hadera=12,5,12,5,3- haifa=99,42,99,42,25- jerusalem=84,29,84,29,22- netanya=12,5,12,5,3- petah_tikva=22,10,22,10,6- rehovot=13,5,13,5,3- rishon_lezion=10,5,10,5,3- rosh_pinna=1,0,1,0,0- safed=2,1,2,1,1- tel_aviv=248,106,248,90,64- tiberias=6,2,6,2,1- zikhron_yaakov=2,1,2,1,1+ hadera=12,5,15,5,0,c0.2540659340659341 [3FD0429DC375D0F7]+ haifa=99,42,120,42,4,c0.2538443449593976 [3FD03EFC59F8028B]+ jerusalem=84,29,102,29,4,c0.25059889032971866 [3FD009CFED985273]+ netanya=12,5,14,5,1,c0.26263736263736265 [3FD0CF0CF0CF0CF1]+ petah_tikva=22,10,27,10,1,c0.2556018208844295 [3FD05BC7BD5FC984]+ rehovot=13,5,16,5,0,c0.24044642857142845 [3FCEC6F2D593BF9E]+ rishon_lezion=10,5,12,5,1,c0.2590909090909091 [3FD094F2094F2095]+ rosh_pinna=1,0,1,0,0,c0.35 [3FD6666666666666]+ safed=2,1,3,1,0,c0.25 [3FD0000000000000]+ tel_aviv=248,106,302,90,10,c0.253441763530126 [3FD03863CD735B73]+ tiberias=6,2,7,2,0,c0.26428571428571435 [3FD0EA0EA0EA0EA2]+ zikhron_yaakov=2,1,3,1,0,c0.3 [3FD3333333333333]food=2556,852,0\ No newline at end of filediff --git a/sim/Statecraft.Sim.Tests/golden/scenario-reckless.txt b/sim/Statecraft.Sim.Tests/golden/scenario-reckless.txtindex 7b465319a..24abfc20c 100644--- a/sim/Statecraft.Sim.Tests/golden/scenario-reckless.txt+++ b/sim/Statecraft.Sim.Tests/golden/scenario-reckless.txt@@ -1,9 +1,9 @@1949-01-15;11400714819323200433;Historical;8;ind{food_supply=0.59921875 [3FE32CCCCCCCCCCD]- housing=0.42228343009948727 [3FDB06B1147AE147]+ housing=0.41685506903832104 [3FDAADC0E22C4014]intl_standing=0.38999999999999996 [3FD8F5C28F5C28F5]- morale=0.5054202700745196 [3FE02C67215693DC]+ morale=0.5046675409969844 [3FE0263C8AFDE9C7]security=0.4636917724609376 [3FDDAD204189374E]pol{border_settlement=0.2 [3FC999999999999A]@@ -14,11 +14,11 @@ eff{border_villages_secure=0.033691772460937505 [3FA1400C49BA5E36]building_houses=0.0722834300994873 [3FB2812AB851EB85]food_lifts_cohesion=0.059140625 [3FAE47AE147AE148]- homes_lift_morale=0.06197826633453369 [3FAFBB9D85F06F69]+ homes_lift_morale=0.06191260485593446 [3FAFB3024A220066]rationing_feeds=0.19921875 [3FC9800000000000]rationing_grates=-0.15 [BFC3333333333333]safety_lifts_morale=0.04317108886718751 [3FA61A855DA27288]- work_lifts_cohesion=0.04113028987279843 [3FA50F0783C1E0F0]+ work_lifts_cohesion=0.04044322227386246 [3FA4B4F95A05AEA4]shift{food_supply=0 [0000000000000000]housing=0 [0000000000000000]@@ -47,7 +47,7 @@ debt=34.960591926047705 [40417AF4AD1D9699]fx=80.85238326859616 [4054368D728D91CC]rung=5;cf=40;mob=1 [3FF0000000000000]-stab=0.5919575738389019 [3FE2F15102883E2B]+stab=0.5916370073185946 [3FE2EEB0BBB12C74]att=4 [4010000000000000]fired[altalena@@ -86,16 +86,16 @@ map[mapturn=0001-01-01:0;over=city{- hadera=12,5,12,5,1- haifa=99,42,99,42,6- jerusalem=84,29,84,29,6- netanya=12,5,12,5,1- petah_tikva=22,10,22,10,1- rehovot=13,5,13,5,1- rishon_lezion=10,5,10,5,1- rosh_pinna=1,0,1,0,0- safed=2,1,2,1,0- tel_aviv=248,106,248,106,16- tiberias=6,2,6,2,0- zikhron_yaakov=2,1,2,1,0+ hadera=12,5,12,5,1,c0.35 [3FD6666666666666]+ haifa=99,42,102,42,3,c0.34408823529411764 [3FD6058AA961B39F]+ jerusalem=84,29,87,29,3,c0.3430628803245436 [3FD5F4BE02DDCA5E]+ netanya=12,5,12,5,1,c0.35 [3FD6666666666666]+ petah_tikva=22,10,23,10,0,c0.3434782608695652 [3FD5FB8C3E54975F]+ rehovot=13,5,14,5,0,c0.33928571428571425 [3FD5B6DB6DB6DB6D]+ rishon_lezion=10,5,10,5,1,c0.35 [3FD6666666666666]+ rosh_pinna=1,0,1,0,0,c0.35 [3FD6666666666666]+ safed=2,1,2,1,0,c0.35 [3FD6666666666666]+ tel_aviv=248,106,256,106,8,c0.34471009036144573 [3FD60FBAE92D0804]+ tiberias=6,2,6,2,0,c0.35 [3FD6666666666666]+ zikhron_yaakov=2,1,2,1,0,c0.35 [3FD6666666666666]food=2253,751,0\ No newline at end of filediff --git a/sim/Statecraft.Sim/Cities.cs b/sim/Statecraft.Sim/Cities.csindex bb421e76a..87be3605e 100644--- a/sim/Statecraft.Sim/Cities.cs+++ b/sim/Statecraft.Sim/Cities.cs@@ -18,11 +18,14 @@ namespace Statecraft.Simpublic static int NearestUnit(decimal people, int peoplePerUnit) =>(int)Math.Round(people / peoplePerUnit, MidpointRounding.AwayFromZero);- /// <summary>Fills the state's cities from cities.yaml, with no refugees yet. Does nothing in the legacy loop.</summary>+ /// <summary>Fills the state's cities from cities.yaml, with no refugees yet and the start housing condition (R-HOUSE-001). Does nothing in the legacy loop.</summary>public static void Init(Content c, GameState s){if (!c.IsGdd) return;- foreach (var x in c.Cities) s.Cities[x.Id] = new City(x.Id, x.HousingCapacity, x.JobSlots, x.Civilians, x.Employed, 0);+ var r = c.RulesAt(s.Date).Mvp!;+ foreach (var x in c.Cities) s.Cities[x.Id] = new City(x.Id, x.HousingCapacity, x.JobSlots, x.Civilians, x.Employed, 0, 0, r.HousingStartCondition!.Value);+ var housing = c.At(s.Date).Indicators.FirstOrDefault(i => i.Id == HousingIndicator);+ if (housing != null) s.Indicators[housing.Id] = EffectsSystem.Level(c, s, housing); // R-HOUSE-004 from the first day}/// <summary>R-CITY-001: sets the number of the city's civilians in jobs (a standing order). Refused, state untouched,@@ -52,17 +55,68 @@ namespace Statecraft.Sim}}- /// <summary>R-CITY-004 (D-A5): refugees become civilians, without a job, as far as the city's free housing goes. The cap is- /// a placeholder: what happens to people beyond it is D-D1, still open.</summary>+ /// <summary>R-CITY-004 (D-A5; D-D1, Q-HOUSE-1): no hard cap. Every refugee becomes a civilian, without a job, on the+ /// housing step; the people beyond the city's housing are its overflow (<see cref="Overflow"/>), still counted in it.+ /// Residents are housed automatically (Q-HOUSE-4).</summary>public static void House(Content c, GameState s, List<Cause> why){- // PLACEHOLDER (owner question, #377): only civilians take housing; people in training and recruits do not.foreach (var x in s.Cities.Values.ToList()){- var moved = Math.Min(x.Refugees, Math.Max(0, x.HousingCapacity - x.Civilians));- if (moved == 0) continue;- s.Cities[x.Id] = x.WithCounts(x.Civilians + moved, x.Employed, x.Refugees - moved);- why.Add(new Cause("city", x.Id, moved, FormattableString.Invariant($"{PlayerText.Settlement(c, x.Id)}: {moved} groups of immigrants housed")));+ if (x.Refugees == 0) continue;+ s.Cities[x.Id] = x.WithCounts(x.Civilians + x.Refugees, x.Employed, 0);+ why.Add(new Cause("city", x.Id, x.Refugees, FormattableString.Invariant($"{PlayerText.Settlement(c, x.Id)}: {x.Refugees} groups of immigrants housed")));+ }+ }++ /// <summary>R-HOUSE-003 (Q-HOUSE-5): the people who take the city's housing: its civilians, its recruits and its groups+ /// in training (a halutz group too, until it becomes a movable unit and leaves). Refugees wait for housing and are not+ /// in it. Summed as integers, so the order of the training groups cannot change it.</summary>+ public static int Housed(GameState s, City x)+ {+ var n = x.Civilians + x.Recruits;+ foreach (var k in s.Cohorts.Values) if (k.City == x.Id) n += k.Count;+ return n;+ }++ /// <summary>R-HOUSE-002 (D-D1): the people beyond the city's housing, one capacity point a unit (Q-HOUSE-1); 0 when+ /// they fit.</summary>+ public static int Overflow(GameState s, City x) => Math.Max(0, Housed(s, x) - x.HousingCapacity);++ /// <summary>The national indicator whose base the cities set (R-HOUSE-004).</summary>+ public const string HousingIndicator = "housing";++ /// <summary>R-HOUSE-004 (owner, 17 October 2026, Q-PR3-A option (a)): the people-weighted mean of the cities' housing+ /// condition, each city weighed by its <see cref="Housed"/> people. It replaces the base of the national `housing`+ /// indicator in the GDD loop; policy, map actions and events still act on top (EffectsSystem.Inner). Null when no city+ /// with a condition houses anybody, and the indicator then reads model.yaml's base. The sum runs in ordinal city order+ /// with integer weights, then one division.</summary>+ public static double? HousingLevel(GameState s)+ {+ long people = 0;+ var sum = 0.0;+ foreach (var x in s.Cities.Values) // SortedDictionary, ordinal+ {+ if (x.Condition is not double condition) continue;+ var n = Housed(s, x);+ people += n;+ sum += condition * n;+ }+ return people == 0 ? (double?)null : sum / people;+ }++ /// <summary>R-HOUSE-002 (D-D1, Q-HOUSE-1): after the housing step, each city with overflow loses+ /// <c>overflow_condition_loss * overflow / housed</c> of its housing condition, never below 0. A city with none keeps+ /// its condition; nothing in this rule raises it (housing projects do, Phase 3 PR 4). Each city reads only its own+ /// counts (R-HOUSE-001: the condition is per city).</summary>+ public static void UpdateCondition(Content c, GameState s, MvpRules r, List<Cause> why)+ {+ foreach (var x in s.Cities.Values.ToList())+ {+ var over = Overflow(s, x);+ if (over == 0) continue;+ if (x.Condition is double now)+ s.Cities[x.Id] = x.WithCondition(Math.Max(0.0, now - r.OverflowConditionLoss!.Value * over / Housed(s, x)));+ why.Add(new Cause("city", x.Id, over, FormattableString.Invariant($"{PlayerText.Settlement(c, x.Id)}: {over} groups more than its homes hold")));}}diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex 4b5fae20b..c3c37c863 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -506,6 +506,12 @@ namespace Statecraft.Sim/// <summary>Turns of progress a veteran's project gains each turn, against a halutz's 1 (R-VET-002; D-D9, Q-VET-2)./// Required in the GDD loop, at least 1.</summary>public int? VeteranProgress { get; set; }+ /// <summary>Every city's housing condition on the first day (R-HOUSE-001; D-D2, Q-START-3: one value for all the+ /// cities). Required in the GDD loop, 0 to 1.</summary>+ public double? HousingStartCondition { get; set; }+ /// <summary>How far a city's housing condition falls in a turn when all its people are beyond its housing; a turn takes+ /// this times the city's overflow share (R-HOUSE-002; D-D1, Q-HOUSE-1). Required in the GDD loop, 0 to 1.</summary>+ public double? OverflowConditionLoss { get; set; }}/// <summary>A designated site (sites.yaml; docs/GDD.md "Pioneer work": building is allowed only at designated spots, and adiff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex 502f42357..be4264d1f 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -1074,6 +1074,11 @@ namespace Statecraft.Simif (v == null) throw new ContentException(file, "mvp." + key, "required when eras.yaml systems.loop is gdd");if (v < 1) throw new ContentException(file, "mvp." + key, "must be >= 1");}+ // R-HOUSE-001, R-HOUSE-002: required, so a missing key is never read as a condition of 0 or no loss.+ if (m.HousingStartCondition == null) throw new ContentException(file, "mvp.housing_start_condition", "required when eras.yaml systems.loop is gdd");+ Unit(file, "mvp.housing_start_condition", m.HousingStartCondition.Value);+ if (m.OverflowConditionLoss == null) throw new ContentException(file, "mvp.overflow_condition_loss", "required when eras.yaml systems.loop is gdd");+ Unit(file, "mvp.overflow_condition_loss", m.OverflowConditionLoss.Value);if (c.Indicators.All(i => i.Id != Pools.FoodIndicator))throw new ContentException(file, "mvp.k_food", "the Food stock feeds the food_supply indicator, which model.yaml must define");// One game has one last day (R-LOOP-004): an era cannot move it.diff --git a/sim/Statecraft.Sim/EffectsSystem.cs b/sim/Statecraft.Sim/EffectsSystem.csindex bee6376e3..4459600a3 100644--- a/sim/Statecraft.Sim/EffectsSystem.cs+++ b/sim/Statecraft.Sim/EffectsSystem.cs@@ -77,11 +77,16 @@ namespace Statecraft.Sim: s.Indicators[id];/// <summary>clamp(base + effect contributions) to [0, 1], before event shifts. In the GDD loop food_supply also carries- /// the Food stock's term (R-FOOD-003), exactly 0 at a full cover.</summary>+ /// the Food stock's term (R-FOOD-003), exactly 0 at a full cover, and housing's base is the cities' people-weighted+ /// mean condition when anybody is housed (R-HOUSE-004).</summary>internal static double Inner(Content c, GameState s, Indicator i) =>- Math.Max(0, Math.Min(1, i.Base + c.At(s.Date).Effects.Where(e => e.Target == i.Id).Sum(e => s.EffectContributions[e.Id])+ Math.Max(0, Math.Min(1, Base(c, s, i) + c.At(s.Date).Effects.Where(e => e.Target == i.Id).Sum(e => s.EffectContributions[e.Id])+ (i.Id == Pools.FoodIndicator ? Pools.FoodTerm(c, s) : 0.0)));+ /// <summary>The indicator's base: model.yaml's, except housing's in the GDD loop (R-HOUSE-004).</summary>+ static double Base(Content c, GameState s, Indicator i) =>+ c.IsGdd && i.Id == Cities.HousingIndicator ? Cities.HousingLevel(s) ?? i.Base : i.Base;+/// <summary>clamp(inner + event shift) to [0, 1].</summary>internal static double Level(Content c, GameState s, Indicator i) =>Math.Max(0, Math.Min(1, Inner(c, s, i) + s.IndicatorShifts[i.Id]));diff --git a/sim/Statecraft.Sim/GameState.cs b/sim/Statecraft.Sim/GameState.csindex f6687b8ff..6229e8813 100644--- a/sim/Statecraft.Sim/GameState.cs+++ b/sim/Statecraft.Sim/GameState.cs@@ -184,7 +184,7 @@ namespace Statecraft.Simforeach (var i in items) { Entry(); sb.Append(i); Sep(); }Close(close);}- if (Cities.Count > 0) Section("city", '{', '}', Cities.Values.Select(x => x.Canonical()));+ if (Cities.Count > 0) Section("city", '{', '}', Cities.Values.Select(x => x.Canonical(readable)));if (Units.Count > 0) Section("units", '[', ']', Units.Values.Select(x => x.Canonical()));if (Cohorts.Count > 0) Section("train", '[', ']', Cohorts.Values.Select(x => x.Canonical()));if (Sites.Count > 0) Section("site", '{', '}', Sites.Values.Select(x => x.Canonical()));diff --git a/sim/Statecraft.Sim/GddState.cs b/sim/Statecraft.Sim/GddState.csindex 0c893747d..627752305 100644--- a/sim/Statecraft.Sim/GddState.cs+++ b/sim/Statecraft.Sim/GddState.cs@@ -5,8 +5,8 @@ namespace Statecraft.Sim{/// <summary>A city in the GDD v0.1 loop (docs/GDD.md "Cities and construction"; owner decision D-A2: civilians and/// refugees are counts per city). Counts are population units, each a group (D-A1). Immutable, so GameState.Clone can copy- /// the map shallowly; a change replaces the record. Only the attributes approved decisions define are here: housing- /// condition and craftsmen arrive with the decisions that define them.</summary>+ /// the map shallowly; a change replaces the record. Only the attributes approved decisions define are here: craftsmen+ /// arrive with the decision that defines them (D-D4).</summary>public sealed class City{public string Id { get; }@@ -21,24 +21,40 @@ namespace Statecraft.Sim/// <summary>The recruits who finished basic training here (GDD "Progression"; R-TRAIN-003). A count until Phase 5 makes/// soldiers units.</summary>public int Recruits { get; }+ /// <summary>The city's housing condition, 0 to 1, an average over the city (GDD "Housing condition"; D-D2, Q-HOUSE-2;+ /// R-HOUSE-001). Null only on a record made without one (a test's hand-built city); every GDD game's cities have one.</summary>+ public double? Condition { get; }- public City(string id, int housingCapacity, int jobSlots, int civilians, int employed, int refugees, int recruits = 0)+ public City(string id, int housingCapacity, int jobSlots, int civilians, int employed, int refugees, int recruits = 0, double? condition = null){Id = id; HousingCapacity = housingCapacity; JobSlots = jobSlots; Civilians = civilians; Employed = employed; Refugees = refugees;- Recruits = recruits;+ Recruits = recruits; Condition = condition;}/// <summary>The same city with new population counts.</summary>- public City WithCounts(int civilians, int employed, int refugees) => new City(Id, HousingCapacity, JobSlots, civilians, employed, refugees, Recruits);+ public City WithCounts(int civilians, int employed, int refugees) => new City(Id, HousingCapacity, JobSlots, civilians, employed, refugees, Recruits, Condition);/// <summary>The same city with a new number of recruits.</summary>- public City WithRecruits(int recruits) => new City(Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees, recruits);+ public City WithRecruits(int recruits) => new City(Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees, recruits, Condition);- /// <summary>The record as the state hash writes it. The recruits are written only when there are some, so a city with- /// none hashes as it did before training existed (R-LOOP-002's rule).</summary>- public string Canonical() =>- string.Format(CultureInfo.InvariantCulture, "{0}={1},{2},{3},{4},{5}", Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees)- + (Recruits == 0 ? "" : "," + Recruits.ToString(CultureInfo.InvariantCulture));+ /// <summary>The same city with a new housing condition.</summary>+ public City WithCondition(double condition) => new City(Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees, Recruits, condition);++ /// <summary>The record as the state hash writes it. The recruits are written only when there are some, and the condition+ /// only when it is set (",c" and its 64 bits in hex; readable, the value and then the bits), so a city with neither hashes+ /// as it did before they existed (R-LOOP-002's rule).</summary>+ public string Canonical(bool readable = false)+ {+ var text = string.Format(CultureInfo.InvariantCulture, "{0}={1},{2},{3},{4},{5}", Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees)+ + (Recruits == 0 ? "" : "," + Recruits.ToString(CultureInfo.InvariantCulture));+ if (Condition is double c)+ {+ if (c == 0.0) c = 0.0; // -0 and 0 hash alike, as GameState's numbers do+ var bits = BitConverter.DoubleToInt64Bits(c).ToString("X16", CultureInfo.InvariantCulture);+ text += readable ? ",c" + c.ToString("R", CultureInfo.InvariantCulture) + " [" + bits + "]" : ",c" + bits;+ }+ return text;+ }}/// <summary>A movable unit in the GDD v0.1 loop (owner decision D-A2: halutzim and soldiers are movable units), a groupdiff --git a/sim/Statecraft.Sim/GoldenRun.cs b/sim/Statecraft.Sim/GoldenRun.csindex 462c46537..b8c679a1a 100644--- a/sim/Statecraft.Sim/GoldenRun.cs+++ b/sim/Statecraft.Sim/GoldenRun.cs@@ -15,13 +15,13 @@ namespace Statecraft.Sim/// <summary>Final hash of Play(content, Until1950). Changing it is a deliberate rules or content change: the value/// is pinned in sim/Statecraft.Sim.Tests/golden/manifest.txt, and STATECRAFT_UPDATE_GOLDEN=1 dotnet test rewrites/// both (docs/determinism.md). Say why in the commit message.</summary>- public const string Hash1950 = "e4ebff9b317a02b908434cedb18674608ae820e5e60769ef78272493884590c4";+ public const string Hash1950 = "7cf678b6b2b3d55dc0fee7b2efdee9ec7688cdf18964dcaa6e5a7c0018e34a51";public static readonly DateTime Until1950 = new DateTime(1950, 1, 1);/// <summary>Final hash of Play(content, Until1952): the M3 content range (to 31 December 1951). The GDD game ends on/// 15 January 1952 (R-LOOP-004), the first turn on or after Until1952, so this is also the mvp-end run.</summary>- public const string Hash1952 = "e0d8212a1f6ea8af9211166aa52b76c741c739807d4326b6b6664a5c5d26857f";+ public const string Hash1952 = "9496947232f0c97ed21c0a0b98e6727e7d59c892f9aff12049b5d7e5ee2230e8";public static readonly DateTime Until1952 = new DateTime(1952, 1, 1);diff --git a/sim/Statecraft.Sim/TurnResolver.cs b/sim/Statecraft.Sim/TurnResolver.csindex 3698a927d..14c5b5423 100644--- a/sim/Statecraft.Sim/TurnResolver.cs+++ b/sim/Statecraft.Sim/TurnResolver.cs@@ -20,7 +20,8 @@ namespace Statecraft.SimCities.Produce(c, s, r, yearFraction, why); // 6. productionPools.Harvest(c, s, r, why); // and the plowed fields' Food (R-FIELD-002)Pools.Consume(c, s, r, why); // 7. consumption: the nation eats, then imports (R-FOOD-002)- Cities.House(c, s, why); // 8. housing; Social cohesion is morale, which the effects web moves after the resolution+ Cities.House(c, s, why); // 8. housing, then the housing condition; Social cohesion is morale, which the effects web moves after the resolution+ Cities.UpdateCondition(c, s, r, why);Cities.Arrive(c, s, r, next, why); // 9. arrivals// 10. Occupation timers: Phase 6.Objectives.Complete(c, s, r, next, why); // 11. objectives and scorediff --git a/tools/web_check.py b/tools/web_check.pyindex 575e61ed7..b744f2ca9 100644--- a/tools/web_check.py+++ b/tools/web_check.py@@ -8,7 +8,7 @@ fail on a failure line or a timeout. Uses Chrome for Testing from the Playwright--enable-logging=stderr --v=1 as INFO:CONSOLE... "text", source: ...Usage (from the repo root):- uv run tools/web_check.py unity/Builds/Web-disabled --query "golden" --expect "GOLDEN OK 1950 e4ebff9b317a02b908434cedb18674608ae820e5e60769ef78272493884590c4" --expect "GOLDEN OK 1952 e0d8212a1f6ea8af9211166aa52b76c741c739807d4326b6b6664a5c5d26857f"+ uv run tools/web_check.py unity/Builds/Web-disabled --query "golden" --expect "GOLDEN OK 1950 7cf678b6b2b3d55dc0fee7b2efdee9ec7688cdf18964dcaa6e5a7c0018e34a51" --expect "GOLDEN OK 1952 9496947232f0c97ed21c0a0b98e6727e7d59c892f9aff12049b5d7e5ee2230e8"Options: --query Q (page URL query, without '?'), --expect TEXT (repeatable), --fail REGEX (default: GOLDEN FAIL|SMOKE FAIL|BOOT FAIL),--timeout SECONDS (default 300), --stall SECONDS (fail when no console message arrives for that long; 0 = off),--swiftshader (software WebGL when there is no GPU), --dpr N (default 1), --shots DIR (reassemble the player's