A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: prisoners (GDD Phase 5 PR 12, refs #751) (#1264)
Beribdacaad420bd
diff --git a/changelog.d/sim-gdd-prisoners-751.md b/changelog.d/sim-gdd-prisoners-751.mdnew file mode 100644index 000000000..0df751e3d--- /dev/null+++ b/changelog.d/sim-gdd-prisoners-751.md@@ -0,0 +1,6 @@+- Prisoners (GDD Phase 5 PR 12, #751; R-POW-001 to R-POW-005): a unit that surrenders in combat is now counted, as+ prisoners when it is an enemy unit, as our soldiers held when it is ours. Prisoners eat Food each turn, and a shortfall+ costs Social cohesion, never prisoners. Our soldiers held cost Money each turn. A front's exchange card (new event key+ `prisoners:`) returns both and scores 10 points per population unit of prisoners returned; nothing scores at the+ capture. The four amounts in `rules.yaml` are agent defaults for the owner to set. The four sourced exchange cards+ come in a later PR, after a person has checked their sources.diff --git a/content/rules.yaml b/content/rules.yamlindex 23464fce6..e37f75f6f 100644--- a/content/rules.yaml+++ b/content/rules.yaml@@ -195,6 +195,16 @@ mvp:attacker_loss: [1, 0, 0, 0, 0, 0] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: population units the attackers lose, per face)defender_loss: [1, 1, 1, 2, 2, 2] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: population units the defenders lose, per face)defender_retreats: [0, 1, 1, 1, 1, 1] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: 1 where the defenders retreat, per face)+ # Prisoners (R-POW-002, R-POW-004, R-POW-005; Q-POW-2, Q-POW-4, Q-POW-5, owner, 15 October 2026, #375). The amounts are+ # agent defaults posted on #751 (https://github.com/eyalgolan/statecraft-israel/issues/751#issuecomment-6318787961) for+ # the owner to set or accept; none is a historical figure. A prisoner unit eats the ration any population unit eats (one+ # Food is one unit's food for a month, R-FOOD-001). A return scores a tenth of an objective (D-B6) per unit. The player's+ # soldiers held cost one month of income_per_job_per_year (0.06 / 12) a unit, in Money, so Q-CIV-3 keeps the Food+ # shortfall as its one cohesion exemption.+ food_per_prisoner_unit: 1 # DESIGN VALUE: owner-set balance, not a historical figure (D-C2, Q-POW-5: Food a population unit of prisoners eats a turn)+ prisoner_shortfall_cohesion: 0.01 # DESIGN VALUE: owner-set balance, not a historical figure (D-C1, Q-POW-5: Social cohesion lost per unit of the prisoners' Food not given)+ points_per_prisoner_unit_returned: 10 # DESIGN VALUE: owner-set balance, not a historical figure (D-B6, Q-POW-2: points per population unit of prisoners returned)+ held_soldier_cost_per_turn: 0.005 # DESIGN VALUE: owner-set balance, not a historical figure (D-C6, Q-POW-4: IL millions a turn per population unit of our soldiers held)# 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/content/schema/event.schema.json b/content/schema/event.schema.jsonindex 2a69a7ad7..7fdd3140c 100644--- a/content/schema/event.schema.json+++ b/content/schema/event.schema.json@@ -80,6 +80,7 @@"office": { "$ref": "#/definitions/id", "description": "The office the event goes to when the player does not answer." },"objective": { "$ref": "#/definitions/id", "description": "The objective (objectives.yaml) whose completion card this is. It fires only once that objective is completed, and has exactly one option." },"site": { "$ref": "#/definitions/id", "description": "A swamp site (sites.yaml) whose works this event is about. In the GDD loop it fires only while that site is being worked; the legacy loop ignores it." },+ "prisoners": { "enum": ["egypt", "jordan", "lebanon", "syria"], "description": "The front whose prisoners this exchange card returns (R-POW-004). It fires only while that front holds prisoners or the player's soldiers, and has exactly one option. Jordan's card also returns the Iraqi prisoners." },"from": { "$ref": "#/definitions/date", "description": "First day of the window." },"to": { "$ref": "#/definitions/date", "description": "End of the window (exclusive). Leave out for an open window." },"conditions": {diff --git a/docs/WRITING_EVENTS.md b/docs/WRITING_EVENTS.mdindex 66d7f3839..9b34d82e9 100644--- a/docs/WRITING_EVENTS.md+++ b/docs/WRITING_EVENTS.md@@ -44,6 +44,7 @@ schema too, or that test fails. Keep the comment when you copy a file.| `variants` | no | `kind: reconvergence` only. Course-specific title and text, each with `when`, `text`, optional `title` and `sources` (R-ALT-010). See "kind". || `objective` | no | Makes the event the completion card of an objective in `objectives.yaml`, which must name this event as its `card`. It fires only once the objective is completed (GDD loop only), and has exactly one option. See `docs/gdd/objective-card.md`. || `site` | no | A swamp site in `sites.yaml` whose works the event is about. In the GDD loop it fires only while that site is being worked (R-SWAMP-002); the legacy loop ignores it. See `docs/gdd/fields-and-swamps.md`. |+| `prisoners` | no | Makes the event a front's prisoner-exchange card: `egypt`, `jordan` (which also returns the Iraqi prisoners), `lebanon` or `syria`. It fires only while that front holds prisoners or the player's soldiers (GDD loop only), has exactly one option, and returns them and scores when it resolves (R-POW-004). || `options` | yes | One or more options. See below. || `sources` | no by the loader, yes by the rules | A list of `{ url, checked }`. See below. || `status` | no (default `draft`) | The review status. See below. |diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex faa73a119..d4e21aaf1 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -198,11 +198,11 @@ R-COMBAT-001: `UnitOrder(unit, attack, q, r)` gives one of the player's militaryR-COMBAT-002: Resolver step 2 resolves the attacks of both sides in ascending attacker id: the lowest-id unit with an attack not yet in an engagement leads one, with every unit of its side attacking the same hex (Israel on one side, every Arab side on the other). Each unit's strength is first multiplied by its type's `combat_percent` (R-COMBAT-007, R-COMBAT-008). The attackers' strengths are summed (Q-COMBAT-2); each defender's strength is multiplied by its order's defence percent (`Orders.DefencePercent`: fortify 125, R-ORDER-002) and by `mvp.combat_terrain_percent` for its hex's biome (real values: hills 125, mountains 150, every other land biome 100). The ratio is attack over defence in whole percent, rounded down, in integers only; the row of `mvp.combat_table` is the last whose `min_ratio_percent` it reaches (real rows: below 1:2, 1:2, 1:1, 2:1, 3:1). Each engagement draws exactly one RNG value, a face of the row (six in the real table), whatever its outcome; a step 2 with no engagement draws nothing (docs/determinism.md, "Combat draws"). `Combat.Preview(c, s, unit, q, r)` gives the ratio and row the UI shows (Q-UI-1; spec §2.6), counting the unit and the units of its side already attacking that hex.-R-COMBAT-003: The face gives the population units each side loses and whether the defenders retreat. Losses fall one unit at a time on the side's strongest unit in the engagement (a tie on the lower id; the attackers' losses spare their artillery, R-COMBAT-007); a unit at 0 is destroyed and leaves the state, and its id is never reused (`NextId` does not move). When the face says retreat, each defender left, in id order, moves one hex to the first neighbour in the fixed order (R-MOVE-002) that is land, holds no unit of the other side, has room for its side under `mvp.stack_limit`, and, for a player's unit, is not an enemy-held locality (R-MOVE-005). A defender with no such hex surrenders and leaves the state: the only way a unit is captured (impact plan §4.3 item 1; its prisoners are PR 12). The attackers never advance into the hex (Q-COMBAT-3).+R-COMBAT-003: The face gives the population units each side loses and whether the defenders retreat. Losses fall one unit at a time on the side's strongest unit in the engagement (a tie on the lower id; the attackers' losses spare their artillery, R-COMBAT-007); a unit at 0 is destroyed and leaves the state, and its id is never reused (`NextId` does not move). When the face says retreat, each defender left, in id order, moves one hex to the first neighbour in the fixed order (R-MOVE-002) that is land, holds no unit of the other side, has room for its side under `mvp.stack_limit`, and, for a player's unit, is not an enemy-held locality (R-MOVE-005). A defender with no such hex surrenders and leaves the state: the only way a unit is captured (impact plan §4.3 item 1; its people are counted as prisoners or as the player's soldiers held, R-POW-001, R-POW-005). The attackers never advance into the hex (Q-COMBAT-3).R-COMBAT-004: Each of the player's units pays `mvp.arms_per_attack` (real value 1; artillery pays its `arms_per_fire` instead, R-COMBAT-007) from the Arms stock when it joins an engagement; one the stock cannot pay for has its attack called off, with a line naming the need and the stock. Enemy units pay nothing (Q-ENEMY-4: no supply).-R-COMBAT-005: Combat changes only combatant units and the Arms. No city, locality, resident, building, job or other resource, and no score, changes because of a combat outcome (Q-CIV-2; impact plan §4.3: kills and enemy losses never score). Halutzim are never attackers or targets.+R-COMBAT-005: Combat changes only combatant units, the Arms and, through a surrender, the counts of prisoners and of the player's soldiers held (R-POW-001, R-POW-005). No city, locality, resident, building, job or other resource, and no score, changes because of a combat outcome (Q-CIV-2; impact plan §4.3: kills and enemy losses never score). Halutzim are never attackers or targets.R-COMBAT-006: Each engagement's Why line names the hex, the units on each side and the ratio, and states "the attackers lost N people and the defenders lost M people", the strength each side lost times `people_per_unit`, in the same words whichever side attacks (Q-CIV-4; impact plan §4.2). A destroyed unit gets "Unit N was destroyed", a retreat the hex it went to, a surrender the people it surrendered with. No running count of losses is kept; the war's Israeli total is PR 13's.@@ -212,6 +212,20 @@ R-COMBAT-007: Artillery (a type of class `artillery`, which needs a `range` andR-COMBAT-008: A military type may carry a `combat_percent` (at least 1; none is 100): its units' strength counts at that percent in the ratio, attacking and defending, in integers (R-COMBAT-002). The armoured car's is 150 (real value), with its 5 movement points (R-MOVE-001) and no other rule (Q-ARTY-2).+## Prisoners++Phase 5 PR 12 (#751). The impact plan's §4.3 as written (Q-POW-1), points per unit returned (Q-POW-2), a sourced event card per front (Q-POW-3), the player's soldiers counted with a cost (Q-POW-4) and a Food cost whose shortfall costs cohesion (Q-POW-5): the owner's picks of 15 October 2026 (#375). The four amounts (`rules.yaml` `mvp.food_per_prisoner_unit`, `mvp.prisoner_shortfall_cohesion`, `mvp.points_per_prisoner_unit_returned`, `mvp.held_soldier_cost_per_turn`), the front of each side and the captor of the player's soldiers are agent defaults posted on #751 (https://github.com/eyalgolan/statecraft-israel/issues/751#issuecomment-6318787961) for the owner to set or accept. The four sourced exchange cards are not in `content/` yet: they wait for a person's source check (CONTENT_POLICY §2) and the owner's sensitivity review.++R-POW-001: Prisoners come only from a surrender in combat (R-COMBAT-003). The surrendered enemy unit's strength, in population units, is added to `GameState.PrisonersHeld` under its side; residents never become prisoners (R-CTRL-003). No command and no event effect adds to or takes from the count: no effect target names it. The surrender's Why line ends "They are held as prisoners", and nothing on screen celebrates a capture (impact plan §4.3 item 4).++R-POW-002: In step 7, after the nation eats and the import (R-FOOD-002), the prisoners eat `mvp.food_per_prisoner_unit` (real value 1, one unit's ration) for each population unit held, as far as the stock goes. Each unit of their Food the stock cannot give lowers Social cohesion by `mvp.prisoner_shortfall_cohesion` (real value 0.01), the one cohesion cost of a military matter in Phase 5 (Q-CIV-3); a shortfall never reduces the prisoners (Q-POW-5).++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).++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.+## ObjectivesR-OBJ-001: An objective (`objectives.yaml`) names its condition, `completes_when: { site_built: <site> }` (R-OBJ-004's `absorbed` has no site, so the site rules here apply only to `site_built`), a designated site of kind yishuv whose `founded` date must equal the objective's `reference_date`. In the last step of each GDD turn (spec §2.3, step 11; D-A6), in id order, an objective whose site is built and that is not yet recorded is recorded once, with the turn's end date (the site's `BuiltOn`). Recording it again, or in the legacy loop, changes nothing; a stopped build completes nothing.diff --git a/sim/Statecraft.Sim.Tests/CombatTests.cs b/sim/Statecraft.Sim.Tests/CombatTests.csindex a9bd70857..cc2d78bdf 100644--- a/sim/Statecraft.Sim.Tests/CombatTests.cs+++ b/sim/Statecraft.Sim.Tests/CombatTests.cs@@ -197,7 +197,7 @@ public class CombatTestsvar next = s.NextId;var why = Resolve(c, s);Assert.False(s.Units.ContainsKey(2));- Assert.Contains(why, x => x.Message == "Unit 2 surrendered with 20 people: it had no hex to retreat to");+ Assert.Contains(why, x => x.Message == "Unit 2 surrendered with 20 people: it had no hex to retreat to. They are held as prisoners");Assert.Equal(next, s.NextId);}@@ -281,13 +281,16 @@ public class CombatTestsAssertOnlyCombatantsChanged(before, s);}- /// <summary>R-COMBAT-005: <paramref name="after"/> differs from <paramref name="before"/> only in its units, its Arms and the- /// RNG: with those three copied back, the hashes match.</summary>+ /// <summary>R-COMBAT-005: <paramref name="after"/> differs from <paramref name="before"/> only in its units, its Arms, the+ /// RNG and, from a surrender, the counts of prisoners and of the player's soldiers held (R-POW-001, R-POW-005): with those+ /// copied back, the hashes match.</summary>internal static void AssertOnlyCombatantsChanged(GameState before, GameState after){var copy = before.Clone();copy.Units.Clear();foreach (var u in after.Units.Values) copy.Units.Add(u.Id, u);+ copy.PrisonersHeld = new SortedDictionary<string, int>(after.PrisonersHeld, StringComparer.Ordinal);+ copy.SoldiersHeld = new SortedDictionary<string, int>(after.SoldiersHeld, StringComparer.Ordinal);copy.Arms = after.Arms;copy.RngState = after.RngState;Assert.Equal(after.Describe(), copy.Describe());diff --git a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs b/sim/Statecraft.Sim.Tests/DesignValuesTests.csindex 28cede7af..6b71b79e2 100644--- a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs+++ b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs@@ -172,6 +172,11 @@ public class DesignValuesTests("rules.yaml", "mvp.arms_start"),("rules.yaml", "mvp.arms_price"),("rules.yaml", "mvp.arms_per_recruit_group"),+ // Prisoners (Phase 5 PR 12, #751; Q-POW-2, Q-POW-4, Q-POW-5): agent defaults for the owner to set or accept.+ ("rules.yaml", "mvp.food_per_prisoner_unit"),+ ("rules.yaml", "mvp.prisoner_shortfall_cohesion"),+ ("rules.yaml", "mvp.points_per_prisoner_unit_returned"),+ ("rules.yaml", "mvp.held_soldier_cost_per_turn"),}.Concat(CombatTableCells()).ToArray();/// <summary>rules.yaml mvp.combat_table, every cell: its five rows (below 1:2, 1:2, 1:1, 2:1, 3:1) with their start ratio@@ -276,6 +281,7 @@ public class DesignValuesTestsAssert.Equal((5, 0.5), (m.DelegationLoyaltyFloor, m.DisloyalEffectShare)); // R-EVT-003, #107 (D-H1)Assert.Equal((12, 1.0, 1, 1.0), (m.ArmsStart, m.ArmsPrice, m.ArmsPerRecruitGroup, c.Rules.AttentionCost["buy_arms"])); // #781 (D-G6)Assert.Equal((1, 5, 6), (m.ArmsPerAttack, m.CombatTable.Count, m.CombatTable[0].AttackerLoss.Count)); // #747 (D-G6, D-G3), accepted by the owner 20 Oct 2026+ Assert.Equal((1, 0.01, 10, 0.005), (m.FoodPerPrisonerUnit, m.PrisonerShortfallCohesion, m.PointsPerPrisonerUnitReturned, m.HeldSoldierCostPerTurn)); // #751 (Q-POW-2, Q-POW-4, Q-POW-5), agent defaultsAssert.Equal(12, c.Cities.Count);foreach (var x in c.Cities) // the listed housing and job values are the ones Cities.Init starts fromAssert.Equal(((int)x.Housing!.Value, (int)x.Jobs!.Value), (x.HousingCapacity, x.JobSlots));diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.csindex ee044226b..ec3490674 100644--- a/sim/Statecraft.Sim.Tests/Fixture.cs+++ b/sim/Statecraft.Sim.Tests/Fixture.cs@@ -294,6 +294,10 @@ mvp:rail_move_cost: 2enemy_held_localities: []arms_per_attack: 2+ food_per_prisoner_unit: 2+ prisoner_shortfall_cohesion: 0.05+ points_per_prisoner_unit_returned: 7+ held_soldier_cost_per_turn: 0.5combat_terrain_percent: { coastal_plain: 100, hills: 150, desert: 100 }combat_table:- { min_ratio_percent: 0, attacker_loss: [1, 1], defender_loss: [1, 1], defender_retreats: [0, 0] }diff --git a/sim/Statecraft.Sim.Tests/PrisonersTests.cs b/sim/Statecraft.Sim.Tests/PrisonersTests.csnew file mode 100644index 000000000..e52f54f9c--- /dev/null+++ b/sim/Statecraft.Sim.Tests/PrisonersTests.cs@@ -0,0 +1,384 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>Prisoners (GDD Phase 5 PR 12, #751; impact plan section 4.3 as written, Q-POW-1). Only a surrender in combat takes+/// prisoners; they eat Food in step 7, and a shortfall costs Social cohesion, never prisoners; they are never a resource;+/// each front's exchange card returns them and scores then, per population unit; the player's soldiers held are a count that+/// costs Money while held and comes home on the same card with no score. The fixture's numbers are fixture values: 10 people+/// a population unit, 2 Food per prisoner unit, 0.05 cohesion per unfed Food unit, 7 points per unit returned and IL 0.5m+/// per held soldier unit a turn, chosen so each shows apart from the others.</summary>+public class PrisonersTests+{+ const string Types = Fixture.GddUnitTypes+ + " - { id: soldier, kind: unit, side: israel, class: infantry, movement_points: 3 }\n"+ + " - { id: enemy, kind: unit, side: egypt, class: infantry, movement_points: 3 }\n"+ + " - { id: iraqi, kind: unit, side: iraq, class: infantry, movement_points: 3 }\n"+ + " - { id: irregular, kind: unit, side: ala, class: infantry, movement_points: 3 }\n"+ + " - { id: egypt_gun, kind: unit, side: egypt, class: artillery, movement_points: 2, range: 2, arms_per_fire: 3, combat_percent: 200 }\n";++ static string Card(string id, string front, string from) => $@"+id: {id}+title: Prisoners exchanged+text: The prisoners are exchanged.+anchor: hard+prisoners: {front}+from: {from}+to: 1950-01-01+options:+ - id: continue+ text: Continue+ historical: true+";++ static readonly Dictionary<string, string> Cards = new Dictionary<string, string>+ {+ ["pow_egypt.yaml"] = Card("pow_egypt", "egypt", "1948-07-01"),+ ["pow_jordan.yaml"] = Card("pow_jordan", "jordan", "1948-07-01"),+ };++ static Content Load(Dictionary<string, string>? cards = null, string? rules = null)+ {+ var files = Fixture.Gdd(new Dictionary<string, string>+ {+ ["unit_types.yaml"] = Types, ["map/hexes.json"] = MovementTests.Board(), ["corridors.yaml"] = "corridors: []\n"+ });+ if (rules != null) files["rules.yaml"] = rules;+ return ContentLoader.Load(Fixture.Write(files, cards ?? Cards));+ }++ static string Rules(string from, string to)+ {+ var rules = Fixture.Gdd()["rules.yaml"];+ Assert.Contains(from, rules);+ return rules.Replace(from, to);+ }++ static Unit Soldier(int id, int q, int r, int strength) => new Unit(id, "soldier", q, r, side: "israel", strength: strength);+ static Unit Enemy(int id, int q, int r, int strength, string type = "enemy", string side = "egypt") =>+ new Unit(id, type, q, r, side: side, strength: strength);+ static Unit Attacking(Unit u, int q, int r) =>+ new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, Combat.Attack, FormattableString.Invariant($"{q},{r}"));++ /// <summary>A new fixture game on 15 May 1948, before the cards' window opens, with two soldiers ordered to attack the corner+ /// (0, 0) from both its land neighbours and an enemy unit of strength 3 there: 8 against 3 is 2:1, so it loses 1 and,+ /// with nowhere to go, surrenders with 2 units (CombatTests.ADefenderWithNoHexToRetreatToSurrenders).</summary>+ static GameState Surrounded(Content c, Unit? defender = null) =>+ CombatTests.With(c, Attacking(Soldier(1, 1, 0, 4), 0, 0), Attacking(Soldier(3, 0, 1, 4), 0, 0), defender ?? Enemy(2, 0, 0, 3));++ static List<Cause> Fight(Content c, GameState s)+ {+ var why = new List<Cause>();+ Combat.Resolve(c, s, why);+ return why;+ }++ static List<Cause> Upkeep(Content c, GameState s)+ {+ var why = new List<Cause>();+ Prisoners.Upkeep(c, s, c.RulesAt(s.Date).Mvp!, why);+ return why;+ }++ // R-POW-001: a surrender adds the unit's population units to its side's prisoners, and the Why line says so without a+ // word of celebration (impact plan section 4.3 item 4).+ [Fact]+ public void ASurrenderTakesPrisoners()+ {+ var c = Load();+ var s = Surrounded(c);+ var why = Fight(c, s);+ Assert.False(s.Units.ContainsKey(2));+ Assert.Equal(new[] { ("egypt", 2) }, s.PrisonersHeld.Select(kv => (kv.Key, kv.Value)));+ Assert.Empty(s.SoldiersHeld);+ Assert.Contains(why, x => x.Message == "Unit 2 surrendered with 20 people: it had no hex to retreat to. They are held as prisoners");+ }++ // R-POW-001: a destroyed unit and a unit that retreats take no prisoners.+ [Fact]+ public void ADestroyedOrRetreatingUnitTakesNoPrisoners()+ {+ var c = Load();+ var destroyed = CombatTests.With(c, Attacking(Soldier(1, 3, 0, 1), 2, 0), Enemy(2, 2, 0, 1));+ Fight(c, destroyed);+ Assert.False(destroyed.Units.ContainsKey(2));+ var retreated = CombatTests.With(c, Attacking(Soldier(1, 3, 0, 9), 2, 0), Enemy(2, 2, 0, 3));+ Fight(c, retreated);+ Assert.True(retreated.Units.ContainsKey(2));+ Assert.Empty(destroyed.PrisonersHeld);+ Assert.Empty(retreated.PrisonersHeld);+ }++ // R-POW-001: no command takes prisoners: every command kind (CommandGuardTests.Samples, which fails when a kind is added+ // without a sample), played on a state that holds some and has no engagement, leaves the count as it was.+ [Fact]+ public void OnlySurrenderTakesPrisoners()+ {+ var c = Load();+ foreach (var cmd in CommandGuardTests.Samples.Values)+ {+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ s.PrisonersHeld["egypt"] = 2;+ s.SoldiersHeld["egypt"] = 1;+ var r = Simulation.Step(c, s, new[] { cmd });+ Assert.Equal(new[] { ("egypt", 2) }, r.State.PrisonersHeld.Select(kv => (kv.Key, kv.Value)));+ Assert.Equal(new[] { ("egypt", 1) }, r.State.SoldiersHeld.Select(kv => (kv.Key, kv.Value)));+ }+ }++ // R-POW-001, R-POW-003: no event effect reaches the prisoners: the loader refuses any target that would name them.+ [Theory]+ [InlineData("prisoners")]+ [InlineData("prisoners_held")]+ [InlineData("soldiers_held")]+ public void NoEventEffectTargetsThePrisoners(string target)+ {+ Assert.DoesNotContain(target, EventRules.SpecialTargets);+ var card = $"id: deal\ntitle: A deal\ntext: A deal.\nfrom: 1948-05-15\noptions:\n - {{ id: a, text: A, effects: [{{ target: {target}, delta: 1 }}] }}\n";+ var ex = Assert.Throws<ContentException>(() => Load(new Dictionary<string, string> { ["deal.yaml"] = card }));+ Assert.Equal($"options[a].effects.{target}", ex.Field.Substring(ex.Field.IndexOf("options", StringComparison.Ordinal)));+ Assert.Contains("unknown target", ex.Message);+ }++ // R-POW-003: prisoners are never labour, Money, Arms or housing: for every command kind, a state with prisoners and one+ // without end the turn with the same Money, Arms, cities (housing, jobs, people) and units, and Food that differs by the+ // upkeep alone.+ [Fact]+ public void PrisonersAreNeverAResource()+ {+ var c = Load();+ var m = c.RulesAt(new DateTime(1948, 5, 15)).Mvp!;+ foreach (var cmd in CommandGuardTests.Samples.Values)+ {+ var without = Simulation.NewGame(c, 1, Mode.Historical);+ var with = without.Clone();+ with.PrisonersHeld["egypt"] = 3;+ var a = Simulation.Step(c, without, new[] { cmd }).State;+ var b = Simulation.Step(c, with, new[] { cmd }).State;+ Assert.Equal((a.Treasury, a.Debt, a.Arms), (b.Treasury, b.Debt, b.Arms));+ Assert.Equal(a.Food - 3 * m.FoodPerPrisonerUnit!.Value, b.Food);+ Assert.Equal(string.Join(";", a.Cities.Values.Select(x => x.Canonical(false))), string.Join(";", b.Cities.Values.Select(x => x.Canonical(false))));+ Assert.Equal(string.Join(";", a.Units.Values.Select(x => x.Canonical())), string.Join(";", b.Units.Values.Select(x => x.Canonical())));+ }+ }++ // R-POW-004 (impact plan section 4.3 item 3): the score does not move on the turn of a surrender. The mutation run scores+ // at capture and must fail here.+ [Fact]+ public void NoScoreAtCapture()+ {+ var c = Load();+ var s = Surrounded(c);+ s.Score = 7;+ var r = Simulation.Step(c, s, Array.Empty<Command>());+ Assert.Equal(2, r.State.PrisonersHeld["egypt"]);+ Assert.Equal(7, r.State.Score);+ }++ /// <summary>Plays empty turns (the fixture's are weekly) until <paramref name="card"/> waits for a decision, checking it+ /// does not fire before its window opens on 1 July 1948.</summary>+ static StepResult UntilCard(Content c, GameState s, string card)+ {+ for (int i = 0; i < 20; i++)+ {+ var r = Simulation.Step(c, s, Array.Empty<Command>());+ if (r.State.PendingEvents.Contains(card))+ {+ Assert.True(r.State.Date >= new DateTime(1948, 7, 1));+ return r;+ }+ s = r.State;+ }+ throw new InvalidOperationException(card + " never fired");+ }++ // R-POW-004 (Q-POW-2, Q-POW-3): the front's card fires on the first turn in its window with prisoners held; resolving+ // it returns them and scores points_per_prisoner_unit_returned per unit. The Jordan card returns the Iraqi prisoners too+ // (Q-OBJ-1: the Jordan agreement takes over the Iraqi sector); nothing returns the ALA's (no front).+ [Fact]+ public void ScoredAtTheReturn()+ {+ var c = Load();+ var points = c.RulesAt(new DateTime(1948, 5, 15)).Mvp!.PointsPerPrisonerUnitReturned!.Value;+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ s.PrisonersHeld["egypt"] = 3;+ s.PrisonersHeld["iraq"] = 2;+ s.PrisonersHeld["ala"] = 4;+ var r = UntilCard(c, s, "pow_egypt");+ Assert.Contains("pow_jordan", r.State.PendingEvents); // both cards fire on the same turn+ Assert.Equal(0, r.State.Score);+ r = Simulation.Step(c, r.State, new Command[] { new ChooseEventOption("pow_egypt", "continue") }); // pow_jordan is delegated+ Assert.Equal(5 * points, r.State.Score);+ Assert.Equal(new[] { ("ala", 4) }, r.State.PrisonersHeld.Select(kv => (kv.Key, kv.Value)));+ Assert.Equal(new[] { ("egypt", 3), ("iraq", 2) }, r.State.PrisonersReturned.Select(kv => (kv.Key, kv.Value)));+ Assert.Contains(r.Why, x => x.Message == "Prisoners exchanged: 30 prisoners returned to Egypt");+ }++ // R-POW-004: a front's card waits for prisoners: with none held either way it does not fire, so a run with no surrender+ // fires no card (and its goldens do not move).+ [Fact]+ public void TheCardWaitsForPrisoners()+ {+ var c = Load();+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ s.PrisonersHeld["ala"] = 1; // no front's card returns them+ for (int i = 0; i < 4; i++) s = Simulation.Step(c, s, Array.Empty<Command>()).State;+ Assert.DoesNotContain("pow_egypt", s.FiredEvents);+ Assert.DoesNotContain("pow_jordan", s.FiredEvents);+ }++ // R-POW-002 (Q-POW-5): prisoners eat food_per_prisoner_unit a unit in step 7, after the nation and the import.+ [Fact]+ public void PrisonersEatFood()+ {+ var c = Load();+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ s.PrisonersHeld["egypt"] = 3;+ s.Food = 100;+ var morale = s.Indicators["morale"];+ var why = Upkeep(c, s);+ Assert.Equal(94, s.Food);+ Assert.Equal(morale, s.Indicators["morale"]);+ Assert.Contains(why, x => x.Message == "The prisoners held ate 6 units of Food");+ }++ // R-POW-002: a shortfall never reduces the prisoners.+ [Fact]+ public void AFoodShortfallNeverReducesPrisoners()+ {+ var c = Load();+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ s.PrisonersHeld["egypt"] = 3;+ s.Food = 1;+ Upkeep(c, s);+ Assert.Equal(0, s.Food);+ Assert.Equal(3, s.PrisonersHeld["egypt"]);+ }++ // R-POW-002 (Q-POW-5): what the stock cannot give costs prisoner_shortfall_cohesion of Social cohesion a Food unit.+ [Fact]+ public void AFoodShortfallCostsCohesion()+ {+ var c = Load();+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ s.PrisonersHeld["egypt"] = 3;+ s.Food = 1;+ var morale = s.Indicators["morale"];+ var why = Upkeep(c, s);+ Assert.Equal(morale - 5 * 0.05, s.Indicators["morale"], 12); // 6 needed, 1 given+ Assert.Contains(why, x => x.Message.StartsWith("The prisoners held went short of 5 units of Food: ", StringComparison.Ordinal));+ }++ // R-POW-002: the cost survives the whole turn: the effects web that runs after step 7 keeps the shift.+ [Fact]+ public void AFoodShortfallCostsCohesionOverATurn()+ {+ var c = Load();+ var without = Simulation.NewGame(c, 1, Mode.Historical);+ var with = without.Clone();+ with.PrisonersHeld["egypt"] = 1000; // more than the stock after the import can feed+ var a = Simulation.Step(c, without, Array.Empty<Command>()).State;+ var b = Simulation.Step(c, with, Array.Empty<Command>()).State;+ Assert.Equal(0, b.Food);+ Assert.True(b.Indicators["morale"] < a.Indicators["morale"]);+ Assert.Equal(1000, b.PrisonersHeld["egypt"]);+ }++ // R-POW-005 (Q-POW-4): a surrendered unit of the player's is counted under the side of the engagement's lowest-id+ // attacker, not as prisoners and not in its units.+ [Fact]+ public void OwnSoldiersAreCountedWhenTheySurrender()+ {+ var c = Load();+ var s = CombatTests.With(c, Attacking(Enemy(4, 1, 0, 4, "iraqi", "iraq"), 0, 0), Attacking(Enemy(2, 0, 1, 4), 0, 0), Soldier(5, 0, 0, 3));+ Fight(c, s);+ Assert.False(s.Units.ContainsKey(5));+ Assert.Empty(s.PrisonersHeld);+ Assert.Equal(new[] { ("egypt", 2) }, s.SoldiersHeld.Select(kv => (kv.Key, kv.Value)));+ }++ // R-POW-005 with R-COMBAT-007: step 2 lists the guns after the other attackers, but the captor is still the lowest-id+ // attacker, here Egypt's gun and not the Iraqi unit beside it.+ [Fact]+ public void OwnSoldiersAreHeldByTheLowestIdAttackerWhenItIsAGun()+ {+ var c = Load();+ var s = CombatTests.With(c, Attacking(Enemy(2, 0, 1, 4, "egypt_gun"), 0, 0), Attacking(Enemy(4, 1, 0, 4, "iraqi", "iraq"), 0, 0), Soldier(5, 0, 0, 3));+ Fight(c, s);+ Assert.False(s.Units.ContainsKey(5));+ Assert.Equal(new[] { ("egypt", 2) }, s.SoldiersHeld.Select(kv => (kv.Key, kv.Value)));+ }++ // R-POW-005: the player's soldiers come home on their front's card, with no score.+ [Fact]+ public void OwnSoldiersReturnWithNoScore()+ {+ var c = Load();+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ s.SoldiersHeld["egypt"] = 2;+ s.Score = 7;+ s = UntilCard(c, s, "pow_egypt").State; // the soldiers held alone make the card fire+ var r = Simulation.Step(c, s, Array.Empty<Command>());+ Assert.Empty(r.State.SoldiersHeld);+ Assert.Equal(7, r.State.Score);+ Assert.Contains(r.Why, x => x.Message == "Prisoners exchanged: 20 of our soldiers came home from Egypt");+ }++ // R-POW-005 (Q-POW-4): each turn they are held, the Treasury pays held_soldier_cost_per_turn a unit, borrowing what it lacks.+ [Fact]+ public void OwnSoldiersCostWhileHeld()+ {+ var c = Load();+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ s.SoldiersHeld["egypt"] = 2;+ s.Treasury = 0.4;+ var debt = s.Debt;+ Upkeep(c, s);+ Assert.Equal((0.0, debt + 0.6), (s.Treasury, s.Debt)); // IL 1m: 0.4 paid, 0.6 borrowed+ }++ // The counts are in the hash and the clone copies them (docs/determinism.md); a state with none hashes as before.+ [Fact]+ public void TheCountsAreState()+ {+ var c = Load();+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ var none = s.Hash();+ var copy = s.Clone();+ copy.PrisonersHeld["egypt"] = 1;+ Assert.Empty(s.PrisonersHeld);+ Assert.NotEqual(none, copy.Hash());+ var back = s.Clone(); back.PrisonersReturned["egypt"] = 1; Assert.NotEqual(none, back.Hash());+ var held = s.Clone(); held.SoldiersHeld["egypt"] = 1; Assert.NotEqual(none, held.Hash());+ Assert.Equal(none, s.Clone().Hash());+ }++ // The card's front is a known front and the card has one option (it resolves without a draw); the values are required.+ [Theory]+ [InlineData("prisoners: egypt", "prisoners: iraq", "prisoners", "unknown front 'iraq'")]+ [InlineData(" historical: true\n", " historical: true\n - id: other\n text: Other\n alternative: { basis: design }\n", "options", "exactly one option")]+ public void BadCardsFailNamingTheField(string from, string to, string field, string message)+ {+ var ex = Assert.Throws<ContentException>(() => Load(new Dictionary<string, string> { ["pow_egypt.yaml"] = Card("pow_egypt", "egypt", "1948-07-01").Replace(from, to) }));+ Assert.Equal("events/pow_egypt.yaml", ex.File);+ Assert.Equal("events[pow_egypt]." + field, ex.Field);+ Assert.Contains(message, ex.Message);+ }++ [Theory]+ [InlineData("food_per_prisoner_unit: 2", "", "mvp.food_per_prisoner_unit", "required")]+ [InlineData("food_per_prisoner_unit: 2", "food_per_prisoner_unit: -1", "mvp.food_per_prisoner_unit", "must be >= 0")]+ [InlineData("prisoner_shortfall_cohesion: 0.05", "", "mvp.prisoner_shortfall_cohesion", "required")]+ [InlineData("prisoner_shortfall_cohesion: 0.05", "prisoner_shortfall_cohesion: -0.1", "mvp.prisoner_shortfall_cohesion", "must be a finite number >= 0")]+ [InlineData("points_per_prisoner_unit_returned: 7", "", "mvp.points_per_prisoner_unit_returned", "required")]+ [InlineData("points_per_prisoner_unit_returned: 7", "points_per_prisoner_unit_returned: -1", "mvp.points_per_prisoner_unit_returned", "must be >= 0")]+ [InlineData("held_soldier_cost_per_turn: 0.5", "", "mvp.held_soldier_cost_per_turn", "required")]+ [InlineData("held_soldier_cost_per_turn: 0.5", "held_soldier_cost_per_turn: -1", "mvp.held_soldier_cost_per_turn", "must be a finite number >= 0")]+ public void BadValuesFailNamingTheField(string from, string to, string field, string message)+ {+ var ex = Assert.Throws<ContentException>(() => Load(rules: Rules(from, to)));+ Assert.Equal(("rules.yaml", field), (ex.File, ex.Field));+ Assert.Contains(message, ex.Message);+ }+}diff --git a/sim/Statecraft.Sim/Combat.cs b/sim/Statecraft.Sim/Combat.csindex 807a919f4..586b2f9d4 100644--- a/sim/Statecraft.Sim/Combat.cs+++ b/sim/Statecraft.Sim/Combat.cs@@ -221,10 +221,13 @@ namespace Statecraft.Sim}else{- // The only way a unit is captured (impact plan section 4.3 item 1); the prisoners themselves are Phase 5 PR 12.+ // The only way a unit is captured (impact plan section 4.3 item 1; R-POW-001). Its captor is the engagement's+ // lowest-id attacker (not attackers[0]: the guns are listed last, R-COMBAT-007), whose side holds the+ // player's soldiers (R-POW-005).s.Units.Remove(u.Id);+ var held = Prisoners.Take(s, u, attackers.OrderBy(x => x.Id).First());why.Add(new Cause("map", u.Id.ToString(CultureInfo.InvariantCulture), 0,- FormattableString.Invariant($"Unit {u.Id} surrendered with {u.Strength * ppu:N0} people: it had no hex to retreat to")));+ FormattableString.Invariant($"Unit {u.Id} surrendered with {u.Strength * ppu:N0} people: it had no hex to retreat to. {held}")));}}}diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex 4091e1c72..1b083436b 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -636,6 +636,16 @@ namespace Statecraft.Sim/// <summary>The share of each numeric effect a delegated option applies when its minister is below the loyalty floor/// (R-EVT-003; #107). Required in the GDD loop, 0 to 1.</summary>public double? DisloyalEffectShare { get; set; }+ /// <summary>Food each population unit of prisoners eats a turn, in step 7 (R-POW-002; Q-POW-5). Required in the GDD loop, >= 0.</summary>+ public int? FoodPerPrisonerUnit { get; set; }+ /// <summary>Social cohesion lost for each unit of the prisoners' Food the stock cannot give (R-POW-002; Q-POW-5).+ /// Required in the GDD loop, >= 0.</summary>+ public double? PrisonerShortfallCohesion { get; set; }+ /// <summary>Points scored for each population unit of prisoners returned (R-POW-004; Q-POW-2). Required in the GDD loop, >= 0.</summary>+ public int? PointsPerPrisonerUnitReturned { get; set; }+ /// <summary>IL millions the Treasury pays a turn for each population unit of the player's soldiers held (R-POW-005;+ /// Q-POW-4). Required in the GDD loop, >= 0.</summary>+ public double? HeldSoldierCostPerTurn { get; set; }}/// <summary>One row of rules.yaml mvp.combat_table (R-COMBAT-002, R-COMBAT-003): it applies from an attack : defence@@ -1049,6 +1059,10 @@ namespace Statecraft.Sim/// only while that site is being worked (R-SWAMP-002; Q-SWAMP-2). The legacy loop reads no sites and ignores it./// Empty for every other event.</summary>public string Site { get; set; } = "";+ /// <summary>The front (one of Prisoners.Fronts) whose prisoners this card returns (R-POW-004; Q-POW-3): it fires only+ /// while that front holds prisoners or the player's soldiers, has exactly one option and resolves without a draw.+ /// Empty for every other event.</summary>+ public string Prisoners { get; set; } = "";/// <summary>Path relative to the content root, set by the loader (not read from YAML).</summary>[YamlIgnore] public string File { get; set; } = "";}diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex 2ba801f5e..e2e69dc84 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -353,6 +353,8 @@ namespace Statecraft.Sim// that objective is recorded, and has exactly one option// site a swamp site (sites.yaml) whose works the event is about: in the GDD loop it// fires only while that site is being worked; the legacy loop ignores it+ // prisoners a front (Prisoners.Fronts) whose prisoners the card returns: it fires only while+ // that front holds some either way, and has exactly one option (R-POW-004)foreach (var rel in eventFiles.OrderBy(p => p, StringComparer.Ordinal)){var e = Read<GameEvent>(readFile, rel);@@ -1265,6 +1267,18 @@ namespace Statecraft.Simthrow 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.if (m.End != c.Rules.Mvp!.End) throw new ContentException(file, "mvp.end", "must be the same in every era (the game has one end)");+ // R-POW-002, R-POW-004, R-POW-005 (Q-POW-2, Q-POW-4, Q-POW-5): required, so a missing key is never read as+ // prisoners who eat nothing, a shortfall that costs nothing or a return that scores nothing.+ foreach (var (key, v) in new[] { ("food_per_prisoner_unit", m.FoodPerPrisonerUnit), ("points_per_prisoner_unit_returned", m.PointsPerPrisonerUnitReturned) })+ {+ if (v == null) throw new ContentException(file, "mvp." + key, "required when eras.yaml systems.loop is gdd");+ if (v < 0) throw new ContentException(file, "mvp." + key, "must be >= 0");+ }+ foreach (var (key, v) in new[] { ("prisoner_shortfall_cohesion", m.PrisonerShortfallCohesion), ("held_soldier_cost_per_turn", m.HeldSoldierCostPerTurn) })+ {+ if (v == null) throw new ContentException(file, "mvp." + key, "required when eras.yaml systems.loop is gdd");+ if (!(v >= 0 && IsFinite(v.Value))) throw new ContentException(file, "mvp." + key, "must be a finite number >= 0");+ }// R-OBJ-002. Required, so a missing key is not read as 0. Zero is allowed (a balance choice); a negative value// would take points away for finishing.foreach (var (key, v) in new[] { ("objective_points", m.ObjectivePoints), ("objective_bonus_per_month", m.ObjectiveBonusPerMonth), ("objective_bonus_cap", m.ObjectiveBonusCap) })@@ -1290,10 +1304,23 @@ namespace Statecraft.SimValidateSites(c);ValidateObjectiveConditions(c);ValidateEventSites(c);+ ValidateEventPrisoners(c);ValidateProjects(c);ValidateCorridors(c);}+ /// <summary>An exchange card (R-POW-004): a known front, and one option, which Delegate resolves without a draw.</summary>+ static void ValidateEventPrisoners(Content c)+ {+ foreach (var e in c.Events.Where(e => e.Prisoners != ""))+ {+ if (!Prisoners.Fronts.Contains(e.Prisoners))+ throw new ContentException(e.File, $"events[{e.Id}].prisoners", $"unknown front '{e.Prisoners}' (one of {string.Join(", ", Prisoners.Fronts)})");+ if (e.Options.Count != 1)+ throw new ContentException(e.File, $"events[{e.Id}].options", "an exchange card has exactly one option");+ }+ }+/// <summary>An event's site (R-SWAMP-002): a designated swamp site, whose works the event is about. Only the GDD loop/// reads sites.yaml, so only it can check this; the legacy loop ignores the key.</summary>static void ValidateEventSites(Content c)diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.csindex e77d00af5..d59ef8db0 100644--- a/sim/Statecraft.Sim/EventSystem.cs+++ b/sim/Statecraft.Sim/EventSystem.cs@@ -31,6 +31,9 @@ namespace Statecraft.Sim// R-SWAMP-002: an event about a site's works waits for those works, and stops once the site is built (drained).// The legacy loop reads no sites, so it ignores the key and the legacy goldens hold..Where(e => e.Site == "" || !c.IsGdd || (s.Sites.TryGetValue(e.Site, out var works) && works.BuiltOn == null))+ // R-POW-004: a front's exchange card waits for prisoners held either way. Only the GDD loop takes any, so the+ // legacy loop never fires one.+ .Where(e => e.Prisoners == "" || Prisoners.Held(s, e.Prisoners))// A late fire can come after a dated indicator's window has ended (chapters design 3.2): a condition on it is not met..Where(e => e.Conditions.All(k => s.Indicators.TryGetValue(k.Indicator, out var v)&& (!k.Min.HasValue || v >= k.Min.Value) && (!k.Max.HasValue || v <= k.Max.Value)))@@ -144,6 +147,8 @@ namespace Statecraft.Simwhy.Add(new Cause("events", kv.Key, kv.Value, $"{PlayerText.Target(c, kv.Key)} set to {PlayerText.Percent(kv.Value)} ({title})"));}if (o.SetRung.HasValue) SecuritySystem.SetRung(c, s, o.SetRung.Value, why);+ // R-POW-004: an exchange card returns its front's prisoners, whichever way it was resolved (it has one option).+ if (Get(c, eventId).Prisoners is var front && front != "") Prisoners.Return(c, s, front, why);}/// <summary>A late-fired event can be resolved after a dated record's window has ended (chapters design 3.2): an@@ -209,7 +214,7 @@ namespace Statecraft.Sim{var e = Get(c, id);var minister = DelegatedTo(c, s, e);- if (e.Objective != "")+ if (e.Objective != "" || e.Prisoners != "") // R-POW-004: an exchange card, like an objective's, has one option and draws nothing{Resolve(c, s, id, e.Options[0], $"delegated to {minister?.Name ?? "the cabinet"}", why);continue;diff --git a/sim/Statecraft.Sim/GameState.cs b/sim/Statecraft.Sim/GameState.csindex 84bc7849c..7935f0af2 100644--- a/sim/Statecraft.Sim/GameState.cs+++ b/sim/Statecraft.Sim/GameState.cs@@ -94,6 +94,13 @@ namespace Statecraft.Simpublic int ExhaustedTurns;/// <summary>The national Arms stock (R-ARMS-001; D-G6): one Arms is the equipment package for one 1,000-person recruit group. Never below 0.</summary>public int Arms;+ /// <summary>The enemy prisoners held, in population units, by the side of the unit that surrendered (R-POW-001; impact+ /// plan section 4.3). Only a surrender in combat adds to it; only a front's exchange card takes from it (R-POW-004).</summary>+ public SortedDictionary<string, int> PrisonersHeld = new SortedDictionary<string, int>(StringComparer.Ordinal);+ /// <summary>The prisoners returned so far, in population units, by side (R-POW-004).</summary>+ public SortedDictionary<string, int> PrisonersReturned = new SortedDictionary<string, int>(StringComparer.Ordinal);+ /// <summary>The player's soldiers held by the enemy, in population units, by the side that took them (R-POW-005; Q-POW-4).</summary>+ public SortedDictionary<string, int> SoldiersHeld = new SortedDictionary<string, int>(StringComparer.Ordinal);public double TotalPopulation => Population.Values.Sum();@@ -121,6 +128,9 @@ namespace Statecraft.Simc.UnlockedProjects = new SortedSet<string>(UnlockedProjects, StringComparer.Ordinal);c.Objectives = new SortedDictionary<string, DateTime>(Objectives, StringComparer.Ordinal);c.Settlements = new SortedDictionary<string, SettlementControl>(Settlements, StringComparer.Ordinal);+ c.PrisonersHeld = new SortedDictionary<string, int>(PrisonersHeld, StringComparer.Ordinal);+ c.PrisonersReturned = new SortedDictionary<string, int>(PrisonersReturned, StringComparer.Ordinal);+ c.SoldiersHeld = new SortedDictionary<string, int>(SoldiersHeld, StringComparer.Ordinal);return c;}@@ -224,6 +234,11 @@ namespace Statecraft.Sim}if (ExhaustedTurns != 0) { Sep(); Nl(); sb.Append("exhausted=").Append(ExhaustedTurns.ToString(CultureInfo.InvariantCulture)); }if (Arms != 0) { Sep(); Nl(); sb.Append("arms=").Append(Arms.ToString(CultureInfo.InvariantCulture)); }+ // Prisoners (R-POW-001 to R-POW-005): written only once a surrender has happened, so a run with none hashes as before.+ IEnumerable<string> Counts(SortedDictionary<string, int> m) => m.Select(kv => kv.Key + "=" + kv.Value.ToString(CultureInfo.InvariantCulture));+ if (PrisonersHeld.Count > 0) Section("pow", '{', '}', Counts(PrisonersHeld));+ if (PrisonersReturned.Count > 0) Section("powret", '{', '}', Counts(PrisonersReturned));+ if (SoldiersHeld.Count > 0) Section("ownheld", '{', '}', Counts(SoldiersHeld));return sb.ToString();}}diff --git a/sim/Statecraft.Sim/Prisoners.cs b/sim/Statecraft.Sim/Prisoners.csnew file mode 100644index 000000000..6e6671c7b--- /dev/null+++ b/sim/Statecraft.Sim/Prisoners.cs@@ -0,0 +1,101 @@+using System;+using System.Collections.Generic;+using System.Globalization;+using System.Linq;++namespace Statecraft.Sim+{+ /// <summary>Prisoners in the GDD v0.1 loop (Phase 5 PR 12; docs/rules/mvp.md R-POW-001 to R-POW-005), the impact plan's+ /// section 4.3 as written (Q-POW-1, owner, 15 October 2026). Only a surrender in combat takes prisoners; residents never+ /// are. They are held on Food upkeep and are never labour, Money, Arms or anything a command or event can spend. Each+ /// front's sourced exchange card returns them, and the points come then, never at the capture. The player's soldiers+ /// taken in a surrender are a count that costs Money while held and comes home on the same card, with no score. Nothing+ /// here celebrates a capture: the Why lines state counts in people, as combat states its losses (Q-CIV-4).</summary>+ public static class Prisoners+ {+ /// <summary>The front whose exchange card returns each enemy side's prisoners: the armistice agreements' parties+ /// (Q-OBJ-1), with Iraq under Jordan, whose agreement took over the Iraqi sector (Art. VI). The ALA and the local+ /// forces belong to no front, so no card returns their prisoners (they stay held to the game's end).</summary>+ static readonly Dictionary<string, string> FrontOf = new Dictionary<string, string>(StringComparer.Ordinal)+ {+ ["egypt"] = "egypt", ["lebanon"] = "lebanon", ["syria"] = "syria", ["jordan"] = "jordan", ["iraq"] = "jordan",+ };++ /// <summary>The fronts an exchange card may name (GameEvent.Prisoners), in ordinal order.</summary>+ public static readonly IReadOnlyList<string> Fronts = FrontOf.Values.Distinct().OrderBy(x => x, StringComparer.Ordinal).ToList();++ static string Name(string front) => PlayerText.Capitalised(front);++ static void Add(SortedDictionary<string, int> m, string side, int units) =>+ m[side] = (m.TryGetValue(side, out var n) ? n : 0) + units;++ /// <summary>R-POW-001, R-POW-005: unit <paramref name="u"/> surrendered to <paramref name="captor"/>'s side. An enemy unit's+ /// people become prisoners under its own side; the player's soldiers are counted under the captor's side. Called only by+ /// Combat's surrender, the one way a unit is captured.</summary>+ internal static string Take(GameState s, Unit u, Unit captor)+ {+ if (u.Side == Movement.PlayerSide)+ {+ Add(s.SoldiersHeld, captor.Side, u.Strength);+ return "They are held by the enemy";+ }+ Add(s.PrisonersHeld, u.Side, u.Strength);+ return "They are held as prisoners";+ }++ 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>+ internal static bool Held(GameState s, string front) =>+ Sides(front).Any(x => s.PrisonersHeld.ContainsKey(x) || s.SoldiersHeld.ContainsKey(x));++ /// <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+ /// cohesion and never a prisoner (Q-POW-5). Then the Treasury pays held_soldier_cost_per_turn for each unit of the+ /// player's soldiers held, borrowing what it lacks (Q-POW-4; R-MONEY-003).</summary>+ public static void Upkeep(Content c, GameState s, MvpRules r, List<Cause> why)+ {+ var need = (long)s.PrisonersHeld.Values.Sum() * r.FoodPerPrisonerUnit!.Value;+ if (need > 0)+ {+ var eaten = (int)Math.Min(need, s.Food);+ s.Food -= eaten;+ why.Add(new Cause("economy", "food", -eaten, FormattableString.Invariant($"The prisoners held ate {eaten} units of Food")));+ var unfed = need - eaten;+ if (unfed > 0)+ {+ var change = EffectsSystem.Shift(c, s, "morale", -unfed * r.PrisonerShortfallCohesion!.Value);+ why.Add(new Cause("economy", "morale", change, FormattableString.Invariant($"The prisoners held went short of {unfed} units of Food: {PlayerText.Change(c, "morale", change)}")));+ }+ }+ var held = s.SoldiersHeld.Values.Sum();+ if (held == 0) return;+ var cost = held * r.HeldSoldierCostPerTurn!.Value;+ if (cost > 0) EconomySystem.PayOrBorrow(c, s, cost, "for our soldiers held by the enemy", why);+ }++ /// <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>+ internal static void Return(Content c, GameState s, string front, List<Cause> why)+ {+ // 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;+ int returned = 0, home = 0;+ foreach (var side in Sides(front))+ {+ if (s.PrisonersHeld.TryGetValue(side, out var n)) { s.PrisonersHeld.Remove(side); Add(s.PrisonersReturned, side, n); returned += n; }+ if (s.SoldiersHeld.TryGetValue(side, out var m)) { s.SoldiersHeld.Remove(side); home += m; }+ }+ if (returned > 0)+ {+ s.Score += returned * points;+ why.Add(new Cause("events", "prisoners", returned, FormattableString.Invariant($"Prisoners exchanged: {returned * ppu:N0} prisoners returned to {Name(front)}")));+ }+ if (home > 0)+ why.Add(new Cause("events", "prisoners", home, FormattableString.Invariant($"Prisoners exchanged: {home * ppu:N0} of our soldiers came home from {Name(front)}")));+ }+ }+}diff --git a/sim/Statecraft.Sim/TurnResolver.cs b/sim/Statecraft.Sim/TurnResolver.csindex 07b092495..a0859f4f9 100644--- a/sim/Statecraft.Sim/TurnResolver.cs+++ b/sim/Statecraft.Sim/TurnResolver.cs@@ -24,6 +24,7 @@ namespace Statecraft.SimCities.Produce(c, s, r, yearFraction, why); // 6. productionPools.Harvest(c, s, r, why); // and the plowed fields' Food (R-FIELD-002)Pools.Consume(c, s, r, why); // 7. consumption: the nation eats, then imports (R-FOOD-002)+ Prisoners.Upkeep(c, s, r, why); // then the prisoners eat, and the soldiers held are paid for (R-POW-002, R-POW-005)EconomySystem.PayCivilianUpkeep(c, s, r, yearFraction, why); // and pays Money upkeep (R-MONEY-002)Cities.House(c, s, r, why); // 8. housing, then the housing condition; Social cohesion is morale, which the effects web moves after the resolutionCities.UpdateCondition(c, s, r, why);