A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: economy defeat after three exhausted turns (Phase 7 PR 5, economy half) (#989)
Beri4f4a3c61cad8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bdc581aa9..c74c787ff 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -28,6 +28,12 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIBshort, at most 2 starts a turn; `CancelProject(id)` returns no Money. The kinds are labelled design values in the new`content/projects.yaml` (Q-PROJ-1 to Q-PROJ-5, Q-HOUSE-3; R-PROJ-001 to R-PROJ-003; refs #735). The reference playerstarts a housing project, one at a time, where the overflow is largest, so `hash1950`, `hash1952` and `mvp-end` move.+- The game can be lost to the economy (GDD Phase 7 PR 5, D-B5; refs #8): Money is exhausted when the debt is at or above+ `mvp.debt_ceiling` (IL 250m) and Food when the national stock is 0 (R-END-001); three turn ends in a row with both+ (`mvp.defeat_turns`) end the game with `defeat_economy` (R-END-002). Both are labelled design values (Q-DEF-1, Q-DEF-2,+ #784). The state counts the turns (`ExhaustedTurns`, hashed only when above 0, so no existing golden moves), and the+ new `scenario-mvp-defeat` golden plays a run to the defeat. The war loss waits for Phase 5 (#749), and the defeat+ texts for the owner (Q-DEF-4).- Release gate: consequence cards and variants need a person's sign-off (`reviewed_by`) before a build is shared;`Statecraft.Cli --timeline-report` lists each road not taken and what follows it, and `Timeline.Entries` /`Timeline.Origin` give the timeline screen its rows (R-ALT-011; refs #939, #953).diff --git a/content/rules.yaml b/content/rules.yamlindex 326bfe24b..26918d6fd 100644--- a/content/rules.yaml+++ b/content/rules.yaml@@ -77,6 +77,12 @@ mvp:# design values", owner, 15 October 2026, #375); the owner may override them. Neither is a historical figure.housing_start_condition: 0.35 # DESIGN VALUE: owner-set balance, not a historical figure (D-D2, Q-START-3: every city's start condition)overflow_condition_loss: 0.15 # DESIGN VALUE: owner-set balance, not a historical figure (D-D1, Q-HOUSE-1: condition lost a turn at a full overflow share)+ # The economic defeat (R-END-001, R-END-002; D-B5). Money is exhausted when the debt is at or above debt_ceiling (Q-DEF-1,+ # owner, 17 October 2026, #784: "a debt ceiling", first value IL 250m, as recommended), Food when the national stock is+ # 0; defeat_turns turn ends in a row with both end the game (Q-DEF-2, owner, 18 October 2026, #784: "3 turns"). Neither+ # is a historical figure; the Phase 7 balance pass (PR 12) sets the final ceiling.+ defeat_turns: 3 # DESIGN VALUE: owner-set balance, not a historical figure (D-B5, Q-DEF-2: turn ends in a row with Money and Food exhausted)+ debt_ceiling: 250 # DESIGN VALUE: owner-set balance, not a historical figure (D-B5, Q-DEF-1: IL millions of debt at which Money is exhausted)# Coalition stability lost by replacing a minister (Cabinet.Appoint): a seat taken from the minister's party, or a# reshuffle within it.appoint_stability_cost_other_party: 0.06diff --git a/docs/determinism.md b/docs/determinism.mdindex 1130263f1..2bd8c2175 100644--- a/docs/determinism.md+++ b/docs/determinism.md@@ -81,9 +81,10 @@ them from a seed (default 1948) in Historical mode until `until:`, and `Scenarioscripted command passes. A command the sim rejects fails the test with the date, the order and the reason, and a step that never runsfails too. To add one: write the file, run `STATECRAFT_UPDATE_GOLDEN=1 dotnet test sim/Statecraft.sln --filter ScenarioTests` (it adds themanifest line and the snapshot), then run the tests plain. A scenario that moves is re-pinned with the hash goldens by the same-command; its snapshot diff in the PR shows what moved, and the commit message says why. All three play the real content.+command; its snapshot diff in the PR shows what moved, and the commit message says why. All four play the real content.`cautious` and `reckless` stay in 1948, so they move only when a 1948 rule or event does; `mvp-absorb-first` (GDD Phase 1-PR 3) fills Tel Aviv's jobs on the first turn and plays to 15 June 1949.+PR 3) fills Tel Aviv's jobs on the first turn and plays to 15 June 1949; `mvp-defeat` (GDD Phase 7 PR 5) overspends and+turns down every source of foreign currency until Money and Food run out, and ends in `defeat_economy` (R-END-002).**MVP goldens after the cutover.** The real game is the GDD game, so every golden above is an MVP golden. Each PR thatchanges an MVP rule or a design value (R-LOOP-005) moves the goldens it reaches, re-pins them in the same PR, adds a row to@@ -292,3 +293,4 @@ The hash reads the state keys, so it never sees a record outside its window. An| GDD Phase 3 PR 4 | 1950 | `9922495a` | city projects (R-PROJ-001 to R-PROJ-003, #735; Q-PROJ-1 to Q-PROJ-5, Q-HOUSE-3, owner, 15 October 2026, #375): the reference player's stated policy (D-A7) now starts a housing project, one at a time, in the city with the most overflow, on the first free hex next to it, borrowing as its other orders do. Its first start is on 1949-03-15 in Tel Aviv, built on 1949-08-15 (+5 capacity, +0.03 condition); the second is being built. `cproj[...]` joins the state; `mapturn` now counts the turn's project starts. Tel Aviv's capacity 253 (was 248) and condition 0.0168 (was 0), so `housing` 0.0932 (was 0.0850), `morale` 0.5018 (was 0.4990), stability 0.5002 (was 0.4970); debt IL 91.5m (was 79.5m, 2 x IL 6m); rebased on Kiryat Shmona and Beit Shemesh (#944) and the event city effect (#1001) (was `69ac1384`) || GDD Phase 3 PR 4 | 1952 | `548a6acc` | same; five Tel Aviv projects built (1949-08-15 to 1951-08-15; capacity 273, was 248) and a sixth, in Haifa, being built. Every city is back at condition 0 by the end, so `housing` is unchanged and `morale` moves only in the 10th decimal; debt IL 223.9m (was 187.9m, 6 x IL 6m), inside invariants.yaml's 100 to 300 band; stability 0.4432 (unchanged to 4 places) (was `b34faec6`) || GDD Phase 3 PR 4 | mvp-end | `548a6acc` | same; the same run as hash1952 (was `b34faec6`) |+| GDD Phase 7 PR 5 | scenario-mvp-defeat | `d1e0dcf6` | new: full mobilisation and the non-historical option of the four foreign currency cards; the debt passes the IL 250m ceiling on 15 April 1951, foreign currency runs out on 15 August, food imports stop, the stock is empty from 15 November, and the third turn end with Money and Food both exhausted ends the game with `defeat_economy` on 15 January 1952 (`exhausted=3`). No other golden moves: the reference and the no-order runs never have Food at 0, so the counter stays at 0 and out of the hash. Rebased on the Hula swamp (#968): `hula_drainage` no longer fires in this run (no works at the Hula) and, as in the 1952 run on main, `iraqi_exodus` resolves to `airlift` (was `pace`), so the end state differs; the defeat dates above are unchanged (was `cbebedfa` before the rebase) |diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex b66e8f96e..59076eab6 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -142,6 +142,14 @@ R-FOOD-002: In step 7 the nation eats the turn's need from the stock as far as iR-FOOD-003: `food_supply` stays the 0 to 1 level the UI, the situations and the events read (Q-POOL-3, decided 15 October 2026), with a stock term inside its effect sum: `k_food * (stock - full) / full - unmet / need`, where `full` is `cover_months` of the last need. The term is exactly 0 at a full stock, `-k_food` when the stock is empty, and the unmet share lowers it further; rationing, the other effects and event shifts act on top as before, and the level's clamp to 0..1 bounds the result. The GDD loop requires the `food_supply` indicator.+## Defeat++The game can be lost (D-B5, decided: "Money and Food exhausted for N turns, or a war loss. Values for the owner. Coalition collapse is off in the MVP"; Phase 7 PR 5, #8). This part covers the economic defeat; the war loss waits for Phase 5's enemy units (#749). The defeat texts are the owner's pick (Q-DEF-4, #784, open): until then the game ends with the code `defeat_economy`, and its reason reads "Money and Food ran out", the plan's short option (a).++R-END-001: Money is exhausted when the debt is at or above `debt_ceiling` (Q-DEF-1, owner, 17 October 2026, #784: a debt ceiling; below it borrowing goes on as R-MONEY-003 allows). Food is exhausted when the national stock is 0 (R-FOOD-002; Q-POOL-5, "The stock stops at 0"). One of them alone ends nothing. `debt_ceiling` is IL 250m, a labelled design value (the recommended first value; the Phase 7 balance pass, PR 12, sets the final number), required in the GDD loop, a finite number >= 0.++R-END-002: In the resolver's last step, after the objectives and the score (spec §2.3, step 11), a turn end with Money and Food both exhausted adds 1 to `ExhaustedTurns`, and any other turn end sets it back to 0. When it reaches `defeat_turns`, the game ends with `defeat_economy` and a cause in the turn's causes, under the game's end (`era`) like the MVP end. `defeat_turns` is 3, a labelled design value (Q-DEF-2, owner, 18 October 2026, #784: "3 turns"), required in the GDD loop, at least 1. The step reads the debt as it finds it: the turn's deficit is borrowed after the resolution, so it counts from the next turn's end. A defeat on the game's last turn ends it as a defeat. `ExhaustedTurns` is in the state hash only when above 0, so a run that never has both exhausted hashes as before; the legacy loop never counts.+## GovernmentD-C5 as decided (12 October 2026): the cabinet and Attention stay, the coalition is optional with no collapse. The coalition votes, the budget shares and the policies keep running and visible as before (Q-GOV-1, decided 15 October 2026, "Take all recommendations", #375). The defeat (D-B5) is built in Phase 7 (Q-GOV-2, decided the same day).diff --git a/sim/Statecraft.Sim.Tests/DefeatTests.cs b/sim/Statecraft.Sim.Tests/DefeatTests.csnew file mode 100644index 000000000..ddc65d574--- /dev/null+++ b/sim/Statecraft.Sim.Tests/DefeatTests.cs@@ -0,0 +1,203 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>The economic defeat (GDD Phase 7 PR 5, D-B5; #8): Money is exhausted when the debt is at or above+/// mvp.debt_ceiling (Q-DEF-1) and Food when the national stock is 0 (R-END-001); after mvp.defeat_turns consecutive turn+/// ends with both, the game ends with defeat_economy (Q-DEF-2, N = 3), and a turn with either one not exhausted resets the+/// count (R-END-002). The war loss waits for Phase 5's enemy units (#749).</summary>+public class DefeatTests+{+ static readonly Content Real = ContentLoader.Load(RealContentTests.ContentRoot());++ /// <summary>The GDD fixture with a ceiling of IL 10m and N = 3 (fixture values, not the game's).</summary>+ static Content Gdd(string defeat = " defeat_turns: 3\n debt_ceiling: 10\n")+ {+ var files = Fixture.Gdd();+ files["rules.yaml"] = files["rules.yaml"].Replace(" defeat_turns: 3\n debt_ceiling: 10\n", "").Replace("mvp:\n", "mvp:\n" + defeat);+ return ContentLoader.Load(Fixture.Write(files));+ }++ static GameState Step(Content c, GameState s) => Simulation.Step(c, s, Array.Empty<Command>()).State;++ /// <summary>Money exhausted: the debt at the ceiling. Borrowing only adds to the debt, so it stays exhausted.</summary>+ static void Broke(GameState s, double debt = 10) => s.Debt = debt;++ /// <summary>Food exhausted and kept so: an empty stock, and a foreign currency crisis deep enough to last, so nothing+ /// is imported (R-FOOD-002).</summary>+ static void Starving(GameState s)+ {+ s.Food = 0;+ s.FxReserves = -1e9;+ s.ActiveSituations.Add(EconomySystem.FxCrisis);+ }++ // R-END-002+ [Fact]+ public void NTurnsExhaustedEndsTheGame()+ {+ var c = Gdd();+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ Broke(s); Starving(s);+ for (int turn = 1; turn <= 2; turn++)+ {+ s = Step(c, s);+ Assert.Equal(turn, s.ExhaustedTurns);+ Assert.Null(s.GameOver);+ }+ var last = Simulation.Step(c, s, Array.Empty<Command>());+ Assert.Equal(3, last.State.ExhaustedTurns);+ Assert.Equal(GameOverCodes.DefeatEconomy, last.State.GameOver);+ Assert.Contains(last.Why, w => w.System == "era" && w.Target == GameOverCodes.DefeatEconomy);+ // The game is over: an order is refused with the reason, and the turn does not advance.+ var after = Simulation.Step(c, last.State, new Command[] { new SetMobilization(0.5) });+ Assert.Single(after.Rejected);+ Assert.Equal(last.State.Date, after.State.Date);+ }++ // R-END-002+ [Fact]+ public void NMinusOneDoesNotAndARecoveryResetsTheCount()+ {+ var c = Gdd();+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ Broke(s); Starving(s);+ s = Step(c, Step(c, s));+ Assert.Equal(2, s.ExhaustedTurns);+ Assert.Null(s.GameOver);++ // The crisis ends and food is imported again: the count goes back to 0, and the next run of empty turns starts at 1.+ s.ActiveSituations.Remove(EconomySystem.FxCrisis);+ s.FxReserves = 1e9;+ s = Step(c, s);+ Assert.True(s.Food > 0);+ Assert.Equal(0, s.ExhaustedTurns);+ Starving(s);+ s = Step(c, s);+ Assert.Equal(1, s.ExhaustedTurns);+ Assert.Null(s.GameOver);+ }++ // R-END-001+ [Fact]+ public void OneResourceAloneNeverEndsIt()+ {+ var c = Gdd();+ // Money exhausted, Food in stock (imports go on).+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ Broke(s, 1000);+ for (int i = 0; i < 6; i++) s = Step(c, s);+ Assert.True(s.Food > 0);+ Assert.Equal(0, s.ExhaustedTurns);+ Assert.Null(s.GameOver);++ // Food exhausted, the debt one step below the ceiling.+ var t = Simulation.NewGame(c, 1, Mode.Historical);+ Starving(t);+ t.Treasury = 1e9; // no shortfall, so nothing is borrowed+ t.Debt = Math.BitDecrement(10.0);+ for (int i = 0; i < 6; i++) t = Step(c, t);+ Assert.Equal(0, t.Food);+ Assert.True(t.Debt < 10);+ Assert.Equal(0, t.ExhaustedTurns);+ Assert.Null(t.GameOver);+ }++ // R-END-002: the count is the rules' N, read from rules.yaml.+ [Fact]+ public void NComesFromTheRules()+ {+ var c = Gdd(" defeat_turns: 1\n debt_ceiling: 10\n");+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ Broke(s); Starving(s);+ Assert.Equal(GameOverCodes.DefeatEconomy, Step(c, s).GameOver);+ }++ // R-END-001, R-END-002: the owner's values (Q-DEF-1: IL 250m; Q-DEF-2: 3 turns), labelled design values.+ [Fact]+ public void TheRealRulesCarryTheOwnersValues()+ {+ Assert.Equal(3, Real.Rules.Mvp!.DefeatTurns);+ Assert.Equal(250.0, Real.Rules.Mvp!.DebtCeiling);+ }++ // R-END-001, R-END-002: both values are required in the GDD loop, so a missing key is never read as 0 (a defeat on+ // the first turn with no debt, or no defeat at all).+ [Theory]+ [InlineData(" defeat_turns: 3\n debt_ceiling: 10\n", " debt_ceiling: 10\n", "mvp.defeat_turns", "required")]+ [InlineData(" defeat_turns: 3\n debt_ceiling: 10\n", " defeat_turns: 3\n", "mvp.debt_ceiling", "required")]+ [InlineData(" defeat_turns: 3\n debt_ceiling: 10\n", " defeat_turns: 0\n debt_ceiling: 10\n", "mvp.defeat_turns", ">= 1")]+ [InlineData(" defeat_turns: 3\n debt_ceiling: 10\n", " defeat_turns: 3\n debt_ceiling: -1\n", "mvp.debt_ceiling", ">= 0")]+ [InlineData(" defeat_turns: 3\n debt_ceiling: 10\n", " defeat_turns: 3\n debt_ceiling: .inf\n", "mvp.debt_ceiling", ">= 0")]+ public void TheDefeatValuesAreRequiredAndInRange(string line, string replacement, string field, string reason)+ {+ var files = Fixture.Gdd();+ Assert.Contains(line, files["rules.yaml"]);+ files["rules.yaml"] = files["rules.yaml"].Replace(line, replacement);+ var e = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(files)));+ Assert.Contains(field, e.Message);+ Assert.Contains(reason, e.Message);+ }++ // R-END-002 (plan risk 3): the reference run and the Historical-mode run with no orders reach 15 January 1952 and+ // are never defeated, so the existing goldens do not move.+ [Fact]+ public void TheHistoricalRunIsNeverDefeated()+ {+ foreach (var (name, orders) in new (string, Func<GameState, IReadOnlyList<Command>>)[]+ {+ ("reference", s => GoldenRun.Orders(Real, s)),+ ("no orders", _ => Array.Empty<Command>()),+ })+ {+ var s = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);+ while (s.GameOver == null)+ {+ s = Simulation.Step(Real, s, orders(s)).State;+ Assert.True(s.ExhaustedTurns == 0, $"{name}: Money and Food both exhausted on {s.Date:yyyy-MM-dd}");+ }+ Assert.Equal(GameOverCodes.MvpEnded, s.GameOver);+ Assert.Equal(Real.End, s.Date);+ }+ }++ // R-END-001, R-END-002: scenario-mvp-defeat overspends and refuses foreign currency until it is defeated.+ [Fact]+ public void TheDefeatScenarioEndsInDefeat()+ {+ var sc = Scenario.Parse(System.IO.File.ReadAllText(System.IO.Path.Combine(ScenarioTests.Dir(), "mvp-defeat.yaml")));+ var s = sc.Play(Real);+ Assert.Equal(GameOverCodes.DefeatEconomy, s.GameOver);+ Assert.Equal(Real.Rules.Mvp!.DefeatTurns, s.ExhaustedTurns);+ Assert.Equal(0, s.Food);+ Assert.True(s.Debt >= Real.Rules.Mvp!.DebtCeiling);+ }++ // R-END-002, R-LOOP-002: the counter is in the hash only when above 0, so a state that never had both exhausted+ // hashes as before.+ [Fact]+ public void TheCounterIsHashedOnlyWhenSet()+ {+ var s = new GameState();+ var before = s.Hash();+ Assert.DoesNotContain("exhausted=", s.Describe());+ s.ExhaustedTurns = 1;+ Assert.Contains("exhausted=1", s.Describe());+ Assert.NotEqual(before, s.Hash());+ s.ExhaustedTurns = 0;+ Assert.Equal(before, s.Hash());+ }++ // R-END-002: the counter belongs to the GDD loop; a legacy game never counts.+ [Fact]+ public void TheLegacyLoopNeverCounts()+ {+ var c = ContentLoader.Load(Fixture.Write());+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ s.Debt = 1e9; s.Food = 0;+ s = Step(c, s);+ Assert.Equal(0, s.ExhaustedTurns);+ Assert.Null(s.GameOver);+ }+}diff --git a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs b/sim/Statecraft.Sim.Tests/DesignValuesTests.csindex bc22afe93..d828aa478 100644--- a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs+++ b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs@@ -42,6 +42,8 @@ public class DesignValuesTests("rules.yaml", "mvp.veteran_progress"),("rules.yaml", "mvp.housing_start_condition"),("rules.yaml", "mvp.overflow_condition_loss"),+ ("rules.yaml", "mvp.defeat_turns"),+ ("rules.yaml", "mvp.debt_ceiling"),// Q-START-1 (owner, 15 October 2026, #375): no city has a sourced housing stock or job count, so every city's// housing is its start people and its job slots its start employed; seven towns with no CBS working share take// the national one. The census people and the five CBS shares are sourced, not design values (R-CITY-006).diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.csindex ce1887fe0..990ef57f6 100644--- a/sim/Statecraft.Sim.Tests/Fixture.cs+++ b/sim/Statecraft.Sim.Tests/Fixture.cs@@ -239,6 +239,8 @@ mvp:veteran_progress: 2housing_start_condition: 0.5overflow_condition_loss: 0.2+ defeat_turns: 3+ debt_ceiling: 10";public static readonly string GddCities = "\ncities:\n" + City("town_a", 12, 8, 10, 6, "[military_camp, hakhshara]");diff --git a/sim/Statecraft.Sim.Tests/golden/manifest.txt b/sim/Statecraft.Sim.Tests/golden/manifest.txtindex 238eda44b..86ed62b3c 100644--- a/sim/Statecraft.Sim.Tests/golden/manifest.txt+++ b/sim/Statecraft.Sim.Tests/golden/manifest.txt@@ -9,3 +9,4 @@ scenario-reckless 8041988a2c6b5b72a8351fd79ab07c2afca0672f686586cc8b7f9777c20610scenario-cautious 6507ddc31437eaf8b0a8858a84c539860dcd7a6febacb0f1d142cb59489e2a9fscenario-mvp-absorb-first a77a8f20063c741a680a964e3824946dfee27b5675b9cead5e23bbf4bd146183mvp-end 548a6acce93c677f566e7d6febdeb50ed6aeba0e4f61a884708ef0fc38774d87+scenario-mvp-defeat d1e0dcf687c6af5431c08d319bba128b3b13a84545162320911d3c2b82eea1d1diff --git a/sim/Statecraft.Sim.Tests/golden/scenario-mvp-defeat.txt b/sim/Statecraft.Sim.Tests/golden/scenario-mvp-defeat.txtnew file mode 100644index 000000000..f3e2789e9--- /dev/null+++ b/sim/Statecraft.Sim.Tests/golden/scenario-mvp-defeat.txt@@ -0,0 +1,137 @@+1952-01-15;8709371129873692656;Historical;44;+ind{+ food_supply=0 [0000000000000000]+ housing=0.08504947742483629 [3FB5C5CD7414E142]+ intl_standing=0.8100000000000003 [3FE9EB851EB851EE]+ morale=0.6946063955988723 [3FE63A3731161129]+ security=0.5061322526321603 [3FE0323C441030A6]+pol{+ border_settlement=0.2 [3FC999999999999A]+ housing_construction=0.3 [3FD3333333333333]+ maabarot=1 [3FF0000000000000]+ rationing=0 [0000000000000000]+eff{+ border_villages_secure=0.04113225263216018 [3FA50F495FBB5C36]+ building_houses=0.08504947742483629 [3FB5C5CD7414E142]+ food_lifts_cohesion=0.012063175589914928 [3F88B49405281EDE]+ homes_lift_morale=0.012767192434855364 [3F8A25AF8FC16B04]+ rationing_feeds=0 [0000000000000000]+ rationing_grates=0 [0000000000000000]+ safety_lifts_morale=0.05054370052651369 [3FA9E0DD298F75A0]+ work_lifts_cohesion=0.0192323270475882 [3F93B1A39EC80E6F]+shift{+ food_supply=-0.04999999999999999 [BFA9999999999998]+ housing=0 [0000000000000000]+ intl_standing=0.3100000000000003 [3FD3D70A3D70A3DC]+ morale=0.050000000000000044 [3FA99999999999A0]+ security=0.16500000000000015 [3FC51EB851EB8524]+bud{+ agriculture_minister=0.07 [3FB1EB851EB851EC]+ defense_minister=0.45 [3FDCCCCCCCCCCCCD]+ education_minister=0.06 [3FAEB851EB851EB8]+ finance_minister=0.05 [3FA999999999999A]+ health_minister=0.07 [3FB1EB851EB851EC]+ interior_minister=0.05 [3FA999999999999A]+ labour_minister=0.1 [3FB999999999999A]+ prime_minister=0.15 [3FC3333333333333]+pop{+ africa=96949.99317400213 [40F7AB5FE40A6C26]+ america_oceania=5289.453220790847 [40B4A97406471A8E]+ asia=243048.8631066492 [410DAB46E7A4757A]+ europe=338908.0345349915 [4114AF70235D240C]+ unknown=25443.180026717586 [40D8D8CB858EC81C]+ veterans=690883.9968027371 [41251587FE5CEDA9]+sit[+ food_crisis+ fx_crisis+ housing_crisis+treasury=0 [0000000000000000]+debt=339.14012071283804 [4075323DEF37721B]+fx=-74.99043132809655 [C052BF633A14C6F2]+rung=2;cf=0;+mob=1 [3FF0000000000000]+stab=0.4570368468090611 [3FDD401779872908]+att=4 [4010000000000000]+fired[+ altalena+ armistice_egypt+ armistice_jordan+ armistice_lebanon+ armistice_syria+ austerity_1949+ bernadotte_assassination+ clothing_rationing_1950+ education_registration_1951+ elections_1949+ first_truce+ forex_crisis_1951+ frumkin_commission+ idf_founding+ iraqi_exodus+ israel_bonds+ jerusalem_ceasefire+ jerusalem_military_government+ latrun_proposal+ law_of_return+ maabarot_policy+ ministry_supply_crisis+ operation_hiram+ operation_horev+ operation_yoav+ reparations_claim+ rhodes_talks+ second_truce+ sinai_withdrawal+ ten_days+pending[+chosen{+ altalena=enforce+ armistice_egypt=sign+ armistice_jordan=sign+ armistice_lebanon=sign+ armistice_syria=sign+ austerity_1949=decline+ bernadotte_assassination=outlaw+ clothing_rationing_1950=relax+ education_registration_1951=press_plan+ elections_1949=hold+ first_truce=accept+ forex_crisis_1951=request_aid+ frumkin_commission=inquiry+ idf_founding=one_army+ iraqi_exodus=airlift+ israel_bonds=donations_only+ jerusalem_ceasefire=keep+ jerusalem_military_government=military_government+ latrun_proposal=accept_vote+ law_of_return=enact+ maabarot_policy=maabarot+ ministry_supply_crisis=restructure+ operation_hiram=stop_at_ceasefire+ operation_horev=launch+ operation_yoav=stop_at_ceasefire+ reparations_claim=refuse+ rhodes_talks=send_delegation+ second_truce=comply+ sinai_withdrawal=withdraw+ ten_days=central_front+appt{+under=;+map[+mapturn=0001-01-01:0;+over=defeat_economy+city{+ hadera=12,5,26,5,0,c0 [0000000000000000]+ haifa=99,42,215,42,2,c0 [0000000000000000]+ jerusalem=84,29,183,29,1,c0 [0000000000000000]+ netanya=12,5,25,5,1,c0 [0000000000000000]+ petah_tikva=22,10,48,10,0,c0 [0000000000000000]+ rehovot=13,5,28,5,0,c0 [0000000000000000]+ rishon_lezion=10,5,22,5,0,c0 [0000000000000000]+ rosh_pinna=1,0,2,0,0,c0 [0000000000000000]+ safed=2,1,5,1,0,c0 [0000000000000000]+ tel_aviv=248,106,541,106,4,c0 [0000000000000000]+ tiberias=6,2,13,2,0,c0 [0000000000000000]+ zikhron_yaakov=2,1,4,1,0,c0 [0000000000000000]+food=0,1390,1390+exhausted=3\ No newline at end of filediff --git a/sim/Statecraft.Sim.Tests/scenarios/mvp-defeat.yaml b/sim/Statecraft.Sim.Tests/scenarios/mvp-defeat.yamlnew file mode 100644index 000000000..2e2380ce2--- /dev/null+++ b/sim/Statecraft.Sim.Tests/scenarios/mvp-defeat.yaml@@ -0,0 +1,25 @@+# A player who overspends and turns down every source of foreign currency (GDD Phase 7 PR 5, D-B5): full mobilisation+# from the first turn, then the non-historical option of each foreign currency card (no austerity, clothing rationing+# relaxed, no reparations claim, donations instead of Israel Bonds). The debt passes the ceiling in April 1951, foreign+# currency runs out in August, food imports stop, and after three turn ends with Money and Food both exhausted the game+# ends with defeat_economy on 15 January 1952 (R-END-001, R-END-002), the game's last day: a defeat on the last turn is+# a defeat. A balance change that delays the third empty turn makes this run end as mvp_ended, and DefeatTests says so.+# It plays the real content, so it moves whenever a rule or value it reaches changes.+name: mvp-defeat+until: 1952-01-15+steps:+ - on: 1948-05-15+ commands:+ - { kind: set_mobilization, level: 1.0 }+ - on: 1949-05-15+ commands:+ - { kind: choose_event_option, event: austerity_1949, option: decline }+ - on: 1950-07-15+ commands:+ - { kind: choose_event_option, event: clothing_rationing_1950, option: relax }+ - on: 1951-03-15+ commands:+ - { kind: choose_event_option, event: reparations_claim, option: refuse }+ - on: 1951-05-15+ commands:+ - { kind: choose_event_option, event: israel_bonds, option: donations_only }diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex a4b8c9235..12dba04b9 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -519,6 +519,12 @@ namespace Statecraft.Sim/// <summary>How far a city's housing condition falls in a turn when all its people are beyond its housing; a turn takes/// this times the city's overflow share (R-HOUSE-002; D-D1, Q-HOUSE-1). Required in the GDD loop, 0 to 1.</summary>public double? OverflowConditionLoss { get; set; }+ /// <summary>Consecutive turn ends with Money and Food both exhausted that end the game (R-END-002; D-B5, Q-DEF-2).+ /// Required in the GDD loop, at least 1.</summary>+ public int? DefeatTurns { get; set; }+ /// <summary>The debt, in IL millions, at or above which Money is exhausted (R-END-001; D-B5, Q-DEF-1). Required in the+ /// GDD loop, a finite number >= 0.</summary>+ public double? DebtCeiling { get; set; }}/// <summary>A kind of city project (projects.yaml; GDD "Cities and construction"; R-PROJ-001 to R-PROJ-003): permanentdiff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex 2848192c9..6a6a37c47 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -1092,6 +1092,11 @@ namespace Statecraft.SimUnit(file, "mvp.housing_start_condition", m.HousingStartCondition.Value);if (m.OverflowConditionLoss == null) throw new ContentException(file, "mvp.overflow_condition_loss", "required when eras.yaml systems.loop is gdd");Unit(file, "mvp.overflow_condition_loss", m.OverflowConditionLoss.Value);+ // R-END-001, R-END-002: required, so a missing key is never read as 0 (a defeat with no debt, or on the first turn).+ if (m.DefeatTurns == null) throw new ContentException(file, "mvp.defeat_turns", "required when eras.yaml systems.loop is gdd");+ if (m.DefeatTurns < 1) throw new ContentException(file, "mvp.defeat_turns", "must be >= 1");+ if (m.DebtCeiling == null) throw new ContentException(file, "mvp.debt_ceiling", "required when eras.yaml systems.loop is gdd");+ if (!(m.DebtCeiling >= 0 && IsFinite(m.DebtCeiling.Value))) throw new ContentException(file, "mvp.debt_ceiling", "must be a finite number >= 0");if (c.Indicators.All(i => i.Id != Pools.FoodIndicator))throw new ContentException(file, "mvp.k_food", "the Food stock feeds the food_supply indicator, which model.yaml must define");// One game has one last day (R-LOOP-004): an era cannot move it.diff --git a/sim/Statecraft.Sim/GameState.cs b/sim/Statecraft.Sim/GameState.csindex 496e75682..0565d1686 100644--- a/sim/Statecraft.Sim/GameState.cs+++ b/sim/Statecraft.Sim/GameState.cs@@ -15,6 +15,8 @@ namespace Statecraft.Sim/// <summary>The GDD game's last day was reached (rules.yaml mvp.end, R-LOOP-004).</summary>public const string MvpEnded = "mvp_ended";public const string CoalitionCollapse = "coalition_collapse";+ /// <summary>Money and Food were both exhausted for mvp.defeat_turns turn ends in a row (R-END-002; D-B5).</summary>+ public const string DefeatEconomy = "defeat_economy";}public enum Mode { Historical, Open }@@ -81,6 +83,8 @@ namespace Statecraft.Simpublic int FoodNeed;/// <summary>The part of <see cref="FoodNeed"/> the stock could not cover in the last turn (R-FOOD-002, Q-POOL-5).</summary>public int FoodUnmet;+ /// <summary>Consecutive turn ends with Money and Food both exhausted (R-END-001, R-END-002); 0 when either was not.</summary>+ public int ExhaustedTurns;public double TotalPopulation => Population.Values.Sum();@@ -202,6 +206,7 @@ namespace Statecraft.Simsb.Append("food=").Append(Food.ToString(CultureInfo.InvariantCulture)).Append(',').Append(FoodNeed.ToString(CultureInfo.InvariantCulture)).Append(',').Append(FoodUnmet.ToString(CultureInfo.InvariantCulture));}+ if (ExhaustedTurns != 0) { Sep(); Nl(); sb.Append("exhausted=").Append(ExhaustedTurns.ToString(CultureInfo.InvariantCulture)); }return sb.ToString();}}diff --git a/sim/Statecraft.Sim/PlayerText.cs b/sim/Statecraft.Sim/PlayerText.csindex c9968c117..9abf2f54e 100644--- a/sim/Statecraft.Sim/PlayerText.cs+++ b/sim/Statecraft.Sim/PlayerText.cs@@ -21,6 +21,8 @@ namespace Statecraft.SimGameOverCodes.EraEnded => "The chapter has ended",GameOverCodes.MvpEnded => "The game has reached its last turn",GameOverCodes.CoalitionCollapse => "The coalition collapsed",+ // Interim: the plan's short option (a) wording. The defeat texts are the owner's pick (Q-DEF-4, #784, open).+ GameOverCodes.DefeatEconomy => "Money and Food ran out",_ => throw Unknown("game over reason", code),};diff --git a/sim/Statecraft.Sim/TurnResolver.cs b/sim/Statecraft.Sim/TurnResolver.csindex eb60ed1e6..ded496593 100644--- a/sim/Statecraft.Sim/TurnResolver.cs+++ b/sim/Statecraft.Sim/TurnResolver.cs@@ -26,6 +26,19 @@ namespace Statecraft.SimCities.Arrive(c, s, r, next, why); // 9. arrivals// 10. Occupation timers: Phase 6.Objectives.Complete(c, s, r, next, why); // 11. objectives and score+ Defeat(s, r, why); // then the defeat (D-B5); the war loss waits for Phase 5+ }++ /// <summary>R-END-001, R-END-002: counts the turn ends with Money (the debt at or above mvp.debt_ceiling) and Food (an+ /// empty national stock) both exhausted; a turn with either not exhausted resets the count, and mvp.defeat_turns in a+ /// row end the game. The debt is read as this step finds it: the turn's deficit is borrowed after the resolution, so+ /// it counts from the next turn's end.</summary>+ static void Defeat(GameState s, MvpRules r, List<Cause> why)+ {+ s.ExhaustedTurns = s.Debt >= r.DebtCeiling!.Value && s.Food == 0 ? s.ExhaustedTurns + 1 : 0;+ if (s.ExhaustedTurns < r.DefeatTurns!.Value) return;+ s.GameOver = GameOverCodes.DefeatEconomy;+ why.Add(new Cause("era", s.GameOver, s.ExhaustedTurns, PlayerText.GameOver(s.GameOver))); // the game's end, grouped with the MVP end}}}