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.

Add synthetic reception progress and eligibility (Refs #1696) (#1962)

Eyal Golan3e40bd8c497e
diff --git a/changelog.d/1696-reception-catalogue-consistency.md b/changelog.d/1696-reception-catalogue-consistency.md
new file mode 100644
index 000000000..6061fe697
--- /dev/null
+++ b/changelog.d/1696-reception-catalogue-consistency.md
@@ -0,0 +1 @@
+- Refuse synthetic reception evaluation when the supplied duration differs from the initialized population ledger, including civilian eligibility checks.
diff --git a/changelog.d/1696-reception-fixtures.md b/changelog.d/1696-reception-fixtures.md
new file mode 100644
index 000000000..9356ee709
--- /dev/null
+++ b/changelog.d/1696-reception-fixtures.md
@@ -0,0 +1 @@
+- Add isolated synthetic reception fixtures for dedicated bed allocation, ordinary progress and civilian eligibility.
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 96d878e3f..398c8df3d 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -100,6 +100,12 @@ R-CITY-008: Under legacy/gdd-0.1, `GameState.Population` is the one record of th
R-CITY-004: Each turn, on the housing step, a city's refugees become civilians without a job (R-CITY-009's default may then give them jobs), `floor(pool x m)` of them at the Immigration minister's multiplier since the ministers (R-MIN-002; all of them before); the rest wait as refugees for the next turns. 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).
+For R-CITY-004, the preceding live absorption rule remains unchanged. The inactive gdd-0.3 addition is `Gdd03ReceptionFixture.ResolveWholeTurn`, an internal synthetic ordinary-bed fixture requiring exact gdd-0.3 content/state and an initialized population ledger. It reads positive Agreed integer `reception.capacity` and `reception.turns` without fallback (currently 3 beds and 6 turns); the ledger remains the person/progress authority under R-POP-002/003, reused here without a new persistence contract (`sim/Statecraft.Sim/Gdd03ReceptionFixture.cs:36-65@a30013863`; `sim/Statecraft.Sim.Tests/Gdd03ReceptionFixtureTests.cs:4-16@a30013863`, `:149-190`; `content/gdd03-balance.yaml:214-221@a30013863`). Source: `docs/gdd/training.md:23@605277dfa511dc512562ececeb273b8393b21d35`, "Completion changes the same unit into a free civilian, retaining id and experience."; `docs/gdd/balance.md:97-98` at that revision supplies the capacity and duration.
+
+Fixture conventions only: retained opening occupants have priority and gain one tick; reaching the requirement makes the same id an unassigned free civilian, preserving history, equipment, home and location. New claims are allocated at step end by ascending person id then ordinal camp target, only at an explicitly supplied operating, exactly colocated camp with space. Admission, including reuse of a just-released bed, gives no tick. Work eligibility is captured at opening, so completion grants no work in that step; the standalone eligibility predicate requires completed reception, free-civilian status and no assignment, and does not wire job/farm/build/course entry points. Invalid retained claims (including missing/inoperative/mismatched/overfull camps or completed/non-refugee occupants), duplicate camp targets and Course/Teaching assignments are refused rather than choosing interruption or shared-bed policy. With no available camp, an unassigned refugee stays unassigned. Changes are made on a reconciled clone, with no turn/date, RNG or resource advancement (`sim/Statecraft.Sim/Gdd03ReceptionFixture.cs:41-118@a30013863`; behavior fixtures in `sim/Statecraft.Sim.Tests/Gdd03ReceptionFixtureTests.cs:35-146@a30013863`, invalid completed claims at `:194-201`). These ordering and timing conventions are not adopted live timing rulings.
+
+The #1696 status comment of 27 October 2026 says, "It does not yet provide the live port queue or integrated camp routing." Live arrivals (#1695), map/region binding and approved source rows/coordinates/hexes (#1690/#1691), shared course beds (#1697), military credit/capping/deduplication and return queues (#1699), transit charging and queue-cohesion settlement (#1702/#1696), monthly timing and committing once (#1716), live activity guards, commands and save/replay integration remain pending. The fixture is "not a monthly settlement receipt or a replayable command" (`sim/Statecraft.Sim/Gdd03ReceptionFixture.cs:23-24@a30013863`); its exclusions at `:36-54` and the status comment's "Remaining integration needs" list do not authorize routing, settlement or timing defaults.
+
R-CITY-009: The job default (Q-JOBS-1, owner, 15 October 2026). On each housing step, after the refugees become civilians (R-CITY-004), each city whose default is on sets its employed to `min(job slots, civilians + craftsmen)`, in ascending city id, at no Attention cost. Every city's default is on at the start; an accepted `AssignWorkers` order fixes that city's number and turns its default off for the rest of the game. Each change is a `city` cause on the Why screen ("Town: N groups in work"). A city's record writes `jobs=manual` into the state hash only when its default is off.
R-CITY-005: The cities' employed share (employed over civilians and craftsmen, summed over all cities; 1 with none) 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).
diff --git a/sim/Statecraft.Sim.Tests/Gdd03ReceptionFixtureTests.cs b/sim/Statecraft.Sim.Tests/Gdd03ReceptionFixtureTests.cs
new file mode 100644
index 000000000..50e275987
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/Gdd03ReceptionFixtureTests.cs
@@ -0,0 +1,241 @@
+using Statecraft.Sim;
+using System.Globalization;
+
+// #1696 slice 1, R-CITY-004 / R-POP-002 / R-POP-003.
+// All ids, locations, counts, histories and operating flags below are test-only synthetic values.
+public class Gdd03ReceptionFixtureTests
+{
+ static readonly PopulationLocation Site = new("synthetic-context", facilityOrPort: "synthetic-site");
+ static readonly PopulationLocation Elsewhere = new("synthetic-context", facilityOrPort: "synthetic-other-site");
+ static Content Catalogue()
+ {
+ var c = PopulationLedgerTests.Content();
+ // content/gdd03-balance.yaml:214-221 at the pinned base: Agreed 3 beds, 6 turns.
+ c.Gdd03Balance!.Values["reception.capacity"] = new Gdd03DesignValue {
+ Basis = "Agreed", Values = new() { 3 }, Note = "Agreed catalogue reception.capacity" };
+ return c;
+ }
+ static SyntheticReceptionCamp Camp(string id = "synthetic-a", bool operating = true) => new(id, Site, operating);
+ static PopulationUnit Person(int ticks = 0, string? bed = null, PopulationLocation? location = null,
+ PopulationStatus status = PopulationStatus.Refugee) => new(0, status, ticks, location ?? Site,
+ bed == null ? PopulationAssignment.Unassigned : new(PopulationAssignmentKind.Reception, bed),
+ CivilianProfession.Farmer, CivilianTier.Trained, 7, "basic", 9, PopulationEquipment.None);
+ static GameState State(params PopulationUnit[] people)
+ {
+ var bindings = new PopulationBindings(new[] { Site, Elsewhere },
+ new[] { new PopulationTarget("synthetic-a", PopulationAssignmentKind.Reception, Site.Region),
+ new PopulationTarget("synthetic-b", PopulationAssignmentKind.Reception, Site.Region),
+ new PopulationTarget("synthetic-work", PopulationAssignmentKind.Work, Site.Region),
+ new PopulationTarget("synthetic-course", PopulationAssignmentKind.Course, Site.Region, 6) },
+ Array.Empty<string>(), new[] { "basic" });
+ return PopulationLedger.CreateFixture(Catalogue(), bindings, people.Select((p, i) =>
+ new PopulationInventoryRow("synthetic-start", i, p)));
+ }
+
+ // R-POP-002: the hashed ledger duration and the caller catalogue must agree.
+ [Theory] [InlineData(4)] [InlineData(8)]
+ public void DifferentAgreedDurationRefusesBeforeProgressOrEligibility(int turns)
+ {
+ var state = State(Person(3, "synthetic-a"));
+ var before = state.Hash();
+ var content = Catalogue();
+ content.Gdd03Balance!.Values["reception.turns"].Values = new() { turns };
+ Assert.Throws<ContentException>(() => Gdd03ReceptionFixture.ResolveWholeTurn(
+ content, state, new[] { Camp() }));
+ Assert.Equal(before, state.Hash());
+ var completed = State(Person(4, status: PopulationStatus.FreeCivilian));
+ Assert.Throws<ContentException>(() => Gdd03ReceptionFixture.CanStartCivilianActivity(
+ content, completed.PopulationLedger, completed.PopulationLedger.Get(0)));
+ Assert.False(Gdd03ReceptionFixture.CanStartCivilianActivity(
+ Catalogue(), completed.PopulationLedger, completed.PopulationLedger.Get(0)));
+ }
+
+ // R-POP-002: eligibility reads the current record of this ledger only.
+ [Theory] [InlineData(false)] [InlineData(true)]
+ public void ForeignOrStalePersonCannotBorrowAnotherLedgerEligibility(bool stale)
+ {
+ var state = State(Person(6, status: PopulationStatus.FreeCivilian));
+ var person = state.PopulationLedger.Get(0);
+ if (stale)
+ state.PopulationLedger.ChangeAssignment(0, new(PopulationAssignmentKind.Work, "synthetic-work"));
+ else
+ state = State(Person());
+ var before = state.Hash();
+ Assert.Throws<ArgumentException>(() => Gdd03ReceptionFixture.CanStartCivilianActivity(
+ Catalogue(), state.PopulationLedger, person));
+ Assert.Equal(before, state.Hash());
+ }
+
+ [Fact] public void SixthWholeBedTurnCompletesSamePersonWithoutCompletionTurnWork()
+ {
+ var refugee = Person(bed: "synthetic-a");
+ refugee = new PopulationUnit(0, refugee.Status, 0, refugee.Location, refugee.Assignment,
+ refugee.Profession, refugee.Tier, refugee.WorkXp, refugee.Qualification, refugee.CombatXp,
+ new PopulationEquipment("synthetic-tools", true, "synthetic-arms", true), home: Site);
+ var s = State(refugee); var opening = s; var original = s.Hash();
+ var p = s.PopulationLedger.Get(0);
+ for (int turn = 1; turn <= 6; turn++)
+ {
+ var result = Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), s, new[] { Camp() });
+ Assert.Empty(result.WorkEligibleAtOpening);
+ s = result.State;
+ Assert.Equal(turn, s.PopulationLedger.Get(0).ReceptionTicks);
+ Assert.Equal(turn == 6 ? PopulationStatus.FreeCivilian : PopulationStatus.Refugee,
+ s.PopulationLedger.Get(0).Status);
+ s.PopulationLedger.Reconcile();
+ }
+ var done = s.PopulationLedger.Get(0);
+ Assert.Equal(p.Id, done.Id); Assert.Equal(p.Profession, done.Profession); Assert.Equal(p.Tier, done.Tier);
+ Assert.Equal(p.WorkXp, done.WorkXp); Assert.Equal(p.CombatXp, done.CombatXp);
+ Assert.Equal(p.Qualification, done.Qualification); Assert.Same(p.Equipment, done.Equipment);
+ Assert.Same(p.Location, done.Location); Assert.Same(p.Home, done.Home); Assert.Equal(PopulationAssignmentKind.Unassigned, done.Assignment.Kind);
+ Assert.Equal(new[] { 0 }, Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), s, new[] { Camp() }).WorkEligibleAtOpening);
+ Assert.Equal(original, opening.Hash());
+ Assert.Equal(opening.Turn, s.Turn); Assert.Equal(opening.RngState, s.RngState);
+ Assert.Equal(opening.Treasury, s.Treasury); Assert.Equal(opening.Debt, s.Debt);
+ }
+
+ [Fact] public void ThreeDedicatedBedsAndStableUnitCampOrderGiveNoAdmissionTurnCredit()
+ {
+ var s = State(Enumerable.Range(0, 7).Select(_ => Person()).ToArray()); var before = s.Hash();
+ var a = Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), s, new[] { Camp("synthetic-b"), Camp() });
+ var b = Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), s.Clone(), new[] { Camp(), Camp("synthetic-b") });
+ Assert.Equal(a.State.Hash(), b.State.Hash()); Assert.Equal(before, s.Hash());
+ Assert.All(a.State.PopulationLedger.Units, p => Assert.Equal(0, p.ReceptionTicks));
+ Assert.All(a.State.PopulationLedger.Units.Take(3), p => Assert.Equal("synthetic-a", p.Assignment.Target));
+ Assert.All(a.State.PopulationLedger.Units.Skip(3).Take(3), p => Assert.Equal("synthetic-b", p.Assignment.Target));
+ Assert.Equal(PopulationAssignmentKind.Unassigned, a.State.PopulationLedger.Get(6).Assignment.Kind);
+ var next = Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), a.State, new[] { Camp(), Camp("synthetic-b") });
+ Assert.All(next.State.PopulationLedger.Units.Take(6), p => Assert.Equal(1, p.ReceptionTicks));
+ Assert.Equal(0, next.State.PopulationLedger.Get(6).ReceptionTicks);
+ }
+
+ [Fact] public void RetainedBedWinsAndReleasedBedDoesNotGiveReplacementAnotherTurn()
+ {
+ var s = State(Person(), Person(5, "synthetic-a"), Person(2, "synthetic-a"), Person(2, "synthetic-a"), Person());
+ var result = Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), s, new[] { Camp() });
+ Assert.Equal(6, result.State.PopulationLedger.Get(1).ReceptionTicks);
+ Assert.Equal(PopulationStatus.FreeCivilian, result.State.PopulationLedger.Get(1).Status);
+ Assert.Equal("synthetic-a", result.State.PopulationLedger.Get(0).Assignment.Target);
+ Assert.Equal(0, result.State.PopulationLedger.Get(0).ReceptionTicks);
+ Assert.Equal(3, result.State.PopulationLedger.Get(2).ReceptionTicks);
+ Assert.Equal(3, result.State.PopulationLedger.Get(3).ReceptionTicks);
+ Assert.Null(result.State.PopulationLedger.Get(4).Assignment.Target);
+ }
+
+ [Fact] public void OnlyExplicitColocationAndOperatingBedsAllowAdmission()
+ {
+ var s = State(Person(location: Elsewhere), Person());
+ var unavailable = Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), s, new[] { Camp(operating: false) });
+ Assert.All(unavailable.State.PopulationLedger.Units, p => Assert.Null(p.Assignment.Target));
+ var available = Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), s, new[] { Camp() });
+ Assert.Null(available.State.PopulationLedger.Get(0).Assignment.Target);
+ Assert.Equal("synthetic-a", available.State.PopulationLedger.Get(1).Assignment.Target);
+ var none = Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), s, Array.Empty<SyntheticReceptionCamp>());
+ Assert.Equal(s.Hash(), none.State.Hash());
+ }
+
+ [Fact] public void InvalidRetainedReservationsRefuseAtomicallyWithoutChoosingInterruptionPolicy()
+ {
+ var cases = new[] {
+ (State(Person(bed: "synthetic-a")), new[] { Camp(operating: false) }),
+ (State(Person(bed: "synthetic-a", location: Elsewhere)), new[] { Camp() }),
+ (State(Person(bed: "synthetic-a")), Array.Empty<SyntheticReceptionCamp>()),
+ (State(Enumerable.Range(0, 4).Select(_ => Person(bed: "synthetic-a")).ToArray()), new[] { Camp() }),
+ (State(Person()), new[] { Camp(), Camp() }) };
+ foreach (var (s, camps) in cases)
+ {
+ var before = s.Hash();
+ Assert.ThrowsAny<ArgumentException>(() => Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), s, camps));
+ Assert.Equal(before, s.Hash());
+ }
+ var unknown = State(Person()); var hash = unknown.Hash();
+ Assert.Throws<ArgumentException>(() => Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), unknown,
+ new[] { Camp("synthetic-unknown") }));
+ Assert.Equal(hash, unknown.Hash());
+ }
+
+ [Fact] public void PredicateRequiresCompletedFreeUnassignedCivilianForEveryFutureWorkConsumer()
+ {
+ static bool Eligible(PopulationUnit template)
+ {
+ var state = State(template);
+ return Gdd03ReceptionFixture.CanStartCivilianActivity(
+ Catalogue(), state.PopulationLedger, state.PopulationLedger.Get(0));
+ }
+ foreach (var ticks in new[] { 0, 5 })
+ {
+ Assert.False(Eligible(Person(ticks)));
+ Assert.False(Eligible(Person(ticks, status: PopulationStatus.FreeCivilian)));
+ }
+ Assert.True(Eligible(Person(6, status: PopulationStatus.FreeCivilian)));
+ Assert.False(Eligible(Person(6)));
+ var s = State(Person(6, status: PopulationStatus.FreeCivilian));
+ s.PopulationLedger.ChangeAssignment(0, new(PopulationAssignmentKind.Work, "synthetic-work"));
+ Assert.False(Gdd03ReceptionFixture.CanStartCivilianActivity(Catalogue(), s.PopulationLedger, s.PopulationLedger.Get(0)));
+ // This tests the proposed shared predicate; job/farm/build/course entry points are deliberately unwired.
+ }
+
+ [Fact] public void CourseFixturesRefuseRatherThanPretendToOwnSharedReservations()
+ {
+ var s = State(Person());
+ s.PopulationLedger.Transition(0, PopulationStatus.Trainee, Site,
+ new(PopulationAssignmentKind.Course, "synthetic-course"));
+ var before = s.Hash();
+ Assert.Throws<NotSupportedException>(() => Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), s, new[] { Camp() }));
+ Assert.Equal(before, s.Hash());
+ }
+
+ [Fact] public void ExactIdentityInitializedLedgerAndAgreedIntegralCatalogueAreRequired()
+ {
+ var s = State(Person()); var before = s.Hash();
+ foreach (var identity in new[] { SaveGame.LegacyRuleset, SaveGame.GddRuleset })
+ Assert.Throws<InvalidOperationException>(() => Gdd03ReceptionFixture.ResolveWholeTurn(
+ PopulationLedgerTests.Content(identity), s, new[] { Camp() }));
+ Assert.Throws<InvalidOperationException>(() => Gdd03ReceptionFixture.ResolveWholeTurn(
+ Catalogue(), new GameState(Catalogue()), new[] { Camp() }));
+ foreach (var key in new[] { "reception.capacity", "reception.turns" })
+ {
+ var missing = Catalogue(); missing.Gdd03Balance!.Values.Remove(key);
+ Assert.Throws<ContentException>(() => Gdd03ReceptionFixture.ResolveWholeTurn(missing, s, new[] { Camp() }));
+ foreach (var value in new[] { 0m, -1m, 1.5m, 2147483648m }) // test-only malformed inputs
+ {
+ var c = Catalogue(); c.Gdd03Balance!.Values[key].Values = new() { value };
+ Assert.Throws<ContentException>(() => Gdd03ReceptionFixture.ResolveWholeTurn(c, s, new[] { Camp() }));
+ }
+ var deferred = Catalogue(); var row = deferred.Gdd03Balance!.Values[key];
+ row.Basis = "Deferred"; row.Values.Clear(); row.Expression = "Deferred";
+ Assert.Throws<ContentException>(() => Gdd03ReceptionFixture.ResolveWholeTurn(deferred, s, new[] { Camp() }));
+ }
+ Assert.Equal(before, s.Hash());
+ }
+
+ [Theory] [InlineData("he-IL")] [InlineData("en-US")]
+ public void SyntheticProgressHasCultureIndependentCloneAndCanonicalState(string cultureName)
+ {
+ var s = State(Person(5, "synthetic-a"), Person());
+ var expected = Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), s, new[] { Camp() }).State.Hash();
+ var old = CultureInfo.CurrentCulture; var oldUi = CultureInfo.CurrentUICulture;
+ try
+ {
+ CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(cultureName);
+ CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;
+ var result = Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), s.Clone(), new[] { Camp() });
+ Assert.Equal(expected, result.State.Hash()); result.State.PopulationLedger.Reconcile();
+ Assert.Equal(5, s.PopulationLedger.Get(0).ReceptionTicks);
+ }
+ finally { CultureInfo.CurrentCulture = old; CultureInfo.CurrentUICulture = oldUi; }
+ }
+
+ // R-CITY-004: representable retained claims still require an incomplete refugee.
+ [Theory]
+ [InlineData(PopulationStatus.Refugee, 6)]
+ [InlineData(PopulationStatus.FreeCivilian, 0)]
+ public void CompletedOrFreeCivilianRetainedClaimsRefuseWithoutMutation(PopulationStatus status, int ticks)
+ {
+ var state = State(Person(ticks, "synthetic-a", status: status));
+ var before = state.Describe();
+ Assert.Throws<ArgumentException>(() => Gdd03ReceptionFixture.ResolveWholeTurn(Catalogue(), state, new[] { Camp() }));
+ Assert.Equal(before, state.Describe());
+ }
+}
diff --git a/sim/Statecraft.Sim/Gdd03ReceptionFixture.cs b/sim/Statecraft.Sim/Gdd03ReceptionFixture.cs
new file mode 100644
index 000000000..f4cd30261
--- /dev/null
+++ b/sim/Statecraft.Sim/Gdd03ReceptionFixture.cs
@@ -0,0 +1,133 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+
+namespace Statecraft.Sim
+{
+ /// <summary>Explicit test-only facility input. No map lookup, capacity inference or operating-date policy.
+ /// Several artificial camp targets may share the exact same synthetic location.</summary>
+ internal sealed class SyntheticReceptionCamp
+ {
+ internal string Target { get; }
+ internal PopulationLocation Location { get; }
+ internal bool Operating { get; }
+ internal SyntheticReceptionCamp(string target, PopulationLocation location, bool operating)
+ {
+ if (string.IsNullOrWhiteSpace(target)) throw new ArgumentException("Explicit synthetic reception target required.");
+ PopulationText.ValidateText(target);
+ Target = target; Location = location ?? throw new ArgumentNullException(nameof(location)); Operating = operating;
+ }
+ }
+
+ /// <summary>A new fixture state plus opening eligibility. Completing reception grants no work in this step.
+ /// This is not a monthly settlement receipt or a replayable command.</summary>
+ internal sealed class SyntheticReceptionTurn
+ {
+ internal GameState State { get; }
+ internal IReadOnlyList<int> WorkEligibleAtOpening { get; }
+ internal SyntheticReceptionTurn(GameState state, IEnumerable<int> eligible)
+ {
+ State = state;
+ WorkEligibleAtOpening = new ReadOnlyCollection<int>(eligible.ToArray());
+ }
+ }
+
+ /// <summary>#1696 ordinary-bed fixture only; R-CITY-004's proposed exact-gdd-0.3 exception.
+ /// No production caller. Shared course reservations, travel, arrival producers, settlement and military
+ /// credit are excluded. Uses the existing population ledger as the only person/progress authority.</summary>
+ internal static class Gdd03ReceptionFixture
+ {
+ // Synthetic fixture eligibility: completed reception, free civilian, unassigned.
+ // not proof of a job/field/project/course slot or permission to change an existing assignment.
+ internal static bool CanStartCivilianActivity(Content content, PopulationLedger ledger, PopulationUnit person)
+ {
+ var turns = MatchingReceptionTurns(content, ledger);
+ if (person == null) throw new ArgumentNullException(nameof(person));
+ if (!ReferenceEquals(ledger.Get(person.Id), person))
+ throw new ArgumentException("Eligibility requires the current record from the supplied ledger.", nameof(person));
+ return person.ReceptionTicks == turns && person.Status == PopulationStatus.FreeCivilian
+ && person.Assignment.Kind == PopulationAssignmentKind.Unassigned;
+ }
+
+ /// <summary>Pure fixture step: caller supplies an opening snapshot and the facilities operating throughout
+ /// this whole turn. Only retained opening bed occupants earn a tick. New claims are made at the end,
+ /// without work/progress; repeated evaluation of the same input produces the same candidate.
+ /// No turn/date/RNG/resources are advanced. The future #1716 owner must commit exactly once per turn.</summary>
+ internal static SyntheticReceptionTurn ResolveWholeTurn(Content content, GameState opening,
+ IEnumerable<SyntheticReceptionCamp> syntheticCamps)
+ {
+ if (content == null) throw new ArgumentNullException(nameof(content));
+ if (opening == null) throw new ArgumentNullException(nameof(opening));
+ if (syntheticCamps == null) throw new ArgumentNullException(nameof(syntheticCamps));
+ if (!content.UsesPopulationLedger || !opening.UsesPopulationLedger || !opening.PopulationLedger.IsInitialized)
+ throw new InvalidOperationException("Reception requires an initialized exact-gdd-0.3 synthetic fixture.");
+ // M content/gdd03-balance.yaml:214-221: Agreed capacity 3 and duration 6; no fallback or duplicate constants.
+ var capacity = content.RequirePopulationInteger("reception.capacity");
+ var turns = MatchingReceptionTurns(content, opening.PopulationLedger);
+ opening.PopulationLedger.Reconcile();
+ var camps = new SortedDictionary<string, SyntheticReceptionCamp>(StringComparer.Ordinal);
+ foreach (var camp in syntheticCamps)
+ {
+ if (camp == null) throw new ArgumentException("Null synthetic camp.");
+ camps.Add(camp.Target, camp);
+ }
+ var people = opening.PopulationLedger.Units.OrderBy(p => p.Id).ToArray();
+ if (people.Any(p => p.Assignment.Kind == PopulationAssignmentKind.Course
+ || p.Assignment.Kind == PopulationAssignmentKind.Teaching))
+ throw new NotSupportedException("Shared course/teacher reservation fixtures are outside ordinary reception.");
+ var occupied = camps.Keys.ToDictionary(id => id, _ => 0, StringComparer.Ordinal);
+ foreach (var p in people)
+ {
+ if (p.ReceptionTicks > turns) throw new ArgumentException("Reception exceeds the supplied catalogue limit.");
+ if (p.Assignment.Kind != PopulationAssignmentKind.Reception) continue;
+ // Invalid retained claims refuse atomically: no invented interruption, relocation or preemption.
+ if (p.Status != PopulationStatus.Refugee || p.ReceptionTicks >= turns
+ || !camps.TryGetValue(p.Assignment.Target!, out var camp) || !camp.Operating
+ || !Colocated(p, camp) || ++occupied[camp.Target] > capacity)
+ throw new ArgumentException("Invalid retained ordinary-bed reservation; interruption policy is excluded.");
+ }
+ var eligible = people.Where(p => CanStartCivilianActivity(content, opening.PopulationLedger, p)).Select(p => p.Id).ToArray();
+ var candidate = opening.Clone();
+ var ledger = candidate.PopulationLedger;
+ foreach (var p in people.Where(p => p.Assignment.Kind == PopulationAssignmentKind.Reception))
+ {
+ // Every admitted incomplete occupant is below the positive integer limit: +1 cannot overflow.
+ var progressed = p.WithReception(p.ReceptionTicks + 1);
+ if (progressed.ReceptionTicks == turns)
+ {
+ progressed = progressed.WithPlacement(PopulationStatus.FreeCivilian, p.Location,
+ PopulationAssignment.Unassigned, p.Captor, p.Home);
+ occupied[p.Assignment.Target!]--;
+ }
+ ledger.Replace(progressed);
+ }
+ // Synthetic fixture ordering: ascending unit id, then ordinal camp target.
+ // New claims never progress here, including a bed released by completion in this step.
+ foreach (var p in people.Where(p => p.Status == PopulationStatus.Refugee
+ && p.ReceptionTicks < turns && p.Assignment.Kind == PopulationAssignmentKind.Unassigned))
+ {
+ var camp = camps.Values.FirstOrDefault(c => c.Operating && Colocated(p, c) && occupied[c.Target] < capacity);
+ if (camp == null) continue;
+ ledger.ChangeAssignment(p.Id, new PopulationAssignment(PopulationAssignmentKind.Reception, camp.Target));
+ occupied[camp.Target]++;
+ }
+ ledger.Reconcile();
+ return new SyntheticReceptionTurn(candidate, eligible);
+ }
+
+ static int MatchingReceptionTurns(Content content, PopulationLedger ledger)
+ {
+ if (content == null) throw new ArgumentNullException(nameof(content));
+ if (ledger == null) throw new ArgumentNullException(nameof(ledger));
+ var turns = content.RequirePopulationInteger("reception.turns");
+ if (turns != ledger.ReceptionLimit)
+ throw new ContentException(Gdd03BalanceCatalogue.FileName, "values.reception.turns",
+ "must match the initialized population ledger");
+ return turns;
+ }
+
+ static bool Colocated(PopulationUnit person, SyntheticReceptionCamp camp) =>
+ person.Location != null && person.Location.Canonical() == camp.Location.Canonical();
+ }
+}
diff --git a/sim/Statecraft.Sim/PopulationLedger.cs b/sim/Statecraft.Sim/PopulationLedger.cs
index b83c900cf..1b3b32bd0 100644
--- a/sim/Statecraft.Sim/PopulationLedger.cs
+++ b/sim/Statecraft.Sim/PopulationLedger.cs
@@ -106,6 +106,7 @@ namespace Statecraft.Sim
SortedDictionary<int, string> losses = new SortedDictionary<int, string>();
PopulationBindings? bindings;
int receptionLimit;
+ internal int ReceptionLimit { get { RequireInitialized(); return receptionLimit; } }
int peoplePerUnit;
public bool IsInitialized { get; private set; }
public int NextPopulationId { get; private set; }