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.

Preserve gdd-0.3 play after city loss (Refs #1711) (#1841)

Eyal Golan83953b9623f8
diff --git a/changelog.d/1711-no-city-loss-defeat.md b/changelog.d/1711-no-city-loss-defeat.md
new file mode 100644
index 000000000..78ff22140
--- /dev/null
+++ b/changelog.d/1711-no-city-loss-defeat.md
@@ -0,0 +1,3 @@
+### Fixed
+
+- Under gdd-0.3, an enemy holding a city no longer ends the game. Economic and dated ends still apply; legacy and gdd-0.1 keep their existing rules. (Refs #1711)
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 4061180e0..37e00ee8f 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -384,13 +384,15 @@ R-ARMS-003: Recruit training (R-TRAIN-001) takes `arms_per_recruit_group` (1) Ar
## 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 both defeats: the economic one (R-END-001, R-END-002) and the war loss (R-END-003). The defeat texts are decided (Q-DEF-4 (b), owner, 18 October 2026, #784): a short factual line per cause - "Money and Food ran out" and "The enemy holds a city" - plus one sourced history note beside each, which goes on the end screen with #812.
+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 (R-END-001, R-END-002), which remains in gdd-0.3, and the gdd-0.1 war loss (R-END-003). The defeat texts are decided (Q-DEF-4 (b), owner, 18 October 2026, #784): a short factual line per cause - "Money and Food ran out" and "The enemy holds a city" - plus one sourced history note beside each, which goes on the end screen with #812.
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.
-R-END-003: When an enemy military unit (a unit with a `side` other than the player's; a halutz has no side, R-UNIT-001) holds the hex of one of the player's GDD cities (`cities.yaml`; the hex in `map/settlement_hexes.yaml`) at the end of a turn, the game ends at once with `defeat_war` and a cause in the turn's causes, under the game's end (`era`). One turn is enough, any of the GDD cities, at any time, truces included (Q-WAR-5; Q-DEF-3, owner, 17 October 2026, #784). The check runs in the resolver's last step after the economic count (R-END-002), so a turn the economic defeat also ends keeps `defeat_economy`.
+R-END-003: Under gdd-0.1, when an enemy military unit (a unit with a `side` other than the player's; a halutz has no side, R-UNIT-001) holds the hex of one of the player's GDD cities (`cities.yaml`; the hex in `map/settlement_hexes.yaml`) at the end of a turn, the game ends at once with `defeat_war` and a cause in the turn's causes, under the game's end (`era`). One turn is enough, any of the GDD cities, at any time, truces included (Q-WAR-5; Q-DEF-3, owner, 17 October 2026, #784). The check runs in the resolver's last step after the economic count (R-END-002), so a turn the economic defeat also ends keeps `defeat_economy`.
+
+Under the explicit `gdd-0.3` ruleset, this city-loss check is skipped before scanning cities or units: losing a city or region alone does not set `GameOver` or emit a `defeat_war` cause. The existing economic and dated ends retain their order; an already-ended game is never revived. Authority: the owner's two rulings recorded on 25 October 2026 on #1668, [“there is an economic defeat”](https://github.com/eyalgolan/statecraft-israel/pull/1668#issuecomment-6403926601) and [city or region loss does not end the game](https://github.com/eyalgolan/statecraft-israel/pull/1668#issuecomment-6403936877). This exception does not implement region transfer, evacuation, recapture or new enemy capture permissions (R-CTRL-006 remains unbuilt); it changes no legacy or gdd-0.1 rule.
## The end report
diff --git a/sim/Statecraft.Sim.Tests/NoCityLossDefeatTests.cs b/sim/Statecraft.Sim.Tests/NoCityLossDefeatTests.cs
new file mode 100644
index 000000000..ce86c179e
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/NoCityLossDefeatTests.cs
@@ -0,0 +1,163 @@
+using Statecraft.Sim;
+
+/// <summary>#1711 adopted slice only. Occupation is injected into fixture state: this does not authorize enemy capture.</summary>
+public class NoCityLossDefeatTests
+{
+ static Content Load(string ruleset = SaveGame.Gdd03Ruleset)
+ {
+ var files = Fixture.Gdd(new Dictionary<string, string>
+ {
+ ["unit_types.yaml"] = Fixture.GddUnitTypes +
+ " - { id: enemy, kind: unit, side: egypt, class: infantry, movement_points: 3 }\n",
+ ["corridors.yaml"] = "corridors: []\n",
+ });
+ var loop = ruleset == SaveGame.LegacyRuleset ? "legacy" : "gdd";
+ files["eras.yaml"] = Fixture.Files["eras.yaml"] + $" systems: {{ loop: {loop}, ruleset: {ruleset} }}\n";
+ files["cities.yaml"] += Fixture.City("town_b", 12, 8, 10, 6);
+ files["map/settlement_hexes.yaml"] = Fixture.Files["map/settlement_hexes.yaml"] + " - { id: town_b, q: 3, r: 1 }\n";
+ files["map/settlements_1948.yaml"] = Fixture.Files["map/settlements_1948.yaml"] +
+ " - { id: town_b, name: Town B, lon: 34.51, lat: 33.28, type: town, founded: 1900, pre_modern: false }\n";
+ files["map/locations_1948.yaml"] = Fixture.Files["map/locations_1948.yaml"] +
+ Fixture.Files["map/locations_1948.yaml"].Replace("locations:\n", "").Replace("town_a", "town_b")
+ .Replace("Town A", "Town B").Replace("עיר א", "עיר ב").Replace("34.29", "34.51")
+ .Replace("33.35", "33.28").Replace("q: 1", "q: 3").Replace("r: 0", "r: 1");
+ if (ruleset == SaveGame.Gdd03Ruleset)
+ files[Gdd03BalanceCatalogue.FileName] = File.ReadAllText(Path.Combine(RealContentTests.ContentRoot(), Gdd03BalanceCatalogue.FileName));
+ return ContentLoader.Load(Fixture.Write(files));
+ }
+
+ static void Occupy(GameState s, int q = 1, int r = 0, int id = 1) =>
+ s.Units.Add(id, new Unit(id, "enemy", q, r, side: "egypt", strength: 3));
+
+ static void Exhaust(GameState s)
+ {
+ s.Debt = 10; s.Food = 0; s.FxReserves = -1e9;
+ s.ActiveSituations.Add(EconomySystem.FxCrisis);
+ }
+
+ // R-END-003: every fixture city, multiple cities, ordinary dates and truce dates; no war-loss cause either.
+ [Theory]
+ [InlineData(1, 0, false, false)]
+ [InlineData(3, 1, false, false)]
+ [InlineData(1, 0, true, false)]
+ [InlineData(1, 0, false, true)]
+ public void Gdd03KeepsPlayingWhileEnemyUnitsHoldCities(int q, int r, bool both, bool truce)
+ {
+ var c = Load();
+ var session = GameSession.New(c, 1, Mode.Historical);
+ if (truce) session.State.Date = new DateTime(1948, 6, 15);
+ Occupy(session.State, q, r);
+ if (both) Occupy(session.State, 3, 1, 2);
+ session.State.Units.Add(3, new Unit(3, "veteran_soldier", 4, 0, side: "israel", strength: 3));
+ var cityIds = session.State.Cities.Keys.ToArray();
+ var units = session.State.Units.Keys.ToArray();
+ // An already-awarded objective is not revoked by occupation.
+ session.State.Objectives["already_awarded"] = session.State.Date;
+ session.State.Score = 100;
+ for (int i = 0; i < 3; i++)
+ {
+ var before = session.State;
+ var result = session.EndTurn(Array.Empty<Command>());
+ Assert.Null(result.State.GameOver);
+ Assert.DoesNotContain(result.Why, w => w.System == "era" && w.Target == GameOverCodes.DefeatWar);
+ Assert.True(result.State.Date > before.Date);
+ Assert.Equal(before.Turn + 1, result.State.Turn);
+ Assert.Equal(units, result.State.Units.Keys);
+ Assert.Equal(cityIds, result.State.Cities.Keys);
+ Assert.Equal(before.Objectives["already_awarded"], result.State.Objectives["already_awarded"]);
+ Assert.Equal(100, result.State.Score);
+ Assert.Equal(q, result.State.Units[1].Q);
+ Assert.Equal(r, result.State.Units[1].R);
+ // An instant order is still accepted after the occupied-city turn.
+ Assert.Null(session.Commit(new UnitOrder(3, i % 2 == 0 ? "hold" : "fortify")));
+ }
+ }
+
+ // R-END-001, R-END-002, R-END-003: occupation neither suppresses nor accelerates economic defeat.
+ [Theory]
+ [InlineData(false)]
+ [InlineData(true)]
+ public void Gdd03StillEndsAtTheEconomicCount(bool occupied)
+ {
+ var c = Load(); var s = Simulation.NewGame(c, 1, Mode.Historical);
+ if (occupied) Occupy(s);
+ Exhaust(s);
+ for (int i = 1; i <= 3; i++)
+ {
+ var result = Simulation.Step(c, s, Array.Empty<Command>()); s = result.State;
+ Assert.Equal(i, s.ExhaustedTurns);
+ Assert.Equal(i == 3 ? GameOverCodes.DefeatEconomy : null, s.GameOver);
+ Assert.DoesNotContain(result.Why, w => w.Target == GameOverCodes.DefeatWar);
+ }
+ }
+
+ // R-END-001: either resource alone is insufficient, even with an occupied city.
+ [Theory]
+ [InlineData(true)]
+ [InlineData(false)]
+ public void Gdd03OneExhaustedResourceDoesNotEndTheGame(bool debtOnly)
+ {
+ var c = Load(); var s = Simulation.NewGame(c, 1, Mode.Historical); Occupy(s);
+ if (debtOnly) s.Debt = 1000;
+ else { Exhaust(s); s.Debt = 0; s.Treasury = 1e9; }
+ for (int i = 0; i < 4; i++) s = Simulation.Step(c, s, Array.Empty<Command>()).State;
+ Assert.Null(s.GameOver); Assert.Equal(0, s.ExhaustedTurns);
+ }
+
+ // R-END-002, R-END-003: the retained economic end precedes the dated end; otherwise the dated end still fires.
+ [Theory]
+ [InlineData(false, false)]
+ [InlineData(false, true)]
+ [InlineData(true, false)]
+ [InlineData(true, true)]
+ public void Gdd03PreservesDatedEndAndEconomicPrecedence(bool occupied, bool economic)
+ {
+ var c = Load(); var s = Simulation.NewGame(c, 1, Mode.Historical);
+ s.Date = c.End.AddDays(-1);
+ if (occupied) Occupy(s);
+ if (economic) { Exhaust(s); s.ExhaustedTurns = 2; }
+ var result = Simulation.Step(c, s, Array.Empty<Command>());
+ Assert.Equal(c.End, result.State.Date);
+ Assert.Equal(economic ? GameOverCodes.DefeatEconomy : GameOverCodes.EraEnded, result.State.GameOver);
+ Assert.Single(result.Why, w => w.System == "era" && w.Target == result.State.GameOver);
+ Assert.DoesNotContain(result.Why, w => w.Target == GameOverCodes.DefeatWar);
+ }
+
+ // R-END-003: the old rules keep city defeat and its priority before the dated end, but after economic defeat.
+ [Theory]
+ [InlineData(false, false)]
+ [InlineData(true, false)]
+ [InlineData(true, true)]
+ public void Gdd01KeepsItsOriginalWarLossPrecedence(bool lastDay, bool economic)
+ {
+ var c = Load(SaveGame.GddRuleset); var s = Simulation.NewGame(c, 1, Mode.Historical); Occupy(s);
+ if (lastDay) s.Date = c.End.AddDays(-1);
+ if (economic) { Exhaust(s); s.ExhaustedTurns = 2; }
+ var result = Simulation.Step(c, s, Array.Empty<Command>());
+ Assert.Equal(economic ? GameOverCodes.DefeatEconomy : GameOverCodes.DefeatWar, result.State.GameOver);
+ Assert.Contains(result.Why, w => w.System == "era" && w.Target == result.State.GameOver);
+ }
+
+ // R-END-003: legacy never entered the GDD war/economic checks and must still not do so.
+ [Fact]
+ public void LegacyKeepsItsNonGddEndRules()
+ {
+ var c = Load(SaveGame.LegacyRuleset); var s = Simulation.NewGame(c, 1, Mode.Historical);
+ Occupy(s); Exhaust(s);
+ for (int i = 0; i < 4; i++) s = Simulation.Step(c, s, Array.Empty<Command>()).State;
+ Assert.Null(s.GameOver); Assert.Equal(0, s.ExhaustedTurns);
+ }
+
+ // R-END-003: don't revive already-ended saves or allow another command to change their state.
+ [Theory]
+ [InlineData(GameOverCodes.DefeatWar)]
+ [InlineData(GameOverCodes.DefeatEconomy)]
+ [InlineData(GameOverCodes.EraEnded)]
+ public void Gdd03PreservesAnExistingEnd(string code)
+ {
+ var c = Load(); var s = Simulation.NewGame(c, 1, Mode.Historical); Occupy(s); s.GameOver = code;
+ var before = s.Describe();
+ var result = Simulation.Step(c, s, new Command[] { new UnitOrder(1, "hold") });
+ Assert.Equal(before, result.State.Describe()); Assert.Single(result.Rejected); Assert.Empty(result.Why);
+ }
+}
diff --git a/sim/Statecraft.Sim/TurnResolver.cs b/sim/Statecraft.Sim/TurnResolver.cs
index 94d90f7c5..1e29d2708 100644
--- a/sim/Statecraft.Sim/TurnResolver.cs
+++ b/sim/Statecraft.Sim/TurnResolver.cs
@@ -54,12 +54,13 @@ namespace Statecraft.Sim
why.Add(new Cause("era", s.GameOver, s.ExhaustedTurns, PlayerText.GameOver(s.GameOver), key: CauseKeys.EraEnded)); // the game's end, grouped with the MVP end
}
- /// <summary>R-END-003: an enemy military unit holding the hex of one of the player's GDD cities at the turn's
+ /// <summary>R-END-003: gdd-0.3 has no city-loss defeat. Under gdd-0.1 an enemy military unit holding a city at the turn's
/// end ends the game at once with defeat_war (Q-WAR-5; Q-DEF-3, owner, 17 Oct 2026, #784: one turn is enough, any
/// of the GDD cities, at any time, truces included). A halutz or the player's own unit on the hex ends nothing
/// (R-UNIT-001: a halutz has no side), and a game the economic count has just ended this turn keeps its code.</summary>
static void WarLoss(Content c, GameState s, List<Cause> why)
{
+ if (c.Ruleset == SaveGame.Gdd03Ruleset) return; // R-END-003: city or region loss alone is not a defeat in 0.3
if (s.GameOver != null) return;
var cities = new HashSet<(int Q, int R)>();
foreach (var city in c.Cities)