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.

Sim: Historical ledger fixture records in their regions (Refs #1689 region slice) (#2323)

Beri9f59edbb398e
diff --git a/changelog.d/1689-ledger-regions.md b/changelog.d/1689-ledger-regions.md
new file mode 100644
index 000000000..62603d162
--- /dev/null
+++ b/changelog.d/1689-ledger-regions.md
@@ -0,0 +1,5 @@
+### Changed
+- Under the gdd-0.3 rules only, the sim's test fixture of the Historical start's population ledger puts each census
+ city's population units in the region of `content/regions.yaml` that holds the city, and each starting formation's
+ units in the region of its starting hex (Refs #1689). A unit with no region is refused. The ledger is not yet in the
+ game; the game players play (gdd-0.1) is unchanged.
diff --git a/docs/population-ledger.md b/docs/population-ledger.md
index 42aa13c5f..a45c35a61 100644
--- a/docs/population-ledger.md
+++ b/docs/population-ledger.md
@@ -14,4 +14,4 @@ No save/reload round trip for population identity is claimed. The existing seed/
## Historical start inventory (R-POP-004)
-`HistoricalPopulation.Inventory` is internal and reads the shipped content under exact `gdd-0.3`: one free-civilian row per census city start unit (R-CITY-007) and one active-soldier row per population unit of each Israeli starting formation of `map/units_1948.yaml` (R-UNIT-006), at `rules.yaml`'s 1,000 people a unit (owner, 1 November 2026, D2). Rows carry a source key (`census/<city id>`, `units_1948/<row id>`) and a within-source ordinal, in R-POP-001's order. Enemy formations and dated arrivals (R-UNIT-009) are not in it. It builds no `PopulationUnit` and initializes no ledger: each record still needs a region/location binding (#1690, #1691), and an initialized ledger refuses the aggregate systems a `gdd-0.3` game still runs (R-POP-002). The test `HistoricalPopulationTests` checks it, city by city and formation by formation, against the aggregate start of the same content.
+`HistoricalPopulation.Inventory` is internal and reads the shipped content under exact `gdd-0.3`: one free-civilian row per census city start unit (R-CITY-007) and one active-soldier row per population unit of each Israeli starting formation of `map/units_1948.yaml` (R-UNIT-006), at `rules.yaml`'s 1,000 people a unit (owner, 1 November 2026, D2). Rows carry a source key (`census/<city id>`, `units_1948/<row id>`) and a within-source ordinal, in R-POP-001's order. Enemy formations and dated arrivals (R-UNIT-009) are not in it. It builds no `PopulationUnit` itself. `HistoricalPopulation.LedgerFixture` (internal, fixture-only) turns it into an initialized Historical ledger and binds each record to a region of `content/regions.yaml`: a census record takes the region whose `member_locations` hold its city, a formation record the region whose member hexes hold its starting anchor hex (R-POP-004); a source with no region is refused. `NewGame` does not call it, because an initialized ledger refuses the aggregate systems a `gdd-0.3` game still runs (R-POP-002). The test `HistoricalPopulationTests` checks it, city by city and formation by formation, against the aggregate start of the same content.
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 0461f51d9..dd0b83758 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -571,7 +571,7 @@ R-POP-002: A ledger record has exactly one typed status and assignment, validate
R-POP-003: Clone copies all ledger containers; immutable records and frozen bindings may be shared. The canonical writer emits a gdd-0.3-only section ordered by numeric population id, with fixed field order, stable machine tokens, invariant integer formatting and length-prefixed reference strings. It covers every record/assignment/equipment/reference field, binding, creation/loss provenance and allocator even after the last combat loss. Legacy/gdd-0.1 emit no ledger section or allocator marker. R-SAVE-001/002 still govern identity mismatch refusal and replay: no ledger snapshot or new command syntax is added in this foundation, and fixture injection is not replay evidence. Existing unpublished schema-4 draft hashes change; no migration promise is made.
-R-POP-004: The Historical start inventory under exact `gdd-0.3` (#1689; owner, 1 November 2026, D2: "Approve all six (Recommended)", and D4). It is read from the same content as the aggregate start: each census city (R-CITY-006) gives its R-CITY-007 start units as free civilians, and each Israeli starting formation of `map/units_1948.yaml` (R-UNIT-006) gives its strength as active soldiers, no more and no less. Enemy formations are not own population, and a dated arrival (R-UNIT-009) is not in the start inventory: it takes new ids when it arrives (Q11). Counts use `rules.yaml`'s `people_per_unit` (1,000, D2), as R-CITY-007 and R-UNIT-006 do; the `gdd-0.3` catalogue's `population.people_per_unit` (10,000) is Open mode's (D2). A city's records have source key `census/<city id>` and a formation's `units_1948/<row id>`, each with within-source ordinals from 0, so R-POP-001's order (source key by ordinal string comparison, then ordinal) gives the ascending population ids that Q10's "N units" commands take. Legacy and `gdd-0.1` content refuse it. It reads no RNG and changes no state. It is not yet wired into `Simulation.NewGame`: an initialized ledger refuses every aggregate system (R-POP-002), so a new `gdd-0.3` game keeps the aggregate start until the producers are integrated. Still Deferred: the region or location binding of each record (#1690, #1689; `content/regions.yaml` has the nine regions of #1691, which no game initializes yet), the work assignments of the employed share, which census units are farmers (fields, #1691/#1717; the owner's 1:2:1 novice/trained/veteran ratio per city then applies), and the formations' military qualification, combat experience and issued equipment (#1717). The ledger scale for this start is no longer Deferred: a Historical ledger fixture counts each record at `rules.yaml`'s `people_per_unit` for the start day, 1,000 people (R-POP-001; D2: "The Historical MVP keeps main's start: census cities at 1,000 people a unit (`R-CITY-007`)").
+R-POP-004: The Historical start inventory under exact `gdd-0.3` (#1689; owner, 1 November 2026, D2: "Approve all six (Recommended)", and D4). It is read from the same content as the aggregate start: each census city (R-CITY-006) gives its R-CITY-007 start units as free civilians, and each Israeli starting formation of `map/units_1948.yaml` (R-UNIT-006) gives its strength as active soldiers, no more and no less. Enemy formations are not own population, and a dated arrival (R-UNIT-009) is not in the start inventory: it takes new ids when it arrives (Q11). Counts use `rules.yaml`'s `people_per_unit` (1,000, D2), as R-CITY-007 and R-UNIT-006 do; the `gdd-0.3` catalogue's `population.people_per_unit` (10,000) is Open mode's (D2). A city's records have source key `census/<city id>` and a formation's `units_1948/<row id>`, each with within-source ordinals from 0, so R-POP-001's order (source key by ordinal string comparison, then ordinal) gives the ascending population ids that Q10's "N units" commands take. Legacy and `gdd-0.1` content refuse it. It reads no RNG and changes no state. It is not yet wired into `Simulation.NewGame`: an initialized ledger refuses every aggregate system (R-POP-002), so a new `gdd-0.3` game keeps the aggregate start until the producers are integrated. A fixture builder (`HistoricalPopulation.LedgerFixture`, internal, fixture-only) turns the inventory into an initialized Historical ledger with mode Historical (R-POP-001's 1,000 a record), each record in a region of `content/regions.yaml` (#1691): a census record takes the region whose `member_locations` hold its city (`census/tel_aviv` is `tel_aviv_jaffa`; Jaffa gets no records), and a formation record takes the region whose member hexes hold the formation's starting anchor hex (owner, 3 November 2026, #1689 open question 1: "Its anchor hex's region (Recommended)"). A source with no region is refused; no region is invented. Census records are free civilians with no assignment, and formation records are active soldiers whose service target is their own formation. Still Deferred: the work assignments of the employed share, which census units are farmers (fields, #1691/#1717; the owner's 1:2:1 novice/trained/veteran ratio per city then applies), and the formations' military qualification, combat experience and issued equipment (#1717). The ledger scale for this start is no longer Deferred: a Historical ledger fixture counts each record at `rules.yaml`'s `people_per_unit` for the start day, 1,000 people (R-POP-001; D2: "The Historical MVP keeps main's start: census cities at 1,000 people a unit (`R-CITY-007`)").
#1706 slices 0/1 (coordinator decision, 26 Oct 2026, Q5): the synthetic combat catalogue foundation is inactive in the actual game. R-COMBAT-001 through R-COMBAT-008 retain their current runtime meanings. See [the catalogue foundation](../gdd03-catalogue.md#1706-slices-01-inactive-combat-catalogue-foundation) for its data contract and sources.
diff --git a/sim/Statecraft.Sim.Tests/HistoricalPopulationTests.cs b/sim/Statecraft.Sim.Tests/HistoricalPopulationTests.cs
index 53df9773e..d742608bc 100644
--- a/sim/Statecraft.Sim.Tests/HistoricalPopulationTests.cs
+++ b/sim/Statecraft.Sim.Tests/HistoricalPopulationTests.cs
@@ -231,4 +231,102 @@ public class HistoricalPopulationTests
{
Assert.False(Simulation.NewGame(Real(true), 1, Mode.Historical).PopulationLedger.IsInitialized);
}
+
+ // R-POP-003, R-POP-004 (#1689 region slice): the region-bound fixture builder adds no NewGame path. gdd-0.1 and legacy
+ // games still have no ledger and write no ledger section, so their hashes stay; gdd-0.1 content refuses the builder.
+ [Fact]
+ public void NewGameStillHasNoLedger()
+ {
+ foreach (var (content, ruleset) in new[] { (Real(false), SaveGame.GddRuleset), (RealContentTests.Legacy(), SaveGame.LegacyRuleset) })
+ {
+ Assert.Equal(ruleset, content.Ruleset);
+ var s = Simulation.NewGame(content, 1, Mode.Historical);
+ Assert.False(s.PopulationLedger.IsInitialized);
+ Assert.DoesNotContain("population-ledger", s.Describe());
+ }
+ Assert.Throws<InvalidOperationException>(() => HistoricalPopulation.LedgerFixture(Real(false)));
+ }
+
+ // R-POP-004 (#1689 region slice): the Historical ledger fixture holds the inventory, no more and no less: per source, as
+ // many records as Inventory lists, census records free civilians and formation records active soldiers.
+ [Fact]
+ public void HistoricalFixtureHoldsTheInventoryNoMoreNoLess()
+ {
+ var c = Real(true);
+ var inventory = HistoricalPopulation.Inventory(c);
+ var units = HistoricalPopulation.LedgerFixture(c).PopulationLedger.Units;
+ Assert.Equal(inventory.Count, units.Count);
+ Assert.Equal(inventory.Select(r => r.Status), units.Select(u => u.Status));
+ Assert.Equal(inventory.Count(r => r.Status == PopulationStatus.FreeCivilian), units.Count(u => u.Status == PopulationStatus.FreeCivilian));
+ Assert.Equal(inventory.Count(r => r.Status == PopulationStatus.ActiveSoldier), units.Count(u => u.Status == PopulationStatus.ActiveSoldier));
+ }
+
+ // R-POP-001, R-POP-004, D2: the builder goes through #2299's Historical path, so its records count at 1,000 people.
+ [Fact]
+ public void HistoricalFixtureCountsAtTheRulesScale()
+ {
+ var c = Real(true);
+ var s = HistoricalPopulation.LedgerFixture(c);
+ Assert.Equal(Mode.Historical, s.Mode);
+ Assert.Equal((double)s.PopulationLedger.Units.Count * 1000, s.PopulationLedger.TotalPeople);
+ }
+
+ // R-POP-002, R-POP-004 (#1691 regions): each census record carries the content/regions.yaml region that lists its city
+ // (census/tel_aviv is tel_aviv_jaffa; Jaffa gets no records of its own), and no record has an empty or unknown region.
+ [Fact]
+ public void EveryCensusRecordCarriesItsCitysRegion()
+ {
+ var c = Real(true);
+ var inventory = HistoricalPopulation.Inventory(c);
+ var units = HistoricalPopulation.LedgerFixture(c).PopulationLedger.Units;
+ for (int i = 0; i < inventory.Count; i++)
+ {
+ Assert.Contains(units[i].Location!.Region, c.PlayerRegions.Regions.Keys);
+ if (inventory[i].Source.StartsWith(HistoricalPopulation.CensusPrefix, StringComparison.Ordinal))
+ Assert.Equal(c.PlayerRegions.AtLocation(inventory[i].Source.Substring(HistoricalPopulation.CensusPrefix.Length))!.Id,
+ units[i].Location!.Region);
+ }
+ var telAviv = inventory.Select((r, i) => (r, i)).Where(x => x.r.Source == HistoricalPopulation.CensusPrefix + "tel_aviv").ToList();
+ Assert.NotEmpty(telAviv);
+ Assert.All(telAviv, x => Assert.Equal("tel_aviv_jaffa", units[x.i].Location!.Region));
+ Assert.DoesNotContain(inventory, r => r.Source == HistoricalPopulation.CensusPrefix + "jaffa");
+ }
+
+ // R-POP-001, R-POP-004, Q10: ids run from 0 with no gaps in the inventory's order (source key by ordinal string compare,
+ // then ordinal), and two builds are identical.
+ [Fact]
+ public void IdsAscendBySourceKeyThenOrdinal()
+ {
+ var c = Real(true);
+ var s = HistoricalPopulation.LedgerFixture(c);
+ var units = s.PopulationLedger.Units;
+ Assert.Equal(Enumerable.Range(0, units.Count), units.Select(u => u.Id));
+ Assert.Equal(units.Count, s.PopulationLedger.NextPopulationId);
+ Assert.Equal(s.Hash(), HistoricalPopulation.LedgerFixture(Real(true)).Hash());
+ }
+
+ // R-POP-001: the fixture reconciles; the created ids are exactly the living ones.
+ [Fact]
+ public void HistoricalFixtureReconciles()
+ {
+ var l = HistoricalPopulation.LedgerFixture(Real(true)).PopulationLedger;
+ Assert.True(l.IsInitialized);
+ l.Reconcile();
+ }
+
+ // R-POP-004: a record whose city or formation has no region in regions.yaml is refused; no region is invented.
+ [Fact]
+ public void ARecordWithNoRegionIsRefused()
+ {
+ var c = Real(true);
+ c.Cities.First(x => x.Id == "rosh_pinna").Id = "nowhere";
+ var e = Assert.Throws<InvalidOperationException>(() => HistoricalPopulation.LedgerFixture(c));
+ Assert.Contains("census/nowhere", e.Message);
+
+ c = Real(true);
+ var golani = c.StartingForces.First(f => f.Row == "golani");
+ (golani.Q, golani.R) = (1000, 1000);
+ e = Assert.Throws<InvalidOperationException>(() => HistoricalPopulation.LedgerFixture(c));
+ Assert.Contains("units_1948/golani", e.Message);
+ }
}
diff --git a/sim/Statecraft.Sim/HistoricalPopulation.cs b/sim/Statecraft.Sim/HistoricalPopulation.cs
index 707fd91c4..7d0ce4e9d 100644
--- a/sim/Statecraft.Sim/HistoricalPopulation.cs
+++ b/sim/Statecraft.Sim/HistoricalPopulation.cs
@@ -47,5 +47,36 @@ namespace Statecraft.Sim
for (int i = 0; i < units; i++) rows.Add(new HistoricalPopulationRow(source, i, status));
return rows.AsReadOnly();
}
+
+ /// <summary>R-POP-004 (#1689 region slice): the Inventory as an initialized Historical ledger fixture, each record in
+ /// its real region of regions.yaml. A census record takes the region that lists its city (AtLocation). A formation
+ /// record takes the region of its starting anchor hex (AtHex): the owner's ruling on #1689's open question 1
+ /// (3 November 2026: "Its anchor hex's region (Recommended)"). A source with no region is refused; no region is invented. Records
+ /// are free civilians with no assignment and soldiers serving in their own formation, with no profession, tier or
+ /// qualification (#1717 and #1692 add those). mode Historical gives #2299's 1,000-a-record scale (D2). Fixture-only:
+ /// NewGame does not call it (R-POP-002).</summary>
+ internal static GameState LedgerFixture(Content c)
+ {
+ var inventory = Inventory(c);
+ var sources = new HashSet<string>(inventory.Select(r => r.Source), StringComparer.Ordinal); // only sources with records
+ var regions = new SortedDictionary<string, string>(StringComparer.Ordinal);
+ foreach (var city in c.Cities)
+ if (sources.Contains(CensusPrefix + city.Id)) regions[CensusPrefix + city.Id] = c.PlayerRegions.AtLocation(city.Id)?.Id ?? "";
+ foreach (var f in c.StartingForces)
+ if (sources.Contains(FormationPrefix + f.Row)) regions[FormationPrefix + f.Row] = c.PlayerRegions.AtHex(f.Q, f.R)?.Id ?? "";
+ var missing = regions.Where(x => x.Value == "").Select(x => x.Key).ToList();
+ if (missing.Count > 0)
+ throw new InvalidOperationException("No region in regions.yaml for " + string.Join(", ", missing) + " (R-POP-004).");
+ var locations = regions.Values.Distinct(StringComparer.Ordinal).ToDictionary(r => r, r => new PopulationLocation(r), StringComparer.Ordinal);
+ // A formation is its soldiers' ActiveService target, in the formation's region.
+ var targets = regions.Where(x => x.Key.StartsWith(FormationPrefix, StringComparison.Ordinal))
+ .Select(x => new PopulationTarget(x.Key, PopulationAssignmentKind.ActiveService, x.Value));
+ var bindings = new PopulationBindings(locations.Values, targets, Array.Empty<string>(), Array.Empty<string>());
+ var rows = inventory.Select(r => new PopulationInventoryRow(r.Source, r.Ordinal, new PopulationUnit(0, r.Status, 0,
+ locations[regions[r.Source]], r.Status == PopulationStatus.ActiveSoldier
+ ? new PopulationAssignment(PopulationAssignmentKind.ActiveService, r.Source) : PopulationAssignment.Unassigned,
+ CivilianProfession.None, CivilianTier.None, 0, "", 0, PopulationEquipment.None)));
+ return PopulationLedger.CreateFixture(c, bindings, rows, mode: Mode.Historical);
+ }
}
}