A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: ResolveCapture, the options helper, Raid and withdraw (GDD Phase 6 PR 5, refs #797) (#1257)
Berifdd5e6017705
diff --git a/changelog.d/sim-gdd-raid-797.md b/changelog.d/sim-gdd-raid-797.mdnew file mode 100644index 000000000..02a1a4c5e--- /dev/null+++ b/changelog.d/sim-gdd-raid-797.md@@ -0,0 +1,7 @@+- Answering a capture, GDD Phase 6 PR 5 (#797; R-CTRL-007 to R-CTRL-010): a new `ResolveCapture(settlement, outcome)`+ order, one kind for every outcome at `attention_cost.resolve_capture` 0 (a design value proposed on #797). The sim's+ `SettlementControl.CaptureOptions` lists Raid and withdraw, Occupy and Deport in that fixed order, with nothing+ pre-selected and a preview worked out on a copy of the state. Occupy and Deport are refused as not built yet. Raid+ moves the player's units off the place to the first free neighbouring hex and puts it back under enemy control, with+ its residents unchanged. `HistoricalAI` and the reference player answer every capture with Raid, and a capture still+ waiting at the game's end counts as Raid. No golden moves: the shipped target list is empty.diff --git a/content/rules.yaml b/content/rules.yamlindex 7c074df93..8d064eaba 100644--- a/content/rules.yaml+++ b/content/rules.yaml@@ -22,6 +22,7 @@ attention_cost:cancel_project: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6, D-C5, Q-PROJ-5: cancel_training's cost)move: 0 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6: unit orders are free)buy_arms: 1 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6, D-G6, #781: one order, whatever the quantity)+ resolve_capture: 0 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6: unit orders are free; Q-TECH-3: one key, so Raid, Occupy and Deport cost the same; proposed on #797)# Turn length on each security rung, rungs 1 to 5 (R-TURN-001). The GDD MVP plays monthly turns on every rung (D-B1), so# turns from 15 May 1948 end on the 15th of each month.turn_lengths: [month, month, month, month, month]diff --git a/docs/determinism.md b/docs/determinism.mdindex bd5ddd919..40443a015 100644--- a/docs/determinism.md+++ b/docs/determinism.md@@ -21,6 +21,9 @@ The simulation must produce the same state, bit for bit, on .NET, Unity Mono and- **Settlement control (resolver step 3):** targets resolve in ordinal id order, and the capture check reads only unitpositions, with no RNG draw (R-CTRL-004; `CaptureTests.SettlementsResolveInOrdinalOrder` and `NoRngDraw`). The shippedtarget list is empty, so no golden captures a place.+- **Answering a capture (Raid and withdraw):** the units on the place leave in ascending id, each to the first free hex in+ the fixed neighbour order, and the captures still waiting at the game's end resolve in ordinal id order, with no RNG+ draw (R-CTRL-008, R-CTRL-010; `RaidTests.RaidDrawsNothing`). No golden captures a place, so none answers one.## Golden playthroughsdiff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex bd3d4ceed..a8b4a7046 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -40,6 +40,14 @@ R-CTRL-004: Resolver step 3 is the capture check, after combat (step 2), in ordiR-CTRL-005: Capture writes the settlement state only. It changes no resident field (the place stays inhabited), no unit, no resource, parameter, city or score, and counts towards no objective (constraint 6 of the Phase 6 plan; impact plan section 4.3).+R-CTRL-007: `ResolveCapture(settlement, outcome)` answers a capture. It is one command kind for every outcome, with one `attention_cost.resolve_capture` (Q-TECH-3, owner, 18 October 2026, #783 batch 1), set at 0 as a design value proposed on #797 (D-A6: unit orders are free). It is valid only for a settlement whose record is awaiting the choice, from the turn after its capture until it is answered, and only for an outcome that is built. Otherwise it is refused with a reason, the state unchanged and the Attention refunded: the place is not awaiting a decision, the outcome is not known, or Occupy or Deport is not built yet (Phase 6 PRs 6 and 8). The legacy loop refuses it before charging Attention.++R-CTRL-008: `SettlementControl.CaptureOptions(content, state, settlement)` lists the outcomes in one fixed order, Raid and withdraw, Occupy, Deport, so Deport is never first (impact plan section 4.1 item 1). An option carries no default or selected flag. Each option has either the reason it is refused or a preview: the change resolving it makes at once to Attention, Money (the Treasury and the debt), Food, Arms, Social cohesion, International Support and the score, computed by resolving it on a copy of the state, so the preview is the outcome (spec section 2.6). A place not awaiting the choice offers no option. A capture the player does not answer waits, and the units stay (Q-HIST-1 (a), owner, 18 October 2026, #783 batch 3). On the turn that reaches the game's end, where resolver step 10 sits and before objectives and score, every capture still awaiting the choice counts as Raid, in ordinal id order (owner, 18 October 2026 on #797, "Counts as Raid"): the units leave as R-CTRL-010 says, nothing changes for the residents and the score gains nothing. A unit with nowhere to go stays while the others leave, and the record goes all the same. No unanswered choice ever resolves as Deport.++R-CTRL-009: `HistoricalAI` answers every capture awaiting the choice with Raid, in ordinal id order, leaving out a Raid the sim would refuse (a unit with nowhere to go), which then waits, and the reference player sends `HistoricalAI`'s orders, so it does too (Q-REF-1 (a), owner, 18 October 2026, #783 batch 3). Neither ever issues Deport, and nothing delegates a capture: `EventSystem.Delegate` answers events only (impact plan section 4.1 item 1).++R-CTRL-010: Raid and withdraw (Q-RAID-1 (a), owner, 18 October 2026, #783 batch 3). The player's units on the place's hex, soldiers and halutzim alike, leave in ascending id, each to the first neighbouring hex in the fixed neighbour order (R-MOVE-002) that is land, holds no enemy unit, is not an enemy-held locality (R-MOVE-005) and has room under the stack limit (R-MOVE-003). Leaving costs no movement points, and the units keep their orders, as after a `Move` that ends on another hex: a fortify is lost at the turn's order step (R-ORDER-002); both are defaults proposed on #797. The record is removed, so the place is under enemy control again at once, and its residents are unchanged. Raid changes nothing else: no resource, parameter, city, score or objective, and no RNG draw. If a unit has no such hex, Raid is refused with a reason and the state is unchanged, so the choice waits.+## SavesR-SAVE-001: A save names the ruleset it was played under (`ruleset legacy` or `ruleset gdd-0.1`, save schema 2). A game refuses a save made under another ruleset. A schema 1 save has no ruleset line and is legacy, so the GDD game refuses it as made under earlier rules. The refusal carries a code (`older_rules`) the UI translates, and the sim's reason does not itself ask for a new game: the player reads that once (N4).diff --git a/sim/Statecraft.Sim.Tests/CaptureOptionsTests.cs b/sim/Statecraft.Sim.Tests/CaptureOptionsTests.csnew file mode 100644index 000000000..863528239--- /dev/null+++ b/sim/Statecraft.Sim.Tests/CaptureOptionsTests.cs@@ -0,0 +1,98 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;+using Statecraft.Sim.Reference;++/// <summary>The capture options helper and the automated players (GDD Phase 6 PR 5, #797). Impact plan section 4.1 item 1:+/// Deport is never the default, never first, never pre-selected, and never chosen by the reference player or delegation;+/// Q-REF-1 (a) (owner, 18 October 2026, #783 batch 3): the reference player and HistoricalAI always Raid. The places are+/// CaptureTests' fixture values, not history.</summary>+public class CaptureOptionsTests+{+ static Content Load() => CaptureTests.Load(CaptureTests.AllTargets);++ static GameState Awaiting(Content c, params string[] ids)+ {+ var s = CombatTests.With(c, CaptureTests.Soldier(1, 1, 0), CaptureTests.Soldier(2, 4, 0));+ foreach (var id in ids) s.Settlements[id] = new SettlementControl(Movement.PlayerSide, SettlementControl.AwaitingChoice, s.Date);+ return s;+ }++ // R-CTRL-008: the options come in one fixed order, Raid, Occupy, Deport, so Deport is never first; and an option+ // carries no default or selected flag, so the helper cannot pre-select one.+ [Fact]+ public void DeportIsNeverFirstOrDefault()+ {+ var c = Load();+ var options = SettlementControl.CaptureOptions(c, Awaiting(c, "town_a"), "town_a");+ Assert.Equal(new[] { SettlementControl.Raid, SettlementControl.Occupy, SettlementControl.Deport }, options.Select(o => o.Outcome).ToArray());+ Assert.NotEqual(SettlementControl.Deport, options[0].Outcome);+ Assert.Equal(new[] { "Outcome", "Preview", "Refusal" },+ typeof(CaptureOption).GetProperties().Select(p => p.Name).OrderBy(x => x, StringComparer.Ordinal).ToArray());+ }++ // R-CTRL-007, R-CTRL-008: only Raid is built in this PR. Occupy (PR 6) and Deport (PR 8) carry the "not built yet"+ // refusal and no preview; a place not awaiting the choice offers nothing.+ [Fact]+ public void OnlyRaidIsBuiltYet()+ {+ var c = Load();+ var s = Awaiting(c, "town_a");+ var options = SettlementControl.CaptureOptions(c, s, "town_a");+ Assert.Null(options[0].Refusal);+ Assert.NotNull(options[0].Preview);+ Assert.All(options.Skip(1), o => { Assert.Contains("not built yet", o.Refusal); Assert.Null(o.Preview); });+ Assert.Empty(SettlementControl.CaptureOptions(c, s, "town_c"));+ Assert.Empty(SettlementControl.CaptureOptions(c, s, "nowhere"));+ }++ // R-CTRL-008, spec section 2.6: each built option's preview is the change resolving it makes, checked here on a clone+ // the test resolves itself; for Raid every number is 0. CaptureOptions leaves the state as it found it.+ [Fact]+ public void ThePreviewIsTheOutcome()+ {+ var c = Load();+ var s = Awaiting(c, "town_a");+ s.Attention = 5;+ var before = s.Describe();+ foreach (var o in SettlementControl.CaptureOptions(c, s, "town_a").Where(o => o.Preview != null))+ {+ var after = s.Clone();+ Assert.Null(AttentionSystem.TrySpend(c, after, SettlementControl.ResolveKind));+ Assert.Null(SettlementControl.Resolve(c, after, "town_a", o.Outcome, new List<Cause>()));+ var p = o.Preview!;+ Assert.Equal(after.Attention - s.Attention, p.Attention);+ Assert.Equal(after.Treasury - s.Treasury, p.Money);+ Assert.Equal(after.Debt - s.Debt, p.Debt);+ Assert.Equal(after.Food - s.Food, p.Food);+ Assert.Equal(after.Arms - s.Arms, p.Arms);+ Assert.Equal(after.Indicators.GetValueOrDefault("morale") - s.Indicators.GetValueOrDefault("morale"), p.SocialCohesion);+ Assert.Equal(after.Indicators.GetValueOrDefault("intl_standing") - s.Indicators.GetValueOrDefault("intl_standing"), p.InternationalSupport);+ Assert.Equal(after.Score - s.Score, p.Score);+ }+ var raid = SettlementControl.CaptureOptions(c, s, "town_a")[0].Preview!;+ Assert.Equal((0.0, 0.0, 0.0, 0, 0, 0.0, 0.0, 0), (raid.Attention, raid.Money, raid.Debt, raid.Food, raid.Arms, raid.SocialCohesion, raid.InternationalSupport, raid.Score));+ Assert.Equal(before, s.Describe());+ }++ // R-CTRL-009 (section 4.1 item 1; Q-REF-1 (a)): HistoricalAI, and the reference player that sends its orders, answer+ // every capture awaiting the choice with Raid, in ordinal id order, and never with Deport. Nothing delegates a capture:+ // EventSystem.Delegate answers events only, and an unanswered capture waits (Q-HIST-1 (a)).+ [Fact]+ public void NoAutomatedPlayerDeports()+ {+ var c = Load();+ var s = Awaiting(c, "town_c", "town_a");+ foreach (var orders in new[] { HistoricalAI.Commands(c, s), ReferencePlayer.Commands(c, s) })+ {+ var captures = orders.OfType<ResolveCapture>().ToList();+ Assert.Equal(new[] { "town_a", "town_c" }, captures.Select(x => x.Settlement).ToArray());+ Assert.All(captures, x => Assert.Equal(SettlementControl.Raid, x.Outcome));+ Assert.DoesNotContain(orders, x => x is ResolveCapture r && r.Outcome == SettlementControl.Deport);+ }+ var next = Simulation.Step(c, s, ReferencePlayer.Commands(c, s));+ Assert.DoesNotContain(next.Rejected, x => x.Command is ResolveCapture);+ Assert.Empty(next.State.Settlements);+ }+}diff --git a/sim/Statecraft.Sim.Tests/CaptureTests.cs b/sim/Statecraft.Sim.Tests/CaptureTests.csindex 1211c7615..0b5f77810 100644--- a/sim/Statecraft.Sim.Tests/CaptureTests.cs+++ b/sim/Statecraft.Sim.Tests/CaptureTests.cs@@ -27,7 +27,7 @@ public class CaptureTests/// <summary>MovementTests' 6 x 3 coastal plain with the four places; <paramref name="targets"/> lists the targets in/// file order.</summary>- static Content Load(params string[] targets)+ internal static Content Load(params string[] targets){var files = Fixture.Gdd(new Dictionary<string, string>{@@ -41,11 +41,11 @@ public class CaptureTestsreturn ContentLoader.Load(Fixture.Write(files));}- static readonly string[] AllTargets = { "town_a", "town_c", "town_d" };+ internal static readonly string[] AllTargets = { "town_a", "town_c", "town_d" };static GameState With(Content c, params Unit[] units) => CombatTests.With(c, units);- static Unit Soldier(int id, int q, int r) => new Unit(id, "soldier", q, r, side: "israel", strength: 2);- static Unit Enemy(int id, int q, int r) => new Unit(id, "enemy", q, r, side: "egypt", strength: 2);+ internal static Unit Soldier(int id, int q, int r) => new Unit(id, "soldier", q, r, side: "israel", strength: 2);+ internal static Unit Enemy(int id, int q, int r) => new Unit(id, "enemy", q, r, side: "egypt", strength: 2);static GameState Step(Content c, GameState s) => Simulation.Step(c, s, Array.Empty<Command>()).State;diff --git a/sim/Statecraft.Sim.Tests/CommandGuardTests.cs b/sim/Statecraft.Sim.Tests/CommandGuardTests.csindex a35cb8659..154622ed7 100644--- a/sim/Statecraft.Sim.Tests/CommandGuardTests.cs+++ b/sim/Statecraft.Sim.Tests/CommandGuardTests.cs@@ -28,6 +28,7 @@ public class CommandGuardTests[typeof(CancelProject)] = new CancelProject(1),[typeof(Move)] = new Move(1, 2, 0),[typeof(BuyArms)] = new BuyArms(0), // refused (fewer than one unit), as GovernmentTests.ARefusedGddOrderRefundsItsAttention needs+ [typeof(ResolveCapture)] = new ResolveCapture("town_a", "raid"), // refused (nothing awaits a decision), like BuyArms(0)};static IEnumerable<Type> CommandTypes() =>diff --git a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs b/sim/Statecraft.Sim.Tests/DesignValuesTests.csindex 8fa2b1208..576467f59 100644--- a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs+++ b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs@@ -170,6 +170,7 @@ public class DesignValuesTests("unit_types.yaml", "types[arab_liberation_army].movement_points"), // #743, owner, 20 October 2026// The national Arms pool (Phase 2 PR 3b; #781, owner 18 October 2026: "Approve as drafted").("rules.yaml", "attention_cost.buy_arms"),+ ("rules.yaml", "attention_cost.resolve_capture"), // #797 (Q-TECH-3): proposed, for owner override("rules.yaml", "mvp.arms_start"),("rules.yaml", "mvp.arms_price"),("rules.yaml", "mvp.arms_per_recruit_group"),diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.csindex fe3ab7abe..b7fd70388 100644--- a/sim/Statecraft.Sim.Tests/Fixture.cs+++ b/sim/Statecraft.Sim.Tests/Fixture.cs@@ -243,7 +243,7 @@ series:}/// <summary>The fixture's attention_cost line with the GDD command kinds added (replaces "map_action: 1 }").</summary>- public const string GddCosts = "map_action: 1, assign_workers: 1, train: 1, cancel_training: 1, pioneer_work: 0, stop_work: 0, start_project: 1, cancel_project: 0.5, buy_arms: 1, move: 0, unit_order: 0 }";+ public const string GddCosts = "map_action: 1, assign_workers: 1, train: 1, cancel_training: 1, pioneer_work: 0, stop_work: 0, start_project: 1, cancel_project: 0.5, buy_arms: 1, move: 0, unit_order: 0, resolve_capture: 0 }";public const string GddRules = @"mvp:diff --git a/sim/Statecraft.Sim.Tests/RaidTests.cs b/sim/Statecraft.Sim.Tests/RaidTests.csnew file mode 100644index 000000000..7cd662834--- /dev/null+++ b/sim/Statecraft.Sim.Tests/RaidTests.cs@@ -0,0 +1,194 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>ResolveCapture and Raid and withdraw (GDD Phase 6 PR 5, #797). The owner's rulings of 18 October 2026 (#783,+/// batch 3): Q-RAID-1 (a), the player's units leave and the place returns to enemy control at once with its residents+/// unchanged; Q-HIST-1 (a), a capture the player does not answer waits and the units stay. The owner's ruling of 18 October+/// 2026 on #797, "Counts as Raid": a capture still waiting at the MVP's end makes the units leave, changes nothing for the+/// residents and adds nothing to the score. Where the units go is the default proposed on #797: each steps to the first+/// free neighbouring hex in the fixed order. The places are CaptureTests' fixture values, not history: town_a sits on+/// (1, 0) of the 6 x 3 board, whose neighbours on the board are (2, 0), (0, 0), (0, 1) and (1, 1), in that order.</summary>+public class RaidTests+{+ static Content Load() => CaptureTests.Load(CaptureTests.AllTargets);+ static Unit Soldier(int id, int q, int r) => CaptureTests.Soldier(id, q, r);+ static Unit Enemy(int id, int q, int r) => CaptureTests.Enemy(id, q, r);++ /// <summary>A new game with <paramref name="units"/> and town_a captured and awaiting the choice.</summary>+ static GameState Awaiting(Content c, params Unit[] units)+ {+ var s = CombatTests.With(c, units);+ s.Settlements["town_a"] = new SettlementControl(Movement.PlayerSide, SettlementControl.AwaitingChoice, s.Date);+ return s;+ }++ static StepResult Step(Content c, GameState s, params Command[] commands) => Simulation.Step(c, s, commands);++ static ResolveCapture Raid(string id = "town_a") => new ResolveCapture(id, SettlementControl.Raid);++ // R-CTRL-010 (Q-RAID-1 (a)): the player's units leave, the soldier and a halutz alike, each to the first free+ // neighbouring hex, and the place's record goes at once: it is under enemy control again, so the turn's capture check+ // finds nobody there and nothing to take.+ [Fact]+ public void RaidWithdrawsThePlayersUnitsAndReturnsThePlaceToEnemyControl()+ {+ var c = Load();+ var s = Awaiting(c, Soldier(1, 1, 0), new Unit(2, "halutz", 1, 0));+ var result = Step(c, s, Raid());+ Assert.Empty(result.Rejected);+ Assert.Empty(result.State.Settlements);+ Assert.Equal((2, 0), (result.State.Units[1].Q, result.State.Units[1].R));+ Assert.Equal((2, 0), (result.State.Units[2].Q, result.State.Units[2].R));+ Assert.Contains(result.Why, x => x.Target == "town_a" && x.Message.Contains("under enemy control again"));+ Assert.Contains(Movement.NoEntry(c, result.State), h => h == (1, 0)); // the player may not walk back in (R-MOVE-005)+ }++ // R-CTRL-010 (Q-RAID-1 (a), "residents unchanged"): Raid changes the units' hexes and removes the record, and nothing+ // else: the turn ends exactly as it does for a twin whose units were moved by hand and whose record was never written.+ [Fact]+ public void RaidChangesOnlyTheUnitsHexesAndTheRecord()+ {+ var c = Load();+ var s = Awaiting(c, Soldier(1, 1, 0));+ var twin = CombatTests.With(c, Soldier(1, 2, 0));+ Assert.Equal(Step(c, twin).State.Describe(), Step(c, s, Raid()).State.Describe());+ }++ // R-CTRL-010: a neighbour with an enemy unit, or one already full under the stack limit (the fixture's 2), is passed+ // over for the next in the fixed order.+ [Fact]+ public void AUnitSkipsAHexWithAnEnemyOrNoRoom()+ {+ var c = Load();+ var s = Awaiting(c, Soldier(1, 1, 0), Soldier(2, 1, 0), Enemy(3, 2, 0), Soldier(4, 0, 0));+ var next = Step(c, s, Raid()).State;+ Assert.Equal((0, 0), (next.Units[1].Q, next.Units[1].R)); // (2, 0) holds an enemy unit+ Assert.Equal((0, 1), (next.Units[2].Q, next.Units[2].R)); // (0, 0) now holds two Israeli units+ Assert.Empty(next.Settlements);+ }++ // R-CTRL-010, R-CTRL-007: when a unit has no free hex to withdraw to, Raid is refused with a reason, the Attention is+ // refunded and the state is unchanged, a unit that had already found a hex included, so the choice waits. Here unit 1+ // fits on (2, 0) beside unit 7, which leaves no room there for unit 6, and enemy units hold the other three neighbours.+ [Fact]+ public void RaidWithNowhereToGoIsRefused()+ {+ var c = Load();+ var s = Awaiting(c, Soldier(1, 1, 0), Soldier(6, 1, 0), Soldier(7, 2, 0), Enemy(3, 0, 0), Enemy(4, 0, 1), Enemy(5, 1, 1));+ var before = s.Clone();+ var why = new List<Cause>();+ Assert.Contains("Unit 6 has no free hex", SettlementControl.Resolve(c, s, "town_a", SettlementControl.Raid, why));+ Assert.Empty(why);+ Assert.Equal(before.Describe(), s.Describe());+ Assert.Single(Step(c, before, Raid()).Rejected);+ }++ // R-CTRL-007: ResolveCapture is valid only for a settlement awaiting the choice, and only for an outcome that is built;+ // otherwise it is refused with a reason and the state is unchanged.+ [Theory]+ [InlineData("town_c", "raid", "not awaiting a decision")] // a target with no record+ [InlineData("nowhere", "raid", "not awaiting a decision")] // not a settlement+ [InlineData("town_a", "surrender", "not known")]+ [InlineData("town_a", "occupy", "not built yet")]+ [InlineData("town_a", "deport", "not built yet")]+ public void ResolveCaptureIsRefusedWithAReason(string id, string outcome, string reason)+ {+ var c = Load();+ var s = Awaiting(c, Soldier(1, 1, 0));+ var before = s.Clone();+ var why = new List<Cause>();+ Assert.Contains(reason, SettlementControl.Resolve(c, s, id, outcome, why));+ Assert.Empty(why);+ Assert.Equal(before.Describe(), s.Describe());+ Assert.Contains(reason, Assert.Single(Step(c, before, new ResolveCapture(id, outcome)).Rejected).Reason);+ }++ // R-CTRL-007: a record that is not awaiting the choice (a later state, PR 6) is refused too.+ [Fact]+ public void ARecordInAnotherStateIsRefused()+ {+ var c = Load();+ var s = CombatTests.With(c, Soldier(1, 1, 0));+ s.Settlements["town_a"] = new SettlementControl(Movement.PlayerSide, "occupied", s.Date);+ Assert.Contains("not awaiting a decision", SettlementControl.Resolve(c, s, "town_a", SettlementControl.Raid, new List<Cause>()));+ }++ // R-CTRL-008 (Q-HIST-1 (a)): before the MVP's end, a capture the player does not answer waits and the units stay.+ [Fact]+ public void AnUnansweredCaptureWaits()+ {+ var c = Load();+ var next = Step(c, Awaiting(c, Soldier(1, 1, 0))).State;+ Assert.Equal(SettlementControl.AwaitingChoice, next.Settlements["town_a"].State);+ Assert.Equal((1, 0), (next.Units[1].Q, next.Units[1].R));+ }++ // R-CTRL-008 (#797, "Counts as Raid"): on the turn that reaches the game's end, a capture still waiting resolves as+ // Raid: the units leave and the record goes, and the end state, score included, is the twin's that raided by hand.+ [Fact]+ public void ACaptureStillWaitingAtTheEndCountsAsRaid()+ {+ var c = Load();+ var s = Awaiting(c, Soldier(1, 1, 0));+ var twin = CombatTests.With(c, Soldier(1, 2, 0));+ s.Date = twin.Date = c.End.AddDays(-10); // the next turn ends on the game's end+ var result = Step(c, s);+ Assert.NotNull(result.State.GameOver);+ Assert.Empty(result.State.Settlements);+ Assert.Equal((2, 0), (result.State.Units[1].Q, result.State.Units[1].R));+ Assert.Contains(result.Why, x => x.Target == "town_a" && x.Message.Contains("counts as a raid"));+ var other = Step(c, twin).State;+ Assert.Equal(other.Score, result.State.Score);+ Assert.Equal(other.Describe(), result.State.Describe());+ }++ // R-CTRL-008: at the end, a unit with nowhere to go stays while the others leave, and the record still goes (the game+ // is over). Unit 1 fits on (2, 0) beside unit 7; unit 6 then has no room, and enemy units hold the other neighbours.+ [Fact]+ public void AtTheEndTheRecordGoesEvenWithNowhereToWithdraw()+ {+ var c = Load();+ var s = Awaiting(c, Soldier(1, 1, 0), Soldier(6, 1, 0), Soldier(7, 2, 0), Enemy(3, 0, 0), Enemy(4, 0, 1), Enemy(5, 1, 1));+ s.Date = c.End.AddDays(-10); // the next turn ends on the game's end+ var next = Step(c, s).State;+ Assert.NotNull(next.GameOver);+ Assert.Empty(next.Settlements);+ Assert.Equal((2, 0), (next.Units[1].Q, next.Units[1].R));+ Assert.Equal((1, 0), (next.Units[6].Q, next.Units[6].R));+ }++ // R-CTRL-010: a unit keeps its orders when it withdraws, as after a Move; a fortify names the place's hex, so the+ // turn's order step drops it (R-ORDER-002), and hold goes with the unit.+ [Fact]+ public void AFortifyIsLostAndHoldKeptOnWithdrawal()+ {+ var c = Load();+ var fortified = new Unit(1, "soldier", 1, 0, side: "israel", strength: 2, order: Orders.Fortify, orderTarget: "1,0");+ var holding = new Unit(2, "soldier", 1, 0, side: "israel", strength: 2, order: Orders.Hold);+ var next = Step(c, Awaiting(c, fortified, holding), Raid()).State;+ Assert.Equal("", next.Units[1].Order);+ Assert.Equal(Orders.Hold, next.Units[2].Order);+ }++ // R-CTRL-009: HistoricalAI leaves out a Raid the sim would refuse, so its orders are never rejected and the capture waits.+ [Fact]+ public void HistoricalAIWaitsWhenRaidIsRefused()+ {+ var c = Load();+ var s = Awaiting(c, Soldier(1, 1, 0), Enemy(2, 2, 0), Enemy(3, 0, 0), Enemy(4, 0, 1), Enemy(5, 1, 1));+ Assert.DoesNotContain(HistoricalAI.Commands(c, s), x => x is ResolveCapture);+ }++ // R-CTRL-010, determinism: Raid draws nothing from the RNG.+ [Fact]+ public void RaidDrawsNothing()+ {+ var c = Load();+ var s = Awaiting(c, Soldier(1, 1, 0));+ var rng = s.RngState;+ Assert.Null(SettlementControl.Resolve(c, s, "town_a", SettlementControl.Raid, new List<Cause>()));+ Assert.Equal(rng, s.RngState);+ }+}diff --git a/sim/Statecraft.Sim.Tests/SaveGameTests.cs b/sim/Statecraft.Sim.Tests/SaveGameTests.csindex 01286c14b..88608c540 100644--- a/sim/Statecraft.Sim.Tests/SaveGameTests.cs+++ b/sim/Statecraft.Sim.Tests/SaveGameTests.cs@@ -29,7 +29,7 @@ public class SaveGameTestsnew Command[] { new SetPolicy("odd id with spaces%", 0.5), new MapAction("transit_camp", 4, 0) },new Command[] { new AssignWorkers("town_a", "job", 1), new UnitOrder(1, "hold") }, // GDD orders: the legacy fixture refuses themnew Command[] { new Train("town_a", "halutz", 1), new CancelTraining(1) }, // GDD orders too- new Command[] { new PioneerWork(1, "build_yishuv", "site_a"), new StopWork(1), new StartProject("housing", "town_a", 1, 1), new CancelProject(1), new BuyArms(2), new Move(1, -2, 3) },+ new Command[] { new PioneerWork(1, "build_yishuv", "site_a"), new StopWork(1), new StartProject("housing", "town_a", 1, 1), new CancelProject(1), new BuyArms(2), new Move(1, -2, 3), new ResolveCapture("town_a", "raid") },new Command[] { new SecurityOrder(1) }, new Command[0],};foreach (var o in orders) g.Step(o);diff --git a/sim/Statecraft.Sim/AttentionSystem.cs b/sim/Statecraft.Sim/AttentionSystem.csindex bd9c8b877..a84ef6f65 100644--- a/sim/Statecraft.Sim/AttentionSystem.cs+++ b/sim/Statecraft.Sim/AttentionSystem.cs@@ -8,11 +8,11 @@ namespace Statecraft.Simpublic static class AttentionSystem{static readonly HashSet<string> Kinds = new HashSet<string>- { "set_policy", "allocate_budget", "choose_event_option", "set_mobilization", "security_order", "appoint", "map_action", "assign_workers", "train", "cancel_training", "pioneer_work", "stop_work", "start_project", "cancel_project", "buy_arms", "move", "unit_order" };+ { "set_policy", "allocate_budget", "choose_event_option", "set_mobilization", "security_order", "appoint", "map_action", "assign_workers", "train", "cancel_training", "pioneer_work", "stop_work", "start_project", "cancel_project", "buy_arms", "move", "unit_order", "resolve_capture" };/// <summary>The kinds only the GDD v0.1 loop runs. Rules price them only when systems.loop is gdd, and the legacy loop/// refuses them before charging Attention.</summary>- static readonly HashSet<string> GddKinds = new HashSet<string> { "assign_workers", "train", "cancel_training", "pioneer_work", "stop_work", "start_project", "cancel_project", "buy_arms", "move", "unit_order" };+ static readonly HashSet<string> GddKinds = new HashSet<string> { "assign_workers", "train", "cancel_training", "pioneer_work", "stop_work", "start_project", "cancel_project", "buy_arms", "move", "unit_order", "resolve_capture" };public static IReadOnlyCollection<string> CommandKinds => Kinds;diff --git a/sim/Statecraft.Sim/Commands.cs b/sim/Statecraft.Sim/Commands.csindex f43698b8b..c92da888a 100644--- a/sim/Statecraft.Sim/Commands.cs+++ b/sim/Statecraft.Sim/Commands.cs@@ -150,6 +150,16 @@ namespace Statecraft.Simpublic BuyArms(int count) { Count = count; }}+ /// <summary>Answers the capture of <see cref="Settlement"/> with <see cref="Outcome"/>: raid, occupy or deport+ /// (SettlementControl.Resolve, R-CTRL-007 to R-CTRL-010). One kind for every outcome, so they cost the same Attention+ /// (Q-TECH-3). GDD v0.1 loop only.</summary>+ public sealed class ResolveCapture : Command+ {+ public override string Kind => SettlementControl.ResolveKind;+ public string Settlement { get; } public string Outcome { get; }+ public ResolveCapture(string settlement, string outcome) { Settlement = settlement; Outcome = outcome; }+ }+public sealed class Rejection{public Command Command { get; } public string Reason { get; }@@ -188,6 +198,7 @@ namespace Statecraft.Simcase CancelProject _: break;case Move _: break;case BuyArms _: break;+ case ResolveCapture r: Text(r.Settlement, "Settlement"); Text(r.Outcome, "Outcome"); break;case SetMobilization _: case SecurityOrder _: break;default: throw new ArgumentException("unknown command type " + cmd.GetType().Name, "commands");}diff --git a/sim/Statecraft.Sim/HistoricalAI.cs b/sim/Statecraft.Sim/HistoricalAI.csindex 8800bd8b4..2e92b47d1 100644--- a/sim/Statecraft.Sim/HistoricalAI.cs+++ b/sim/Statecraft.Sim/HistoricalAI.cs@@ -4,11 +4,12 @@ using System.Linq;namespace Statecraft.Sim{- /// <summary>Plays what really happened: picks each pending event's historical option (else its first), then sends- /// reserves home down to the current security level's minimum call-up (the army demobilised after the 1949- /// armistices). It sends no budget allocation, so the budget stays at rules.yaml budget_start. Like the UI's order- /// queue (SimBridge.Queue), it leaves out an order the turn's remaining attention cannot cover, so Step never has to- /// refuse one of its orders.</summary>+ /// <summary>Plays what really happened: picks each pending event's historical option (else its first), answers each+ /// capture awaiting the choice, in ordinal id order, with Raid, never Deport (R-CTRL-009; Q-REF-1 (a), owner, 18+ /// October 2026, #783 batch 3; impact plan section 4.1 item 1), then sends reserves home down to the current security+ /// level's minimum call-up (the army demobilised after the 1949 armistices). It sends no budget allocation, so the+ /// budget stays at rules.yaml budget_start. Like the UI's order queue (SimBridge.Queue), it leaves out an order the+ /// turn's remaining attention cannot cover, so Step never has to refuse one of its orders.</summary>public static class HistoricalAI{public static IReadOnlyList<Command> Commands(Content c, GameState s)@@ -17,6 +18,12 @@ namespace Statecraft.Sim.Select(id => c.Events.First(e => e.Id == id)).Select(e => (Command)new ChooseEventOption(e.Id, (e.Options.FirstOrDefault(o => o.Historical) ?? e.Options[0]).Id)).ToList();+ // Settlements is ordinal. Each Raid is tried on a copy after the ones before it, as Step will run them, and one the+ // sim would refuse (a unit with nowhere to go) is left out, so that capture waits.+ var probe = s.Clone();+ foreach (var kv in s.Settlements.Where(kv => kv.Value.State == SettlementControl.AwaitingChoice))+ if (SettlementControl.Resolve(c, probe, kv.Key, SettlementControl.Raid, new List<Cause>()) == null)+ wanted.Add(new ResolveCapture(kv.Key, SettlementControl.Raid));var floor = SecuritySystem.MinMobilization(c, s.Date, s.Rung);if (s.Mobilization > floor) wanted.Add(new SetMobilization(floor));var list = new List<Command>();diff --git a/sim/Statecraft.Sim/Movement.cs b/sim/Statecraft.Sim/Movement.csindex 8f256aab2..a6967891c 100644--- a/sim/Statecraft.Sim/Movement.cs+++ b/sim/Statecraft.Sim/Movement.cs@@ -84,7 +84,7 @@ namespace Statecraft.Sim}/// <summary>R-MOVE-003: the refusal when (q, r) already holds stack_limit units of <paramref name="u"/>'s side, else null.</summary>- static string? Full(Content c, GameState s, Unit u, int q, int r)+ internal static string? Full(Content c, GameState s, Unit u, int q, int r){var limit = c.RulesAt(s.Date).Mvp!.StackLimit!.Value; // the loader requires it in the GDD loopvar held = s.Units.Values.Count(x => x.Id != u.Id && x.Side == u.Side && x.Q == q && x.R == r);diff --git a/sim/Statecraft.Sim/Reference/ReferencePlayer.cs b/sim/Statecraft.Sim/Reference/ReferencePlayer.csindex 36a871d72..e5387fbb6 100644--- a/sim/Statecraft.Sim/Reference/ReferencePlayer.cs+++ b/sim/Statecraft.Sim/Reference/ReferencePlayer.cs@@ -5,7 +5,7 @@ using System.Linq;namespace Statecraft.Sim.Reference{/// <summary>Test policy for the GDD goldens (D-A7): a stated simple policy, not game AI and not historical. It sends- /// HistoricalAI's orders and no AssignWorkers (R-CITY-009's default fills the jobs, and an order would turn it off), then+ /// HistoricalAI's orders (so it answers every capture with Raid and never Deport, Q-REF-1 (a), R-CTRL-009) and no AssignWorkers (R-CITY-009's default fills the jobs, and an order would turn it off), then/// has each of Israel's units with no attack, in id order, attack the first neighbouring hex (in the fixed order) whose/// enemy units it meets at <see cref="AttackRatioPercent"/> percent or better by the combat preview, while the Arms last/// for every standing attack and the new one (R-COMBAT-001, R-COMBAT-004), then,diff --git a/sim/Statecraft.Sim/SaveGame.cs b/sim/Statecraft.Sim/SaveGame.csindex d16442080..70fe14560 100644--- a/sim/Statecraft.Sim/SaveGame.cs+++ b/sim/Statecraft.Sim/SaveGame.cs@@ -39,7 +39,8 @@ namespace Statecraft.Sim/// <command> ... policy ID LEVEL | budget OFFICE=SHARE,... | event ID OPTION | mobilize LEVEL |/// security DELTA | appoint OFFICE PERSON | map ACTION Q R | work CITY ROLE N |/// train CITY TRACK N | untrain COHORT | pioneer UNIT ACTION SITE | stop UNIT |- /// project KIND CITY Q R | unproject PROJECT | arms N+ /// project KIND CITY Q R | unproject PROJECT | arms N |+ /// capture SETTLEMENT OUTCOME/// end <hex> GameState.Hash() after the last turn (checks the replay)/// Doubles are IEEE bit patterns in hex, so replays are exact; strings are percent-escaped (Uri.EscapeDataString)./// </summary>@@ -128,6 +129,7 @@ namespace Statecraft.SimCancelProject p => $"unproject {Int(p.Project)}",Move m => $"move {Int(m.Unit)} {Int(m.Q)} {Int(m.R)}",BuyArms a => $"arms {Int(a.Count)}",+ ResolveCapture r => $"capture {Esc(r.Settlement)} {Esc(r.Outcome)}",_ => throw new ArgumentException($"Cannot save command kind '{cmd.Kind}'", nameof(cmd)),};@@ -228,6 +230,7 @@ namespace Statecraft.Simcase "unproject": Arity(2); return new CancelProject(I(f[1]));case "move": Arity(4); return new Move(I(f[1]), I(f[2]), I(f[3]));case "arms": Arity(2); return new BuyArms(I(f[1]));+ case "capture": Arity(3); return new ResolveCapture(Str(f[1]), Str(f[2]));default: throw new SaveException(line, $"unknown command '{f[0]}'");}}diff --git a/sim/Statecraft.Sim/Scenario.cs b/sim/Statecraft.Sim/Scenario.csindex bcf00fbae..0072bbcf5 100644--- a/sim/Statecraft.Sim/Scenario.cs+++ b/sim/Statecraft.Sim/Scenario.cs@@ -68,7 +68,7 @@ namespace Statecraft.Sim["unit_order"] = new[] { "unit", "order", "q", "r" }, // q and r: an attack's hex only (R-COMBAT-001)["start_project"] = new[] { "project", "city", "q", "r" }, ["cancel_project"] = new[] { "project" },["move"] = new[] { "unit", "q", "r" },- ["buy_arms"] = new[] { "count" },+ ["buy_arms"] = new[] { "count" }, ["resolve_capture"] = new[] { "settlement", "outcome" },};public static IReadOnlyCollection<string> Kinds => Allowed.Keys;@@ -103,6 +103,7 @@ namespace Statecraft.Simcase "cancel_project": return new CancelProject(Whole(c, "project"));case "move": return new Move(Whole(c, "unit"), Whole(c, "q"), Whole(c, "r"));case "buy_arms": return new BuyArms(Whole(c, "count"));+ case "resolve_capture": return new ResolveCapture(Str(c, "settlement"), Str(c, "outcome"));default: throw new InvalidDataException($"command kind '{kind}' has no builder");}}@@ -145,7 +146,7 @@ namespace Statecraft.SimUnitOrder o => FormattableString.Invariant($"{o.Unit} {o.Order}") + (o.Q is int q && o.R is int r ? FormattableString.Invariant($" {q},{r}") : ""),StartProject p => FormattableString.Invariant($"{p.ProjectKind} {p.City} {p.Q},{p.R}"), CancelProject p => p.Project.ToString(CultureInfo.InvariantCulture),Move m => FormattableString.Invariant($"{m.Unit} {m.Q},{m.R}"),- BuyArms a => a.Count.ToString(CultureInfo.InvariantCulture),+ BuyArms a => a.Count.ToString(CultureInfo.InvariantCulture), ResolveCapture r => $"{r.Settlement} {r.Outcome}",_ => c.Kind,};}diff --git a/sim/Statecraft.Sim/SettlementControl.cs b/sim/Statecraft.Sim/SettlementControl.csindex ee381d575..0af56dfdb 100644--- a/sim/Statecraft.Sim/SettlementControl.cs+++ b/sim/Statecraft.Sim/SettlementControl.cs@@ -1,11 +1,13 @@using System;using System.Collections.Generic;+using System.Globalization;using System.Linq;namespace Statecraft.Sim{/// <summary>Settlement control in the GDD v0.1 loop (GDD Phase 6; docs/gdd/settlement-control.md). This half holds resolver- /// step 3, the capture check (R-CTRL-004, R-CTRL-005). The record itself is in GddState.cs.</summary>+ /// step 3, the capture check (R-CTRL-004, R-CTRL-005), and the answer to a capture: the options helper, ResolveCapture and+ /// Raid and withdraw (R-CTRL-007 to R-CTRL-010). The record itself is in GddState.cs.</summary>public sealed partial class SettlementControl{/// <summary>The <see cref="State"/> of a target the player has captured and has not yet chosen an outcome for.</summary>@@ -40,6 +42,107 @@ namespace Statecraft.Sim}}+ /// <summary>The kind of <see cref="ResolveCapture"/>: one attention_cost key for every outcome, so none is cheaper (Q-TECH-3).</summary>+ public const string ResolveKind = "resolve_capture";+ public const string Raid = "raid";+ public const string Occupy = "occupy";+ public const string Deport = "deport";++ /// <summary>R-CTRL-008: the outcomes in their one fixed order. Deport is never first (impact plan section 4.1 item 1).</summary>+ static readonly string[] Outcomes = { Raid, Occupy, Deport };++ /// <summary>R-CTRL-008 (spec section 2.6): what the capture of <paramref name="id"/> offers, in the fixed order, each with+ /// the reason it is refused or the preview of what it does; empty when the place is not awaiting the choice. Nothing is+ /// pre-selected. A preview is what resolving the option, Attention included, does to a clone of the state, as Step would,+ /// so it cannot drift from the outcome. Leaves <paramref name="s"/> as it found it.</summary>+ public static IReadOnlyList<CaptureOption> CaptureOptions(Content c, GameState s, string id)+ {+ if (NotAwaiting(s, id) != null) return Array.Empty<CaptureOption>();+ var options = new List<CaptureOption>();+ foreach (var outcome in Outcomes)+ {+ var after = s.Clone();+ var refusal = AttentionSystem.TrySpend(c, after, ResolveKind) ?? Resolve(c, after, id, outcome, new List<Cause>());+ options.Add(new CaptureOption(outcome, refusal, refusal == null ? Preview(s, after) : null));+ }+ return options;+ }++ static CapturePreview Preview(GameState s, GameState after) => new CapturePreview(after.Attention - s.Attention,+ after.Treasury - s.Treasury, after.Debt - s.Debt, after.Food - s.Food, after.Arms - s.Arms,+ Indicator(after, "morale") - Indicator(s, "morale"), Indicator(after, "intl_standing") - Indicator(s, "intl_standing"), after.Score - s.Score);++ static double Indicator(GameState s, string id) => s.Indicators.TryGetValue(id, out var v) ? v : 0;++ /// <summary>R-CTRL-007: carries out ResolveCapture. Null when done, else the reason, with the state unchanged: the place+ /// is not awaiting the choice, the outcome is not known, or it is not built yet (Occupy is PR 6, Deport PR 8).</summary>+ internal static string? Resolve(Content c, GameState s, string id, string outcome, List<Cause> why)+ {+ if (NotAwaiting(s, id) is string no) return no;+ switch (outcome)+ {+ case Raid: return Withdraw(c, s, id, why, false);+ case Occupy: return "Occupy is not built yet";+ case Deport: return "Deport is not built yet";+ default: return "That outcome is not known";+ }+ }++ static string? NotAwaiting(GameState s, string id) =>+ s.Settlements.TryGetValue(id, out var x) && x.State == AwaitingChoice ? null : "That place is not awaiting a decision on its capture";++ /// <summary>R-CTRL-010, Raid and withdraw (Q-RAID-1 (a)): the player's units on the place's hex, soldiers and halutzim+ /// alike, leave in id order, each to the first neighbouring hex in the fixed <see cref="Movement.Neighbours"/> order+ /// that is land, holds no enemy unit, is no enemy-held locality (R-MOVE-005) and has room for it (R-MOVE-003). Leaving+ /// costs no movement points (the default proposed on #797). The record goes, so the place is under enemy control again+ /// at once, and its residents are unchanged. Refused, the state untouched, when a unit has nowhere to go, unless+ /// <paramref name="atTheEnd"/>: then that unit stays, the others leave and the record still goes.</summary>+ static string? Withdraw(Content c, GameState s, string id, List<Cause> why, bool atTheEnd)+ {+ var t = c.SettlementTargets.First(x => x.Id == id); // only a target gets a record (R-CTRL-004)+ var name = c.SettlementNames[id];+ var moved = new List<(Unit From, Unit To)>();+ foreach (var u in s.Units.Values.Where(u => u.Q == t.Q && u.R == t.R && !IsEnemy(u)).ToList()) // ascending id+ {+ var to = Movement.Neighbours.Select(d => ((int Q, int R)?)(t.Q + d.Q, t.R + d.R)).FirstOrDefault(h => Free(c, s, u, h!.Value.Q, h.Value.R));+ if (to == null && atTheEnd) continue;+ if (to == null)+ {+ foreach (var (from, _) in moved) s.Units[from.Id] = from; // back as it was+ return $"Unit {u.Id} has no free hex next to {name} to withdraw to";+ }+ var w = new Unit(u.Id, u.Type, to.Value.Q, to.Value.R, u.Service, u.Side, u.Strength, u.Order, u.OrderTarget);+ s.Units[u.Id] = w;+ moved.Add((u, w));+ }+ s.Settlements.Remove(id);+ foreach (var (_, w) in moved)+ why.Add(new Cause("map", w.Id.ToString(CultureInfo.InvariantCulture), 0, FormattableString.Invariant($"Unit {w.Id} withdrew from {name} to hex {w.Q},{w.R}")));+ why.Add(new Cause("map", id, 0, moved.Count > 0+ ? $"{name}: Israeli units withdrew and it is under enemy control again. Its residents are unchanged"+ : $"{name} is under enemy control again. Its residents are unchanged"));+ return null;+ }++ static bool IsEnemy(Unit u) => u.Side != "" && u.Side != Movement.PlayerSide;++ static bool Free(Content c, GameState s, Unit u, int q, int r) =>+ c.HexAt(q, r) is MapHex hex && hex.Land && !s.Units.Values.Any(x => x.Q == q && x.R == r && IsEnemy(x))+ && !Movement.NoEntry(c, s).Contains((q, r)) && Movement.Full(c, s, u, q, r) == null;++ /// <summary>R-CTRL-008 (owner, 18 October 2026 on #797, "Counts as Raid"), where resolver step 10 sits on the turn that+ /// reaches the game's end: every capture still awaiting the choice, in ordinal id order, resolves as Raid. A unit with+ /// nowhere to go stays while the others leave, and the record goes all the same, since the game is over. It runs before objectives and score+ /// (step 11) and changes neither, so it adds nothing to the score.</summary>+ internal static void EndPending(Content c, GameState s, List<Cause> why)+ {+ foreach (var id in s.Settlements.Where(kv => kv.Value.State == AwaitingChoice).Select(kv => kv.Key).ToList()) // ordinal+ {+ why.Add(new Cause("map", id, 0, $"{c.SettlementNames[id]}: no decision was made before the end, so it counts as a raid"));+ Withdraw(c, s, id, why, true); // at the end it never refuses+ }+ }+const string Enemy = "enemy";/// <summary>Who holds (q, r): <see cref="Movement.PlayerSide"/> when only Israeli military units are on it,@@ -52,4 +155,30 @@ namespace Statecraft.Simreturn player == on.Count ? Movement.PlayerSide : player == 0 ? Enemy : null;}}++ /// <summary>One outcome of a capture as SettlementControl.CaptureOptions offers it (R-CTRL-008): the reason it is refused,+ /// or null and its <see cref="Preview"/>. It has no default or selected flag on purpose.</summary>+ public sealed class CaptureOption+ {+ public string Outcome { get; }+ public string? Refusal { get; }+ public CapturePreview? Preview { get; }+ public CaptureOption(string outcome, string? refusal, CapturePreview? preview) { Outcome = outcome; Refusal = refusal; Preview = preview; }+ }++ /// <summary>What resolving a capture option changes at once, as deltas: Attention, Money (the Treasury and the debt), Food,+ /// Arms, Social cohesion (morale), International Support (intl_standing) and the score (spec section 2.6; impact plan+ /// section 4.1's sober cost preview).</summary>+ public sealed class CapturePreview+ {+ public double Attention { get; } public double Money { get; } public double Debt { get; }+ public int Food { get; } public int Arms { get; }+ public double SocialCohesion { get; } public double InternationalSupport { get; }+ public int Score { get; }+ public CapturePreview(double attention, double money, double debt, int food, int arms, double socialCohesion, double internationalSupport, int score)+ {+ Attention = attention; Money = money; Debt = debt; Food = food; Arms = arms;+ SocialCohesion = socialCohesion; InternationalSupport = internationalSupport; Score = score;+ }+ }}diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.csindex f868ae517..6067bbcf8 100644--- a/sim/Statecraft.Sim/Simulation.cs+++ b/sim/Statecraft.Sim/Simulation.cs@@ -185,6 +185,8 @@ namespace Statecraft.Simreturn Movement.Move(c, s, m.Unit, m.Q, m.R, spent, why);case BuyArms a:return Pools.BuyArms(c, s, a.Count, why);+ case ResolveCapture x:+ return SettlementControl.Resolve(c, s, x.Settlement, x.Outcome, why);case SecurityOrder o:// long arithmetic: an extreme delta clamps to the ladder's end instead of wrapping around.SecuritySystem.SetRung(c, s, (int)Math.Max(1L, Math.Min(5L, (long)s.Rung + o.Delta)), why);diff --git a/sim/Statecraft.Sim/TurnResolver.cs b/sim/Statecraft.Sim/TurnResolver.csindex eb50f3f23..b6d59379c 100644--- a/sim/Statecraft.Sim/TurnResolver.cs+++ b/sim/Statecraft.Sim/TurnResolver.cs@@ -30,7 +30,9 @@ namespace Statecraft.SimCities.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);Cities.Arrive(c, s, r, next, why); // 9. arrivals- // 10. Occupation timers: Phase 6.+ // 10. Occupation timers: Phase 6 PR 6. On the turn that reaches the game's end, a capture still awaiting the choice+ // counts as Raid (R-CTRL-008, #797).+ if (next >= c.End) SettlementControl.EndPending(c, s, why);Objectives.Complete(c, s, r, next, why); // 11. objectives and scoreDefeat(s, r, why); // then the economic defeat (D-B5, R-END-002)WarLoss(c, s, why); // and the war loss (R-END-003)diff --git a/unity/Assets/Scripts/UI/SimBridge.cs b/unity/Assets/Scripts/UI/SimBridge.csindex fefa413b9..0e03cabfc 100644--- a/unity/Assets/Scripts/UI/SimBridge.cs+++ b/unity/Assets/Scripts/UI/SimBridge.cs@@ -63,6 +63,7 @@ namespace Statecraft.Game.UIStartProject p => FormattableString.Invariant($"project:{p.Q},{p.R}"),CancelProject x => FormattableString.Invariant($"unproject:{x.Project}"),Move m => FormattableString.Invariant($"move:{m.Unit}"),+ ResolveCapture r => "capture:" + r.Settlement,_ => c.Kind,};@@ -145,6 +146,9 @@ namespace Statecraft.Game.UIreturn Unknown("city_project", x.Project.ToString(System.Globalization.CultureInfo.InvariantCulture), State.CityProjects.Keys.Select(k => k.ToString(System.Globalization.CultureInfo.InvariantCulture)));// Buying Arms (#781): no ids; the sim refuses a count below one itself.case BuyArms _: return null;+ // Answering a capture (#797): the sim refuses a place not awaiting the choice, or an outcome not built yet, with+ // its own reason and never throws on the id. The capture dialog is PR 10.+ case ResolveCapture _: return null;default: return text["order.invalid"];}}diff --git a/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs b/unity/Assets/Tests/EditMode/SimBridgeGuardTests.csindex d24c5fe7e..79b85165a 100644--- a/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs+++ b/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs@@ -36,6 +36,7 @@ public class SimBridgeGuardTests[typeof(CancelProject)] = new CancelProject(1),[typeof(Move)] = new Move(1, 2, 0),[typeof(BuyArms)] = new BuyArms(0),+ [typeof(ResolveCapture)] = new ResolveCapture("town_a", "raid"),};static IEnumerable<Type> CommandTypes() =>