A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
feat(sim): formation service runs on a Historical ledger game (#1725 PR 7, producer 11) (#2961)
Eyal Golanc9ddb732b3f9
diff --git a/changelog.d/1725-pr7-military-service.md b/changelog.d/1725-pr7-military-service.mdnew file mode 100644index 000000000..9cb4ade06--- /dev/null+++ b/changelog.d/1725-pr7-military-service.md@@ -0,0 +1,3 @@+- GDD 0.3 starting population (Refs #1725, Refs #1689): formation service (R-UNIT-004) now runs on the inactive dark+ start's Historical ledger. A recruit formation gains its service turn as in the aggregate game and, under gdd-0.3,+ never promotes; no ledger record changes. No new-game wiring, so there is no change in the game.diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex d2825eb14..683e4d6bf 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -266,7 +266,7 @@ R-UNIT-002: A unit's side, strength, order and order target are written into theR-UNIT-003: A finished recruit cohort becomes exactly one Israeli infantry formation at its city's settlement hex, with `Strength` equal to the cohort's `Count` in population units, service 0 and the next id (Q-UNIT-1, Q-UNIT-4; owner, 15 October 2026). The cohort leaves the state: nobody is lost or duplicated. Its reserved Arms are neither charged again nor refunded on completion (R-ARMS-003). A cohort aimed at a unit adds to that unit instead of making a new one (R-TRAIN-004).-R-UNIT-004: Each Israeli recruit formation already in play before step 4 gains one service turn; a cohort graduating in step 4 starts serving on the next turn. At `veteran_soldier_service` it becomes `veteran_soldier`, keeping id, hex, service, side, strength and standing order, with a Why cause. Veterans stop accumulating service. Combat gives no extra service, and Phase 5 adds no return to civilian life (Q-UNIT-2, Q-UNIT-6; owner, 15 October 2026). The owner-accepted initial threshold is 6 turns, a labelled design value under Q-GEN-1, not a historical period (19 October 2026, https://github.com/eyalgolan/statecraft-israel/pull/1130#issuecomment-6269103829). The loader requires it to be at least 1 and requires the Israeli veteran infantry type when recruits exist. Under exact `gdd-0.3` service is a statistic only and never promotes: a recruit still gains its service turn, and veterancy comes from combat experience, R-UNIT-011 (owner, 1 November 2026, Q16: "Under gdd-0.3, yes: veterancy comes from combat experience. gdd-0.1 keeps R-UNIT-004.").+R-UNIT-004: Each Israeli recruit formation already in play before step 4 gains one service turn; a cohort graduating in step 4 starts serving on the next turn. At `veteran_soldier_service` it becomes `veteran_soldier`, keeping id, hex, service, side, strength and standing order, with a Why cause. Veterans stop accumulating service. Combat gives no extra service, and Phase 5 adds no return to civilian life (Q-UNIT-2, Q-UNIT-6; owner, 15 October 2026). The owner-accepted initial threshold is 6 turns, a labelled design value under Q-GEN-1, not a historical period (19 October 2026, https://github.com/eyalgolan/statecraft-israel/pull/1130#issuecomment-6269103829). The loader requires it to be at least 1 and requires the Israeli veteran infantry type when recruits exist. Under exact `gdd-0.3` service is a statistic only and never promotes: a recruit still gains its service turn, and veterancy comes from combat experience, R-UNIT-011 (owner, 1 November 2026, Q16: "Under gdd-0.3, yes: veterancy comes from combat experience. gdd-0.1 keeps R-UNIT-004."). Service also runs on a game with an initialized Historical ledger (the dark start, R-POP-002; #1725 PR 7): a recruit formation gains its service turn as in the aggregate game and, under `gdd-0.3`, never promotes. Service stays on the formation only, so no ledger record or ledger hash changes, and service checks no formation strength against the ledger's soldiers; a synthetic or Open ledger is still refused (maintainer calls by coordinator eyalgolan-30, 8 November 2026, not owner rulings).R-UNIT-005: `UnitOrder(unit, send_home)` (the unit card's "Send home", #1309) is the player's order and the only way home: no automatic demobilisation happens (owner, 22 October 2026, #1309: https://github.com/eyalgolan/statecraft-israel/issues/1309#issuecomment-6334162964). It is refused, the state unchanged, with the orders' own reasons for an unknown unit, a unit with no side or an enemy unit (R-ORDER-001's wording) and "That order names no hex" when a hex is given, and with "The armistice with <front> is not signed" while the armistice on the unit's front is unsigned. A unit's front is the front of the enemy side it attacked this turn or borders; ties take the nearest enemy unit, then the lowest unit id (owner, 22 October 2026, #1309: https://github.com/eyalgolan/statecraft-israel/issues/1309#issuecomment-6340226644). A side that belongs to no front (the ALA and the local forces, Q-OBJ-1; R-POW-004's map) names none (accepted per maintainer comment, 22 October 2026, #1309: https://github.com/eyalgolan/statecraft-israel/issues/1309#issuecomment-6341877062: the ALA and the local forces belong to no front, having no armistice of their own), and a unit attacking and bordering no front-bearing enemy may be sent home once any armistice is signed, refused with "No armistice is signed" until then (accepted per maintainer comment 6341877062 on #1309: "no enemy units in play" means attacking and bordering no enemy that has a front). Taken, the order waits for End turn and can be withdrawn until then, as Send home is not an instant order (R-TURN-004); when it runs, it acts at once: the unit leaves the map and its strength, in population units, joins the nearest of the twelve cities as civilians without a job (owner, 22 October 2026, #1309: https://github.com/eyalgolan/statecraft-israel/issues/1309#issuecomment-6334162964: "nearest ... as unemployed civilians"), counting in the city's jobs and housing from the same turn; nearest by hex distance to the city's settlement hex, ties by the city's id (agent default - the ruling sets no tie break). The Why line states the count in people (Q-CIV-4): "Unit N is sent home: its P people are civilians in <city> now". A veteran keeps nothing (none suggested, #1309).diff --git a/sim/Statecraft.Sim.Tests/LedgerMilitaryServiceTests.cs b/sim/Statecraft.Sim.Tests/LedgerMilitaryServiceTests.csnew file mode 100644index 000000000..5d7c4b4d6--- /dev/null+++ b/sim/Statecraft.Sim.Tests/LedgerMilitaryServiceTests.cs@@ -0,0 +1,78 @@+using Statecraft.Sim;++/// <summary>#1725 PR 7, producer 11: formation service (R-UNIT-004) on a game with an initialized Historical ledger, the+/// dark start. Under exact gdd-0.3 service is a statistic only: a recruit formation gains its service turn and never+/// promotes (R-UNIT-011, Q16), and no ledger record changes (R-POP-002). Maintainer calls by coordinator eyalgolan-30,+/// 8 November 2026, not owner rulings: the guard is RefuseUnlessHistorical (Q1 a); service stays on the formation, with+/// no ledger field (Q2 a); Serve checks no strength (Q3 a); the dark start has no recruit, so these tests hand-place one+/// (Q4 a); Serve only, PayUpkeep keeps its own row (Q5 a).</summary>+public class LedgerMilitaryServiceTests+{+ static Content Gdd03() => HistoricalPopulationTests.Real(true);++ static GameState Dark(Content c) => Simulation.NewGame(c, 1, Mode.Historical, darkStart: true);++ // Q4 (a): a hand-placed Israeli recruit formation, on the hex of the first Israeli formation, with a fresh id.+ static int AddRecruit(GameState s, int service)+ {+ var at = s.Units.Values.First(u => u.Side == "israel");+ var id = s.Units.Keys.Max() + 1;+ s.Units[id] = new Unit(id, "recruit", at.Q, at.R, service, side: "israel", strength: 3);+ return id;+ }++ // R-UNIT-004, R-POP-002: the dark start's recruit gains one service turn and stays a recruit; every other unit and+ // the ledger (its records and its hash section, Canonical()) are unchanged, and the ledger still reconciles.+ [Fact]+ public void TheDarkStartServesARecruitFormation()+ {+ var c = Gdd03();+ var s = Dark(c);+ Assert.True(s.PopulationLedger.IsHistorical);+ var id = AddRecruit(s, 2);+ var others = s.Units.Values.Where(u => u.Id != id).Select(u => u.Canonical()).ToList();+ var ledger = s.PopulationLedger.Canonical().ToList();+ var why = new List<Cause>();+ Military.Serve(c, s, c.RulesAt(s.Date).Mvp!, why);+ var after = s.Units[id];+ Assert.Equal(("recruit", 3, "israel", 3), (after.Type, after.Service, after.Side, after.Strength));+ Assert.Equal(others, s.Units.Values.Where(u => u.Id != id).Select(u => u.Canonical()).ToList());+ Assert.Empty(why);+ s.PopulationLedger.Reconcile();+ Assert.Equal(ledger, s.PopulationLedger.Canonical().ToList());+ }++ // R-UNIT-004 re-pointed (Q16), R-UNIT-011: under gdd-0.3 a ledger game's recruit far beyond veteran_soldier_service+ // stays a recruit, with no RecruitsVeteran cause (as Gdd03CombatXpTests.Gdd03ServiceNeverPromotes on the aggregate game).+ [Fact]+ public void ServiceNeverPromotesOnALedgerGame()+ {+ var c = Gdd03();+ var s = Dark(c);+ var r = c.RulesAt(s.Date).Mvp!;+ var id = AddRecruit(s, r.VeteranSoldierService!.Value + 14);+ var ledger = s.PopulationLedger.Canonical().ToList();+ var why = new List<Cause>();+ Military.Serve(c, s, r, why);+ Assert.Equal(("recruit", r.VeteranSoldierService!.Value + 15), (s.Units[id].Type, s.Units[id].Service));+ Assert.DoesNotContain(why, w => w.Key == CauseKeys.RecruitsVeteran);+ Assert.Equal(ledger, s.PopulationLedger.Canonical().ToList());+ }++ // R-POP-002 (#1725 PR 7 review S2): only a ledger initialized with mode Historical is let through. An initialized Open+ // ledger, like a synthetic one (no mode), is still refused by Serve, with the state unchanged.+ [Theory]+ [InlineData(true)] [InlineData(false)]+ public void AnOpenOrSyntheticLedgerIsStillRefused(bool open)+ {+ var c = PopulationLedgerTests.Content();+ var s = PopulationLedger.CreateFixture(c, PopulationLedgerTests.Bindings(),+ new[] { new PopulationInventoryRow("fixture", 0, PopulationLedgerTests.Person()) }, mode: open ? Mode.Open : null);+ Assert.Equal((true, false), (s.PopulationLedger.IsInitialized, s.PopulationLedger.IsHistorical));+ s.Units[1] = new Unit(1, "recruit", 0, 1, 2, side: "israel", strength: 3);+ var why = new List<Cause>();+ var before = s.Describe(); var hash = s.Hash();+ Assert.Contains("integration is held", Assert.Throws<NotSupportedException>(() => Military.Serve(c, s, new MvpRules(), why)).Message);+ Assert.Equal(before, s.Describe()); Assert.Equal(hash, s.Hash()); Assert.Empty(why);+ }+}diff --git a/sim/Statecraft.Sim/Military.cs b/sim/Statecraft.Sim/Military.csindex 7f0f18c2a..348ead452 100644--- a/sim/Statecraft.Sim/Military.cs+++ b/sim/Statecraft.Sim/Military.cs@@ -8,10 +8,13 @@ namespace Statecraft.Sim{/// <summary>R-UNIT-004: recruits already in play serve this turn. Run before training completes, so training time/// never counts as service. Promotion preserves the formation and its standing order; combat adds no service. Under- /// exact gdd-0.3 service is a statistic only and never promotes: veterancy comes from combat experience (R-UNIT-011, Q16).</summary>+ /// exact gdd-0.3 service is a statistic only and never promotes: veterancy comes from combat experience (R-UNIT-011, Q16).+ /// It runs on an initialized Historical ledger (the dark start, #1725 PR 7): service stays on the formation, so it reads+ /// and writes no ledger record; a synthetic or Open ledger stays refused (R-POP-002). Maintainer calls by coordinator+ /// eyalgolan-30, 8 November 2026, not owner rulings.</summary>public static void Serve(Content c, GameState s, MvpRules r, List<Cause> why){- PopulationLedger.RefuseAggregate(s);+ PopulationLedger.RefuseUnlessHistorical(s); // #1725 PR 7: service is the formation's, no ledger fieldvar byService = !Gdd03Military.Applies(c);foreach (var u in s.Units.Values.ToList()){