A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
GDD 0.3: bound synthetic regional job occupancy (#1991)
Eyal Golan1dc09619d8d2
diff --git a/changelog.d/gdd03-regional-fixture-occupancy.md b/changelog.d/gdd03-regional-fixture-occupancy.mdnew file mode 100644index 000000000..0f7b10d44--- /dev/null+++ b/changelog.d/gdd03-regional-fixture-occupancy.md@@ -0,0 +1,3 @@+### Fixed++- Bound synthetic GDD 0.3 Industry and Workshop assignments by their initialized regional job pools, preserving atomic refusals and independent work kinds. The fixture remains internal with no playable or production hookup.diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex d8931a43b..f3f558ca6 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -96,6 +96,8 @@ R-CITY-002: Each turn every city's employed units add `employed * income_per_jobGDD 0.3 fixture clarification for R-CITY-001/002: the owner’s 28 October Q34 answer makes reassignment to the same job a no-op ([owner-relayed answer](https://github.com/eyalgolan/statecraft-israel/pull/1668#issuecomment-6465662174)). The detached generic Work fixture returns `NoOp` and preserves the complete state when given its current target; its different-target transition already applies immediately. This records the settled fixture result, without a production command or a new course, service or save policy.+Synthetic regional fixtures additionally enforce R-CITY-001/002 and R-CITY-006: Industry and Workshop occupancy is counted separately in each worker’s initialized region and cannot exceed its effective `PlayerRegionPool` job slots, including facility contributions. Reassignment excludes the mover’s current reservation before checking the destination; refusals preserve the complete state. Farm and Builder retain their explicit slot bounds. This adds no real job/facility mapping, command, production payment or gameplay activation; fixtures without regional pools keep their existing slot-only behavior.+R-CITY-003: Arrivals from the CBS series (`aliyah.yaml`) become refugees in the cities. Let `P(t)` be the people the series brings from `city_arrivals_from` to the date `t` (0 before it), summed over the origin groups in ordinal order. `city_arrivals_from` is 8 November 1948, the census day the cities' start values count: the census already holds the people who arrived from 15 May, so the cities take none before it (Q-ARRV-3, owner, 15 October 2026). The cities' arrived units by `t` are `U(t) = floor(P(t) / people_per_unit)`, and a turn from date `d` to date `e` adds `U(e) - U(d)` refugees over all cities. `people_per_unit` and `city_arrivals_from` are the same in every era (the loader refuses an era that changes either), so over any run of turns the refugees added are `U(end) - U(start)`: no unit is lost or counted twice. The units are split in proportion to the cities' census `people` (Q-ARRV-1): the first `U` units are handed out one at a time, unit `n` to the city with the largest remainder `n * people / total people - units it holds`, a tie to the lower city id (ordinal), and a turn gives each city its share of `U(e)` minus its share of `U(d)`. Building the split up one unit at a time keeps it cumulative: a fresh largest-remainder split of each total could take a unit back from a city as the total grows (the Alabama paradox; on the twelve cities it first happens at 7 units). The loader refuses a GDD game with no city.R-CITY-008: Under legacy/gdd-0.1, `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, craftsmen, 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. In initialized gdd-0.3 fixtures, the own-population ledger is authoritative instead: profession, employment, training and captivity are attributes/statuses of the same ids (R-POP-001), never extra people. No old headcount is rounded into ledger records.diff --git a/sim/Statecraft.Sim.Tests/Gdd03AssignmentFixtureTests.cs b/sim/Statecraft.Sim.Tests/Gdd03AssignmentFixtureTests.csindex cfdf3c154..ddfdbc9d0 100644--- a/sim/Statecraft.Sim.Tests/Gdd03AssignmentFixtureTests.cs+++ b/sim/Statecraft.Sim.Tests/Gdd03AssignmentFixtureTests.cs@@ -24,6 +24,32 @@ public class Gdd03AssignmentFixtureTestsnew PopulationBindings(new[] { Place }, Slots.Select(x => new PopulationTarget(x.Id, PopulationAssignmentKind.Work, Place.Region)),Array.Empty<string>(), Array.Empty<string>()), people.Select((p, i) => new PopulationInventoryRow("synthetic", i, p)));+ // R-CITY-001/002/006: synthetic composition of the existing regional pool and assignment fixture: occupancy, not a second inventory.+ [Theory] [InlineData(false)] [InlineData(true)]+ public void RegionalPoolRefusesAThirdWorkerWithoutReleasingTheirAssignment(bool workshop)+ {+ const string region = "tel_aviv_jaffa";+ var c = PlayerRegionsContentTests.Load();+ c.Gdd03Balance!.Values["industry.income"] = new Gdd03DesignValue {+ Basis = "Agreed", Note = "synthetic regional fixture rates", Values = new() { 1m, 2m, 3m } };+ var work = workshop ? Gdd03FixtureWork.Workshop : Gdd03FixtureWork.Industry;+ var slots = Enumerable.Range(0, 3).Select(i => new Gdd03FixtureSlot("synthetic-regional-" + i, work, 1, "job")).ToArray();+ var place = new PopulationLocation(region, -3, 19);+ var people = Enumerable.Range(0, 3).Select(i => new PopulationInventoryRow("synthetic", i,+ new PopulationUnit(0, PopulationStatus.FreeCivilian, c.RequirePopulationInteger("reception.turns"), place,+ PopulationAssignment.Unassigned, CivilianProfession.None, CivilianTier.None, 0, "", 0, PopulationEquipment.None)));+ var state = PlayerRegions.CreateFixture(c,+ new[] { new PlayerRegionPool(region, 3, 1m, 2, 2, Array.Empty<PlayerRegionFacility>()) }, people,+ slots.Select(x => new PopulationTarget(x.Id, PopulationAssignmentKind.Work, region)), Array.Empty<string>(), Array.Empty<string>());+ var fixture = new Gdd03AssignmentFixture(c, state, slots);+ fixture.Assign(0, slots[0].Id); fixture.Assign(1, slots[1].Id);+ var before = state.Describe();+ Assert.Throws<ArgumentException>(() => fixture.Assign(2, slots[2].Id));+ Assert.Equal(before, state.Describe());+ Assert.Equal(2, PlayerRegions.Assigned(state, region, PopulationAssignmentKind.Work));+ state.PopulationLedger.Reconcile();+ }+// R-CITY-001, R-POP-002: assignment and reception share the initialized ledger's completion limit.[Theory][InlineData(-1)]@@ -192,4 +218,103 @@ public class Gdd03AssignmentFixtureTestsAssert.Throws<ArgumentException>(() => f.Assign(1, Slots[1].Id)); Assert.Equal(before, s.Describe());Assert.Throws<ArgumentException>(() => new Gdd03AssignmentFixture(c, s, Slots)); Assert.Equal(before, s.Describe());}+ // R-CITY-001: actual-region pool occupancy over existing ledger locations and slot kinds. Synthetic quantities.+ const string RegionA = "tel_aviv_jaffa", RegionB = "central_plain";+ static Content RegionalContent()+ {+ var c = PlayerRegionsContentTests.Load("player_regions:\n" + PlayerRegionsContentTests.TelAviv + PlayerRegionsContentTests.Central);+ c.Gdd03Balance!.Values["industry.income"] = new Gdd03DesignValue {+ Basis = "Agreed", Note = "synthetic", Values = new() { 1m, 2m, 3m } };+ return c;+ }+ static (GameState, Gdd03AssignmentFixture) Regional(int industry, int workshop, Gdd03FixtureSlot[] slots, int people)+ {+ var c = RegionalContent(); var ticks = c.RequirePopulationInteger("reception.turns");+ var at = new PopulationLocation(RegionA, -3, 19);+ var rows = Enumerable.Range(0, people).Select(i => new PopulationInventoryRow("synthetic", i,+ new PopulationUnit(0, PopulationStatus.FreeCivilian, ticks, at, PopulationAssignment.Unassigned,+ CivilianProfession.None, CivilianTier.None, 0, "", 0, PopulationEquipment.None)));+ var s = PlayerRegions.CreateFixture(c, new[] {+ new PlayerRegionPool(RegionA, 0, 0m, industry, workshop, Array.Empty<PlayerRegionFacility>()),+ new PlayerRegionPool(RegionB, 0, 0m, 0, 0, Array.Empty<PlayerRegionFacility>()) },+ rows, slots.Select(x => new PopulationTarget(x.Id, PopulationAssignmentKind.Work, RegionA)),+ Array.Empty<string>(), Array.Empty<string>());+ return (s, new Gdd03AssignmentFixture(c, s, slots));+ }+ static Gdd03FixtureSlot S(string id, Gdd03FixtureWork w) => new(id, w, 1, "generic");+ static void Refused(GameState s, Action a) { var b = s.Describe(); Assert.Throws<ArgumentException>(a); Assert.Equal(b, s.Describe()); }++ [Fact] public void IndustryAndWorkshopGroupsAreIndependentWithMoveOutAndNoOp()+ {+ var slots = new[] { S("i1", Gdd03FixtureWork.Industry), S("i2", Gdd03FixtureWork.Industry),+ S("w1", Gdd03FixtureWork.Workshop), S("w2", Gdd03FixtureWork.Workshop), S("farm", Gdd03FixtureWork.Farm) };+ var (s, f) = Regional(1, 1, slots, 3);+ f.Assign(0, "i1");+ Refused(s, () => f.Assign(1, "i2"));+ Assert.Equal(Gdd03FixtureAssignmentResult.Applied, f.Assign(1, "w1")); // other group unaffected+ Refused(s, () => f.Assign(0, "w2"));+ var same = s.Describe();+ Assert.Equal(Gdd03FixtureAssignmentResult.NoOp, f.Assign(0, "i1")); Assert.Equal(same, s.Describe());+ Assert.Equal(Gdd03FixtureAssignmentResult.Applied, f.Assign(0, "i2")); // mover excluded from its own group+ Assert.Equal(Gdd03FixtureAssignmentResult.Applied, f.Assign(2, "farm")); // Farm not pooled+ Assert.Equal(Gdd03FixtureAssignmentResult.Applied, f.Assign(0, null)); // move-out frees the group+ Assert.Equal(Gdd03FixtureAssignmentResult.Applied, f.Assign(2, "i1"));+ }++ [Fact] public void ZeroRegionalCapacityRefusesPooledKindsOnly()+ {+ var slots = new[] { S("i1", Gdd03FixtureWork.Industry), S("w1", Gdd03FixtureWork.Workshop),+ S("farm", Gdd03FixtureWork.Farm), S("builder", Gdd03FixtureWork.Builder) };+ var (s, f) = Regional(0, 0, slots, 2);+ Refused(s, () => f.Assign(0, "i1")); Refused(s, () => f.Assign(0, "w1"));+ Assert.Equal(Gdd03FixtureAssignmentResult.Applied, f.Assign(0, "farm"));+ Assert.Equal(Gdd03FixtureAssignmentResult.Applied, f.Assign(1, "builder"));+ }++ [Fact] public void ExistingRegionalOverfillIsRefusedAndClonesStayIndependent()+ {+ var slots = new[] { S("i1", Gdd03FixtureWork.Industry), S("i2", Gdd03FixtureWork.Industry), S("farm", Gdd03FixtureWork.Farm) };+ var (s, f) = Regional(1, 0, slots, 2);+ f.Assign(0, "i1");+ var clone = s.Clone(); var cf = new Gdd03AssignmentFixture(RegionalContent(), clone, slots);+ Assert.Equal(Gdd03FixtureAssignmentResult.Applied, cf.Assign(0, null));+ Assert.Equal("i1", s.PopulationLedger.Get(0).Assignment.Target);+ // Direct ledger write bypasses the fixture; the region now holds two Industry occupants.+ s.PopulationLedger.ChangeAssignment(1, new PopulationAssignment(PopulationAssignmentKind.Work, "i2"));+ Refused(s, () => f.IndustryRate("i1"));+ Refused(s, () => f.Assign(1, "farm"));+ Refused(s, () => new Gdd03AssignmentFixture(RegionalContent(), s, slots));+ Assert.Equal(Gdd03FixtureAssignmentResult.Applied, cf.Assign(1, "i2")); // clone unaffected+ }++ [Theory] [InlineData(false)] [InlineData(true)]+ public void RegionalOccupancySeparatesRegionsAndUsesFacilityContributions(bool workshop)+ {+ var content = RegionalContent();+ var kind = workshop ? Gdd03FixtureWork.Workshop : Gdd03FixtureWork.Industry;+ var facilityKind = workshop ? PlayerRegionFacilityKind.Workshop : PlayerRegionFacilityKind.Industry;+ var slots = Enumerable.Range(0, 4).Select(i => S("synthetic-regional-boundary-" + i, kind)).ToArray();+ var locations = new[] { new PopulationLocation(RegionA, -3, 19), new PopulationLocation(RegionB, -4, 21) };+ var rows = Enumerable.Range(0, 4).Select(i => new PopulationInventoryRow("synthetic", i,+ new PopulationUnit(0, PopulationStatus.FreeCivilian, content.RequirePopulationInteger("reception.turns"), locations[i / 2],+ PopulationAssignment.Unassigned, CivilianProfession.None, CivilianTier.None, 0, "", 0, PopulationEquipment.None)));+ var state = PlayerRegions.CreateFixture(content, new[] {+ new PlayerRegionPool(RegionA, 2, 0m, 0, 0, new[] { new PlayerRegionFacility("synthetic-a-facility", "tel_aviv", facilityKind, 1) }),+ new PlayerRegionPool(RegionB, 2, 0m, 0, 0, new[] { new PlayerRegionFacility("synthetic-b-facility", "rishon_lezion", facilityKind, 1) }) },+ rows, slots.Select((slot, i) => new PopulationTarget(slot.Id, PopulationAssignmentKind.Work, i < 2 ? RegionA : RegionB)),+ Array.Empty<string>(), Array.Empty<string>());+ var fixture = new Gdd03AssignmentFixture(content, state, slots);+ Assert.Equal(Gdd03FixtureAssignmentResult.Applied, fixture.Assign(0, slots[0].Id));+ Assert.Equal(Gdd03FixtureAssignmentResult.Applied, fixture.Assign(2, slots[2].Id));+ var before = state.Describe();+ Assert.Equal(Gdd03FixtureAssignmentResult.NoOp, fixture.Assign(0, slots[0].Id));+ Assert.Equal(Gdd03FixtureAssignmentResult.NoOp, fixture.Assign(2, slots[2].Id));+ Refused(state, () => fixture.Assign(1, slots[1].Id)); Refused(state, () => fixture.Assign(3, slots[3].Id));+ Assert.Equal(workshop ? 0m : 1m, fixture.IndustryRate(slots[0].Id));+ Assert.Equal(before, state.Describe());+ Assert.Equal(1, PlayerRegions.Assigned(state, RegionA, PopulationAssignmentKind.Work));+ Assert.Equal(1, PlayerRegions.Assigned(state, RegionB, PopulationAssignmentKind.Work));+ state.PopulationLedger.Reconcile();+ }+}diff --git a/sim/Statecraft.Sim/Gdd03AssignmentFixture.cs b/sim/Statecraft.Sim/Gdd03AssignmentFixture.csindex 163e4866f..828b9ad0f 100644--- a/sim/Statecraft.Sim/Gdd03AssignmentFixture.cs+++ b/sim/Statecraft.Sim/Gdd03AssignmentFixture.cs@@ -84,6 +84,17 @@ namespace Statecraft.Simforeach (var slot in slots.Values)if (state.PopulationLedger.Units.Count(p => p.Assignment.Kind == PopulationAssignmentKind.Work && p.Assignment.Target == slot.Id) > slot.Capacity)throw new ArgumentException("Fixture inventory is over capacity.");+ // Synthetic composition only: the ledger owns workers; immutable regional pools bound pooled job occupancy.+ if (state.PlayerRegions.Count == 0) return;+ foreach (var group in state.PopulationLedger.Units.Where(p => p.Assignment.Kind == PopulationAssignmentKind.Work)+ .Where(p => slots[p.Assignment.Target!].Work == Gdd03FixtureWork.Industry || slots[p.Assignment.Target!].Work == Gdd03FixtureWork.Workshop)+ .GroupBy(p => (Region: p.Location!.Region, Work: slots[p.Assignment.Target!].Work)))+ {+ if (!state.PlayerRegions.TryGetValue(group.Key.Region, out var pool))+ throw new ArgumentException("Fixture worker has no initialized regional pool.");+ var capacity = group.Key.Work == Gdd03FixtureWork.Industry ? pool.IndustrySlots : pool.WorkshopSlots;+ if (group.Count() > capacity) throw new ArgumentException("Fixture regional job occupancy is over capacity.");+ }}bool Eligible(PopulationUnit p) => p.Status == PopulationStatus.FreeCivilian && p.ReceptionTicks == receptionTurns;internal Gdd03FixtureAssignmentResult Assign(int id, string? target)@@ -99,6 +110,15 @@ namespace Statecraft.Simif (person.Assignment.Target == target) return Gdd03FixtureAssignmentResult.NoOp;if (ledger.Units.Count(p => p.Assignment.Kind == PopulationAssignmentKind.Work && p.Assignment.Target == target) >= slot.Capacity)throw new ArgumentException("Fixture destination is full.");+ if (state.PlayerRegions.Count > 0 && (slot.Work == Gdd03FixtureWork.Industry || slot.Work == Gdd03FixtureWork.Workshop))+ {+ if (person.Location == null || !state.PlayerRegions.TryGetValue(person.Location.Region, out var pool))+ throw new ArgumentException("Fixture worker has no initialized regional pool.");+ var used = ledger.Units.Count(p => p.Id != id && p.Assignment.Kind == PopulationAssignmentKind.Work+ && p.Location?.Region == person.Location.Region && slots[p.Assignment.Target!].Work == slot.Work);+ var capacity = slot.Work == Gdd03FixtureWork.Industry ? pool.IndustrySlots : pool.WorkshopSlots;+ if (used >= capacity) throw new ArgumentException("Fixture regional destination is full.");+ }}var assignment = target == null ? PopulationAssignment.Unassigned : new PopulationAssignment(PopulationAssignmentKind.Work, target);// Replace validates the complete candidate before publishing it. Never release first.