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.

Prisoners: a stored 0 holds nobody; the loader caps cover_months and field_food_per_turn (Refs #2733, Refs #2804) (#2920)

Eyal Golan0252c7a5248b
diff --git a/changelog.d/2733-2804-prisoners-held-food-bounds.md b/changelog.d/2733-2804-prisoners-held-food-bounds.md
new file mode 100644
index 000000000..93f47748d
--- /dev/null
+++ b/changelog.d/2733-2804-prisoners-held-food-bounds.md
@@ -0,0 +1,5 @@
+### Fixed
+
+- An exchange card no longer fires for a side whose stored count of prisoners or held soldiers is 0.
+- The loader now refuses `mvp.cover_months` above 120 and `mvp.field_food_per_turn` above 1,000, so a content edit can't
+ wrap the Food stock.
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 50efd28cb..bd7490d03 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -238,7 +238,7 @@ R-SITE-005: At most one `yishuv` site sits in a hex, so a hex shows at most one
R-FIELD-001: `PioneerWork(unit, plow_fields, site)` plows a field at a site whose kinds include `field`, by R-SITE-001 to R-SITE-003's rules, with `plow_fields_turns` and `plow_fields_cost` (labelled design values, Q-FIELD-3, decided 17 October 2026). A field site in a yishuv site's hex is ready only once that yishuv is built; before that the order is refused with the state unchanged and the Attention refunded (Q-FIELD-1, decided 17 October 2026). Built, the field site is plowed. A field site is not also a yishuv site, so building a yishuv cannot plow it; the loader refuses a row that gives it both kinds.
-R-FIELD-002: Each turn in step 6, after the cities' production and in ordinal site id order, every plowed field adds `field_food_per_turn` Food units to the national stock (R-FOOD-001), with no workers (Q-FIELD-2, decided 17 October 2026). A field being plowed adds nothing. The Food arrives before the nation eats in step 7, so in a turn with imports (R-FOOD-002) the import tops the stock up by that much less. `field_food_per_turn` is 1, a labelled design value (Q-FIELD-3: "1 Food a turn"), and required in the GDD loop.
+R-FIELD-002: Each turn in step 6, after the cities' production and in ordinal site id order, every plowed field adds `field_food_per_turn` Food units to the national stock (R-FOOD-001), with no workers (Q-FIELD-2, decided 17 October 2026). A field being plowed adds nothing. The Food arrives before the nation eats in step 7, so in a turn with imports (R-FOOD-002) the import tops the stock up by that much less. `field_food_per_turn` is 1, a labelled design value (Q-FIELD-3: "1 Food a turn"), and required in the GDD loop; a value below 0 or above 1,000 (`Pools.MaxFieldFoodPerTurn`, #2804) is a load error.
Then changed (3 Nov 2026): under exact `gdd-0.3`, in synthetic fixtures only (R-POP-004), each authored starting field (`regions.yaml` `field_hexes`, Q36) is one Work slot for one farmer (`field.slots` 1; owner, 3 November 2026, "One farmer per field (Recommended)"), staffed only by a farmer located in its region (Q27) while the field is Israeli-held (Q37). Only a farmer may hold a field (owner, 4 November 2026: asked "May only a unit with the Farmer profession staff a field?", the owner answered "yes", [recorded on #1694](https://github.com/eyalgolan/statecraft-israel/issues/1694#issuecomment-6623124984)). A field staffed in the month's snapshot (27M-2) and still Israeli-held yields `farmer.output` (2 / 3 / 5) times `field_food_per_turn` by the snapshot tier, and no Money; an unworked field yields nothing. Then changed (#2471): the fixture's settlement adds that yield to the national Food stock (R-FOOD-001), each field's once and in ordinal field-id order, with one Why line per field that yields. Control is checked again at settlement as well as at the snapshot's freeze, and a field lost by either adds nothing while its farmer keeps the same id, tier and assignment (D6: "its people stay"); once retaken, the next month's snapshot yields again with no new assignment (D6: "On retaking, everything resumes and nothing is deleted."). The caller states which fields are Israeli-held (maintainer reading: the sim has no hex control for fields yet). No game-loop caller is added, and the legacy and gdd-0.1 plowed-field harvest above is unchanged.
@@ -398,7 +398,7 @@ R-POW-002: In step 7, after the nation eats and the import (R-FOOD-002), the pri
R-POW-003: Prisoners are never labour, Money, Arms, housing occupants, jobs or a resource any command or event can spend: a state with prisoners and one without end every command's turn with the same Money, Arms, cities and units, and Food that differs by the upkeep alone.
-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 (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-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.
@@ -446,7 +446,7 @@ The top bar shows the net position, Treasury minus debt (`HudModel.From`), so it
The national Food pool (D-C2, "National pools", decided 15 October 2026), built on the maintainer's food rule of 16 October 2026 (#382, option (b): "food_supply adds a stock term: it rises and falls with months of cover (new design values `k_food`, `cover_months`), rationing and events still act on top, and the unmet share lowers it further").
-R-FOOD-001: Food is a national stock of whole units (`GameState.Food`); one unit is one population unit's food for one month, and there is no storage cap (Q-POOL-2, decided 15 October 2026). A new game starts the stock at `cover_months` of the start's need, the need being the national head count in population units (`people_per_unit`), rounded half away from zero. `k_food` and `cover_months` are required in the GDD loop (`rules.yaml` `mvp:`, labelled design values); a missing or out-of-range value is a load error.
+R-FOOD-001: Food is a national stock of whole units (`GameState.Food`); one unit is one population unit's food for one month, and there is no storage cap (Q-POOL-2, decided 15 October 2026). A new game starts the stock at `cover_months` of the start's need, the need being the national head count in population units (`people_per_unit`), rounded half away from zero. `k_food` and `cover_months` are required in the GDD loop (`rules.yaml` `mvp:`, labelled design values); a missing or out-of-range value is a load error. `cover_months` runs from 1 to 120 (`Pools.MaxCoverMonths`), so its multiply cannot wrap the stock (#2804); the stock itself still has no cap.
R-FOOD-002: In step 7 the nation eats the turn's need from the stock as far as it goes: the stock stops at 0, and the rest is the unmet share, kept in the state with the need (Q-POOL-5, decided 15 October 2026). Then a monthly import brings the stock back to `cover_months` of the need, unless foreign currency is exhausted (the `fx_crisis` situation at the turn's start), when nothing is imported (Q-POOL-4, decided 15 October 2026). Imports are already paid for in foreign currency per head (`imports_per_capita_per_year`), so they are not charged again. In the GDD loop the crisis cuts the imports, not `food_supply` directly: `fx_crisis_food_per_year` acts in the legacy loop only.
diff --git a/sim/Statecraft.Sim.Tests/FieldsTests.cs b/sim/Statecraft.Sim.Tests/FieldsTests.cs
index 991312211..3ff76fa4f 100644
--- a/sim/Statecraft.Sim.Tests/FieldsTests.cs
+++ b/sim/Statecraft.Sim.Tests/FieldsTests.cs
@@ -190,6 +190,29 @@ public class FieldsTests
Assert.Contains(message, e.Message);
}
+ // R-FIELD-002: field_food_per_turn has a ceiling, so the harvest cannot wrap the Food stock (#2804 item 5). The ceiling loads.
+ [Theory]
+ [InlineData(1001)]
+ [InlineData(int.MaxValue)]
+ public void FieldFoodAboveTheCeilingFailsLoad(int food)
+ {
+ var e = Assert.Throws<ContentException>(() => LoadWithFieldFood(food));
+ Assert.Equal(("rules.yaml", "mvp.field_food_per_turn"), (e.File, e.Field));
+ Assert.Contains("<= 1000", e.Message);
+ }
+
+ [Fact]
+ public void FieldFoodAtTheCeilingLoads() =>
+ Assert.Equal(1000, LoadWithFieldFood(1000).Rules.Mvp!.FieldFoodPerTurn);
+
+ static Content LoadWithFieldFood(int food)
+ {
+ var files = Fixture.Gdd();
+ Assert.Contains(" field_food_per_turn: 7\n", files["rules.yaml"]);
+ files["rules.yaml"] = files["rules.yaml"].Replace(" field_food_per_turn: 7\n", FormattableString.Invariant($" field_food_per_turn: {food}\n"));
+ return ContentLoader.Load(Fixture.Write(files));
+ }
+
// The real content: every field site lies in a yishuv's hex (Q-FIELD-1) or the swamp's (Q-SWAMP-1), and the design
// values are those of Q-FIELD-3.
[Fact]
diff --git a/sim/Statecraft.Sim.Tests/PoolsTests.cs b/sim/Statecraft.Sim.Tests/PoolsTests.cs
index eba53fe07..6fdae0576 100644
--- a/sim/Statecraft.Sim.Tests/PoolsTests.cs
+++ b/sim/Statecraft.Sim.Tests/PoolsTests.cs
@@ -275,6 +275,25 @@ public class PoolsTests
Assert.Contains(message, ex.Message);
}
+ // R-FOOD-001: cover_months has a ceiling, so the stock's int multiply cannot wrap (#2804 item 5). The ceiling itself loads.
+ [Theory]
+ [InlineData(121)]
+ [InlineData(int.MaxValue)]
+ public void CoverMonthsAboveTheCeilingFailsLoad(int months)
+ {
+ var ex = Assert.Throws<ContentException>(() => Gdd(FormattableString.Invariant($" k_food: 0.1\n cover_months: {months}\n")));
+ Assert.Equal(("rules.yaml", "mvp.cover_months"), (ex.File, ex.Field));
+ Assert.Contains("<= 120", ex.Message);
+ }
+
+ // R-FOOD-001: at the ceiling the stock is exactly that many months of the fixture's need of 100.
+ [Fact]
+ public void CoverMonthsAtTheCeilingLoads()
+ {
+ var s = Simulation.NewGame(Gdd(" k_food: 0.1\n cover_months: 120\n"), 1, Mode.Historical);
+ Assert.Equal(120 * 100, s.Food);
+ }
+
// R-FOOD-003: the GDD loop needs the food_supply indicator the pool feeds.
[Fact]
public void TheGddLoopNeedsAFoodSupplyIndicator()
diff --git a/sim/Statecraft.Sim.Tests/PrisonersTests.cs b/sim/Statecraft.Sim.Tests/PrisonersTests.cs
index 2a96ace3d..4b6463f32 100644
--- a/sim/Statecraft.Sim.Tests/PrisonersTests.cs
+++ b/sim/Statecraft.Sim.Tests/PrisonersTests.cs
@@ -232,6 +232,34 @@ sources: [{{ url: https://example.org/event, checked: 2026-10-18 }}]
Assert.DoesNotContain("pow_jordan", s.FiredEvents);
}
+ // R-POW-004: a stored 0 holds nobody, so the card keeps waiting (#2733 item 6). The entry itself stays as it was: the
+ // filter reads it and saved state does not change. Only a zero-strength surrender or a hand-built state can store a 0.
+ [Theory]
+ [InlineData(false)]
+ [InlineData(true)]
+ public void ACountOfZeroHoldsNobody(bool ownSoldiers)
+ {
+ var c = Load();
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ (ownSoldiers ? s.SoldiersHeld : s.PrisonersHeld)["egypt"] = 0;
+ for (int i = 0; i < 16; i++) s = Simulation.Step(c, s, Array.Empty<Command>()).State;
+ Assert.True(s.Date > new DateTime(1948, 7, 1));
+ Assert.DoesNotContain("pow_egypt", s.FiredEvents);
+ Assert.Equal(0, (ownSoldiers ? s.SoldiersHeld : s.PrisonersHeld)["egypt"]);
+ }
+
+ // R-POW-004: the count is per front, so a 0 on one of its sides does not hide a positive count on the other.
+ [Fact]
+ public void AZeroOnOneSideLeavesTheFrontsOtherSideHeld()
+ {
+ var c = Load();
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ s.PrisonersHeld["jordan"] = 0;
+ s.PrisonersHeld["iraq"] = 1;
+ for (int i = 0; i < 16; i++) s = Simulation.Step(c, s, Array.Empty<Command>()).State;
+ Assert.Contains("pow_jordan", s.FiredEvents);
+ }
+
// R-POW-004: delegating an exchange card draws no RNG, like an objective's card. A soft-anchored card, because a hard-anchored
// one takes its historical option without a draw anyway and would hide the missing exemption.
[Fact]
diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.cs
index 74162cec3..3dd5d4410 100644
--- a/sim/Statecraft.Sim/ContentLoader.cs
+++ b/sim/Statecraft.Sim/ContentLoader.cs
@@ -1466,6 +1466,7 @@ namespace Statecraft.Sim
if (!(m.DrySwampCost >= 0 && IsFinite(m.DrySwampCost.Value))) throw new ContentException(file, "mvp.dry_swamp_cost", "must be a finite number >= 0");
if (m.FieldFoodPerTurn == null) throw new ContentException(file, "mvp.field_food_per_turn", "required when eras.yaml systems.loop is gdd");
if (m.FieldFoodPerTurn < 0) throw new ContentException(file, "mvp.field_food_per_turn", "must be >= 0");
+ if (m.FieldFoodPerTurn > Pools.MaxFieldFoodPerTurn) throw new ContentException(file, "mvp.field_food_per_turn", FormattableString.Invariant($"must be <= {Pools.MaxFieldFoodPerTurn}"));
if (m.RoadSegmentTurns < 1) throw new ContentException(file, "mvp.road_segment_turns", "must be >= 1");
if (!(m.RoadSegmentCost >= 0 && IsFinite(m.RoadSegmentCost))) throw new ContentException(file, "mvp.road_segment_cost", "must be a finite number >= 0");
if (m.RailSegmentTurns < 1) throw new ContentException(file, "mvp.rail_segment_turns", "must be >= 1");
@@ -1475,6 +1476,7 @@ namespace Statecraft.Sim
if (!(m.KFood >= 0 && m.KFood <= 1)) throw new ContentException(file, "mvp.k_food", "must be between 0 and 1");
if (m.CoverMonths == null) throw new ContentException(file, "mvp.cover_months", "required when eras.yaml systems.loop is gdd");
if (m.CoverMonths < 1) throw new ContentException(file, "mvp.cover_months", "must be >= 1");
+ if (m.CoverMonths > Pools.MaxCoverMonths) throw new ContentException(file, "mvp.cover_months", FormattableString.Invariant($"must be <= {Pools.MaxCoverMonths}"));
// R-ARMS-001 to R-ARMS-003: required, so a missing key is never read as 0 (no stock, free Arms, or training without them).
if (m.ArmsStart == null) throw new ContentException(file, "mvp.arms_start", "required when eras.yaml systems.loop is gdd");
if (m.ArmsStart < 0) throw new ContentException(file, "mvp.arms_start", "must be >= 0");
diff --git a/sim/Statecraft.Sim/Pools.cs b/sim/Statecraft.Sim/Pools.cs
index 76f3547b1..317593d9b 100644
--- a/sim/Statecraft.Sim/Pools.cs
+++ b/sim/Statecraft.Sim/Pools.cs
@@ -24,6 +24,16 @@ namespace Statecraft.Sim
/// <summary>The command kind that buys Arms with Money (R-ARMS-002).</summary>
public const string BuyArmsKind = "buy_arms";
+ /// <summary>R-FOOD-001: the loader's ceiling on cover_months, ten years of need, longer than the about 104 months the game can
+ /// run (eras.yaml, 15 May 1948 to 1 January 1957). The stock is an int, so a ceiling keeps cover_months times the need
+ /// from wrapping: it would take a need of 17.9 million population units (#2804 item 5).</summary>
+ public const int MaxCoverMonths = 120;
+
+ /// <summary>R-FIELD-002: the loader's ceiling on field_food_per_turn. Even at the top farmer tier's 5 times it
+ /// (R-VET-002) and SaveGame.MaxTurns turns, that is 10 million Food a field, so an int stock holds 214 such fields
+ /// (#2804 item 5).</summary>
+ public const int MaxFieldFoodPerTurn = 1000;
+
/// <summary>R-FOOD-001: the stock starts at cover_months of the start's need, so food_supply starts at its level.</summary>
public static void Init(Content c, GameState s)
{
diff --git a/sim/Statecraft.Sim/Prisoners.cs b/sim/Statecraft.Sim/Prisoners.cs
index 44f4a53fe..9c5b9f7cd 100644
--- a/sim/Statecraft.Sim/Prisoners.cs
+++ b/sim/Statecraft.Sim/Prisoners.cs
@@ -47,9 +47,10 @@ namespace Statecraft.Sim
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
- /// card waits for this (R-POW-004), so a game with no surrender fires no card.</summary>
+ /// card waits for this (R-POW-004), so a game with no surrender fires no card. A stored 0 (a zero-strength surrender)
+ /// holds nobody, so only a positive count counts; the entry itself stays, so saved state does not change.</summary>
internal static bool Held(GameState s, string front) =>
- Sides(front).Any(x => s.PrisonersHeld.ContainsKey(x) || s.SoldiersHeld.ContainsKey(x));
+ Sides(front).Any(x => s.PrisonersHeld.TryGetValue(x, out var n) && n > 0 || s.SoldiersHeld.TryGetValue(x, out var m) && m > 0);
/// <summary>R-POW-002, R-POW-005, step 7 after the nation eats and the import: the prisoners eat food_per_prisoner_unit a
/// unit from the stock, as far as it goes; each Food unit it cannot give costs prisoner_shortfall_cohesion of Social