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.

GDD 0.3 ledger: a prisoner exchange returns captured population ids (Refs #2473) (#3088)

Eyal Golane73dae9d5656
diff --git a/changelog.d/2473-exchange-ids.md b/changelog.d/2473-exchange-ids.md
new file mode 100644
index 000000000..1d9dc7584
--- /dev/null
+++ b/changelog.d/2473-exchange-ids.md
@@ -0,0 +1,5 @@
+### Changed
+- GDD 0.3 prisoners (Refs #2473): on the inactive dark start's Historical ledger, a front's prisoner exchange brings the
+ player's captured soldiers home under their own population ids, as settled-in civilians in the census city nearest their
+ home region's label place, with their qualification and combat experience kept and their issued military item gone (no
+ Arms added). 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 0813c5842..08e317f08 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -414,7 +414,7 @@ R-POW-003: Prisoners are never labour, Money, Arms, housing occupants, jobs or a
R-POW-004: An event with `prisoners: <front>` (egypt, jordan, lebanon or syria) is that front's exchange card. It fires only while the front holds prisoners either way, a stored 0 holding nobody (the Jordan card also returns the Iraqi prisoners: the Jordan agreement took over the Iraqi sector, Art. VI, Q-OBJ-1; the ALA and the local forces belong to no front, so no card returns theirs). It has exactly one option and resolves without an RNG draw, like an objective's card. Resolving it moves its sides' prisoners from `PrisonersHeld` to `PrisonersReturned` and adds `mvp.points_per_prisoner_unit_returned` (real value 10) to the score for each population unit returned (Q-POW-2). Nothing scores at the capture (impact plan §4.3 item 3). It holds unchanged under gdd-0.3, played with a synthetic exchange card: a returned unit scores 10 (owner, 1 November 2026, O7: "10 per unit, main (Recommended)"; `PrisonersGdd03Tests.AReturnedUnitScoresTenPoints`); the card fires once, so prisoners taken after it has resolved stay held to the end of the game with no points (27M-19; `PrisonersGdd03Tests.PrisonersTakenAfterTheCardStayHeldWithNoPoints`); and a loaded save pays no return twice (`PrisonersGdd03Tests.ASaveAndReloadCannotPayTwice`).
-R-POW-005: A surrendered unit of the player's is added to `GameState.SoldiersHeld` under the side of the engagement's lowest-id attacker. In step 7, after the prisoners eat, the Treasury pays `mvp.held_soldier_cost_per_turn` (real value IL 0.005m) for each population unit held, borrowing what it lacks (R-MONEY-003; Q-POW-4). They come home when that side's front's exchange card resolves, with no score effect. On the dark start's Historical ledger (#1710, #1725 PR 7) the surrender also makes the formation's serving soldier records Captured, in one validated ledger commit after every check. Their captor is that same side: every enemy side with military units (a `unit_types.yaml` side other than `israel` and `""`) is bound as a captor when the Historical ledger is initialized (owner, 8 November 2026: "Winning side, set at start (Recommended)"). Their Home is the formation's region, region only ("Formation's region (Recommended)"). Each keeps its id, history and issued military item, unchanged while held; what happens to the item on return is #2473's (docs/GDD.md Q10; "Stays on record (Recommended)"). `GameState.SoldiersHeld` keeps its count beside the records, and per captor side it must equal the Captured records with that captor: Take and Upkeep check this before any write ("Keep count + check (Recommended)"). The held soldiers keep this Money cost ("Yes, as today (Recommended)"; docs/gdd/military-combat.md calls the exemption non-operative). The records captured are the active soldiers on the formation's target, found as battles find them (`Training.FormationTarget`: an opening formation's `units_1948/<row>`, a trained formation's `formation/<unit id>` from R-TRAIN-003), so a trained formation's soldiers become captives too (owner, 9 November 2026: "Yes, in #1706 (Recommended)"). A formation whose serving records do not number its strength is not refused, and the turn goes on (owner, 9 November 2026: "Go ahead on strength (Recommended)"): with more records than its strength, its strength of them are captured, the lowest ids first (as "Lowest id first (Recommended)" and docs/GDD.md's ascending population ids), and the rest leave service as soldiers sent home do (owner, 9 November 2026: "Sent home (Recommended)"): R-UNIT-005's ledger outcome, by Send home's own code (`Demobilization.RecordsHome`, written in the capture's one ledger commit, `PopulationLedger.Capture`, then `Demobilization.ReturnArms`), with "Nearest city, unemployed (Recommended)", "Settled in (Recommended)", "Keep both (Recommended)", "Back to Arms stock (Recommended)" and "No, records only (Recommended)". Each becomes a free civilian without an assignment, located in the nearest city to the formation's hex by R-UNIT-005's rule (its region plus the city), with reception ticks `reception.turns`, its qualification and combat XP kept, and its issued military item back in the Arms stock once; after the surrender line come Send home's own Why lines, in Send home's order (owner, 9 November 2026: "Yes, reuse Send home's (Recommended)"): its people line (key `sent_home`, "Unit N is sent home: its P people are civilians in <city> now", P the leftover records times `people_per_unit`), then, only when Arms go back, its Arms line ("Yes, one Why line (Recommended)", key `sent_home_arms_returned`). No aggregate city field is written. Every check comes before the first write: the captives and the leftovers change in one validated ledger commit, so a leftover location the ledger does not bind, like an unbound captor, refuses the surrender with nothing written; the Arms go back after that commit. With fewer records than its strength, all of them are captured. On a ledger game `SoldiersHeld` grows by the number of records captured, not by the unit's strength, so the check above still holds; without a ledger it grows by the strength, as before. For a formation whose records do not match its strength, the count held, and with it the Money cost per population unit held, therefore follows the records captured. A surrender to a side that is not a bound captor, or made while the held count already disagrees with the Captured records, is refused: Take throws before it writes anything. Called from combat, the throw comes after the engagement's draw and losses and after any earlier engagement of the same command or turn; on a direct call to `Combat.Strike` or `Combat.Resolve` those writes stay on the state object given. In the game that object is `Simulation.Step`'s clone (`sim/Statecraft.Sim/Simulation.cs:52`; combat's callers are `Simulation.cs:311`, a chosen event option's attack in `EventSystem.Choose` at `EventSystem.cs:347`, and `TurnResolver.cs:21`), so the whole command's or turn's result is discarded and the caller's state is unchanged. Since #1725 PR 6, Step takes a dark start's Historical ledger (`Simulation.cs:49`, R-POP-002), so a player's attack order runs `Combat.Strike` on that clone (`Simulation.cs:311`) and can reach the refusal there; if no order refuses, the turn then refuses the Historical ledger at `TurnResolver.cs:16`, before its step-2 `Combat.Resolve`. Either way the throw ends the Step and the caller's state is unchanged. An event option's attack is not reached on a ledger game: `EventSystem.Choose` refuses any initialized ledger at its entry (`EventSystem.cs:207`), and a waiting card is refused at `EventSystem.Delegate`'s entry (`EventSystem.cs:520`). So in the game only a player's attack order reaches the refusal in combat, and otherwise only a direct `Combat.Strike` or `Combat.Resolve` does (`LedgerPrisonersTests.ARefusedCaptureInCombatThrowsAndAPriorCloneIsUnchanged`). `Prisoners.Return` still refuses any initialized ledger, a Historical one included (`LedgerPrisonersTests.ReturnStillRefusesAHistoricalLedger`): it removes the `SoldiersHeld` count but moves no Captured record, so the change that lifts that refusal (#2473) must move the Captured records back in the same commit. Since #1706 the engagement's losses have already removed the surrendering formation's lost records as combat losses (R-COMBAT-006's ledger paragraph).
+R-POW-005: A surrendered unit of the player's is added to `GameState.SoldiersHeld` under the side of the engagement's lowest-id attacker. In step 7, after the prisoners eat, the Treasury pays `mvp.held_soldier_cost_per_turn` (real value IL 0.005m) for each population unit held, borrowing what it lacks (R-MONEY-003; Q-POW-4). They come home when that side's front's exchange card resolves, with no score effect. On the dark start's Historical ledger (#1710, #1725 PR 7) the surrender also makes the formation's serving soldier records Captured, in one validated ledger commit after every check. Their captor is that same side: every enemy side with military units (a `unit_types.yaml` side other than `israel` and `""`) is bound as a captor when the Historical ledger is initialized (owner, 8 November 2026: "Winning side, set at start (Recommended)"). Their Home is the formation's region, region only ("Formation's region (Recommended)"). Each keeps its id, history and issued military item, unchanged while held (docs/GDD.md Q10; "Stays on record (Recommended)"). `GameState.SoldiersHeld` keeps its count beside the records, and per captor side it must equal the Captured records with that captor: Take and Upkeep check this before any write ("Keep count + check (Recommended)"). The held soldiers keep this Money cost ("Yes, as today (Recommended)"; docs/gdd/military-combat.md calls the exemption non-operative). The records captured are the active soldiers on the formation's target, found as battles find them (`Training.FormationTarget`: an opening formation's `units_1948/<row>`, a trained formation's `formation/<unit id>` from R-TRAIN-003), so a trained formation's soldiers become captives too (owner, 9 November 2026: "Yes, in #1706 (Recommended)"). A formation whose serving records do not number its strength is not refused, and the turn goes on (owner, 9 November 2026: "Go ahead on strength (Recommended)"): with more records than its strength, its strength of them are captured, the lowest ids first (as "Lowest id first (Recommended)" and docs/GDD.md's ascending population ids), and the rest leave service as soldiers sent home do (owner, 9 November 2026: "Sent home (Recommended)"): R-UNIT-005's ledger outcome, by Send home's own code (`Demobilization.RecordsHome`, written in the capture's one ledger commit, `PopulationLedger.Capture`, then `Demobilization.ReturnArms`), with "Nearest city, unemployed (Recommended)", "Settled in (Recommended)", "Keep both (Recommended)", "Back to Arms stock (Recommended)" and "No, records only (Recommended)". Each becomes a free civilian without an assignment, located in the nearest city to the formation's hex by R-UNIT-005's rule (its region plus the city), with reception ticks `reception.turns`, its qualification and combat XP kept, and its issued military item back in the Arms stock once; after the surrender line come Send home's own Why lines, in Send home's order (owner, 9 November 2026: "Yes, reuse Send home's (Recommended)"): its people line (key `sent_home`, "Unit N is sent home: its P people are civilians in <city> now", P the leftover records times `people_per_unit`), then, only when Arms go back, its Arms line ("Yes, one Why line (Recommended)", key `sent_home_arms_returned`). No aggregate city field is written. Every check comes before the first write: the captives and the leftovers change in one validated ledger commit, so a leftover location the ledger does not bind, like an unbound captor, refuses the surrender with nothing written; the Arms go back after that commit. With fewer records than its strength, all of them are captured. On a ledger game `SoldiersHeld` grows by the number of records captured, not by the unit's strength, so the check above still holds; without a ledger it grows by the strength, as before. For a formation whose records do not match its strength, the count held, and with it the Money cost per population unit held, therefore follows the records captured. A surrender to a side that is not a bound captor, or made while the held count already disagrees with the Captured records, is refused: Take throws before it writes anything. Called from combat, the throw comes after the engagement's draw and losses and after any earlier engagement of the same command or turn; on a direct call to `Combat.Strike` or `Combat.Resolve` those writes stay on the state object given. In the game that object is `Simulation.Step`'s clone (`sim/Statecraft.Sim/Simulation.cs:52`; combat's callers are `Simulation.cs:311`, a chosen event option's attack in `EventSystem.Choose` at `EventSystem.cs:347`, and `TurnResolver.cs:21`), so the whole command's or turn's result is discarded and the caller's state is unchanged. Since #1725 PR 6, Step takes a dark start's Historical ledger (`Simulation.cs:49`, R-POP-002), so a player's attack order runs `Combat.Strike` on that clone (`Simulation.cs:311`) and can reach the refusal there; if no order refuses, the turn then refuses the Historical ledger at `TurnResolver.cs:16`, before its step-2 `Combat.Resolve`. Either way the throw ends the Step and the caller's state is unchanged. An event option's attack is not reached on a ledger game: `EventSystem.Choose` refuses any initialized ledger at its entry (`EventSystem.cs:207`), and a waiting card is refused at `EventSystem.Delegate`'s entry (`EventSystem.cs:520`). So in the game only a player's attack order reaches the refusal in combat, and otherwise only a direct `Combat.Strike` or `Combat.Resolve` does (`LedgerPrisonersTests.ARefusedCaptureInCombatThrowsAndAPriorCloneIsUnchanged`). Since #2473, `Prisoners.Return` runs on a Historical ledger (a synthetic or Open one is still refused) and, after the same count check and before any other write, returns the Captured records that the front's sides hold, in ascending population id, in one validated ledger commit, by Send home's own code (`Demobilization.RecordsHome`) (owner, 9 November 2026, recorded on #2473). Each keeps its population id and becomes a free civilian without an assignment, captor or home. "It's gone (Recommended)": its issued military item is removed from the record and nothing is added to Arms (`LedgerPrisonersTests.AReturnedCaptivesIssuedItemIsGoneAndNoArmsAreAdded`). "Yes, settled in (Recommended)": its reception ticks are `reception.turns`, as for soldiers sent home (`LedgerPrisonersTests.AReturnedCaptiveIsASettledInFreeCivilianUnderTheSameId`, which also pins that another front's captives stay captured and that a second exchange changes nothing). "Keep both (Recommended)": its qualification and combat XP stay (`LedgerPrisonersTests.AReturnedCaptiveKeepsQualificationAndCombatExperience`). "Nearest to region label (Recommended)": it goes to the nearest of the twelve census cities to its home region's label place (`regions.yaml` `capital_location`), by Send home's hex distance and city-id tie (`Demobilization.Nearest`), located in that city's region plus the city (`LedgerPrisonersTests.AReturnedCaptiveGoesToTheCityNearestTheirHomeRegionsLabelPlace`, `LedgerPrisonersTests.AReturnedCaptiveTiedBetweenTwoCitiesGoesToTheLowerCityId`). No score and no Arms line are written for them; the front's `SoldiersHeld` count goes as before, so the count still equals the Captured records. In the game the exchange card does not reach a ledger game yet: `EventSystem.Choose` refuses any initialized ledger at its entry and `TurnResolver.cs:16` holds the dark turn. Since #1706 the engagement's losses have already removed the surrendering formation's lost records as combat losses (R-COMBAT-006's ledger paragraph).
Under gdd-0.3 (#1710), the prisoners in these pins come from a real surrender (R-POW-001). `PrisonersGdd03Tests.PrisonersEatAndAFoodShortfallCostsCohesion` pins R-POW-002, `PrisonersGdd03Tests.PrisonersAreNeverAResource` pins R-POW-003, and `PrisonersGdd03Tests.OwnSoldiersAreCapturedCostMoneyAndComeHome` pins R-POW-005. The real per-front exchange cards wait on #751, so the return and homecoming pins use the synthetic card until those cards land. On the dark start, `LedgerPrisonersTests` pins R-POW-001, R-POW-002 and R-POW-005 against the aggregate start with the same counts.
diff --git a/sim/Statecraft.Sim.Tests/LedgerPrisonersTests.cs b/sim/Statecraft.Sim.Tests/LedgerPrisonersTests.cs
index 07afb70f9..f5a751f5e 100644
--- a/sim/Statecraft.Sim.Tests/LedgerPrisonersTests.cs
+++ b/sim/Statecraft.Sim.Tests/LedgerPrisonersTests.cs
@@ -419,22 +419,152 @@ public class LedgerPrisonersTests
Assert.Contains(lines, x => x.Key == WhyKeys.Engagement);
}
- // R-POW-005, #2473: Prisoners.Return still refuses a Historical ledger. It removes a front's SoldiersHeld count but moves
- // no Captured record, so on a dark start after a real capture it must throw before any write; lifting that refusal must
- // move the records home in the same change, or the next Take or Upkeep finds the count and the records disagree.
+ // #2473: a front's exchange on the dark start returns the player's captured records by their population ids (R-POW-005,
+ // R-POW-004, R-POP-002). The owner's rulings of 9 November 2026, recorded on #2473: "It's gone (Recommended)", "Yes,
+ // settled in (Recommended)", "Keep both (Recommended)" and "Nearest to region label (Recommended)". In the game the
+ // exchange card does not reach a ledger game yet (EventSystem.Choose refuses any initialized ledger at its entry, and
+ // TurnResolver.cs:16 holds the dark turn), so these call Prisoners.Return directly, as the tests above call Take and Upkeep.
+ static List<PopulationUnit> Captives(GameState s, string side) => s.PopulationLedger.Units
+ .Where(p => p.Status == PopulationStatus.Captured && p.Captor == side).OrderBy(p => p.Id).ToList();
+
+ // R-POW-005, ruling 1, "It's gone (Recommended)": the issued military item is removed from the returned record and
+ // nothing is added to Arms; no score either (Q-POW-4), and no Send home Arms line.
[Fact]
- public void ReturnStillRefusesAHistoricalLedger()
+ public void AReturnedCaptivesIssuedItemIsGoneAndNoArmsAreAdded()
{
var c = Gdd03();
var s = Dark(c);
Take(c, s, Own(c, s)[0], Enemy(s, "egypt"));
- Assert.True(s.SoldiersHeld["egypt"] > 0);
- Assert.True(s.PopulationLedger.IsHistorical);
- var before = s.Describe(); var hash = s.Hash(); var ledger = s.PopulationLedger.Canonical().ToList(); var why = new List<Cause>();
- Assert.Contains("integration is held", Assert.Throws<NotSupportedException>(() => Prisoners.Return(c, s, "egypt", why)).Message);
- Assert.Equal(before, s.Describe()); Assert.Equal(hash, s.Hash());
- Assert.Equal(ledger, s.PopulationLedger.Canonical()); Assert.Empty(why);
+ var held = Captives(s, "egypt");
+ Assert.NotEmpty(held);
+ Assert.All(held, p => Assert.NotNull(p.Equipment.MilitaryId));
+ var items = held.Select(p => p.Equipment.MilitaryId!).ToList();
+ var arms = s.Arms; var score = (s.Score, s.ScorePrisonerPoints); var why = new List<Cause>();
+ Prisoners.Return(c, s, "egypt", why);
+ foreach (var was in held)
+ {
+ var p = s.PopulationLedger.Get(was.Id);
+ Assert.Null(p.Equipment.MilitaryId);
+ Assert.False(p.Equipment.MilitaryPaid);
+ Assert.Equal((was.Equipment.ToolsId, was.Equipment.ToolsPaid), (p.Equipment.ToolsId, p.Equipment.ToolsPaid));
+ }
+ Assert.DoesNotContain(s.PopulationLedger.Units, p => p.Equipment.MilitaryId is string id && items.Contains(id));
+ Assert.Equal(arms, s.Arms);
+ Assert.Equal(score, (s.Score, s.ScorePrisonerPoints));
+ Assert.DoesNotContain(why, x => x.Key == CauseKeys.SentHomeArmsReturned);
+ Assert.Equal(held.Count, Assert.Single(why, x => x.Key == CauseKeys.SoldiersReturned).Delta);
+ s.PopulationLedger.Reconcile();
+ }
+
+ // R-POW-005, R-POP-002, ruling 2, "Yes, settled in (Recommended)": each record the front held comes home under the same
+ // population id as a free civilian without an assignment or captor, its reception ticks reception.turns, as soldiers
+ // sent home are. No record is made or lost; another front's captives stay captured with their count; the front's count
+ // goes, so the count still equals the records; a second exchange of the same front changes nothing.
+ [Fact]
+ public void AReturnedCaptiveIsASettledInFreeCivilianUnderTheSameId()
+ {
+ var c = Gdd03();
+ var s = Dark(c);
+ var own = Own(c, s);
+ Take(c, s, own[0], Enemy(s, "egypt"));
+ Take(c, s, own[1], Enemy(s, "jordan"));
+ var held = Captives(s, "egypt"); var jordan = Captives(s, "jordan").Select(p => p.Canonical()).ToList();
+ Assert.NotEmpty(held); Assert.NotEmpty(jordan);
+ var received = c.RequirePopulationInteger("reception.turns");
+ var next = s.PopulationLedger.NextPopulationId; var count = s.PopulationLedger.Units.Count; var people = s.PopulationLedger.TotalPeople;
+ var jordanHeld = s.SoldiersHeld["jordan"];
+ Prisoners.Return(c, s, "egypt", new List<Cause>());
+ foreach (var was in held)
+ {
+ var p = s.PopulationLedger.Get(was.Id);
+ Assert.Equal(PopulationStatus.FreeCivilian, p.Status);
+ Assert.Equal(PopulationAssignmentKind.Unassigned, p.Assignment.Kind);
+ Assert.Equal(received, p.ReceptionTicks);
+ Assert.Null(p.Captor);
+ Assert.Null(p.Home);
+ Assert.NotNull(p.Location!.City);
+ }
+ Assert.Empty(Captives(s, "egypt"));
+ Assert.Equal(jordan, Captives(s, "jordan").Select(p => p.Canonical()));
+ Assert.False(s.SoldiersHeld.ContainsKey("egypt"));
+ Assert.Equal(jordanHeld, s.SoldiersHeld["jordan"]);
+ Assert.Equal((next, count, people), (s.PopulationLedger.NextPopulationId, s.PopulationLedger.Units.Count, s.PopulationLedger.TotalPeople));
AssertHeldMatchesRecords(s);
+ var hash = s.Hash(); var again = new List<Cause>();
+ Prisoners.Return(c, s, "egypt", again);
+ Assert.Equal(hash, s.Hash()); Assert.Empty(again);
+ s.PopulationLedger.Reconcile();
+ }
+
+ // R-POW-005, ruling 3, "Keep both (Recommended)": the returned record keeps its military qualification and its combat
+ // experience (here set to distinct values while held), and its civilian history.
+ [Fact]
+ public void AReturnedCaptiveKeepsQualificationAndCombatExperience()
+ {
+ var c = Gdd03();
+ var s = Dark(c);
+ Take(c, s, Own(c, s)[0], Enemy(s, "egypt"));
+ foreach (var p in Captives(s, "egypt"))
+ s.PopulationLedger.Replace(new PopulationUnit(p.Id, p.Status, p.ReceptionTicks, p.Location, p.Assignment, p.Profession,
+ p.Tier, p.WorkXp, p.Qualification, 2 + p.Id % 3, p.Equipment, p.Captor, p.Home));
+ var held = Captives(s, "egypt");
+ Assert.All(held, p => Assert.NotEqual("", p.Qualification));
+ Prisoners.Return(c, s, "egypt", new List<Cause>());
+ foreach (var was in held)
+ {
+ var p = s.PopulationLedger.Get(was.Id);
+ Assert.Equal((was.Qualification, 2 + was.Id % 3, was.Profession, was.Tier, was.WorkXp),
+ (p.Qualification, p.CombatXp, p.Profession, p.Tier, p.WorkXp));
+ }
+ s.PopulationLedger.Reconcile();
+ }
+
+ // R-POW-005, ruling 4, "Nearest to region label (Recommended)": the returned record goes to the nearest of the twelve
+ // census cities to its home region's label place (regions.yaml capital_location), by Send home's hex distance, located
+ // in that city's region plus the city. Each row is a bound home region and the city by hand from settlement_hexes.yaml
+ // and locality_hexes.yaml; negev's label place, Beersheba, is nearest to Jerusalem, outside its own region.
+ [Theory]
+ [InlineData("galilee", "safed")] [InlineData("valleys", "tiberias")] [InlineData("haifa_sharon", "haifa")]
+ [InlineData("tel_aviv_jaffa", "tel_aviv")] [InlineData("central_plain", "rishon_lezion")]
+ [InlineData("jerusalem_hills", "jerusalem")] [InlineData("negev", "jerusalem")]
+ public void AReturnedCaptiveGoesToTheCityNearestTheirHomeRegionsLabelPlace(string home, string city)
+ {
+ var c = Gdd03();
+ var s = Dark(c);
+ Take(c, s, Own(c, s)[0], Enemy(s, "egypt"));
+ foreach (var p in Captives(s, "egypt"))
+ s.PopulationLedger.Transition(p.Id, PopulationStatus.Captured, null, PopulationAssignment.Unassigned, p.Captor, new PopulationLocation(home));
+ var held = Captives(s, "egypt");
+ Assert.All(held, p => Assert.Equal(home, p.Home!.Region));
+ Prisoners.Return(c, s, "egypt", new List<Cause>());
+ var region = c.PlayerRegions.AtLocation(city)!.Id;
+ foreach (var was in held)
+ Assert.Equal((region, city), (s.PopulationLedger.Get(was.Id).Location!.Region, s.PopulationLedger.Get(was.Id).Location!.City));
+ s.PopulationLedger.Reconcile();
+ }
+
+ // R-POW-005, ruling 4's tie, "by the same distance rule and city-id tie as Send home": the Negev Brigade's soldiers (home
+ // region southern_coast, label place Gaza) are as near Rehovot as Rishon LeZion; the city id in ordinal order takes
+ // Rehovot, although cities.yaml lists Rishon LeZion first.
+ [Fact]
+ public void AReturnedCaptiveTiedBetweenTwoCitiesGoesToTheLowerCityId()
+ {
+ var c = Gdd03();
+ var s = Dark(c);
+ var negev = Own(c, s).Single(u => c.StartingForces[u.Id].Row == "negev");
+ Take(c, s, negev, Enemy(s, "egypt"));
+ var held = Captives(s, "egypt");
+ Assert.NotEmpty(held);
+ Assert.All(held, p => Assert.Equal("southern_coast", p.Home!.Region));
+ Assert.Equal("gaza", c.PlayerRegions.Regions["southern_coast"].CapitalLocation);
+ int At(string id) { var g = c.SettlementHexes.Single(h => h.Id == "gaza"); var h2 = c.SettlementHexes.Single(h => h.Id == id); return MapActions.Distance(g.Q, g.R, h2.Q, h2.R); }
+ Assert.Equal(At("rehovot"), At("rishon_lezion"));
+ Assert.Equal(At("rehovot"), c.Cities.Min(x => At(x.Id)));
+ Assert.True(c.Cities.FindIndex(x => x.Id == "rishon_lezion") < c.Cities.FindIndex(x => x.Id == "rehovot"));
+ Prisoners.Return(c, s, "egypt", new List<Cause>());
+ foreach (var was in held)
+ Assert.Equal(("central_plain", "rehovot"), (s.PopulationLedger.Get(was.Id).Location!.Region, s.PopulationLedger.Get(was.Id).Location!.City));
+ s.PopulationLedger.Reconcile();
}
// Determinism: Take and Upkeep draw no RNG; two dark games given the same captures and upkeep end with the same hash and
diff --git a/sim/Statecraft.Sim/PlayerRegions.cs b/sim/Statecraft.Sim/PlayerRegions.cs
index f8d883e53..f612edac8 100644
--- a/sim/Statecraft.Sim/PlayerRegions.cs
+++ b/sim/Statecraft.Sim/PlayerRegions.cs
@@ -65,6 +65,9 @@ namespace Statecraft.Sim
{
public string Id { get; }
public string CapitalLocation { get; }
+ /// <summary>The hex of <see cref="CapitalLocation"/>, the region's label place, as the place files put it (#2473: a
+ /// returned captive goes to the nearest census city to it). Not in <see cref="Canonical"/>.</summary>
+ public (int Q, int R) CapitalHex { get; }
public IReadOnlyList<(int Q, int R)> MemberHexes { get; }
public IReadOnlyList<string> MemberLocations { get; }
public IReadOnlyList<(int Q, int R)> FieldHexes { get; }
@@ -75,9 +78,9 @@ namespace Statecraft.Sim
public string BindingStatus { get; }
public string ControlStatus { get; }
public string? OpeningController { get; }
- internal PlayerRegionGeography(PlayerRegionDefinition row, bool hosts)
+ internal PlayerRegionGeography(PlayerRegionDefinition row, bool hosts, (int Q, int R) capitalHex)
{
- Id = row.Id; CapitalLocation = row.CapitalLocation;
+ Id = row.Id; CapitalLocation = row.CapitalLocation; CapitalHex = capitalHex;
MemberHexes = Array.AsReadOnly(row.MemberHexes.Select(h => (h.Q!.Value, h.R!.Value))
.OrderBy(h => h.Item1).ThenBy(h => h.Item2).ToArray());
MemberLocations = Array.AsReadOnly(row.MemberLocations.OrderBy(x => x, StringComparer.Ordinal).ToArray());
@@ -218,7 +221,7 @@ namespace Statecraft.Sim
else if (!ownPlaces.Contains(h.Host)) Fail(field + ".host", $"{label}: {h.Host} is not a member location of {row.Id}");
}
if (string.IsNullOrWhiteSpace(row.CapitalLocation) || !ownPlaces.Contains(row.CapitalLocation)) Fail("capital_location", "must name a member location on a member hex");
- var frozen = new PlayerRegionGeography(row, readsHosts);
+ var frozen = new PlayerRegionGeography(row, readsHosts, placements[row.CapitalLocation]);
result.regions.Add(row.Id, frozen); result.capitals.Add(row.CapitalLocation, row.Id);
foreach (var h in ownHexes) result.hexes.Add(h, row.Id);
foreach (var p in ownPlaces) result.places.Add(p, row.Id);
diff --git a/sim/Statecraft.Sim/Prisoners.cs b/sim/Statecraft.Sim/Prisoners.cs
index 609653e1d..37f1aadc1 100644
--- a/sim/Statecraft.Sim/Prisoners.cs
+++ b/sim/Statecraft.Sim/Prisoners.cs
@@ -108,6 +108,31 @@ namespace Statecraft.Sim
$"Our soldiers held by {side} number {m} but the population ledger has {n} captured records with that captor (R-POW-005)."));
}
+ /// <summary>#2473, R-POW-005, R-POP-002 (owner, 9 November 2026, recorded on #2473): the Captured records held by
+ /// <paramref name="front"/>'s sides, in ascending population id, come home under the same ids as Send home's records
+ /// leave service (<see cref="Demobilization.RecordsHome"/>): free civilians without an assignment, captor or home,
+ /// "Yes, settled in (Recommended)" (reception ticks reception.turns), "Keep both (Recommended)" (qualification and
+ /// combat XP kept). "It's gone (Recommended)": the issued military item leaves the record and nothing is added to Arms
+ /// (RecordsHome's item count is not returned). "Nearest to region label (Recommended)": each goes to the nearest census
+ /// city to its home region's label place (regions.yaml capital_location), by Send home's distance rule and city-id
+ /// tie (<see cref="Demobilization.Nearest"/>). One validated ledger commit, so a refusal writes nothing.</summary>
+ static void ReturnRecords(Content c, GameState s, string front)
+ {
+ var sides = new HashSet<string>(Sides(front), StringComparer.Ordinal);
+ var captives = s.PopulationLedger.Units.Where(p => p.Status == PopulationStatus.Captured && sides.Contains(p.Captor!))
+ .OrderBy(p => p.Id).ToList();
+ if (captives.Count == 0) return;
+ var civilians = new List<PopulationUnit>();
+ foreach (var g in captives.GroupBy(p => p.Home!.Region, StringComparer.Ordinal))
+ {
+ var label = c.PlayerRegions.Regions.TryGetValue(g.Key, out var region) ? region.CapitalHex
+ : throw new InvalidOperationException("No region in regions.yaml for " + g.Key + " (R-POW-005).");
+ var released = g.Select(p => p.WithPlacement(p.Status, p.Location, p.Assignment, null, null));
+ civilians.AddRange(Demobilization.RecordsHome(c, released, Demobilization.Nearest(c, label.Q, label.R), out _));
+ }
+ s.PopulationLedger.Commit(civilians, Array.Empty<PopulationTarget>());
+ }
+
static IEnumerable<string> Sides(string front) => FrontOf.Where(kv => kv.Value == front).Select(kv => kv.Key).OrderBy(x => x, StringComparer.Ordinal);
/// <summary>True while <paramref name="front"/> holds the player's soldiers or the player holds its prisoners: its exchange
@@ -148,10 +173,12 @@ namespace Statecraft.Sim
/// <summary>R-POW-004, R-POW-005: <paramref name="front"/>'s exchange card was resolved. Its sides' prisoners go home and
/// score points_per_prisoner_unit_returned a unit (Q-POW-2); the player's soldiers that front held come home, with no
- /// score (Q-POW-4).</summary>
+ /// score (Q-POW-4). On an initialized Historical ledger (#2473) the Captured records that front's sides hold come home
+ /// too, by <see cref="ReturnRecords"/>, before any other write; a synthetic or Open ledger is still refused.</summary>
internal static void Return(Content c, GameState s, string front, List<Cause> why)
{
- PopulationLedger.RefuseAggregate(s);
+ PopulationLedger.RefuseUnlessHistorical(s);
+ if (s.PopulationLedger.IsInitialized) { RequireHeldMatchesRecords(s); ReturnRecords(c, s, front); }
// Only GDD combat creates prisoners and the card waits for them, so this runs only in the GDD loop, which has Mvp.
var points = c.RulesAt(s.Date).Mvp!.PointsPerPrisonerUnitReturned!.Value;
var ppu = c.RulesAt(s.Date).Mvp!.PeoplePerUnit;