A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Civ movement S3: the player's attacks are fought when given (Refs #1398) (#1454)
Eyal Golan0da231dfd6a3
diff --git a/changelog.d/1398-s3.md b/changelog.d/1398-s3.mdnew file mode 100644index 000000000..98659bad2--- /dev/null+++ b/changelog.d/1398-s3.md@@ -0,0 +1,6 @@+### Changed+- The player's attacks are fought at once, one unit per attack (the owner, 23 October 2026: "Instant, like Civ", "One+ unit per attack, Civ"): an attack pays its Arms when given, spends the unit's movement for the turn and leaves no+ standing order; artillery fires alone from range and loses nothing. The enemy's attacks still stand and resolve in+ step 2. A unit's front for Send home is that of the enemy it attacked this turn or borders (R-COMBAT-001, R-UNIT-005,+ #1398).diff --git a/docs/determinism.md b/docs/determinism.mdindex 3f1fa580e..d308c86f1 100644--- a/docs/determinism.md+++ b/docs/determinism.md@@ -28,6 +28,11 @@ The simulation must produce the same state, bit for bit, on .NET, Unity Mono andthe fixed neighbour order, and the captures still waiting at the game's end resolve in ordinal id order, with no RNGdraw (R-CTRL-008, R-CTRL-010; `RaidTests.RaidDrawsNothing`). No golden captures a place, so none answers one.+## Combat draws++A player engagement draws `Combat.DrawsPerEngagement` (1) when its order runs in `RunOrders`, after the route step and any+earlier committed order, before every waiting order. The enemy's engagements draw in resolver step 2, in ascending attacker id.+## Golden playthroughs`Statecraft.Sim.GoldenRun.Play(content, until)` starts `Simulation.NewGame(content, GoldenRun.Seed, Mode.Historical)`diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex cafde4b89..80eb42b11 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -166,7 +166,7 @@ R-UNIT-003: A finished recruit cohort becomes exactly one Israeli infantry formaR-UNIT-004: Each Israeli recruit formation already in play before step 4 gains one service turn; a cohort graduating in step 4 starts serving on the next turn. At `veteran_soldier_service` it becomes `veteran_soldier`, keeping id, hex, service, side, strength and standing order, with a Why cause. Veterans stop accumulating service. Combat gives no extra service, and Phase 5 adds no return to civilian life (Q-UNIT-2, Q-UNIT-6; owner, 15 October 2026). The owner-accepted initial threshold is 6 turns, a labelled design value under Q-GEN-1, not a historical period (19 October 2026, https://github.com/eyalgolan/statecraft-israel/pull/1130#issuecomment-6269103829). The loader requires it to be at least 1 and requires the Israeli veteran infantry type when recruits exist.-R-UNIT-005: `UnitOrder(unit, send_home)` (the unit card's "Send home", #1309) is the player's order and the only way home: no automatic demobilisation happens (owner, 22 October 2026, #1309: https://github.com/eyalgolan/statecraft-israel/issues/1309#issuecomment-6334162964). It is refused, the state unchanged, with the orders' own reasons for an unknown unit, a unit with no side or an enemy unit (R-ORDER-001's wording) and "That order names no hex" when a hex is given, and with "The armistice with <front> is not signed" while the armistice on the unit's front is unsigned. A unit's front is the front of the enemy side it attacks (the hex its attack order names) or borders (an adjacent hex); ties take the nearest enemy unit, then the lowest unit id (owner, 22 October 2026, #1309: https://github.com/eyalgolan/statecraft-israel/issues/1309#issuecomment-6340226644). A side that belongs to no front (the ALA and the local forces, Q-OBJ-1; R-POW-004's map) names none (accepted per maintainer comment, 22 October 2026, #1309: https://github.com/eyalgolan/statecraft-israel/issues/1309#issuecomment-6341877062: the ALA and the local forces belong to no front, having no armistice of their own), and a unit attacking and bordering no front-bearing enemy may be sent home once any armistice is signed, refused with "No armistice is signed" until then (accepted per maintainer comment 6341877062 on #1309: "no enemy units in play" means attacking and bordering no enemy that has a front). Taken, the order acts at once: the unit leaves the map and its strength, in population units, joins the nearest of the twelve cities as civilians without a job (owner, 22 October 2026, #1309: https://github.com/eyalgolan/statecraft-israel/issues/1309#issuecomment-6334162964: "nearest ... as unemployed civilians"), counting in the city's jobs and housing from the same turn; nearest by hex distance to the city's settlement hex, ties by the city's id (agent default - the ruling sets no tie break). The Why line states the count in people (Q-CIV-4): "Unit N is sent home: its P people are civilians in <city> now". A veteran keeps nothing (none suggested, #1309).+R-UNIT-005: `UnitOrder(unit, send_home)` (the unit card's "Send home", #1309) is the player's order and the only way home: no automatic demobilisation happens (owner, 22 October 2026, #1309: https://github.com/eyalgolan/statecraft-israel/issues/1309#issuecomment-6334162964). It is refused, the state unchanged, with the orders' own reasons for an unknown unit, a unit with no side or an enemy unit (R-ORDER-001's wording) and "That order names no hex" when a hex is given, and with "The armistice with <front> is not signed" while the armistice on the unit's front is unsigned. A unit's front is the front of the enemy side it attacked this turn or borders; ties take the nearest enemy unit, then the lowest unit id (owner, 22 October 2026, #1309: https://github.com/eyalgolan/statecraft-israel/issues/1309#issuecomment-6340226644). A side that belongs to no front (the ALA and the local forces, Q-OBJ-1; R-POW-004's map) names none (accepted per maintainer comment, 22 October 2026, #1309: https://github.com/eyalgolan/statecraft-israel/issues/1309#issuecomment-6341877062: the ALA and the local forces belong to no front, having no armistice of their own), and a unit attacking and bordering no front-bearing enemy may be sent home once any armistice is signed, refused with "No armistice is signed" until then (accepted per maintainer comment 6341877062 on #1309: "no enemy units in play" means attacking and bordering no enemy that has a front). Taken, the order acts at once: the unit leaves the map and its strength, in population units, joins the nearest of the twelve cities as civilians without a job (owner, 22 October 2026, #1309: https://github.com/eyalgolan/statecraft-israel/issues/1309#issuecomment-6334162964: "nearest ... as unemployed civilians"), counting in the city's jobs and housing from the same turn; nearest by hex distance to the city's settlement hex, ties by the city's id (agent default - the ruling sets no tie break). The Why line states the count in people (Q-CIV-4): "Unit N is sent home: its P people are civilians in <city> now". A veteran keeps nothing (none suggested, #1309).R-UNIT-006: A new Historical game places one military unit per row of `map/units_1948.yaml` that is not `hidden`, has `service: army` (the squadron and the ships stay presentation-only tokens, Q-UNIT-5), has a `strength` whose `as_of` is the start day, and has an anchor window [from, to) covering the start. The unit stands on the hex that holds the first such anchor's coordinates, by the map's projection and cube rounding (`tools/hexgrid.py`, Unity's `HexPicker`), precomputed by `tools/unit_anchor_hexes.py` into `map/unit_anchor_hexes.yaml`, which the sim reads (no projection maths in the sim, docs/determinism.md); the token may stand one hex away (`UnitPlacer`), which is presentation. Every IDF brigade is a `veteran_soldier`; an Arab force takes its side's one military type, a labelled design value of class infantry with 3 movement points. Its strength is the row's people in population units, the nearest unit with a half up and never below 1 (`people_per_unit` 1,000: Golani's 4,095 is 4, Kiryati's 2,504 is 3). The units take ids 0 upward in the file's order, before any other unit (owner, 20 October 2026, #743: "all five defaults"). The file is in the content hash (Q-START-1), and so is the hex file. The loader refuses a starting row whose anchor is off the map or not on land or has no row in the hex file, a hex row for an anchor the unit file does not have, or whose side has no single military type, naming the file and the row. A shareable build refuses while any row a unit starts from is not `fact-checked` (Q-START-3): `Statecraft.Cli --release-gate`, `Build -shareable` and `tools/package_release.py` name them.@@ -226,13 +226,13 @@ R-ORDER-003: Hold acts on the unit's own hex only and does not intercept or stopPhase 5 PR 8 (#747). Q-COMBAT-1 to Q-COMBAT-4 are the plan's recommendations (owner, 15 October 2026, #375: "Take all recommendations"); Q-CIV-2 is the owner's "Enemy units only, no effect" and Q-CIV-4 his "2+3". The numbers (`rules.yaml` `mvp.arms_per_attack`, `mvp.combat_terrain_percent`, `mvp.combat_table`), the loss order, the retreat order and the attack's standing are agent defaults asked on #747 (https://github.com/eyalgolan/statecraft-israel/issues/747#issuecomment-6297295556) and accepted by the owner on 20 October 2026, all six, as design values for the balance pass #813 (https://github.com/eyalgolan/statecraft-israel/issues/747#issuecomment-6299184133). The truce refusal (Q-WAR-3) is PR 11, prisoners PR 12, artillery PR 9 and the enemy's orders PR 10.-R-COMBAT-001: `UnitOrder(unit, attack, q, r)` gives one of the player's military units a standing attack on the hex (q, r), replacing its order (a fortify is lost). The hex must be next to the unit (artillery: within its range, R-COMBAT-007) and hold an enemy military unit; enemy units on a hex with a locality and its residents may be attacked, and the residents are never a target (Q-CIV-2). The order is refused with the state unchanged and a reason for an unknown unit, a halutz, a unit of another side, no hex, the attack it already has, a hex not next to it (artillery: beyond its range) or with no enemy unit, or a stock below the Arms of this attack plus the player's other attacks already ordered, this turn's included (Q-COMBAT-4). Fortify and hold name no hex: one that names a hex is refused. The order costs `attention_cost.unit_order` (0, D-A6) and resolves in the same turn's step 2. It stands, turn after turn, while its hex holds an enemy unit next to the unit (artillery: in its range, R-COMBAT-007); in step 2 an attack whose hex is empty or no longer next to the unit (artillery: in its range) ends, with a line, and so does every attack whose hex step 2 leaves empty. A save writes it as `order <unit> attack <q> <r>`; a scenario takes `q` and `r`.+R-COMBAT-001: `UnitOrder(unit, attack, q, r)` makes one of the player's military units attack the hex (q, r) at once, alone, when the order runs (the owner, 23 October 2026: "Instant, like Civ" and OQ-1: "One unit per attack, Civ"). It replaces the unit's order (a fortify is lost), spends the rest of its movement points for the turn and leaves no attack order. The hex must be next to the unit (artillery: within its range, R-COMBAT-007) and hold an enemy military unit; enemy units on a hex with a locality and its residents may be attacked, and the residents are never a target (Q-CIV-2). The order is refused with the state unchanged and a reason for an unknown unit, a halutz, a unit of another side, no hex, a hex not next to it (artillery: beyond its range), no enemy unit, no movement points left or a stock below the Arms this attack needs. Fortify and hold name no hex: one that names a hex is refused. The order costs `attention_cost.unit_order` (0, D-A6). A save writes it as `order <unit> attack <q> <r>`; a scenario takes `q` and `r`.-R-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-002: Resolver step 2 resolves the enemy's attacks in ascending attacker id: the lowest-id unit with an attack not yet in an engagement leads one, with every enemy unit attacking the same hex. A player's attack is fought when its order runs (R-COMBAT-001), as one engagement with that unit alone and one draw. Each unit's strength is first multiplied by its type's `combat_percent` (R-COMBAT-007, R-COMBAT-008). The attackers' strengths are summed; 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 that unit alone for a player's attack.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-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 the attack is given; an attack the stock cannot pay for is refused. Enemy units pay nothing (Q-ENEMY-4: no supply).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.@@ -240,13 +240,13 @@ R-COMBAT-006: Each engagement's Why line names the hex, the units on each side aPhase 5 PR 9, part 1 (#748): artillery's combat role and the armoured car. Q-ARTY-1 and Q-ARTY-2 are the plan's recommendations (owner, 15 October 2026, #375: "Take all recommendations"). The numbers in `unit_types.yaml` are agent defaults proposed on #748 and accepted by the owner as design values on 21 October 2026, together with three of R-COMBAT-007's mechanics that the Q-ARTY-1 text does not settle: the attackers' losses sparing the guns, the hold refused as "never holds ground", and the 200% counting on defence too (owner, 21 October 2026, #748, https://github.com/eyalgolan/statecraft-israel/issues/748#issuecomment-6317339304). How either type is acquired (R-UNIT-008) is part 2, on top of Phase 5 PR 3's training.-R-COMBAT-007: Artillery (a type of class `artillery`, which needs a `range` and an `arms_per_fire`; real values 2 and 2) supports attacks from range. Its `UnitOrder(unit, attack, q, r)` names an enemy hex at a hex distance of 1 to its `range`; a farther hex is refused with "That hex is beyond the unit's range". In step 2 it joins an engagement after the other attackers of its side, and only when at least one of them joins: otherwise it holds its fire, with a line, pays nothing and keeps its order. When it joins it pays its type's `arms_per_fire` in place of `mvp.arms_per_attack` (R-COMBAT-004 otherwise: refused at the order and called off in step 2 when the stock is short), and its strength counts at its `combat_percent` (real value 200). The attackers' losses fall on the other attackers only; artillery that is attacked defends and takes losses like any unit. It never holds ground: a hold order for it is refused with "Artillery does not hold ground" (fortify is allowed). As in any attack, residents are never a target (Q-CIV-2, R-COMBAT-005).+R-COMBAT-007: Artillery (a type of class `artillery`, which needs a `range` and an `arms_per_fire`; real values 2 and 2) attacks alone from range. Its `UnitOrder(unit, attack, q, r)` names an enemy hex at a hex distance of 1 to its `range`; a farther hex is refused with "That hex is beyond the unit's range". The player's artillery attacks at once like any unit, pays its type's `arms_per_fire` in place of `mvp.arms_per_attack`, and its losses spare it, so it loses nothing. Enemy artillery still joins an engagement in step 2 after the other attackers of its side and only when at least one of them joins; otherwise it holds its fire, with a line, pays nothing and keeps its order. Its strength counts at its `combat_percent` (real value 200). Artillery that is attacked defends and takes losses like any unit. It never holds ground: a hold order for it is refused with "Artillery does not hold ground" (fortify is allowed). As in any attack, residents are never a target (Q-CIV-2, R-COMBAT-005).R-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).Phase 5 PR 11, slice 2 (#750): the truce cards bind the player's attack orders (Q-WAR-3). The windows and the two rulings below are the owner's of 21 and 22 October 2026 (https://github.com/eyalgolan/statecraft-israel/issues/750#issuecomment-6327133246). The card-to-window binding by `ChosenOptions` is an agent default of this PR; the rest of #750's war state replaces R-ENEMY-006's date-alone guard in its own slices.-R-COMBAT-009: From accepting a truce card until its window ends, the player's attack orders are refused with "A truce is in force": from `first_truce`'s `accept` on the turns that start before 8 July 1948, and from `second_truce`'s `comply` on the turns that start before 15 October 1948, on the sourced dates of `events/first_truce.yaml`, `events/ten_days.yaml`, `events/second_truce.yaml` and `events/operation_yoav.yaml` (R-ENEMY-006's windows). A refused or defied card binds nothing: only the accepting option starts the binding. A complying player attacks again from the 15 October 1948 turn (owner ruling 1). The rule reads its turn by the turn's first day (the date the HUD shows) and R-ENEMY-006 by the turn's middle day; on monthly turns the two agree: the turns of 15 June to 15 September 1948 are bound, 15 October is free. Movement and every other order stand. Accepting a truce ends and clears every standing attack of the player's, with a line ("Unit N's attack on hex (q, r) ends: a truce is on"), the same as the enemy side's (owner ruling 2; R-ENEMY-006); the enemy side's own guard is untouched. The truce's refusal takes nothing: the order names its hex before the truce is checked, the state and the Attention are preserved, and no Arms are paid.+R-COMBAT-009: From accepting a truce card until its window ends, the player's attack orders are refused with "A truce is in force": from `first_truce`'s `accept` on the turns that start before 8 July 1948, and from `second_truce`'s `comply` on the turns that start before 15 October 1948, on the sourced dates of `events/first_truce.yaml`, `events/ten_days.yaml`, `events/second_truce.yaml` and `events/operation_yoav.yaml` (R-ENEMY-006's windows). A refused or defied card binds nothing: only the accepting option starts the binding. A complying player attacks again from the 15 October 1948 turn (owner ruling 1). The rule reads its turn by the turn's first day (the date the HUD shows) and R-ENEMY-006 by the turn's middle day; on monthly turns the two agree: the turns of 15 June to 15 September 1948 are bound, 15 October is free. Movement and every other order stand. The enemy side's own guard is untouched. The truce's refusal takes nothing: the order names its hex before the truce is checked, the state and the Attention are preserved, and no Arms are paid.## The enemydiff --git a/sim/Statecraft.Sim.Tests/ArtilleryTests.cs b/sim/Statecraft.Sim.Tests/ArtilleryTests.csindex 3a3c762c1..eb4e886ff 100644--- a/sim/Statecraft.Sim.Tests/ArtilleryTests.cs+++ b/sim/Statecraft.Sim.Tests/ArtilleryTests.cs@@ -4,8 +4,8 @@ using System.Linq;using Statecraft.Sim;/// <summary>Artillery's combat role and the armoured car (GDD Phase 5 PR 9, part 1; #748). Q-ARTY-1 and Q-ARTY-2 are the-/// plan's recommendations, taken by the owner on 15 October 2026 ("Take all recommendations", #375): artillery adds its-/// strength to an attack on a hex within its range, never attacks alone or holds ground, and spends Arms when it fires; the+/// plan's recommendations, updated by OQ-1 on 23 October 2026: player artillery attacks alone at once from range, never+/// holds ground, and spends Arms when it fires; enemy artillery still supports another attacker in resolver step 2. The/// armoured car has its own combat factor and no other special rule. The fixture's numbers are fixture values: a gun with/// range 2, 3 Arms a firing and a factor of 200, a car with a factor of 150, and CombatTests' table (below 2:1 both sides/// lose 1, from 2:1 the defenders lose 1 and retreat), so a test does not depend on the draw.</summary>@@ -44,35 +44,46 @@ public class ArtilleryTestsAssert.Equal("That hex is not next to the unit", Assert.Single(Step(c, s, new UnitOrder(3, Combat.Attack, 2, 0)).Rejected).Reason);}- // R-COMBAT-007: artillery never attacks alone. With no other unit of its side attacking the hex, it holds its fire: no- // draw, no Arms, no loss, a line, and the order stands for a later turn.+ // R-COMBAT-007 (owner, 23 October 2026, OQ-1: "One unit per attack, Civ"): artillery attacks alone from range, at once,+ // pays its arms_per_fire and loses nothing.[Fact]- public void ArtilleryAloneHoldsItsFire()+ public void ArtilleryAloneFiresAtOnceAndLosesNothing(){var c = Load();var s = CombatTests.With(c, Of("gun", 1, 4, 0, 2), Enemy(2, 2, 0, 3));- var r = Step(c, s, new UnitOrder(1, Combat.Attack, 2, 0));- Assert.Empty(r.Rejected);- Assert.Equal(3, r.State.Units[2].Strength);- Assert.Equal(s.Arms, r.State.Arms);- Assert.Equal(Step(c, s).State.RngState, r.State.RngState);- Assert.Equal((Combat.Attack, "2,0"), (r.State.Units[1].Order, r.State.Units[1].OrderTarget));- Assert.Contains(r.Why, w => w.Message == "Unit 1 holds its fire: no attack on hex 2,0 to support");+ var arms = s.Arms;+ var now = Simulation.Preview(c, s, new Command[] { new UnitOrder(1, Combat.Attack, 2, 0) });+ Assert.Empty(now.Rejected);+ Assert.Contains(now.Why, w => w.Key == WhyKeys.Engagement);+ Assert.Equal(arms - 3, now.State.Arms);+ Assert.Equal(2, now.State.Units[1].Strength);+ Assert.Equal((2, 0), now.Attacked[1]);+ }++ // R-UNIT-005 (spec 4.6): a gun's front is that of the enemy it attacked this turn, two hexes away, though it borders none.+ [Fact]+ public void AGunsFrontIsTheEnemyItAttackedThisTurn()+ {+ var c = Load();+ var s = CombatTests.With(c, Of("gun", 1, 4, 0, 2), Enemy(2, 2, 0, 9));+ s.ChosenOptions["armistice_syria"] = "sign";+ Assert.Null(Demobilization.Check(c, s, 1));+ var now = Simulation.Preview(c, s, new Command[] { new UnitOrder(1, Combat.Attack, 2, 0) });+ Assert.Equal("The armistice with Egypt is not signed", Demobilization.Check(c, now.State, 1, now.Attacked));+ Assert.Equal("The armistice with Egypt is not signed",+ Simulation.Step(c, s, new Command[] { new UnitOrder(1, Combat.Attack, 2, 0), new UnitOrder(1, Demobilization.SendHome) }).Rejected.Single().Reason);}- // R-COMBAT-007: in support, the guns add their strength times their factor and pay their own Arms. 1 + 2 x 200% = 5- // against 2 is 250 percent, the 2:1 row; the soldier alone would be at 50.+ // R-COMBAT-007, OQ-1: the preview and engagement count the selected player unit alone, not another standing attacker.[Fact]- public void ArtilleryAddsItsStrengthTimesItsFactorToAnAttack()+ public void APlayersAttackDoesNotAddAStandingGun(){var c = Load();var s = CombatTests.With(c, Attacking(Of("gun", 1, 4, 0, 2), 2, 0), Of("soldier", 3, 3, 0, 1), Enemy(2, 2, 0, 2));- Assert.Equal(250, Combat.Preview(c, s, 3, 2, 0)!.Value.RatioPercent);+ Assert.Equal(50, Combat.Preview(c, s, 3, 2, 0)!.Value.RatioPercent);var r = Step(c, s, new UnitOrder(3, Combat.Attack, 2, 0));Assert.Empty(r.Rejected);- Assert.Equal(1, r.State.Units[2].Strength); // the 2:1 row: the defenders lose 1 and retreat, the attackers nothing- Assert.NotEqual((2, 0), (r.State.Units[2].Q, r.State.Units[2].R));- Assert.Equal(s.Arms - 2 - 3, r.State.Arms); // the soldier's attack and the guns' firing+ Assert.Equal(s.Arms - 2, r.State.Arms);}// R-COMBAT-007: the guns fire from behind the line, so the attackers' losses fall on the other attackers only. 1 + 2 x@@ -90,33 +101,6 @@ public class ArtilleryTestsAssert.Contains(r.Why, w => w.Message.StartsWith("The attack on hex 2,0 (units 1, 3 against unit 2,", StringComparison.Ordinal)); // id order, though the guns join last}- // R-COMBAT-007: the guns pay after the other attackers; a stock that cannot pay for the firing calls it off, and the- // attack goes ahead without them. At the order, the firing counts the attacks already ordered.- [Fact]- public void ArtilleryTheStockCannotPayForIsCalledOff()- {- var c = Load();- var s = CombatTests.With(c, Attacking(Of("gun", 1, 4, 0, 2), 2, 0), Attacking(Of("soldier", 3, 3, 0, 1), 2, 0), Enemy(2, 2, 0, 2));- s.Arms = 4; // the soldier's 2, then 2 left for the guns' 3- var r = Step(c, s);- Assert.Contains(r.Why, w => w.Message == "Unit 1's attack on hex 2,0 is called off: it needs 3 Arms and the stock has 2");- Assert.Equal("", r.State.Units[1].Order);- Assert.Equal(2, r.State.Arms);- Assert.False(r.State.Units.ContainsKey(3)); // 1 against 2, the first row: both sides lose 1- Assert.Equal(1, r.State.Units[2].Strength);-- var t = CombatTests.With(c, Of("gun", 1, 4, 0, 2), Attacking(Of("soldier", 3, 3, 0, 1), 2, 0), Enemy(2, 2, 0, 2));- t.Arms = 4;- Assert.Equal("An attack needs 3 Arms and the stock has 4, of which 2 go to attacks already ordered",- Assert.Single(Step(c, t, new UnitOrder(1, Combat.Attack, 2, 0)).Rejected).Reason);-- // The other way round: a gun already ordered counts at its own 3 Arms, not at one attack's 2.- var g = CombatTests.With(c, Attacking(Of("gun", 1, 4, 0, 2), 2, 0), Of("soldier", 3, 3, 0, 1), Enemy(2, 2, 0, 2));- g.Arms = 4;- Assert.Equal("An attack needs 2 Arms and the stock has 4, of which 3 go to attacks already ordered",- Assert.Single(Step(c, g, new UnitOrder(3, Combat.Attack, 2, 0)).Rejected).Reason);- }-// R-COMBAT-007: artillery never holds ground. The hold order is refused with a reason; fortify is not.[Fact]public void ArtilleryDoesNotHoldGround()diff --git a/sim/Statecraft.Sim.Tests/CombatDrawCountTests.cs b/sim/Statecraft.Sim.Tests/CombatDrawCountTests.csindex f07c4927a..867b54ee8 100644--- a/sim/Statecraft.Sim.Tests/CombatDrawCountTests.cs+++ b/sim/Statecraft.Sim.Tests/CombatDrawCountTests.cs@@ -43,9 +43,8 @@ public class CombatDrawCountTestspublic void AStepTwoWithNoEngagementDrawsNothing(){var c = Load();- // An attack that is called off (the stock is empty) and one whose hex is empty are not engagements.- var s = CombatTests.With(c, Soldier(1, 3, 0, 4, "2,0"), Enemy(2, 2, 0, 3), Soldier(3, 0, 2, 4, "1,2"));- s.Arms = 0;+ // Standing attacks whose hexes are empty are not engagements.+ var s = CombatTests.With(c, Soldier(1, 3, 0, 4, "2,0"), Soldier(3, 0, 2, 4, "1,2"));var before = s.RngState;Combat.Resolve(c, s, new List<Cause>());Assert.Equal(before, s.RngState);diff --git a/sim/Statecraft.Sim.Tests/CombatTests.cs b/sim/Statecraft.Sim.Tests/CombatTests.csindex 8d981072e..88a88e9a3 100644--- a/sim/Statecraft.Sim.Tests/CombatTests.cs+++ b/sim/Statecraft.Sim.Tests/CombatTests.cs@@ -46,7 +46,68 @@ public class CombatTestsreturn why;}- // R-HOUSE-003, R-COMBAT-001: issuing an attack preserves the existing formation's housing home.+ // R-COMBAT-001 (owner, 23 October 2026: "Instant, like Civ"): the attack is fought when it is given; the unit keeps no order.+ [Fact]+ public void AnAttackIsFoughtWhenGiven()+ {+ var c = Load();+ var s = With(c, Soldier(1, 2, 1, 6), Enemy(2, 3, 1, 1));+ var now = Simulation.Preview(c, s, new Command[] { new UnitOrder(1, Combat.Attack, 3, 1) });+ Assert.Empty(now.Rejected);+ Assert.Contains(now.Why, w => w.Message.StartsWith("The attack on hex 3,1"));+ Assert.Equal("", now.State.Units[1].Order);+ Assert.Equal(s.Arms - 2, now.State.Arms);+ }++ // R-COMBAT-001: the attack ends the unit's movement; a unit with no points left cannot attack.+ [Fact]+ public void AnAttackEndsTheUnitsMovement()+ {+ var c = Load();+ var s = With(c, Soldier(1, 2, 1, 6), Enemy(2, 3, 1, 1));+ var now = Simulation.Preview(c, s, new Command[] { new UnitOrder(1, Combat.Attack, 3, 1), new Move(1, 2, 2) });+ Assert.Equal(0, Movement.PointsLeft(c, now.State, 1, now.Spent));+ Assert.Equal("That hex is out of reach this turn", now.Rejected.Single().Reason);+ var tired = Simulation.Preview(c, s, new Command[] { new Move(1, 2, 2), new Move(1, 2, 1), new Move(1, 2, 2), new UnitOrder(1, Combat.Attack, 3, 1) });+ Assert.Equal("That unit has no movement points left this turn", tired.Rejected.Single().Reason);+ }++ // R-COMBAT-002: a player's engagement draws once, when its order runs; step 2 draws only for the enemy.+ [Fact]+ public void APlayersAttackDrawsWhenGiven()+ {+ var c = Load();+ var s = With(c, Soldier(1, 2, 1, 6), Enemy(2, 3, 1, 1));+ var now = Simulation.Preview(c, s, new Command[] { new UnitOrder(1, Combat.Attack, 3, 1) });+ Assert.NotEqual(s.RngState, now.State.RngState);+ var ended = Step(c, s, new UnitOrder(1, Combat.Attack, 3, 1));+ Assert.DoesNotContain(ended.State.Units.Values, u => u.Side == "israel" && u.Order == Combat.Attack);+ }++ // R-COMBAT-004: the Arms are checked and paid at the order, from the stock as it is.+ [Fact]+ public void AnAttackTheStockCannotPayIsRefused()+ {+ var c = Load();+ var s = With(c, Soldier(1, 2, 1, 6), Enemy(2, 3, 1, 1));+ s.Arms = 0;+ var now = Simulation.Preview(c, s, new Command[] { new UnitOrder(1, Combat.Attack, 3, 1) });+ Assert.StartsWith("An attack needs", now.Rejected.Single().Reason);+ Assert.Equal(s.Hash(), now.State.Hash());+ }++ // R-COMBAT-009: after accepting a truce, an attack in its window is refused at the click.+ [Fact]+ public void AnAttackInAnAcceptedTruceIsRefused()+ {+ var c = Load();+ var s = With(c, Soldier(1, 2, 1, 6), Enemy(2, 3, 1, 1));+ s.ChosenOptions["first_truce"] = "accept";+ s.Date = new DateTime(1948, 6, 15);+ Assert.Equal("A truce is in force", Simulation.Preview(c, s, new Command[] { new UnitOrder(1, Combat.Attack, 3, 1) }).Rejected.Single().Reason);+ }++ // R-HOUSE-003, R-COMBAT-001: an attack keeps the formation's home: the survivor is still housed there.[Fact]public void GivingAnAttackRetainsTheFormationsHomeAndHousing(){@@ -55,11 +116,12 @@ public class CombatTestsAssert.Equal("town_a", s.Units[1].HomeCity);Assert.Equal(15, Cities.Housed(s, s.Cities["town_a"]));- Assert.Null(Combat.Give(c, s, 1, 2, 0, new List<Cause>()));+ var now = Simulation.Preview(c, s, new Command[] { new UnitOrder(1, Combat.Attack, 2, 0) });- var u = s.Units[1];- Assert.Equal((1, "israel", 5, "town_a", Combat.Attack, "2,0"), (u.Id, u.Side, u.Strength, u.HomeCity, u.Order, u.OrderTarget));- Assert.Equal(15, Cities.Housed(s, s.Cities["town_a"]));+ Assert.Empty(now.Rejected);+ var u = now.State.Units[1];+ Assert.Equal((1, "israel", "town_a", ""), (u.Id, u.Side, u.HomeCity, u.Order));+ Assert.Equal(15 - (5 - u.Strength), Cities.Housed(now.State, now.State.Cities["town_a"]));}// R-HOUSE-003, R-COMBAT-001: ending an attack does not release a surviving formation's housing.@@ -132,18 +194,16 @@ public class CombatTestsvar city = g.State.Cities["town_a"];Assert.Equal(city.Civilians + city.Craftsmen + city.Recruits + 2, Cities.Housed(g.State, city));- var result = g.Step(new Command[] { new UnitOrder(recruit.Id, Combat.Attack, 2, 0) });-- Assert.Empty(result.Rejected);- var survivor = g.State.Units[recruit.Id];+ Assert.Null(g.Commit(new UnitOrder(recruit.Id, Combat.Attack, 2, 0)));+ var survivor = g.Now.State.Units[recruit.Id];Assert.Equal((recruit.Id, "israel", 1, "town_a"), (survivor.Id, survivor.Side, survivor.Strength, survivor.HomeCity));var loaded = GameSession.Load(c, g.Save.Write(), out var warning);Assert.Empty(warning);- Assert.Equal(g.State.Hash(), loaded.State.Hash());- Assert.Equal(g.State.Describe(), loaded.State.Describe());- Assert.Equal(survivor.Canonical(), loaded.State.Units[recruit.Id].Canonical());- city = loaded.State.Cities["town_a"];- Assert.Equal(city.Civilians + city.Craftsmen + city.Recruits + 1, Cities.Housed(loaded.State, city));+ Assert.Equal(g.Now.State.Hash(), loaded.Now.State.Hash());+ Assert.Equal(g.Now.State.Describe(), loaded.Now.State.Describe());+ Assert.Equal(survivor.Canonical(), loaded.Now.State.Units[recruit.Id].Canonical());+ city = loaded.Now.State.Cities["town_a"];+ Assert.Equal(city.Civilians + city.Craftsmen + city.Recruits + 1, Cities.Housed(loaded.Now.State, city));}// R-COMBAT-001: an attack names an adjacent hex that holds an enemy unit, and the player's unit must have the Arms for@@ -180,12 +240,11 @@ public class CombatTestss.Arms = 2;var given = Step(c, s, new UnitOrder(1, Combat.Attack, 2, 0)).State; // resolved the same turnAssert.Equal(0, given.Arms);- Assert.Equal("That unit already has that order", Assert.Single(Step(c, given, new UnitOrder(1, Combat.Attack, 2, 0)).Rejected).Reason);- Assert.Equal("That unit already has that order", Combat.Check(c, given, 1, 2, 0));+ Assert.Equal("", given.Units[1].Order);}// R-COMBAT-001: Check is null exactly where Give takes the attack (the unit card offers the target, #754), changes- // nothing, and counts the attacks already standing as Give does (Q-COMBAT-4).+ // nothing. Player attacks already standing in an old in-memory state do not reserve Arms under the instant rule.[Fact]public void CheckIsNullForAnAttackGiveTakes(){@@ -198,7 +257,7 @@ public class CombatTestsAssert.Equal(before, s.Hash());Assert.Empty(Step(c, s, new UnitOrder(1, Combat.Attack, 2, 0)).Rejected);s.Units[1] = Attacking(s.Units[1], 2, 0);- Assert.Equal("An attack needs 2 Arms and the stock has 2, of which 2 go to attacks already ordered", Combat.Check(c, s, 3, 2, 0));+ Assert.Null(Combat.Check(c, s, 3, 2, 0));}// R-ENEMY-001: with enemy, Check runs the same checks with the sides swapped and asks for no Arms (Q-ENEMY-4), as Give@@ -243,8 +302,7 @@ public class CombatTests}}- // Q-COMBAT-4: the Arms are paid at resolution, so a new attack counts the attacks already ordered. With the stock for- // one attack, two new orders in one turn: the first is taken, the second refused (#1194 review).+ // R-COMBAT-004: Arms are paid at each order. With the stock for one attack, the first spends it and the second is refused.[Fact]public void ASecondAttackTheStockCannotPayForIsRefused(){@@ -253,7 +311,7 @@ public class CombatTestss.Arms = 2; // the fixture's attack takes 2var r = Step(c, s, new UnitOrder(1, Combat.Attack, 2, 0), new UnitOrder(3, Combat.Attack, 2, 0));var refused = Assert.Single(r.Rejected);- Assert.Equal("An attack needs 2 Arms and the stock has 2, of which 2 go to attacks already ordered", refused.Reason);+ Assert.Equal("An attack needs 2 Arms and the stock has 0", refused.Reason);Assert.Equal("", r.State.Units[3].Order);Assert.Equal(0, r.State.Arms);}@@ -271,10 +329,10 @@ public class CombatTestsAssert.Equal(2, r.State.Units[4].Strength); // the new hex was attacked}- // R-COMBAT-002, R-COMBAT-004: the attack resolves in the turn it is given, in step 2; the player's unit pays the Arms then.+ // R-COMBAT-002, R-COMBAT-004: the attack resolves when it is given; the player's unit pays the Arms then.// Below 2:1 the fixture's row has both sides lose 1.[Fact]- public void AnAttackResolvesInStepTwoAndSpendsArms()+ public void AnAttackResolvesAtOnceAndSpendsArms(){var c = Load();var s = With(c, Soldier(1, 3, 0, 5), Enemy(2, 2, 0, 3));@@ -282,21 +340,21 @@ public class CombatTestsAssert.Empty(r.Rejected);Assert.Equal((4, 2), (r.State.Units[1].Strength, r.State.Units[2].Strength));Assert.Equal(s.Arms - 2, r.State.Arms);- Assert.Equal((Combat.Attack, "2,0"), (r.State.Units[1].Order, r.State.Units[1].OrderTarget));+ Assert.Equal(("", ""), (r.State.Units[1].Order, r.State.Units[1].OrderTarget));}- // R-COMBAT-002: several units attack one hex together, their strengths summed, as one engagement: 2 + 2 against 2 is 2:1.+ // R-COMBAT-002: player attacks are separate engagements in click order, and the preview counts the selected unit alone.[Fact]- public void JointAttacksAddTheirStrengths()+ public void PlayerAttacksFightSeparatelyInClickOrder(){var c = Load();var s = With(c, Soldier(1, 3, 0, 2), Soldier(3, 1, 1, 2), Enemy(2, 2, 0, 2));Assert.Equal(100, Combat.Preview(c, s, 1, 2, 0)!.Value.RatioPercent);var r = Step(c, s, new UnitOrder(1, Combat.Attack, 2, 0), new UnitOrder(3, Combat.Attack, 2, 0));Assert.Empty(r.Rejected);- var e = r.State.Units[2];- Assert.Equal((1, 2, 2), (e.Strength, r.State.Units[1].Strength, r.State.Units[3].Strength)); // 4 against 2, the 2:1 row: the defenders lose 1, the attackers nothing- Assert.NotEqual((2, 0), (e.Q, e.R)); // and retreat+ Assert.Equal(2, r.Why.Count(x => x.Key == WhyKeys.Engagement));+ Assert.Equal((1, 2), (r.State.Units[1].Strength, r.State.Units[3].Strength));+ Assert.False(r.State.Units.ContainsKey(2));Assert.Equal(s.Arms - 4, r.State.Arms);}@@ -318,8 +376,7 @@ public class CombatTestsAssert.Null(Combat.Preview(plain, With(plain, Soldier(1, 3, 0, 9)), 1, 2, 0)); // nothing to attack}- // R-COMBAT-002: engagements resolve in ascending attacker id, so the order the units were added in changes nothing, and- // when the Arms last for one attack only, the lower id attacks and the other is called off.+ // R-COMBAT-002: standing enemy engagements resolve in ascending attacker id, independent of insertion order.[Fact]public void AttackersResolveInAscendingId(){@@ -331,9 +388,8 @@ public class CombatTestsvar why = Resolve(c, a);Resolve(c, b);Assert.Equal(a.Hash(), b.Hash());- Assert.Equal((4, 2, 5, 3), (a.Units[1].Strength, a.Units[2].Strength, a.Units[3].Strength, a.Units[4].Strength));- Assert.Equal("", a.Units[3].Order);- Assert.Contains(why, x => x.Message == "Unit 3's attack on hex 4,0 is called off: it needs 2 Arms and the stock has 0");+ Assert.Equal((4, 2, 4, 2), (a.Units[1].Strength, a.Units[2].Strength, a.Units[3].Strength, a.Units[4].Strength));+ Assert.Equal(2, why.Count(x => x.Key == WhyKeys.Engagement));}// R-COMBAT-003: a defender the row sends back retreats to the first free neighbour in the fixed order: (3, 0) holds the@@ -414,27 +470,6 @@ public class CombatTestsAssert.Equal(arms, s.Arms);}- // R-COMBAT-001: attack is a standing order: it repeats each turn while its hex holds an enemy unit next to the attacker,- // and ends, with a line, once it does not.- [Fact]- public void AnAttackStandsUntilItsHexIsEmpty()- {- var c = Load();- var s = With(c, Soldier(1, 3, 0, 9), Enemy(2, 2, 0, 5));- var r = Step(c, s, new UnitOrder(1, Combat.Attack, 2, 0));- Assert.Equal((8, 4), (r.State.Units[1].Strength, r.State.Units[2].Strength)); // 9 against 5, below 2:1- Assert.Equal(Combat.Attack, r.State.Units[1].Order);- r = Step(c, r.State); // no order: the attack stands, against a unit its AI fortified on turn 1 (R-ENEMY-003)- Assert.Equal((7, 3, 2, 0), (r.State.Units[1].Strength, r.State.Units[2].Strength, r.State.Units[2].Q, r.State.Units[2].R)); // 8 against 4 x 150%, below 2:1- Assert.Equal(Combat.Attack, r.State.Units[1].Order);- r = Step(c, Step(c, r.State).State); // 7 against 3 x 150%, below 2:1; then 6 against 2 x 150%, 2:1- var e = r.State.Units[2];- Assert.Equal((1, 1, 0), (e.Strength, e.Q, e.R)); // lost 1 and retreated- Assert.Equal(s.Arms - 8, r.State.Arms);- Assert.Equal("", r.State.Units[1].Order);- Assert.Contains(r.Why, x => x.Message == "Unit 1's attack on hex 2,0 ends: no enemy unit is there");- }-// R-COMBAT-005, R-COMBAT-001 (Q-CIV-2, "Enemy units only, no effect"): enemy units on town_a's hex may be attacked; the// town, its people and every other part of the state but the units and the Arms are unchanged.[Fact]@@ -477,7 +512,7 @@ public class CombatTests}// R-COMBAT-005, R-ENEMY-001: over the reference war run (the goldens' run to the game's end), steps 1 and 2 run on each- // turn's end state, with its standing attacks and the enemy's orders, change only the units, the Arms and the RNG. The run+ // turn's end state, with its instant attacks and the enemy's orders, change only the units, the Arms and the RNG. The run// has engagements, so the test is not empty: since #1240 the real start has none (Golani's 4 against the Syrian 3 is under// the policy's 3:2), so unit 0 starts at its old 5 (ReferencePlayerTests.AtFive).[Fact]diff --git a/sim/Statecraft.Sim.Tests/DemobilizationTests.cs b/sim/Statecraft.Sim.Tests/DemobilizationTests.csindex d39250a75..c82e23577 100644--- a/sim/Statecraft.Sim.Tests/DemobilizationTests.cs+++ b/sim/Statecraft.Sim.Tests/DemobilizationTests.cs@@ -173,9 +173,10 @@ public class DemobilizationTestsvar c = Load();var s = State(c, new Unit(1, "gun", 3, 0, side: "israel", strength: 2, order: Combat.Attack, orderTarget: "1,0"),new Unit(2, "enemy", 1, 0, side: "egypt", strength: 3));- Assert.Equal("The armistice with Egypt is not signed", Demobilization.Check(c, s, 1));+ var attacked = new Dictionary<int, (int Q, int R)> { [1] = (1, 0) };+ Assert.Equal("The armistice with Egypt is not signed", Demobilization.Check(c, s, 1, attacked));s.ChosenOptions["armistice_jordan"] = "sign"; // would open the order if the target did not count- Assert.Equal("The armistice with Egypt is not signed", Demobilization.Check(c, s, 1));+ Assert.Equal("The armistice with Egypt is not signed", Demobilization.Check(c, s, 1, attacked));}// R-UNIT-005: the front is the nearest enemy unit's, ties by the lowest unit id; an attack order's target counts.@@ -191,7 +192,8 @@ public class DemobilizationTestss.ChosenOptions["armistice_syria"] = "sign";Assert.Null(Demobilization.Check(c, s, 1));- var attacking = State(c, Soldier(1, 3, 0, Combat.Attack, "2,0"), new Unit(2, "enemy", 2, 0, side: "egypt", strength: 3));- Assert.Equal("The armistice with Egypt is not signed", Demobilization.Check(c, attacking, 1));+ var attacking = State(c, Soldier(1, 3, 0), new Unit(2, "enemy", 2, 0, side: "egypt", strength: 3));+ Assert.Equal("The armistice with Egypt is not signed", Demobilization.Check(c, attacking, 1,+ new Dictionary<int, (int Q, int R)> { [1] = (2, 0) }));}}diff --git a/sim/Statecraft.Sim.Tests/GameSessionTurnTests.cs b/sim/Statecraft.Sim.Tests/GameSessionTurnTests.csindex 0f066f925..7303c46c5 100644--- a/sim/Statecraft.Sim.Tests/GameSessionTurnTests.cs+++ b/sim/Statecraft.Sim.Tests/GameSessionTurnTests.cs@@ -79,6 +79,42 @@ public class GameSessionTurnTestsAssert.Equal(SaveException.OlderRules, e.Code);}+ // R-SAVE-003: reloading keeps an attack's result; the same draw comes out.+ [Fact]+ public void AReloadKeepsAnAttacksResult()+ {+ var session = Fresh();+ var (unit, q, r) = FirstAttack(session);+ Assert.Null(session.Commit(new UnitOrder(unit, Combat.Attack, q, r)));+ var loaded = GameSession.Load(C, session.Save.Write(), out _);+ Assert.Equal(session.Now.State.Hash(), loaded.Now.State.Hash());+ }++ // R-TURN-004: a vote queued after an attack runs after it, so it cannot change the attack's draw.+ [Fact]+ public void AVoteQueuedAfterAnAttackDoesNotChangeIt()+ {+ var a = Fresh(); var b = Fresh();+ var (unit, q, r) = FirstAttack(a);+ a.Commit(new UnitOrder(unit, Combat.Attack, q, r)); b.Commit(new UnitOrder(unit, Combat.Attack, q, r));+ var policy = C.At(a.State.Date).Policies.First().Id;+ var withVote = a.EndTurn(new Command[] { new SetPolicy(policy, 0.5) });+ var without = b.EndTurn(new Command[0]);+ Assert.Equal(without.Why.First(w => w.Message.StartsWith("The attack on hex")).Message,+ withVote.Why.First(w => w.Message.StartsWith("The attack on hex")).Message);+ }++ /// <summary>The first (unit, hex) of the player's that Combat.Check takes on the session's shown state. At the start Golani+ /// (unit 0, 10,9) is next to the Syrian unit on 10,10 (docs/determinism.md, #1240's row), so one exists.</summary>+ static (int, int, int) FirstAttack(GameSession s)+ {+ var st = s.Now.State;+ foreach (var u in st.Units.Values.Where(x => x.Side == Movement.PlayerSide))+ foreach (var e in st.Units.Values.Where(x => x.Side != "" && x.Side != Movement.PlayerSide))+ if (Combat.Check(C, st, u.Id, e.Q, e.R, spent: s.Now.Spent) == null) return (u.Id, e.Q, e.R);+ throw new InvalidOperationException("precondition: no attack is possible at the start");+ }+// R-SAVE-004: a schema 2 GDD save that does not replay to its saved hash gets the clear older-rules message; a schema 3// one that does not is still damaged (no code).[Fact]diff --git a/sim/Statecraft.Sim.Tests/TruceTests.cs b/sim/Statecraft.Sim.Tests/TruceTests.csindex 95331405f..ff51accc6 100644--- a/sim/Statecraft.Sim.Tests/TruceTests.cs+++ b/sim/Statecraft.Sim.Tests/TruceTests.cs@@ -6,8 +6,8 @@ using Statecraft.Sim;/// <summary>The player's side of a truce (GDD Phase 5 PR 11, slice 2; Q-WAR-3; #750): from accepting first_truce until/// the turn covering 8 July 1948, and from accepting second_truce until the turn covering 15 October 1948, the player's/// attack orders are refused with "A truce is in force", state unchanged, while movement and the other orders stay-/// allowed; accepting a truce ends and clears a queued attack, as on the enemy side (owner rulings, 22 October 2026,-/// #750). The enemy side's date-driven guard is R-ENEMY-006 (#1263).</summary>+/// allowed. Player attacks are instant and never stand for a later truce answer to clear. The enemy side's date-driven+/// guard is R-ENEMY-006 (#1263).</summary>public class TruceTests{static Content Load(Dictionary<string, string>? events = null) => ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>@@ -98,81 +98,4 @@ public class TruceTestsAssert.Equal(expected, Combat.Check(c, s, 1, 2, 0));}- // R-COMBAT-009 (owner ruling 2): accepting a truce ends and clears the player's standing attacks, with a line;- // fortify and the enemy's orders are untouched. Choosing to fight on keeps them.- [Fact]- public void AcceptingATruceEndsAQueuedAttack()- {- var c = Load(TruceEvents);- var s = State(c, new DateTime(1948, 6, 15));- s.Units[1] = new Unit(1, "soldier", 3, 0, side: "israel", strength: 5, order: Combat.Attack, orderTarget: "2,0");- s.Units[2] = new Unit(2, "enemy", 2, 0, side: "egypt", strength: 3, order: Combat.Attack, orderTarget: "3,0");-- s.PendingEvents.Add("first_truce");- var why = new List<Cause>();- Assert.Null(EventSystem.Choose(c, s, "first_truce", "accept", why));- Assert.Equal("", s.Units[1].Order);- Assert.Equal(Combat.Attack, s.Units[2].Order); // the enemy's guard is R-ENEMY-006's, at resolver step 1- Assert.Contains(why, w => w.Message.Contains("a truce is on"));-- // And from here the player cannot order a new attack until the truce's end.- Assert.Equal("A truce is in force", Assert.Single(Step(c, s, new UnitOrder(1, Combat.Attack, 2, 0)).Rejected).Reason);-- // Choosing to fight on keeps a queued attack.- var t = State(c, new DateTime(1948, 6, 15));- t.Units[1] = new Unit(1, "soldier", 3, 0, side: "israel", strength: 5, order: Combat.Attack, orderTarget: "2,0");- t.PendingEvents.Add("first_truce");- Assert.Null(EventSystem.Choose(c, t, "first_truce", "refuse", new List<Cause>()));- Assert.Equal(Combat.Attack, t.Units[1].Order);- }-- /// <summary>R-COMBAT-009 with Q-HOUSE-5 (#1130): ending an attack for a truce keeps the formation's home city, so it- /// stays housed there.</summary>- [Fact]- public void AcceptingATruceKeepsTheFormationsHomeCity()- {- var c = Load(TruceEvents);- var s = State(c, new DateTime(1948, 6, 15));- s.Units[1] = new Unit(1, "soldier", 3, 0, side: "israel", strength: 5, order: Combat.Attack, orderTarget: "2,0", homeCity: "tel_aviv");- s.PendingEvents.Add("first_truce");- Assert.Null(EventSystem.Choose(c, s, "first_truce", "accept", new List<Cause>()));- Assert.Equal("", s.Units[1].Order);- Assert.Equal("tel_aviv", s.Units[1].HomeCity);- }-- /// <summary>The two truce cards as the fixture needs them: the accepting option and one that fights on. Fixture- /// texts, not the cards'.</summary>- static readonly Dictionary<string, string> TruceEvents = new Dictionary<string, string>- {- ["first_truce.yaml"] = @"-id: first_truce-title: The First Truce-text: The Security Council has called for a cease-fire.-office: prime_minister-from: 1948-06-01-options:- - id: accept- text: Accept the truce- historical: true- recommended: true- - id: refuse- text: Refuse the truce and keep fighting- alternative: { basis: design }-",- ["second_truce.yaml"] = @"-id: second_truce-title: The Second Truce-text: The Security Council has ordered a cease-fire.-office: prime_minister-from: 1948-07-15-options:- - id: comply- text: Comply with the cease-fire- historical: true- recommended: true- - id: defy- text: Defy the order and keep fighting- alternative: { basis: design }-",- };}diff --git a/sim/Statecraft.Sim.Tests/UnitLinesTests.cs b/sim/Statecraft.Sim.Tests/UnitLinesTests.csindex d63516ede..51c720f3e 100644--- a/sim/Statecraft.Sim.Tests/UnitLinesTests.cs+++ b/sim/Statecraft.Sim.Tests/UnitLinesTests.cs@@ -75,23 +75,6 @@ public class UnitLinesTestsNames(ended.Why.Single(w => w.Key == WhyKeys.SentHome), WhyKeys.SentHome, s, id);}- // The player's standing attack ended by a truce (Combat.EndAttacksForTruce) names its unit and the hex.- [Theory]- [InlineData(false)]- [InlineData(true)]- public void APlayerAttackEndedByATruceNamesItsUnit(bool raised)- {- var (s, r) = Start();- var id = raised ? r : 0;- var u = s.Units[id];- s.Units[id] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, Combat.Attack, "10,10", u.HomeCity);- var why = new List<Cause>();- Combat.EndAttacksForTruce(s, why);- var line = why.Single(w => w.Key == WhyKeys.AttackEndedTruce);- Names(line, WhyKeys.AttackEndedTruce, s, id);- Assert.Equal("10,10", line.Args[0]);- }-[Fact]public void AnEnemyAttackEndedByATruceNamesTheEnemyUnit(){@@ -164,41 +147,35 @@ public class UnitLinesTestsAssert.Equal(1, why.Single(w => w.Key == WhyKeys.SurrenderedPrisoners).Units.Single().Id);}- // The attack order, an attack that ends with no enemy there, guns holding fire and an attack called off for Arms name- // their unit and the hex (the called-off line also the need and the stock).+ // The enemy's standing attacks (R-ENEMY-001; the player's are fought at once): the attack order, an attack that ends with+ // no unit there and guns holding fire name their unit and the hex.[Fact]- public void TheAttackOrderLinesNameTheirUnit()+ public void TheEnemysAttackOrderLinesNameTheirUnit(){var c = ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>{["unit_types.yaml"] = Fixture.GddUnitTypes+ " - { id: soldier, kind: unit, side: israel, class: infantry, movement_points: 3 }\n"- + " - { id: gun, kind: unit, side: israel, class: artillery, movement_points: 2, range: 2, arms_per_fire: 3 }\n"- + " - { id: enemy, kind: unit, side: egypt, class: infantry, movement_points: 3 }\n",+ + " - { id: enemy, kind: unit, side: egypt, class: infantry, movement_points: 3 }\n"+ + " - { id: egun, kind: unit, side: egypt, class: artillery, movement_points: 2, range: 2, arms_per_fire: 3 }\n",["map/hexes.json"] = MovementTests.Board(), ["corridors.yaml"] = "corridors: []\n"})));- var s = CombatTests.With(c, Ours(1, 3, 0, 5), new Unit(9, "enemy", 2, 0, side: "egypt", strength: 3));+ var s = CombatTests.With(c, new Unit(9, "enemy", 3, 0, side: "egypt", strength: 5, homeCity: "gaza"), Ours(1, 2, 0, 3));var given = new List<Cause>();- Assert.Null(Combat.Give(c, s, 1, 2, 0, given));+ Assert.Null(Combat.Give(c, s, 9, 2, 0, given, enemy: true));var ordered = given.Single(w => w.Key == WhyKeys.AttackOrdered);- Assert.Equal((1, "town_a", "2,0"), (ordered.Units.Single().Id, ordered.Units.Single().HomeCity, ordered.Args[0]));- s.Units.Remove(9);+ Assert.Equal((9, "gaza", "2,0"), (ordered.Units.Single().Id, ordered.Units.Single().HomeCity, ordered.Args[0]));+ s.Units.Remove(1);var ended = new List<Cause>();Combat.Resolve(c, s, ended);- Assert.Equal((1, "2,0"), (ended.Single(w => w.Key == WhyKeys.AttackEnded).Units.Single().Id, ended.Single(w => w.Key == WhyKeys.AttackEnded).Args[0]));+ var end = ended.Single(w => w.Key == WhyKeys.AttackEnded);+ Assert.Equal((9, "2,0"), (end.Units.Single().Id, end.Args[0]));- var gun = new Unit(5, "gun", 4, 0, side: "israel", strength: 2, order: Combat.Attack, orderTarget: "2,0", homeCity: "town_a");- var quiet = CombatTests.With(c, gun, new Unit(9, "enemy", 2, 0, side: "egypt", strength: 3));+ var gun = new Unit(5, "egun", 4, 0, side: "egypt", strength: 2, order: Combat.Attack, orderTarget: "2,0");+ var quiet = CombatTests.With(c, gun, Ours(1, 2, 0, 3));var held = new List<Cause>();Combat.Resolve(c, quiet, held);- Assert.Equal((5, "2,0"), (held.Single(w => w.Key == WhyKeys.HoldsFire).Units.Single().Id, held.Single(w => w.Key == WhyKeys.HoldsFire).Args[0]));-- var poor = CombatTests.With(c, gun, new Unit(8, "soldier", 3, 0, side: "israel", strength: 2, order: Combat.Attack, orderTarget: "2,0"),- new Unit(9, "enemy", 2, 0, side: "egypt", strength: 3));- poor.Arms = 2;- var off = new List<Cause>();- Combat.Resolve(c, poor, off);- var line = off.Single(w => w.Key == WhyKeys.AttackCalledOff && w.Units[0].Id == 5);- Assert.Equal(new[] { "2,0", "3", "0" }, line.Args);+ var fire = held.Single(w => w.Key == WhyKeys.HoldsFire);+ Assert.Equal((5, "2,0"), (fire.Units.Single().Id, fire.Args[0]));}}diff --git a/sim/Statecraft.Sim/Combat.cs b/sim/Statecraft.Sim/Combat.csindex a0b9758df..c1c2314c4 100644--- a/sim/Statecraft.Sim/Combat.cs+++ b/sim/Statecraft.Sim/Combat.cs@@ -6,9 +6,8 @@ using System.Linq;namespace Statecraft.Sim{/// <summary>Combat in the GDD v0.1 loop (Phase 5 PR 8; docs/rules/mvp.md R-COMBAT-001 to R-COMBAT-006). A unit given- /// UnitOrder(unit, attack, q, r) attacks the adjacent hex (q, r) in resolver step 2 of every turn until its hex holds no- /// enemy unit next to it (spec 2026-10-12 section 2.3: a standing order). Units of one side attacking one hex are one- /// engagement, their strengths summed (Q-COMBAT-2); it draws once from the RNG and reads rules.yaml mvp.combat_table+ /// UnitOrder(unit, attack, q, r) makes a player's unit attack the hex at once; enemy attacks remain standing orders+ /// resolved in step 2. Each player attack is one engagement with that unit alone; it draws once and reads rules.yaml mvp.combat_table/// (Q-COMBAT-1). Combat changes the units and the Arms only (R-COMBAT-005): no resident, city, locality or score is ever/// a target or an outcome (Q-CIV-2, impact plan section 4.3).</summary>public static class Combat@@ -70,31 +69,18 @@ namespace Statecraft.Siminternal static bool TruceInForce(GameState s) =>PlayerTruces.Any(t => s.Date < t.Until && s.ChosenOptions.TryGetValue(t.Event, out var o) && o == t.Option);- /// <summary>R-COMBAT-009: accepting a truce ends and clears every standing attack of the player's, with a- /// line, the same as the enemy side's (owner ruling 2, 22 October 2026, #750; R-ENEMY-006).</summary>- internal static void EndAttacksForTruce(GameState s, List<Cause> why)- {- foreach (var id in s.Units.Keys.ToList())- {- var u = s.Units[id];- if (!Player(u) || u.Order != Attack) continue;- s.Units[id] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, "", "", u.HomeCity);- why.Add(UnitLines.Line(WhyKeys.AttackEndedTruce,- $"Unit {id}'s attack on hex {u.OrderTarget} ends: a truce is on", new[] { u }, u.OrderTarget));- }- }-/// <summary>The enemy military units on (q, r), seen from <paramref name="attacker"/>'s team, in id order.</summary>static List<Unit> Defenders(GameState s, Unit attacker, int q, int r) =>s.Units.Values.Where(x => x.Q == q && x.R == r && Military(x) && Player(x) != Player(attacker)).ToList();- /// <summary>R-COMBAT-001's refusals: null when <see cref="Give"/> takes the attack on (q, r), else the reason shown to- /// the player. Changes nothing: the unit card asks it for each enemy hex before it offers that hex (#754). Refused for- /// an unknown unit, a halutz, an enemy unit, no hex, the attack it already has, a hex not next to it (artillery: beyond- /// its range) or with no enemy unit, a truce the player accepted (R-COMBAT-009), or fewer Arms than one attack takes- /// on top of the player's other attacks already ordered (Q-COMBAT-4). With <paramref name="enemy"/> the enemy AI orders its own unit through the same checks, the- /// sides swapped, and pays no Arms (R-ENEMY-001; Q-ENEMY-4).</summary>- public static string? Check(Content c, GameState s, int unitId, int? q, int? r, bool enemy = false)+ /// <summary>R-COMBAT-001's refusals: null when the player may strike (q, r), else the reason shown to the player.+ /// Changes nothing: the unit card asks it for each enemy hex before it offers that hex (#754). Refused for an unknown+ /// unit, a halutz, an enemy unit, no hex, a hex not next to it (artillery: beyond its range), a hex with no enemy unit,+ /// a truce the player accepted (R-COMBAT-009), no movement points left or fewer Arms than the attack takes. With+ /// <paramref name="enemy"/> the enemy AI orders its own unit through the same checks, the sides swapped, with its+ /// existing-order check and no Arms cost (R-ENEMY-001; Q-ENEMY-4).</summary>+ public static string? Check(Content c, GameState s, int unitId, int? q, int? r, bool enemy = false,+ IReadOnlyDictionary<int, int>? spent = null){if (!s.Units.TryGetValue(unitId, out var u)) return "There is no such unit";if (!Military(u)) return "Only a military unit takes that order";@@ -102,21 +88,20 @@ namespace Statecraft.Simif (q == null || r == null) return "An attack names a hex";if (!enemy && TruceInForce(s)) return "A truce is in force"; // R-COMBAT-009var target = Hex(q.Value, r.Value);- if (u.Order == Attack && u.OrderTarget == target) return "That unit already has that order";+ if (enemy && u.Order == Attack && u.OrderTarget == target) return "That unit already has that order";if (!InReach(c, u, q.Value, r.Value)) return Guns(c, u) ? "That hex is beyond the unit's range" : "That hex is not next to the unit";if (Defenders(s, u, q.Value, r.Value).Count == 0) return "There is no enemy unit on that hex";+ if (!enemy && spent != null && Movement.PointsLeft(c, s, unitId, spent) == 0)+ return "That unit has no movement points left this turn";var mvp = c.RulesAt(s.Date).Mvp!;var need = Need(c, mvp, u);- // Arms are paid at resolution, so the stock must also cover the player's other standing attacks, this turn's- // included; the unit's own attack, which this order replaces, is not counted.- var committed = s.Units.Values.Where(x => x.Id != unitId && x.Order == Attack && Military(x) && Player(x)).Sum(x => Need(c, mvp, x));- return !enemy && s.Arms < need + committed ? Short(need, s.Arms, committed) : null;+ return !enemy && s.Arms < need ? FormattableString.Invariant($"An attack needs {need} Arms and the stock has {s.Arms}") : null;}- /// <summary>R-COMBAT-001: gives the player's military unit a standing attack on the adjacent hex (q, r), replacing its- /// order (a fortify is lost). Refused, state untouched, with <see cref="Check"/>'s reason. It costs no Attention (D-A6)- /// and resolves in this turn's step 2. With <paramref name="enemy"/>, the enemy AI's own unit (see Check).</summary>- internal static string? Give(Content c, GameState s, int unitId, int? q, int? r, List<Cause> why, bool enemy = false)+ /// <summary>R-ENEMY-001: gives the enemy AI's military unit a standing attack on (q, r) for resolver step 2, replacing+ /// its order. Refused, state untouched, with <see cref="Check"/>'s reason. The player's attacks are fought at once by+ /// <see cref="Strike"/> and never stand.</summary>+ internal static string? Give(Content c, GameState s, int unitId, int? q, int? r, List<Cause> why, bool enemy){var refused = Check(c, s, unitId, q, r, enemy);if (refused != null) return refused;@@ -126,24 +111,38 @@ namespace Statecraft.Simreturn null;}- static string Short(int need, int have, int committed) => committed == 0- ? FormattableString.Invariant($"An attack needs {need} Arms and the stock has {have}")- : FormattableString.Invariant($"An attack needs {need} Arms and the stock has {have}, of which {committed} go to attacks already ordered");+ /// <summary>R-COMBAT-001 (owner, 23 October 2026, "Instant, like Civ"): the player's unit attacks (q, r) at once:+ /// refused, the state untouched, with <see cref="Check"/>'s reason; else it pays its Arms (R-COMBAT-004), loses its+ /// order and the rest of its movement points, and fights one engagement alone (OQ-1), drawing once.</summary>+ internal static string? Strike(Content c, GameState s, int unitId, int? q, int? r, Dictionary<int, int> spent,+ Dictionary<int, (int Q, int R)> attacked, List<Cause> why)+ {+ var refused = Check(c, s, unitId, q, r, spent: spent);+ if (refused != null) return refused;+ var mvp = c.RulesAt(s.Date).Mvp!;+ var u = s.Units[unitId];+ s.Arms -= Need(c, mvp, u);+ var attacker = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, "", "", u.HomeCity);+ s.Units[unitId] = attacker;+ if (u.Order == Orders.Fortify)+ why.Add(UnitLines.Line(WhyKeys.FortifyLost,+ $"Unit {unitId} left hex {u.OrderTarget} and is no longer fortified", new[] { u }, u.OrderTarget));+ spent[unitId] = Movement.Points(c, attacker);+ attacked[unitId] = (q!.Value, r!.Value);+ Engage(c, s, mvp, new List<Unit> { attacker }, Defenders(s, attacker, q.Value, r.Value), q.Value, r.Value, why);+ return null;+ }- /// <summary>The attack preview (spec section 2.6; Q-UI-1): the ratio, in percent and rounded down, of unit- /// <paramref name="unitId"/>'s strength plus that of the units of its team already ordered to attack (q, r) from next to- /// it (artillery: from within its range), each at its combat factor, against the enemy units there after fortify and- /// terrain, and the combat_table row it falls in. Null when (q, r) is out of the unit's reach or holds no enemy unit, or- /// the unit is unknown or no military unit. A gun previewed with no other attacker still gets a ratio, though step 2- /// would have it hold its fire (R-COMBAT-007); the unit card shows it with <see cref="Outcomes"/> (#754).</summary>+ /// <summary>The player attack preview (spec section 4.1; Q-UI-1): the ratio, in percent and rounded down, of unit+ /// <paramref name="unitId"/>'s strength alone, at its combat factor, against the enemy units there after fortify and+ /// terrain, and the combat_table row it falls in. Null when (q, r) is out of reach, holds no enemy unit, or the unit is+ /// unknown or not military. The unit card shows it with <see cref="Outcomes"/> (#754).</summary>public static (int RatioPercent, int Row)? Preview(Content c, GameState s, int unitId, int q, int r){if (!s.Units.TryGetValue(unitId, out var u) || !Military(u) || !InReach(c, u, q, r)) return null;var defenders = Defenders(s, u, q, r);if (defenders.Count == 0) return null;- var target = Hex(q, r);- var attackers = s.Units.Values.Where(x => x.Id == unitId- || (x.Order == Attack && x.OrderTarget == target && Military(x) && Player(x) == Player(u) && InReach(c, x, q, r))).ToList();+ var attackers = new List<Unit> { u };var mvp = c.RulesAt(s.Date).Mvp!;var ratio = Ratio(c, mvp, attackers, defenders, q, r);return (ratio, Row(mvp, ratio));@@ -188,11 +187,10 @@ namespace Statecraft.Simreturn row;}- /// <summary>Resolver step 2 (R-COMBAT-002 to R-COMBAT-006): in ascending attacker id, each unit with an attack order not+ /// <summary>Resolver step 2 (R-COMBAT-002 to R-COMBAT-006): enemy units keep standing attacks. In ascending attacker id, each unit with an attack order not/// yet in an engagement this turn leads one, with every unit of its team attacking the same hex. A unit no longer next- /// to its hex (artillery: within its range), or whose hex holds no enemy unit, ends its attack; a player's unit pays- /// its Arms when it joins, and one the stock cannot pay for has its attack called off (Q-COMBAT-4). Enemy units pay- /// nothing (Q-ENEMY-4: no supply). Artillery joins after the other attackers and only beside one of them: alone it+ /// to its hex (artillery: within its range), or whose hex holds no enemy unit, ends its attack. Enemy units pay+ /// nothing (Q-ENEMY-4: no supply). Enemy artillery joins after the other attackers and only beside one of them: alone it/// holds its fire, pays nothing and keeps its order (R-COMBAT-007). An engagement with an attacker left draws once./// Afterwards every attack whose hex is now empty ends.</summary>public static void Resolve(Content c, GameState s, List<Cause> why)@@ -223,18 +221,6 @@ namespace Statecraft.Sim$"Unit {x.Id} holds its fire: no attack on hex {x.OrderTarget} to support", new[] { x }, x.OrderTarget));continue;}- if (Player(x))- {- var need = Need(c, mvp, x);- if (s.Arms < need)- {- End(s, x, WhyKeys.AttackCalledOff,- $"Unit {x.Id}'s attack on hex {x.OrderTarget} is called off: it needs {need.ToString(CultureInfo.InvariantCulture)} Arms and the stock has {s.Arms.ToString(CultureInfo.InvariantCulture)}",- why, x.OrderTarget, need.ToString(CultureInfo.InvariantCulture), s.Arms.ToString(CultureInfo.InvariantCulture));- continue;- }- s.Arms -= need;- }attackers.Add(x);}if (attackers.Count > 0) Engage(c, s, mvp, attackers, defenders, q, r, why);diff --git a/sim/Statecraft.Sim/Commands.cs b/sim/Statecraft.Sim/Commands.csindex 52cea8c0a..7769ec781 100644--- a/sim/Statecraft.Sim/Commands.cs+++ b/sim/Statecraft.Sim/Commands.cs@@ -180,10 +180,12 @@ namespace Statecraft.Sim{public GameState State { get; }public IReadOnlyDictionary<int, int> Spent { get; }+ public IReadOnlyDictionary<int, (int Q, int R)> Attacked { get; }public IReadOnlyList<Cause> Why { get; }public IReadOnlyList<Rejection> Rejected { get; }- public PreviewResult(GameState state, IReadOnlyDictionary<int, int> spent, IReadOnlyList<Cause> why, IReadOnlyList<Rejection> rejected)- { State = state; Spent = spent; Why = why; Rejected = rejected; }+ public PreviewResult(GameState state, IReadOnlyDictionary<int, int> spent, IReadOnlyDictionary<int, (int Q, int R)> attacked,+ IReadOnlyList<Cause> why, IReadOnlyList<Rejection> rejected)+ { State = state; Spent = spent; Attacked = attacked; Why = why; Rejected = rejected; }}/// <summary>Checks that every text an order carries can be saved: a null id or a lone surrogate would make the savediff --git a/sim/Statecraft.Sim/Demobilization.cs b/sim/Statecraft.Sim/Demobilization.csindex a78b1e92e..0d985c5ba 100644--- a/sim/Statecraft.Sim/Demobilization.cs+++ b/sim/Statecraft.Sim/Demobilization.cs@@ -18,20 +18,16 @@ namespace Statecraft.Simstatic bool Signed(GameState s, string front) =>s.ChosenOptions.TryGetValue("armistice_" + front, out var o) && o == "sign";- /// <summary>The front <paramref name="u"/> fights on (owner, 22 October 2026, #1309): of the enemy units it attacks- /// (the hex its attack order names) or borders (an adjacent hex), the ones whose side belongs to a front (R-POW-004's+ /// <summary>The front <paramref name="u"/> fights on (owner, 22 October 2026, #1309): of the enemy units it attacked+ /// this turn or borders (an adjacent hex), the ones whose side belongs to a front (R-POW-004's/// map; the ALA and the local forces belong to none, Q-OBJ-1, so they name no front - accepted per maintainer comment 6341877062 on #1309), the nearest/// one's, ties by the lowest unit id. Null when no front-bearing enemy unit is attacked or bordered: the ruling's/// "no enemy units in play" case, which any signed armistice covers (accepted per maintainer comment 6341877062/// on #1309: a frontless enemy counts as none in play).</summary>- internal static string? Front(GameState s, Unit u)+ internal static string? Front(GameState s, Unit u, IReadOnlyDictionary<int, (int Q, int R)>? attacked = null){(int Q, int R)? attacks = null;- if (u.Order == Combat.Attack)- {- var parts = u.OrderTarget.Split(',');- attacks = (int.Parse(parts[0], CultureInfo.InvariantCulture), int.Parse(parts[1], CultureInfo.InvariantCulture));- }+ if (attacked != null && attacked.TryGetValue(u.Id, out var target)) attacks = target;var candidates = s.Units.Values.Where(e => e.Side != "" && e.Side != Movement.PlayerSide && Prisoners.FrontOf.ContainsKey(e.Side)).Where(e => MapActions.Distance(u.Q, u.R, e.Q, e.R) == 1 || (attacks != null && attacks.Value == (e.Q, e.R)))@@ -45,12 +41,13 @@ namespace Statecraft.Sim/// Changes nothing: the unit card asks it before it offers Send home. Refused for an unknown unit, a unit with no/// side (a halutz) or an enemy unit, as the standing orders are; then while the armistice on the unit's front is/// unsigned, or - no enemy attacked or bordered - while no armistice is signed at all.</summary>- public static string? Check(Content c, GameState s, int unitId)+ public static string? Check(Content c, GameState s, int unitId,+ IReadOnlyDictionary<int, (int Q, int R)>? attacked = null){if (!s.Units.TryGetValue(unitId, out var u)) return "There is no such unit";if (u.Side == "") return "Only a military unit takes that order";if (u.Side != Movement.PlayerSide) return "That unit is not yours";- var front = Front(s, u);+ var front = Front(s, u, attacked);if (front != null)return Signed(s, front) ? null : $"The armistice with {PlayerText.Capitalised(front)} is not signed";return Prisoners.Fronts.Any(f => Signed(s, f)) ? null : "No armistice is signed";@@ -60,9 +57,10 @@ namespace Statecraft.Sim/// leaves the map and its strength joins the nearest city's civilians, employed count untouched, so the people count/// in the city's jobs and housing rules from the same turn. Refused, state untouched, with <see cref="Check"/>'s/// reason.</summary>- internal static string? Give(Content c, GameState s, int unitId, List<Cause> why)+ internal static string? Give(Content c, GameState s, int unitId,+ IReadOnlyDictionary<int, (int Q, int R)>? attacked, List<Cause> why){- var refused = Check(c, s, unitId);+ var refused = Check(c, s, unitId, attacked);if (refused != null) return refused;var u = s.Units[unitId];var city = Nearest(c, u.Q, u.R);diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.csindex dbcc429f9..c50b493eb 100644--- a/sim/Statecraft.Sim/EventSystem.cs+++ b/sim/Statecraft.Sim/EventSystem.cs@@ -149,8 +149,6 @@ 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-COMBAT-009: accepting a truce ends the player's standing attacks (owner ruling 2, 22 Oct 2026, #750).- if (Combat.PlayerTruces.Any(t => t.Event == eventId && t.Option == o.Id)) Combat.EndAttacksForTruce(s, 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);}diff --git a/sim/Statecraft.Sim/Reference/ReferencePlayer.cs b/sim/Statecraft.Sim/Reference/ReferencePlayer.csindex e5387fbb6..27b9a0838 100644--- a/sim/Statecraft.Sim/Reference/ReferencePlayer.cs+++ b/sim/Statecraft.Sim/Reference/ReferencePlayer.cs@@ -6,9 +6,9 @@ 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 (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+ /// has each of Israel's units, 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,+ /// for every attack it orders this turn (R-COMBAT-001, R-COMBAT-004), then,/// when no city project is being built, starts a housing project in the city with the most overflow that has a hex for it, then sends each idle halutz/// unit to the first available yishuv site (then to the first ready field, then to the first available camp site, then to the lowest free segment of the lowest-id corridor), then,/// when there is no halutz and none in training, trains one halutz group in@@ -46,8 +46,8 @@ namespace Statecraft.Sim.Referenceif (!c.IsGdd) return;var cost = AttentionSystem.Cost(c, s, Orders.Kind);var per = c.RulesAt(s.Date).Mvp!.ArmsPerAttack!.Value;- var attacking = s.Units.Values.Count(u => u.Side == Movement.PlayerSide && u.Order == Combat.Attack);- foreach (var u in s.Units.Values.Where(u => u.Side == Movement.PlayerSide && u.Order != Combat.Attack))+ var attacking = 0;+ foreach (var u in s.Units.Values.Where(u => u.Side == Movement.PlayerSide)){if (cost > left + 1e-9 || s.Arms < per * (attacking + 1)) return;foreach (var (dq, dr) in Movement.Neighbours)diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.csindex 9c9d3e1a7..c66cf264d 100644--- a/sim/Statecraft.Sim/Simulation.cs+++ b/sim/Statecraft.Sim/Simulation.cs@@ -45,7 +45,7 @@ namespace Statecraft.Simreturn new StepResult(s, why, rejected);}- RunOrders(c, s, commands, new Dictionary<int, int>(), why, rejected);+ RunOrders(c, s, commands, new Dictionary<int, int>(), new Dictionary<int, (int Q, int R)>(), why, rejected);EventSystem.Delegate(c, s, why);var len = SecuritySystem.TurnLengthFor(c, s.Date, s.Rung);@@ -91,7 +91,7 @@ namespace Statecraft.Simif (commands.Any(x => x == null)) throw new ArgumentException("Commands cannot contain null.", nameof(commands));CommandText.Validate(commands);var s = state.Clone();- if (s.GameOver == null) RunOrders(c, s, commands, new Dictionary<int, int>(), new List<Cause>(), new List<Rejection>());+ if (s.GameOver == null) RunOrders(c, s, commands, new Dictionary<int, int>(), new Dictionary<int, (int Q, int R)>(), new List<Cause>(), new List<Rejection>());return EventSystem.DelegatedTo(c, s, c.Events.First(e => e.Id == eventId));}@@ -106,10 +106,11 @@ namespace Statecraft.SimCommandText.Validate(commands);var s = state.Clone();var why = new List<Cause>(); var rejected = new List<Rejection>(); var spent = new Dictionary<int, int>();+ var attacked = new Dictionary<int, (int Q, int R)>();if (s.GameOver != null)foreach (var cmd in commands) rejected.Add(new Rejection(cmd, $"The game is over: {PlayerText.GameOver(s.GameOver)}"));- else RunOrders(c, s, commands, spent, why, rejected);- return new PreviewResult(s, spent, why, rejected);+ else RunOrders(c, s, commands, spent, attacked, why, rejected);+ return new PreviewResult(s, spent, attacked, why, rejected);}/// <summary>A move, a go-to, an attack, fortify or hold takes effect at once; Send home and every other order waits@@ -119,7 +120,7 @@ namespace Statecraft.Sim/// <summary>The turn's orders in order: each pays Attention first; one that fails validation is refunded and/// rejected with its reason. Step, DelegatedTo and Preview share it, so every dry run sees what End Turn will.</summary>static void RunOrders(Content c, GameState s, IReadOnlyList<Command> commands, Dictionary<int, int> spent,- List<Cause> why, List<Rejection> rejected)+ Dictionary<int, (int Q, int R)> attacked, List<Cause> why, List<Rejection> rejected){if (c.IsGdd) Movement.ContinueRoutes(c, s, spent, why); // R-MOVE-009: the route step, before the turn's ordersvar priceRung = s.Rung; // every command this turn is priced at the rung the turn started at@@ -132,7 +133,7 @@ namespace Statecraft.Sim// before charging, so the state and the Attention are unchanged.if (c.IsGdd && (cmd is SetMobilization || cmd is SecurityOrder)) { rejected.Add(new Rejection(cmd, "That order is not available in this game")); continue; }var before = s.Attention;- var error = AttentionSystem.TrySpend(c, s, cmd.Kind, priceRung) ?? Execute(c, s, cmd, spent, why);+ var error = AttentionSystem.TrySpend(c, s, cmd.Kind, priceRung) ?? Execute(c, s, cmd, spent, attacked, why);if (error != null) { s.Attention = before; rejected.Add(new Rejection(cmd, error)); }}}@@ -140,7 +141,8 @@ namespace Statecraft.Sim/// <summary>Returns null when the command was carried out (a lost vote counts: it consumes the RNG draw and is/// reported as a politics cause), or the reason it failed validation. A command that fails validation leaves/// the state as it found it (attention is refunded by the caller).</summary>- static string? Execute(Content c, GameState s, Command cmd, Dictionary<int, int> spent, List<Cause> why)+ static string? Execute(Content c, GameState s, Command cmd, Dictionary<int, int> spent,+ Dictionary<int, (int Q, int R)> attacked, List<Cause> why){switch (cmd){@@ -201,10 +203,10 @@ namespace Statecraft.Simreturn Projects.Stop(c, s, w.Unit, why);case UnitOrder o:if (o.Order == Movement.GoTo) return Movement.GiveGoTo(c, s, o.Unit, o.Q, o.R, spent, why);- if (o.Order == Combat.Attack) return Combat.Give(c, s, o.Unit, o.Q, o.R, why);+ if (o.Order == Combat.Attack) return Combat.Strike(c, s, o.Unit, o.Q, o.R, spent, attacked, why);if (o.Q != null || o.R != null) return "That order names no hex";return o.Order == Demobilization.SendHome- ? Demobilization.Give(c, s, o.Unit, why)+ ? Demobilization.Give(c, s, o.Unit, attacked, why): Orders.Give(c, s, o.Unit, o.Order, why);case StartProject p:return Projects.StartCity(c, s, p.ProjectKind, p.City, p.Q, p.R, why);