Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

feat(sim): the housing step runs on a Historical ledger game (#1725 PR 7, producer 04) (#2948)

Eyal Golanace327612ab2
diff --git a/changelog.d/1725-pr7-housing-condition.md b/changelog.d/1725-pr7-housing-condition.md
new file mode 100644
index 000000000..16d2e4f7a
--- /dev/null
+++ b/changelog.d/1725-pr7-housing-condition.md
@@ -0,0 +1,4 @@
+- GDD 0.3 starting population (Refs #1725, Refs #1689): the gdd-0.3 housing step (surcharge, condition and Social
+ cohesion) now runs on the inactive dark start's Historical ledger, counting each city's housed people and the own
+ population from the ledger's records. The opening field farmers are housed in their host city; the two at Nir Am and
+ Nirim, which have no city record, are counted in no city. No new-game wiring, so there is no change in the game.
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index bb479d94c..65a77d295 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -138,13 +138,13 @@ R-HOUSE-002: A city's overflow is `max(0, housed - housing_capacity)`, one capac
For R-HOUSE-002, inactive gdd-0.3 synthetic arithmetic prices the surcharge as `SurchargeResidents * max(0, money_threshold - ConditionBefore) * money_slope`, then subtracts the overflow loss and clamps condition. Overflow loss is `(overflow_deterioration / 100) * max(0, Residents - Capacity) / Residents`, with `Residents` the housed residents after the step's arrivals become civilians (27M-15, owner-approved 1 November 2026: "After that step's arrivals become civilians (R-CITY-004)."; #2517); zero residents gives zero loss. There is no unpaid-upkeep loss and the helper takes no upkeep input: there is no housing upkeep (27M-17, R-HOUSE-005), and `housing.max_deterioration` stays in `content/gdd03-balance.yaml` as post-MVP design that nothing reads (#2516). The returned cohesion contribution is `max_cohesion_loss * (CohesionResidents / OwnPopulation) * max(0, (cohesion_threshold - ConditionAfter) / cohesion_threshold)`, zero with no own population. It is displayed points, not an indicator write or a national summation (`sim/Statecraft.Sim/Gdd03HousingFormula.cs:66-88@25938871c`; the after-arrivals, worked-number, distinct-count, post-deterioration and zero-denominator fixtures in `sim/Statecraft.Sim.Tests/Gdd03HousingFormulaTests.cs:77-86,112-172@25938871c`). Source: `docs/gdd/cities.md:29-35@605277dfa511dc512562ececeb273b8393b21d35`; #1703 says, "Price the surcharge from pre-deterioration condition, then deteriorate once, then apply cohesion once." Under `gdd-0.3` this arithmetic is now live, per city, as R-HOUSE-005 (#1703); under `gdd-0.1` and legacy the preceding active rule (0.15) is unchanged. Repairs are R-HOUSE-006 under `gdd-0.3` (#1700); monthly snapshot timing (#1716) remains pending.
-R-HOUSE-003: The people who take a city's housing (`housed`) are its civilians, its craftsmen, 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-003: The people who take a city's housing (`housed`) are its civilians, its craftsmen, 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. With an initialized Historical ledger (the dark start, R-POP-002; #1725 PR 7) the housed people are counted from the ledger's records, one population unit each, not the aggregate city fields: a city houses its free civilian and trainee records located in it, so the opening field farmers are housed in their host city beside the place each adds (R-POP-004). Nir Am and Nirim have no city record, so their two farmers are housed in no city.
For R-HOUSE-003, the inactive gdd-0.3 helper takes independently supplied surcharge, overflow and cohesion resident counts plus own population, the overflow count taken after the step's arrivals (27M-15); it selects no residents and substitutes none of those counts for another (`sim/Statecraft.Sim/Gdd03HousingFormula.cs:66-88@25938871c`, `:130-150`; `sim/Statecraft.Sim.Tests/Gdd03HousingFormulaTests.cs:77-86,135-144@25938871c`). Negative counts or capacity, cohesion residents above total own population, and condition outside 0..1 are refused. A zero-population cohesion input therefore requires zero cohesion residents (`docs/gdd/cities.md:27,31@605277dfa511dc512562ececeb273b8393b21d35`). Source: `docs/gdd/cities.md:25@605277dfa511dc512562ececeb273b8393b21d35`, "A civilian resident without dedicated reception, teacher or military-training housing uses ordinary housing."; `docs/gdd/loop-switch.md:33` at that revision said, "use pre-arrival residents for overcrowding deterioration", which 27M-15 superseded: housing effects count residents after the step's arrivals become civilians (owner-approved 1 November 2026; owner, 2 November 2026: "After housing arrivals (Recommended)"), so `Gdd03SyntheticMonthContext` no longer carries a pre-arrival resident list (#2517). Those are producer requirements, not resident-selection behavior implemented here. Live status selection (#1689), regions/approved housing locations (#1691; #1690 closed on 2 November 2026, its post-MVP regional pools moved to #2233) and which residents to count (#1668) remain pending under the #1703 status comment, which says, "Regional housing settlement is not yet implemented". The preceding legacy/gdd-0.1 resident set remains unchanged. Under `gdd-0.3` (#1703) a city's Israeli formations are not housed: `housed` is its civilians, craftsmen, recruits and groups in training, so the formations whose home it is no longer count toward its overflow, R-HOUSE-004's weights or R-OBJ-004 (27M-18, owner-approved 1 November 2026: "Housed = civilians, craftsmen, recruits and groups in training. Refugees and pioneer units are not housed."; confirmed by the owner, 3 November 2026: "Yes, formations not housed (Recommended)"). `gdd-0.1` keeps counting them (Q-HOUSE-5; `Cities.Housed`).
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).
-R-HOUSE-005: Under `gdd-0.3` only (#1703, the MVP's per-city housing condition), the housing step after R-CITY-004 settles, in #1703's order ("Price the surcharge from pre-deterioration condition, then deteriorate once, then apply cohesion once."), for every city with a condition, with R its housed people (R-HOUSE-003) and P all own population (every city's housed people and refugees plus the strength of every player unit, halutz units included): (1) a surcharge of `R * max(0, money_threshold - c) * money_slope` Money a turn from the condition c before this turn's deterioration, summed over the cities into one Money line (`housing_surcharge`) and borrowed when the Treasury is short (R-MONEY-003); `money_threshold` is 0.50 and `money_slope` is 0.1 Money per housed population unit (owner, 2 November 2026: "Scale it to unit size (Recommended)"; the option read: "0.1 per unit (as #2112 did for Industry), about 7.6 Money a turn at start."), so the shipped census start charges 511 housed units x 0.15 x 0.1 = 7.665 Money on the opening turn; (2) overflow deterioration of `overflow_deterioration * max(0, R - housing_capacity) / R` percentage points (5 pp; owner, 2 November 2026: "Yes, 5 pp under GDD 0.3 (Recommended)"), never below 0, in place of R-HOUSE-002's `overflow_condition_loss`; zero housed loses nothing; (3) a Social cohesion loss of `max_cohesion_loss * sum((R / P) * max(0, (cohesion_threshold - c') / cohesion_threshold))` displayed points (`max_cohesion_loss` 2, `cohesion_threshold` 0.25; owner, 2 November 2026: "Keep the 2-point loss (Recommended)") from the condition c' after deterioration, applied once to `morale` through its permanent shift with one cause line (`housing_cohesion`); zero own population loses nothing. The legacy `homes_lift_morale` link from `housing` into `morale` adds nothing under `gdd-0.3`, so housing lowers Social cohesion only through (3) (#1703 Done-when, with #1715; the Food term stays #1715's). There is no housing upkeep (27M-17, IL 0m), so no unpaid-upkeep deterioration. Values: `content/gdd03-balance.yaml` (`housing.*`), read by `Gdd03HousingFormula`; code: `Cities.UpdateCondition` and `Cities.SettleGdd03`, `EffectsSystem.RetiredGdd03Link`; tests: `Gdd03HousingConditionTests`, `Gdd03MoneyLedgerTests`. The issue's three rules run under `gdd-0.3`: the 5 pp overflow (owner, 2 November 2026: "Yes, 5 pp under GDD 0.3 (Recommended)") and the cohesion term (owner, 2 November 2026: "Keep the 2-point loss (Recommended)"; the option read: "As issue #1703 specifies, GDD 0.3 only."). P is the 12 cities' people as built, plus the player units (owner, 2 November 2026: "The 12 cities' people (Recommended)"; the option read: "As built: only the cities whose housing is tracked."). R is counted after the step's housing arrivals (owner, 2 November 2026: "After housing arrivals (Recommended)"; 27M-15). Formations are not housed (owner, 3 November 2026: "Yes, formations not housed (Recommended)", #1703); repairs are R-HOUSE-006.
+R-HOUSE-005: Under `gdd-0.3` only (#1703, the MVP's per-city housing condition), the housing step after R-CITY-004 settles, in #1703's order ("Price the surcharge from pre-deterioration condition, then deteriorate once, then apply cohesion once."), for every city with a condition, with R its housed people (R-HOUSE-003) and P all own population (every city's housed people and refugees plus the strength of every player unit, halutz units included; with an initialized Historical ledger, every city's housed and refugee records plus the active soldier records, so a record in no tracked city, such as a farmer at Nir Am or Nirim, is not in P, as the owner's 2 November 2026 answer "The 12 cities' people (Recommended)" keeps P to "only the cities whose housing is tracked"; #1725 PR 7): (1) a surcharge of `R * max(0, money_threshold - c) * money_slope` Money a turn from the condition c before this turn's deterioration, summed over the cities into one Money line (`housing_surcharge`) and borrowed when the Treasury is short (R-MONEY-003); `money_threshold` is 0.50 and `money_slope` is 0.1 Money per housed population unit (owner, 2 November 2026: "Scale it to unit size (Recommended)"; the option read: "0.1 per unit (as #2112 did for Industry), about 7.6 Money a turn at start."), so the shipped census start charges 511 housed units x 0.15 x 0.1 = 7.665 Money on the opening turn; (2) overflow deterioration of `overflow_deterioration * max(0, R - housing_capacity) / R` percentage points (5 pp; owner, 2 November 2026: "Yes, 5 pp under GDD 0.3 (Recommended)"), never below 0, in place of R-HOUSE-002's `overflow_condition_loss`; zero housed loses nothing; (3) a Social cohesion loss of `max_cohesion_loss * sum((R / P) * max(0, (cohesion_threshold - c') / cohesion_threshold))` displayed points (`max_cohesion_loss` 2, `cohesion_threshold` 0.25; owner, 2 November 2026: "Keep the 2-point loss (Recommended)") from the condition c' after deterioration, applied once to `morale` through its permanent shift with one cause line (`housing_cohesion`); zero own population loses nothing. The legacy `homes_lift_morale` link from `housing` into `morale` adds nothing under `gdd-0.3`, so housing lowers Social cohesion only through (3) (#1703 Done-when, with #1715; the Food term stays #1715's). There is no housing upkeep (27M-17, IL 0m), so no unpaid-upkeep deterioration. Values: `content/gdd03-balance.yaml` (`housing.*`), read by `Gdd03HousingFormula`; code: `Cities.UpdateCondition` and `Cities.SettleGdd03`, `EffectsSystem.RetiredGdd03Link`; tests: `Gdd03HousingConditionTests`, `Gdd03MoneyLedgerTests`. The issue's three rules run under `gdd-0.3`: the 5 pp overflow (owner, 2 November 2026: "Yes, 5 pp under GDD 0.3 (Recommended)") and the cohesion term (owner, 2 November 2026: "Keep the 2-point loss (Recommended)"; the option read: "As issue #1703 specifies, GDD 0.3 only."). P is the 12 cities' people as built, plus the player units (owner, 2 November 2026: "The 12 cities' people (Recommended)"; the option read: "As built: only the cities whose housing is tracked."). R is counted after the step's housing arrivals (owner, 2 November 2026: "After housing arrivals (Recommended)"; 27M-15). Formations are not housed (owner, 3 November 2026: "Yes, formations not housed (Recommended)", #1703); repairs are R-HOUSE-006. On an initialized Historical ledger (the dark start, #1725 PR 7) the step runs as above, with R and P counted from the ledger's records (R-HOUSE-003), and changes no record; a synthetic or Open ledger is still refused (R-POP-002). The halutz-unit case is not handled yet on a ledger game (R-HOUSE-003, R-HOUSE-005): no record is a halutz unit at the dark start, and the ledger counts have no halutz rule, so a later halutz-unit record would be counted only by its status and city, not as a halutz unit.
R-HOUSE-006: Under `gdd-0.3` only (#1700, #1703), a housing repair is the city project `housing_repair` (`content/projects.yaml`): "A repair costs 0.5 Money and 1 work and raises the city's housing condition by 10 percentage points" (`docs/GDD.md`, "Housing repair price"; owner, 1 November 2026: "Fixed price 0.5 Money + 1 work"; labelled design values). Its row matches `content/gdd03-balance.yaml` `housing_repair`, which the loader checks: `cost` 0.5, `work` 1 as `turns: 1` (maintainer call (not an owner ruling): one turn of a builder's work, as `arms_workshop`'s work 3 is its 3 turns), `condition_pp` 10 as `condition: 0.1`, and no capacity or job slots. It is started, paid, built and cancelled as any city project (R-PROJ-001 to R-PROJ-003, R-CITY-010, R-CITY-011): the Treasury pays 0.5 at the start and borrows what it lacks (R-MONEY-003), it uses the turn's city start (one per city, plus `map_actions_per_turn` 2 nationally), it needs a builder to gain its turn of work, the `housing_construction` multiplier (the Labour minister's, `content/rules.yaml`) scales that work as for every housing build (R-MIN-002; maintainer call (not an owner ruling): a repair counts as a Housing build, so with a weak minister it can take more than one turn), and its builder is freed when it is done or cancelled. When done it adds 10 percentage points to its city's condition, never above 1. A repair is done on the city itself and has no hex of its own (owner, 3 November 2026: "No hex needed (Recommended)"; the option read: "Repairs are done on the city itself; they fix existing housing." [#1700](https://github.com/eyalgolan/statecraft-israel/issues/1700#issuecomment-6610259201)). This departs from Q-PROJ-2 for repairs only: a repair is ordered on its city's settlement hex and nowhere else (refused elsewhere as "A housing repair is done on Town A's own hex"), whatever placement or city project that hex holds, and takes the hex from no other project; once done its record leaves the state, so it leaves no building and the hex still shows its own project. Every other kind keeps Q-PROJ-2's free hex. The repair lands on step 5, before R-HOUSE-005's deterioration on the housing step, so a city with overflow can gain less than 10 points in that turn. `gdd-0.1` and legacy have no repair: the loader keeps the row out of them.
diff --git a/sim/Statecraft.Sim.Tests/LedgerHousingConditionTests.cs b/sim/Statecraft.Sim.Tests/LedgerHousingConditionTests.cs
new file mode 100644
index 000000000..a9a538252
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/LedgerHousingConditionTests.cs
@@ -0,0 +1,141 @@
+using Statecraft.Sim;
+
+/// <summary>#1725 PR 7, producer draft 04: the gdd-0.3 housing step (R-HOUSE-005) on a game with an initialized Historical
+/// ledger. R, a city's housed people (R-HOUSE-003), and P, the own population, are counted from the ledger's records, not
+/// the aggregate city fields. The 20 opening field farmers are civilians, so the 18 in census hosts are housed there, beside
+/// the place each adds (PR 4); the two at Nir Am and Nirim have no city record, so they are in no city's R and not in P
+/// ("The 12 cities' people (Recommended)", "As built: only the cities whose housing is tracked.").</summary>
+public class LedgerHousingConditionTests
+{
+ static Content Gdd03() => HistoricalPopulationTests.Real(true);
+
+ static GameState Dark(Content c) => Simulation.NewGame(c, 1, Mode.Historical, darkStart: true);
+
+ // The farmers per census host city (PR 4: one per field, F01 to F20).
+ static Dictionary<string, int> FarmersByCity(Content c, GameState s) => s.PopulationLedger.Units
+ .Where(u => u.Profession == CivilianProfession.Farmer && u.Location?.City is string city && s.Cities.ContainsKey(city))
+ .GroupBy(u => u.Location!.City!).ToDictionary(g => g.Key, g => g.Count(), StringComparer.Ordinal);
+
+ // The aggregate twin of a dark start: the public start of the same content, with each census host's farmers added to its
+ // civilians and the dark start's housing capacity, so each city holds the same housed people as the ledger's records.
+ static GameState Twin(Content c, GameState dark)
+ {
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ var farmers = FarmersByCity(c, dark);
+ foreach (var x in s.Cities.Values.ToList())
+ {
+ var d = dark.Cities[x.Id];
+ s.Cities[x.Id] = new City(x.Id, d.HousingCapacity, x.JobSlots, x.Civilians + farmers.GetValueOrDefault(x.Id), x.Employed,
+ x.Refugees, x.Recruits, x.Condition, x.Craftsmen, x.JobsDefault, x.Qualified);
+ }
+ return s;
+ }
+
+ // R-HOUSE-005, R-POP-002: the ledger fixture's housing step runs and changes no record.
+ [Fact]
+ public void TheLedgerFixtureRunsTheHousingStep()
+ {
+ var c = Gdd03();
+ var s = HistoricalPopulation.LedgerFixture(c);
+ s.Date = c.Rules.Start;
+ var ledger = s.PopulationLedger.Canonical();
+ Cities.UpdateCondition(c, s, c.RulesAt(s.Date).Mvp!, new List<Cause>());
+ s.PopulationLedger.Reconcile();
+ Assert.Equal(ledger, s.PopulationLedger.Canonical());
+ }
+
+ // R-HOUSE-003 on the ledger: a city's housed people are its civilian records (census and farmers), so each census host
+ // houses its farmers beside the census; R-HOUSE-005: P is the tracked cities' people plus the own soldiers, so the two
+ // farmers with no city record (Nir Am, Nirim) are in neither.
+ [Fact]
+ public void HousedAndOwnPopulationAreTheLedgersRecords()
+ {
+ var c = Gdd03();
+ var dark = Dark(c); var pub = Simulation.NewGame(c, 1, Mode.Historical);
+ var farmers = FarmersByCity(c, dark);
+ Assert.Equal(18, farmers.Values.Sum());
+ foreach (var x in pub.Cities.Values)
+ Assert.Equal(Cities.Housed(pub, x) + farmers.GetValueOrDefault(x.Id), Cities.Housed(dark, dark.Cities[x.Id]));
+ Assert.Equal(Cities.OwnPopulation(pub) + 18, Cities.OwnPopulation(dark));
+ var soldiers = dark.PopulationLedger.Units.Count(u => u.Status == PopulationStatus.ActiveSoldier);
+ Assert.Equal(dark.Cities.Values.Sum(x => Cities.Housed(dark, x)) + soldiers, Cities.OwnPopulation(dark));
+ var unhoused = dark.PopulationLedger.Units.Where(u => u.Profession == CivilianProfession.Farmer && !farmers.ContainsKey(u.Location?.City ?? ""))
+ .Select(u => u.Location?.City).OrderBy(x => x, StringComparer.Ordinal).ToList();
+ Assert.Equal(2, unhoused.Count);
+ Assert.All(unhoused, city => Assert.False(dark.Cities.ContainsKey(city!)));
+ }
+
+ // R-HOUSE-005 (#1703's order: surcharge, then deterioration, then cohesion): the dark start's housing step gives the
+ // surcharge, every city's condition, the Social cohesion loss and the causes of an aggregate game with the same people
+ // per city, borrows the same way (R-MONEY-003), and changes no ledger record.
+ [Fact]
+ public void TheDarkStartsHousingStepMatchesAnAggregateGameWithTheSamePeople()
+ {
+ var c = Gdd03();
+ var dark = Dark(c); var twin = Twin(c, dark);
+ foreach (var x in twin.Cities.Values) Assert.Equal(Cities.Housed(twin, x), Cities.Housed(dark, dark.Cities[x.Id]));
+ var r = c.RulesAt(dark.Date).Mvp!;
+ foreach (var s in new[] { dark, twin }) { s.Treasury = 1; s.Debt = 2; }
+ var ledger = dark.PopulationLedger.Canonical();
+ var darkWhy = new List<Cause>(); var twinWhy = new List<Cause>();
+ Cities.UpdateCondition(c, dark, r, darkWhy);
+ Cities.UpdateCondition(c, twin, r, twinWhy);
+ Assert.Contains(darkWhy, x => x.Key == CauseKeys.HousingSurcharge);
+ Assert.Equal(twinWhy.Select(x => (x.System, x.Target, x.Delta, x.Message)), darkWhy.Select(x => (x.System, x.Target, x.Delta, x.Message)));
+ Assert.Equal((twin.Treasury, twin.Debt), (dark.Treasury, dark.Debt));
+ Assert.Equal(twin.Cities.Values.Select(x => (x.Id, x.Condition)), dark.Cities.Values.Select(x => (x.Id, x.Condition)));
+ Assert.Equal(twin.IndicatorShifts[Cities.CohesionIndicator], dark.IndicatorShifts[Cities.CohesionIndicator]);
+ dark.PopulationLedger.Reconcile();
+ Assert.Equal(ledger, dark.PopulationLedger.Canonical());
+ }
+
+ // R-POP-002 (#1725 PR 7 review S2): only a ledger initialized with mode Historical is let through. An initialized Open
+ // ledger, like a synthetic one (no mode), is still refused by the housing step, with the state unchanged.
+ [Theory]
+ [InlineData(true)] [InlineData(false)]
+ public void AnOpenOrSyntheticLedgerIsStillRefused(bool open)
+ {
+ var c = PopulationLedgerTests.Content();
+ var s = PopulationLedger.CreateFixture(c, PopulationLedgerTests.Bindings(),
+ new[] { new PopulationInventoryRow("fixture", 0, PopulationLedgerTests.Person()) }, mode: open ? Mode.Open : null);
+ Assert.Equal((true, false), (s.PopulationLedger.IsInitialized, s.PopulationLedger.IsHistorical));
+ s.Treasury = 23;
+ var why = new List<Cause>();
+ var before = s.Describe(); var hash = s.Hash();
+ Assert.Contains("integration is held", Assert.Throws<NotSupportedException>(() => Cities.UpdateCondition(c, s, new MvpRules(), why)).Message);
+ Assert.Equal(before, s.Describe()); Assert.Equal(hash, s.Hash()); Assert.Empty(why);
+ }
+
+ // R-HOUSE-003, R-HOUSE-005 on the ledger (#1725 PR 7 review S3): the status filter. In one census city of a Historical
+ // ledger fixture, the free civilians and the trainee are housed; the refugee, the soldier and the civilian in transit
+ // located there are not. P adds the refugee and the soldier, not the one in transit, and not a free civilian with no
+ // city. The city's aggregate fields are set to other numbers to show they are not read.
+ [Fact]
+ public void OnlyFreeCivilianAndTraineeRecordsAreHoused()
+ {
+ var c = Gdd03();
+ var city = c.Cities[0].Id;
+ var region = c.PlayerRegions.AtLocation(city)!.Id;
+ var inCity = new PopulationLocation(region, city: city); var inRegion = new PopulationLocation(region);
+ var bindings = new PopulationBindings(new[] { inRegion, inCity },
+ new[] { new PopulationTarget("course", PopulationAssignmentKind.Course, region, 3),
+ new PopulationTarget("service", PopulationAssignmentKind.ActiveService, region),
+ new PopulationTarget("travel", PopulationAssignmentKind.Travel, region) },
+ Array.Empty<string>(), new[] { "basic" });
+ PopulationInventoryRow Row(int ordinal, PopulationStatus status, PopulationLocation at, PopulationAssignment job) =>
+ new PopulationInventoryRow("fixture", ordinal, new PopulationUnit(0, status, 0, at, job, CivilianProfession.None,
+ CivilianTier.None, 0, status == PopulationStatus.ActiveSoldier ? "basic" : "", 0, PopulationEquipment.None));
+ var s = PopulationLedger.CreateFixture(c, bindings, new[] {
+ Row(0, PopulationStatus.FreeCivilian, inCity, PopulationAssignment.Unassigned),
+ Row(1, PopulationStatus.FreeCivilian, inCity, PopulationAssignment.Unassigned),
+ Row(2, PopulationStatus.Trainee, inCity, new PopulationAssignment(PopulationAssignmentKind.Course, "course", 1)),
+ Row(3, PopulationStatus.Refugee, inCity, PopulationAssignment.Unassigned),
+ Row(4, PopulationStatus.ActiveSoldier, inCity, new PopulationAssignment(PopulationAssignmentKind.ActiveService, "service")),
+ Row(5, PopulationStatus.CivilianInTransit, inCity, new PopulationAssignment(PopulationAssignmentKind.Travel, "travel")),
+ Row(6, PopulationStatus.FreeCivilian, inRegion, PopulationAssignment.Unassigned) }, mode: Mode.Historical);
+ Assert.True(s.PopulationLedger.IsHistorical);
+ s.Cities[city] = new City(city, 100, 0, civilians: 50, employed: 0, refugees: 7, recruits: 4);
+ Assert.Equal(3, Cities.Housed(s, s.Cities[city])); // two free civilians and the trainee
+ Assert.Equal(3 + 1 + 1, Cities.OwnPopulation(s)); // plus the refugee and the soldier
+ }
+}
diff --git a/sim/Statecraft.Sim/Cities.cs b/sim/Statecraft.Sim/Cities.cs
index 5df9a9655..176cc8cd8 100644
--- a/sim/Statecraft.Sim/Cities.cs
+++ b/sim/Statecraft.Sim/Cities.cs
@@ -210,14 +210,39 @@ namespace Statecraft.Sim
/// in it. Under gdd-0.1 Israeli formations retain their home city's housing after graduation, including when they move
/// or become veterans. Under gdd-0.3 they do not (#1703; 27M-18, owner-approved 1 November 2026: "Housed = civilians,
/// craftsmen, recruits and groups in training. Refugees and pioneer units are not housed."). Summed as integers, so the
- /// order of the training groups and formations cannot change it.</summary>
+ /// order of the training groups and formations cannot change it.
+ /// With an initialized Historical ledger (the dark start, #1725 PR 7) it counts the ledger's records instead of these
+ /// fields: <see cref="LedgerHoused"/>.</summary>
public static int Housed(GameState s, City x)
{
+ if (s.PopulationLedger.IsHistorical) return LedgerHoused(s, x.Id);
var n = x.Civilians + x.Craftsmen + x.Recruits;
foreach (var k in s.Cohorts.Values) if (k.City == x.Id) n += k.Count;
return s.Ruleset == SaveGame.Gdd03Ruleset ? n : n + Soldiers(s, x);
}
+ /// <summary>R-HOUSE-003 on an initialized Historical ledger (#1725 PR 7): the city's housed records, one population unit
+ /// each, located in the city: its free civilians (census people, craftsmen, the opening field farmers in their host and
+ /// the training centre's teacher) and its trainees, the groups in training. Refugees wait for housing and soldiers are
+ /// not housed under gdd-0.3 (27M-18). A record with no city, such as a farmer at Nir Am or Nirim, which have no city
+ /// record, is housed in no city.</summary>
+ static int LedgerHoused(GameState s, string city)
+ {
+ var n = 0;
+ foreach (var u in s.PopulationLedger.Units)
+ if ((u.Status == PopulationStatus.FreeCivilian || u.Status == PopulationStatus.Trainee) && u.Location?.City == city) n++;
+ return n;
+ }
+
+ /// <summary>R-HOUSE-005 on an initialized Historical ledger: the city's refugee records.</summary>
+ static int LedgerRefugees(GameState s, string city)
+ {
+ var n = 0;
+ foreach (var u in s.PopulationLedger.Units)
+ if (u.Status == PopulationStatus.Refugee && u.Location?.City == city) n++;
+ return n;
+ }
+
/// <summary>R-HOUSE-003, R-UNIT-004 (Q-HOUSE-5): the Israeli formations the city houses, their strength summed:
/// recruits, veterans, guns and armoured cars whose home it is, wherever they stand (#1345, the panel's soldiers line).</summary>
public static int Soldiers(GameState s, City x)
@@ -260,7 +285,7 @@ namespace Statecraft.Sim
/// rules instead (#1703: the surcharge, 5 pp overflow and the cohesion term).</summary>
public static void UpdateCondition(Content c, GameState s, MvpRules r, List<Cause> why)
{
- PopulationLedger.RefuseAggregate(s);
+ PopulationLedger.RefuseUnlessHistorical(s); // #1725 PR 7: R and P are then the ledger's (Housed, OwnPopulation)
var gdd03 = c.Ruleset == SaveGame.Gdd03Ruleset ? Gdd03HousingFormula.FromCatalogue(c.Gdd03Balance!) : null;
var people = gdd03 == null ? 0 : OwnPopulation(s);
double surcharge = 0.0, cohesion = 0.0;
@@ -321,10 +346,19 @@ namespace Statecraft.Sim
/// strength of every player unit, wherever it stands: the Israeli formations and the halutz units, which have no side
/// (R-UNIT-001). Summed as integers. The owner was asked: "Should P be the 12 cities' people plus units (the PR today),
/// or the national population (649,400 at start, which cuts the loss by ~20%)?" and answered, 2 November 2026: "The 12
- /// cities' people (Recommended)"; the option read: "As built: only the cities whose housing is tracked."</summary>
+ /// cities' people (Recommended)"; the option read: "As built: only the cities whose housing is tracked."
+ /// With an initialized Historical ledger (#1725 PR 7) it is the ledger's: every city's housed and refugee records plus
+ /// the active soldiers, so a record in no tracked city (a farmer at Nir Am or Nirim) is not in it. Halutz units are
+ /// not handled yet on a ledger game: no record is one at the dark start (R-HOUSE-003, R-HOUSE-005).</summary>
public static int OwnPopulation(GameState s)
{
var n = 0;
+ if (s.PopulationLedger.IsHistorical)
+ {
+ foreach (var x in s.Cities.Values) n += LedgerHoused(s, x.Id) + LedgerRefugees(s, x.Id);
+ foreach (var u in s.PopulationLedger.Units) if (u.Status == PopulationStatus.ActiveSoldier) n++;
+ return n;
+ }
foreach (var x in s.Cities.Values) n += Housed(s, x) + x.Refugees;
foreach (var u in s.Units.Values) if (u.Side == "" || u.Side == Movement.PlayerSide) n += u.Strength;
return n;