A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: combat, attack orders and resolver step 2 (GDD Phase 5 PR 8, R-COMBAT-001 to 006; refs #747) (#1194)
Beri5773ace497ab
diff --git a/changelog.d/sim-combat-747.md b/changelog.d/sim-combat-747.mdnew file mode 100644index 000000000..57694b50d--- /dev/null+++ b/changelog.d/sim-combat-747.md@@ -0,0 +1,10 @@+- GDD Phase 5 PR 8: combat (refs #747, #385). `UnitOrder(unit, attack, q, r)` gives one of Israel's units a standing attack+ on an adjacent hex holding an enemy unit, and resolver step 2 resolves the attacks of both sides in ascending attacker+ id (R-COMBAT-001 to R-COMBAT-006): joint attacks sum their strengths, the defender's fortify and biome multiply its+ strength, one RNG draw per engagement picks a face of the combat table's row for the ratio, losses fall on the+ strongest unit, a unit at 0 is destroyed, a defender the row sends back retreats one hex or surrenders when it has+ none, and the attacker does not advance. Each Israeli attacker spends 1 Arms. Combat changes only the units and the+ Arms, never a city, locality, resident or the score, and each engagement's Why line gives the people both sides lost+ in the same words. The table, the terrain percents and the Arms per attack are new labelled design values in+ `content/rules.yaml`, accepted by the owner on #747 (20 October 2026, all six defaults: https://github.com/eyalgolan/statecraft-israel/issues/747#issuecomment-6299184133). The reference player now attacks at 3:2 or better, so the 1950, 1952+ and mvp-end goldens move (re-pinned, docs/determinism.md): unit 0 fights the Syrian unit beside it from 15 May 1948.diff --git a/content/rules.yaml b/content/rules.yamlindex be402a2e3..23464fce6 100644--- a/content/rules.yaml+++ b/content/rules.yaml@@ -157,6 +157,44 @@ mvp:# cross. DRAFT, UNCHECKED: the owner accepted this list as a draft on 19 October 2026 (https://github.com/eyalgolan/statecraft-israel/pull/1073#issuecomment-6259083180).# No person has yet checked each place's control on 15 May 1948; research task #1096 will check it. Do not treat it as history.enemy_held_localities: [acre, nazareth, lod, ramla, gaza, beersheba]+ # Combat (R-COMBAT-001 to R-COMBAT-006; Q-COMBAT-1 to Q-COMBAT-4, owner, 15 October 2026, #375: "Take all+ # recommendations"). PROPOSED in Phase 5 PR 8 (#747) and accepted by the owner as design values on 20 October 2026+ # (all six defaults, asked at+ # https://github.com/eyalgolan/statecraft-israel/issues/747#issuecomment-6297295556, ruling at+ # https://github.com/eyalgolan/statecraft-israel/issues/747#issuecomment-6299184133). They stay labelled design values+ # for the balance pass (#813). None is a historical figure. Each engagement draws once from the RNG: a face 1 to 6, the six+ # entries of its row. A row applies from its min_ratio_percent (the attackers' summed strength over the defenders'+ # strength after fortify and terrain, in percent) up to the next row's: below 1:2, 1:2, 1:1, 2:1 and 3:1 and up.+ # Losses are population units; defender_retreats 1 sends the defenders that are left one hex back.+ arms_per_attack: 1 # DESIGN VALUE: owner-set balance, not a historical figure (D-G6, Q-COMBAT-4: Arms each Israeli unit spends on an attack)+ combat_terrain_percent:+ coastal_plain: 100 # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-2: a defender's strength on this biome, percent)+ valley: 100 # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-2: a defender's strength on this biome, percent)+ lowland: 100 # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-2: a defender's strength on this biome, percent)+ hills: 125 # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-2: a defender's strength on this biome, percent)+ desert: 100 # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-2: a defender's strength on this biome, percent)+ mountains: 150 # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-2: a defender's strength on this biome, percent)+ combat_table:+ - min_ratio_percent: 0 # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-1: the attack : defence ratio the row starts at, percent)+ attacker_loss: [2, 2, 1, 1, 1, 1] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: population units the attackers lose, per face)+ defender_loss: [0, 0, 0, 0, 0, 1] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: population units the defenders lose, per face)+ defender_retreats: [0, 0, 0, 0, 0, 0] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: 1 where the defenders retreat, per face)+ - min_ratio_percent: 50 # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-1: the attack : defence ratio the row starts at, percent)+ attacker_loss: [2, 1, 1, 1, 1, 0] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: population units the attackers lose, per face)+ defender_loss: [0, 0, 0, 1, 1, 1] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: population units the defenders lose, per face)+ defender_retreats: [0, 0, 0, 0, 0, 0] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: 1 where the defenders retreat, per face)+ - min_ratio_percent: 100 # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-1: the attack : defence ratio the row starts at, percent)+ attacker_loss: [1, 1, 1, 1, 0, 0] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: population units the attackers lose, per face)+ defender_loss: [0, 0, 1, 1, 1, 1] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: population units the defenders lose, per face)+ defender_retreats: [0, 0, 0, 0, 0, 1] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: 1 where the defenders retreat, per face)+ - min_ratio_percent: 200 # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-1: the attack : defence ratio the row starts at, percent)+ attacker_loss: [1, 1, 0, 0, 0, 0] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: population units the attackers lose, per face)+ defender_loss: [0, 1, 1, 1, 1, 2] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: population units the defenders lose, per face)+ defender_retreats: [0, 0, 0, 1, 1, 1] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: 1 where the defenders retreat, per face)+ - min_ratio_percent: 300 # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-1: the attack : defence ratio the row starts at, percent)+ attacker_loss: [1, 0, 0, 0, 0, 0] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: population units the attackers lose, per face)+ defender_loss: [1, 1, 1, 2, 2, 2] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: population units the defenders lose, per face)+ defender_retreats: [0, 1, 1, 1, 1, 1] # DESIGN VALUE: owner-set balance, not a historical figure (D-G3, Q-COMBAT-3: 1 where the defenders retreat, per face)# Coalition stability lost by replacing a minister (Cabinet.Appoint): a seat taken from the minister's party, or a# reshuffle within it.appoint_stability_cost_other_party: 0.06diff --git a/docs/RELEASING.md b/docs/RELEASING.mdindex 2c741f3df..78bf8472e 100644--- a/docs/RELEASING.md+++ b/docs/RELEASING.md@@ -27,8 +27,8 @@ macOS IL2CPP parity check is not an MVP release gate."$UNITY" -batchmode -CI false -GITHUB_ACTIONS false -TF_BUILD false -quit -projectPath unity -buildTarget WebGL -executeMethod Statecraft.Game.EditorTools.Build.Web -compression gzip -shareable -logFile "$PWD/unity-build-web-gz.log"git checkout -- unity/Assets/Settings unity/ProjectSettings/ProjectSettings.assetgolden_expect=(); while read -r name hash; do [[ -z "$name" || "$name" == \#* ]] || golden_expect+=(--expect "GOLDEN OK $name $hash"); done < sim/Statecraft.Sim.Tests/golden/manifest.txt- # one GOLDEN OK line per manifest golden (#394), e.g. "GOLDEN OK hash1950 259133fc83a95471547be0cb1a317bae55c8324778864733b88957d7529c8585"- # and "GOLDEN OK hash1952 452c65ece470e844f6898151c4d9328aa0b2e59df82db4763214d43a8e8ea7f1"+ # one GOLDEN OK line per manifest golden (#394), e.g. "GOLDEN OK hash1950 73eb50db39dbc9ee569c18a5e0a68e55a2b88980d06da76e5f5bfffe22997675"+ # and "GOLDEN OK hash1952 d9922fc9baaba3fcc5a6fbcd64de9317f787d7d3a8a0fb61f32a6b1b86462d91"uv run tools/web_check.py unity/Builds/Web-gzip --query "golden&smoke=5" "${golden_expect[@]}" \--expect "SMOKE OK 5 turns 1948-10-15 e5a66f9c2c0c0718d7969289fcc8dd005dedddd37a7c25adfffdc45e2e8b29cd"uv run tools/web_check.py unity/Builds/Web-gzip --startscreen new --timeout 300 --stall 90diff --git a/docs/determinism.md b/docs/determinism.mdindex b97ec21dc..eb0cc78f2 100644--- a/docs/determinism.md+++ b/docs/determinism.md@@ -33,9 +33,9 @@ final `GameState.Hash()` is pinned:| Run | Ends | Hash ||---|---|---|-| to 1950-01-01 (`Hash1950`) | 1950-01-15, turn 20 | `259133fc83a95471547be0cb1a317bae55c8324778864733b88957d7529c8585` |-| to 1952-01-01 (`Hash1952`) | 1952-01-15, turn 44 (the game's end) | `452c65ece470e844f6898151c4d9328aa0b2e59df82db4763214d43a8e8ea7f1` |-| to the game's end (`mvp-end`) | 1952-01-15, turn 44 | `452c65ece470e844f6898151c4d9328aa0b2e59df82db4763214d43a8e8ea7f1` |+| to 1950-01-01 (`Hash1950`) | 1950-01-15, turn 20 | `73eb50db39dbc9ee569c18a5e0a68e55a2b88980d06da76e5f5bfffe22997675` |+| to 1952-01-01 (`Hash1952`) | 1952-01-15, turn 44 (the game's end) | `d9922fc9baaba3fcc5a6fbcd64de9317f787d7d3a8a0fb61f32a6b1b86462d91` |+| to the game's end (`mvp-end`) | 1952-01-15, turn 44 | `d9922fc9baaba3fcc5a6fbcd64de9317f787d7d3a8a0fb61f32a6b1b86462d91` |`hash1952` stops at the first turn on or after 1 January 1952, which is the game's last turn, so it is the same run as`mvp-end` (`DeterminismTests.TheWholeGameToItsEndIsFixed`). Both names are kept (spec 2026-10-12 section 3 step 6): a@@ -330,3 +330,6 @@ The hash reads the state keys, so it never sees a record outside its window. An| GDD Phase 5 PR 4: the sourced starting forces enter the state | scenario-reckless | `8d644f6e` | same as cautious (was `d7dbcf75`) || GDD Phase 5 PR 4: the sourced starting forces enter the state | scenario-mvp-absorb-first | `7d37c0d0` | same as cautious; the longer #738 run now also carries the 12 forces (was `c045ea90`) || GDD Phase 5 PR 4: the sourced starting forces enter the state | scenario-mvp-defeat | `7bd5158f` | same as cautious; the defeat is unchanged (was `f3daaa70`) |+| GDD Phase 5 PR 8: combat (#747) | 1950 | `73eb50db` | The reference player's attack policy (attack a neighbouring enemy hex at 3:2 or better) sends unit 0 (strength 5, 10,9) against the Syrian unit 9 (3, the valley's 10,10) from 15 May 1948. Four engagements, one RNG draw each, 15 May to 15 August 1948: unit 0 ends at strength 3, unit 9 is destroyed and leaves `units[`, and the Arms stock falls from 12 to 8 (1 an attack). The RNG state moves from the seed for the first time in the run, since nothing else in it draws. Nothing else in the snapshot moves; the scenarios and smoke5 give no attack and are unchanged (was `259133fc`) |+| GDD Phase 5 PR 8: combat (#747) | 1952 | `d9922fc9` | same (was `452c65ec`) |+| GDD Phase 5 PR 8: combat (#747) | mvp-end | `d9922fc9` | same as 1952 (was `452c65ec`) |diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex 51892fd36..edf8fd93c 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -184,6 +184,22 @@ R-ORDER-002: Fortify takes one turn to set and costs no Arms or Money (Q-HOLD-1)R-ORDER-003: Hold acts on the unit's own hex only and does not intercept or stop any enemy move, past or next to it (Q-HOLD-2). It names no hex and stays when the unit moves. A holding unit defends at `mvp.hold_defence_percent` of its strength (real value 100: hold keeps the position and adds nothing); a unit with no order defends at 100.+## Combat++Phase 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 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 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; in step 2 an attack whose hex is empty or no longer next to the unit 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-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). The attackers' strengths are summed (Q-COMBAT-2); each defender's strength is multiplied by its order's defence percent (`Orders.DefencePercent`: fortify 125, R-ORDER-002) and by `mvp.combat_terrain_percent` for its hex's biome (real values: hills 125, mountains 150, every other land biome 100). The ratio is attack over defence in whole percent, rounded down, in integers only; the row of `mvp.combat_table` is the last whose `min_ratio_percent` it reaches (real rows: below 1:2, 1:2, 1:1, 2:1, 3:1). Each engagement draws exactly one RNG value, a face of the row (six in the real table), whatever its outcome; a step 2 with no engagement draws nothing (docs/determinism.md, "Combat draws"). `Combat.Preview(c, s, unit, q, r)` gives the ratio and row the UI shows (Q-UI-1; spec §2.6), counting the unit and the units of its side already attacking that hex.++R-COMBAT-003: The face gives the population units each side loses and whether the defenders retreat. Losses fall one unit at a time on the side's strongest unit in the engagement (a tie on the lower id); a unit at 0 is destroyed and leaves the state, and its id is never reused (`NextId` does not move). When the face says retreat, each defender left, in id order, moves one hex to the first neighbour in the fixed order (R-MOVE-002) that is land, holds no unit of the other side, has room for its side under `mvp.stack_limit`, and, for a player's unit, is not an enemy-held locality (R-MOVE-005). A defender with no such hex surrenders and leaves the state: the only way a unit is captured (impact plan §4.3 item 1; its prisoners are PR 12). The attackers never advance into the hex (Q-COMBAT-3).++R-COMBAT-004: Each of the player's units pays `mvp.arms_per_attack` (real value 1) from the Arms stock when it joins an engagement; one the stock cannot pay for has its attack called off, with a line naming the need and the stock. Enemy units pay nothing (Q-ENEMY-4: no supply).++R-COMBAT-005: Combat changes only combatant units and the Arms. No city, locality, resident, building, job or other resource, and no score, changes because of a combat outcome (Q-CIV-2; impact plan §4.3: kills and enemy losses never score). Halutzim are never attackers or targets.++R-COMBAT-006: Each engagement's Why line names the hex, the units on each side and the ratio, and states "the attackers lost N people and the defenders lost M people", the strength each side lost times `people_per_unit`, in the same words whichever side attacks (Q-CIV-4; impact plan §4.2). A destroyed unit gets "Unit N was destroyed", a retreat the hex it went to, a surrender the people it surrendered with. No running count of losses is kept; the war's Israeli total is PR 13's.+## ObjectivesR-OBJ-001: An objective (`objectives.yaml`) names its condition, `completes_when: { site_built: <site> }` (R-OBJ-004's `absorbed` has no site, so the site rules here apply only to `site_built`), a designated site of kind yishuv whose `founded` date must equal the objective's `reference_date`. In the last step of each GDD turn (spec §2.3, step 11; D-A6), in id order, an objective whose site is built and that is not yet recorded is recorded once, with the turn's end date (the site's `BuiltOn`). Recording it again, or in the legacy loop, changes nothing; a stopped build completes nothing.diff --git a/sim/Statecraft.Sim.Tests/CombatDrawCountTests.cs b/sim/Statecraft.Sim.Tests/CombatDrawCountTests.csnew file mode 100644index 000000000..f07c4927a--- /dev/null+++ b/sim/Statecraft.Sim.Tests/CombatDrawCountTests.cs@@ -0,0 +1,54 @@+using System.Collections.Generic;+using Statecraft.Sim;++/// <summary>R-COMBAT-002 (docs/determinism.md, "Combat draws"): each engagement draws exactly Combat.DrawsPerEngagement+/// values from the one RNG, whatever its outcome, and a step 2 with no engagement draws none. Joint attackers on one hex are+/// one engagement.</summary>+public class CombatDrawCountTests+{+ static Content Load() => 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: enemy, kind: unit, side: egypt, class: infantry, movement_points: 3 }\n",+ ["map/hexes.json"] = MovementTests.Board(), ["corridors.yaml"] = "corridors: []\n"+ })));++ static Unit Soldier(int id, int q, int r, int strength, string target) =>+ new Unit(id, "soldier", q, r, side: "israel", strength: strength, order: Combat.Attack, orderTarget: target);+ static Unit Enemy(int id, int q, int r, int strength) => new Unit(id, "enemy", q, r, side: "egypt", strength: strength);++ static ulong After(ulong state, int draws)+ {+ var rng = new Rng(state);+ for (int i = 0; i < draws; i++) rng.NextULong();+ return rng.State;+ }++ [Fact]+ public void EachEngagementDrawsExactlyN()+ {+ var c = Load();+ // Three engagements: a joint attack of units 1 and 3 on (2, 0); unit 5 on (4, 0), which destroys both sides; unit 7+ // on (5, 1), which sends its defender back. Every outcome draws the same.+ var s = CombatTests.With(c, Soldier(1, 3, 0, 4, "2,0"), Enemy(2, 2, 0, 3), Soldier(3, 2, 1, 1, "2,0"),+ Soldier(5, 4, 1, 1, "4,0"), Enemy(6, 4, 0, 1), Soldier(7, 5, 2, 9, "5,1"), Enemy(8, 5, 1, 2));+ var before = s.RngState;+ Combat.Resolve(c, s, new List<Cause>());+ Assert.Equal(1, Combat.DrawsPerEngagement);+ Assert.Equal(After(before, 3 * Combat.DrawsPerEngagement), s.RngState);+ }++ [Fact]+ public 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;+ var before = s.RngState;+ Combat.Resolve(c, s, new List<Cause>());+ Assert.Equal(before, s.RngState);+ Assert.Equal(("", ""), (s.Units[1].Order, s.Units[3].Order));+ }+}diff --git a/sim/Statecraft.Sim.Tests/CombatTests.cs b/sim/Statecraft.Sim.Tests/CombatTests.csnew file mode 100644index 000000000..a9bd70857--- /dev/null+++ b/sim/Statecraft.Sim.Tests/CombatTests.cs@@ -0,0 +1,401 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>Combat (GDD Phase 5 PR 8, #747): UnitOrder(unit, attack, q, r) and resolver step 2. Q-COMBAT-1 to Q-COMBAT-4 are+/// the plan's recommendations, taken by the owner on 15 October 2026 ("Take all recommendations", #375); Q-CIV-2 is his+/// "Enemy units only, no effect" and Q-CIV-4 his "2+3". The numbers were accepted by the owner on #747 (20 October 2026). The fixture's numbers are+/// fixture values: 10 people a population unit, 2 Arms an attack, hills 150, fortify 150, and a two-face table whose faces+/// agree, so a test does not depend on the draw: below 2:1 both sides lose 1, from 2:1 the defenders lose 1 and retreat.</summary>+public class CombatTests+{+ const string Types = Fixture.GddUnitTypes+ + " - { id: soldier, kind: unit, side: israel, class: infantry, movement_points: 3 }\n"+ + " - { id: enemy, kind: unit, side: egypt, class: infantry, movement_points: 3 }\n"+ + " - { id: ally, kind: unit, side: jordan, class: infantry, movement_points: 3 }\n";++ /// <summary>MovementTests' 6 x 3 coastal plain, with <paramref name="biomes"/> replacing hexes; town_a is on (1, 0).</summary>+ static Content Load(params (int Q, int R, string Biome)[] biomes) => ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>+ {+ ["unit_types.yaml"] = Types, ["map/hexes.json"] = MovementTests.Board(biomes), ["corridors.yaml"] = "corridors: []\n"+ })));++ internal static GameState With(Content c, params Unit[] units)+ {+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ foreach (var u in units) s.Units.Add(u.Id, u);+ s.NextId = units.Length == 0 ? s.NextId : Math.Max(s.NextId, units.Max(u => u.Id) + 1);+ return s;+ }++ /// <summary>The real content, loaded once for the tests that play it.</summary>+ static readonly Content Real = ContentLoader.Load(RealContentTests.ContentRoot());++ static Unit Soldier(int id, int q, int r, int strength) => new Unit(id, "soldier", q, r, side: "israel", strength: strength);+ static Unit Enemy(int id, int q, int r, int strength) => new Unit(id, "enemy", q, r, side: "egypt", strength: strength);+ static Unit Attacking(Unit u, int q, int r) =>+ new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, Combat.Attack, FormattableString.Invariant($"{q},{r}"));++ static StepResult Step(Content c, GameState s, params Command[] cmds) => Simulation.Step(c, s, cmds);++ static List<Cause> Resolve(Content c, GameState s)+ {+ var why = new List<Cause>();+ Combat.Resolve(c, s, why);+ return why;+ }++ // R-COMBAT-001: an attack names an adjacent hex that holds an enemy unit, and the player's unit must have the Arms for+ // it. Every refusal leaves the state as it was.+ [Theory]+ [InlineData(9, 2, 0, "There is no such unit")]+ [InlineData(2, 2, 0, "That unit is not yours")]+ [InlineData(3, 2, 0, "Only a military unit takes that order")]+ [InlineData(1, 5, 0, "That hex is not next to the unit")]+ [InlineData(1, 3, 1, "There is no enemy unit on that hex")] // the halutz is no enemy+ public void AnAttackIsRefusedWithAReason(int unit, int q, int r, string reason)+ {+ var c = Load();+ var s = With(c, Soldier(1, 3, 0, 5), Enemy(2, 2, 0, 3), new Unit(3, "halutz", 3, 1));+ var refused = Step(c, s, new UnitOrder(unit, Combat.Attack, q, r));+ Assert.Equal(reason, Assert.Single(refused.Rejected).Reason);+ Assert.Equal(Step(c, s).State.Hash(), refused.State.Hash());+ }++ [Fact]+ public void AnAttackNeedsAHexAndTheArms()+ {+ var c = Load();+ var s = With(c, Soldier(1, 3, 0, 5), Enemy(2, 2, 0, 3));+ Assert.Equal("An attack names a hex", Assert.Single(Step(c, s, new UnitOrder(1, Combat.Attack)).Rejected).Reason);+ Assert.Equal("That order names no hex", Assert.Single(Step(c, s, new UnitOrder(1, Orders.Hold, 2, 0)).Rejected).Reason);+ s.Arms = 1; // the fixture's attack takes 2+ Assert.Equal("An attack needs 2 Arms and the stock has 1", Assert.Single(Step(c, s, new UnitOrder(1, Combat.Attack, 2, 0)).Rejected).Reason);+ s.Arms = 2;+ var given = Step(c, s, new UnitOrder(1, Combat.Attack, 2, 0)).State; // resolved the same turn+ Assert.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);+ }++ // 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).+ [Fact]+ public void ASecondAttackTheStockCannotPayForIsRefused()+ {+ var c = Load();+ var s = With(c, Soldier(1, 3, 0, 5), Soldier(3, 1, 1, 5), Enemy(2, 2, 0, 3));+ s.Arms = 2; // the fixture's attack takes 2+ var 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("", r.State.Units[3].Order);+ Assert.Equal(0, r.State.Arms);+ }++ // A unit that replaces its own attack is not counted twice: the stock for one attack still lets it switch hex.+ [Fact]+ public void ReplacingAnAttackDoesNotCountItTwice()+ {+ var c = Load();+ var s = With(c, Attacking(Soldier(1, 3, 0, 5), 2, 0), Enemy(2, 2, 0, 3), Enemy(4, 4, 0, 3));+ s.Arms = 2;+ var r = Step(c, s, new UnitOrder(1, Combat.Attack, 4, 0));+ Assert.Empty(r.Rejected);+ Assert.Equal(0, r.State.Arms);+ Assert.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.+ // Below 2:1 the fixture's row has both sides lose 1.+ [Fact]+ public void AnAttackResolvesInStepTwoAndSpendsArms()+ {+ var c = Load();+ var s = With(c, Soldier(1, 3, 0, 5), Enemy(2, 2, 0, 3));+ var r = Step(c, s, new UnitOrder(1, Combat.Attack, 2, 0));+ Assert.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));+ }++ // R-COMBAT-002: several units attack one hex together, their strengths summed, as one engagement: 2 + 2 against 2 is 2:1.+ [Fact]+ public void JointAttacksAddTheirStrengths()+ {+ 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(s.Arms - 4, r.State.Arms);+ }++ // R-COMBAT-002: the defender's biome and fortify multiply its strength. 9 against 2 fortified (150) on hills (150) is+ // 9 / 4.5, 200 percent; on the plain, unfortified, 450.+ [Fact]+ public void TerrainAndFortifyModifyTheRatio()+ {+ var c = Load((2, 0, "hills"));+ var s = With(c, Soldier(1, 3, 0, 9), Enemy(2, 2, 0, 2));+ Assert.Equal(300, Combat.Preview(c, s, 1, 2, 0)!.Value.RatioPercent);+ s.Units[2] = new Unit(2, "enemy", 2, 0, side: "egypt", strength: 2, order: Orders.Fortify, orderTarget: "2,0");+ Assert.Equal(200, Combat.Preview(c, s, 1, 2, 0)!.Value.RatioPercent);+ Assert.Equal(1, Combat.Preview(c, s, 1, 2, 0)!.Value.Row);+ s.Units[1] = new Unit(1, "soldier", 3, 0, side: "israel", strength: 8);+ Assert.Equal(0, Combat.Preview(c, s, 1, 2, 0)!.Value.Row); // 177 percent+ var plain = Load();+ Assert.Equal(450, Combat.Preview(plain, With(plain, Soldier(1, 3, 0, 9), Enemy(2, 2, 0, 2)), 1, 2, 0)!.Value.RatioPercent);+ Assert.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.+ [Fact]+ public void AttackersResolveInAscendingId()+ {+ var c = Load();+ var units = new[] { Attacking(Soldier(1, 3, 0, 5), 2, 0), Enemy(2, 2, 0, 3), Attacking(Soldier(3, 4, 1, 5), 4, 0), Enemy(4, 4, 0, 3) };+ var a = With(c, units);+ var b = With(c, units.Reverse().ToArray());+ a.Arms = b.Arms = 2;+ var 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");+ }++ // R-COMBAT-003: a defender the row sends back retreats to the first free neighbour in the fixed order: (3, 0) holds the+ // attacker, so (1, 0)... is town_a's hex, free to an enemy unit (R-MOVE-005 binds the player's units only).+ [Fact]+ public void ALosingDefenderRetreatsOneHex()+ {+ var c = Load();+ var s = With(c, Attacking(Soldier(1, 3, 0, 6), 2, 0), Enemy(2, 2, 0, 3));+ var why = Resolve(c, s);+ var e = s.Units[2];+ Assert.Equal((2, 1, 0), (e.Strength, e.Q, e.R));+ Assert.Contains(why, x => x.Message == "Unit 2 retreated to hex 1,0");+ Assert.Equal((3, 0), (s.Units[1].Q, s.Units[1].R)); // the attacker does not advance+ // The attack ends: no enemy unit is on the hex now.+ Assert.Equal(("", ""), (s.Units[1].Order, s.Units[1].OrderTarget));+ }++ // R-COMBAT-003: a defender that must retreat and has no free hex surrenders and leaves the state. (0, 0) is a corner:+ // its two land neighbours hold the attackers.+ [Fact]+ public void ADefenderWithNoHexToRetreatToSurrenders()+ {+ var c = Load();+ var s = With(c, Attacking(Soldier(1, 1, 0, 4), 0, 0), Attacking(Soldier(3, 0, 1, 4), 0, 0), Enemy(2, 0, 0, 3));+ var next = s.NextId;+ var why = Resolve(c, s);+ Assert.False(s.Units.ContainsKey(2));+ Assert.Contains(why, x => x.Message == "Unit 2 surrendered with 20 people: it had no hex to retreat to");+ Assert.Equal(next, s.NextId);+ }++ // Review focus 4: a unit at 0 is removed, and its id is never reused.+ [Fact]+ public void ADestroyedUnitLeavesTheState()+ {+ var c = Load();+ var s = With(c, Attacking(Soldier(1, 3, 0, 1), 2, 0), Enemy(2, 2, 0, 1));+ var next = s.NextId;+ var why = Resolve(c, s);+ Assert.False(s.Units.ContainsKey(1));+ Assert.False(s.Units.ContainsKey(2));+ Assert.Contains(why, x => x.Message == "Unit 1 was destroyed");+ Assert.Contains(why, x => x.Message == "Unit 2 was destroyed");+ Assert.Equal(next, s.NextId);+ }++ // R-COMBAT-003: losses fall one population unit at a time on the strongest unit of the side, a tie on the lower id.+ [Fact]+ public void LossesFallOnTheStrongestUnit()+ {+ var c = Load();+ var s = With(c, Attacking(Soldier(1, 3, 0, 2), 2, 0), Attacking(Soldier(3, 1, 1, 2), 2, 0), Enemy(2, 2, 0, 5), Enemy(4, 2, 0, 5));+ Resolve(c, s); // 4 against 10: both sides lose 1+ Assert.Equal((1, 2, 4, 5), (s.Units[1].Strength, s.Units[3].Strength, s.Units[2].Strength, s.Units[4].Strength));+ }++ // R-COMBAT-006 (Q-CIV-4, "2+3"): the engagement's Why line gives the people each side lost, in the same words for both.+ [Fact]+ public void TheWhyLineGivesPeopleLostOnBothSides()+ {+ var c = Load();+ var s = With(c, Attacking(Soldier(1, 3, 0, 5), 2, 0), Enemy(2, 2, 0, 3));+ var line = Assert.Single(Resolve(c, s), x => x.Message.StartsWith("The attack on hex", StringComparison.Ordinal));+ Assert.Equal("The attack on hex 2,0 (unit 1 against unit 2, strength ratio 166%): the attackers lost 10 people and the defenders lost 10 people", line.Message);+ }++ // R-COMBAT-002: enemy units attack under the same rule (their orders come from PR 10's AI), and pay no Arms (Q-ENEMY-4:+ // no supply). Units of two Arab sides fight together as one side.+ [Fact]+ public void EnemyAttacksResolveTooAndPayNoArms()+ {+ var c = Load();+ var s = With(c, Soldier(1, 2, 0, 3), Attacking(Enemy(2, 3, 0, 5), 2, 0), Attacking(new Unit(4, "ally", 2, 1, side: "jordan", strength: 1), 2, 0));+ var arms = s.Arms;+ Resolve(c, s);+ Assert.Equal((2, 5, 1), (s.Units[1].Strength, s.Units[2].Strength, s.Units[4].Strength)); // 6 against 3, 2:1: the defender loses 1+ Assert.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+ var e = r.State.Units[2];+ Assert.Equal((3, 1, 0), (e.Strength, e.Q, e.R)); // 8 against 4, 2:1: lost 1 and retreated+ Assert.Equal(s.Arms - 4, 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]+ public void ALocalityHexIsAttackedOnlyThroughItsUnits()+ {+ var c = Load();+ var s = With(c, Attacking(Soldier(1, 2, 0, 9), 1, 0), Enemy(2, 1, 0, 2));+ var before = s.Clone();+ var why = Resolve(c, s);+ Assert.Contains(why, x => x.Message.StartsWith("The attack on hex 1,0", StringComparison.Ordinal));+ Assert.Equal(before.Cities["town_a"].Canonical(), s.Cities["town_a"].Canonical());+ AssertOnlyCombatantsChanged(before, s);+ }++ /// <summary>R-COMBAT-005: <paramref name="after"/> differs from <paramref name="before"/> only in its units, its Arms and the+ /// RNG: with those three copied back, the hashes match.</summary>+ internal static void AssertOnlyCombatantsChanged(GameState before, GameState after)+ {+ var copy = before.Clone();+ copy.Units.Clear();+ foreach (var u in after.Units.Values) copy.Units.Add(u.Id, u);+ copy.Arms = after.Arms;+ copy.RngState = after.RngState;+ Assert.Equal(after.Describe(), copy.Describe());+ }++ // R-COMBAT-005 (§4.3 item 2): no combat outcome changes the score: a destroyed and a surrendered enemy unit score nothing.+ [Fact]+ public void KillsNeverScore()+ {+ var c = Load();+ var s = With(c, Attacking(Soldier(1, 1, 0, 9), 0, 0), Attacking(Soldier(3, 0, 1, 9), 0, 0), Enemy(2, 0, 0, 2));+ s.Score = 7;+ Resolve(c, s);+ Assert.False(s.Units.ContainsKey(2));+ Assert.Equal(7, s.Score);+ }++ // R-COMBAT-005: over the reference war run (the goldens' run to the game's end), step 2 run on each turn's end state, with+ // its standing attacks, changes only the units, the Arms and the RNG. The run has engagements, so the test is not empty.+ [Fact]+ public void CombatTouchesOnlyCombatants()+ {+ var c = Real;+ var s = Simulation.NewGame(c, GoldenRun.Seed, Mode.Historical);+ int engagements = 0;+ for (int turn = 0; turn < 1000 && s.Date < c.End && s.GameOver == null; turn++)+ {+ s = Simulation.Step(c, s, GoldenRun.Orders(c, s)).State;+ var after = s.Clone();+ engagements += Resolve(c, after).Count(x => x.Message.StartsWith("The attack on hex", StringComparison.Ordinal));+ AssertOnlyCombatantsChanged(s, after);+ }+ Assert.True(engagements > 0, "the reference run has no engagement");+ }++ // R-COMBAT-002, R-COMBAT-003: every cell of the real table, on the real map: an attacker and a defender on two+ // neighbouring hexes whose biome counts 100, strengths that land in the row, and the RNG seeded to the face.+ public static IEnumerable<object[]> Cells()+ {+ var table = Real.Rules.Mvp!.CombatTable;+ for (int row = 0; row < table.Count; row++)+ for (int face = 0; face < table[row].AttackerLoss.Count; face++)+ yield return new object[] { row, face };+ }++ [Theory]+ [MemberData(nameof(Cells))]+ public void TheTableIsApplied(int row, int face)+ {+ var c = Real;+ var mvp = c.Rules.Mvp!;+ var cell = mvp.CombatTable[row];+ var faces = cell.AttackerLoss.Count;+ var plain = new HashSet<(int, int)>(c.Hexes.Where(h => h.Land && mvp.CombatTerrainPercent[h.Biome] == 100).Select(h => (h.Q, h.R)));+ var (q, r) = plain.OrderBy(h => h).First(h => plain.Contains((h.Item1 + 1, h.Item2)) && c.SettlementHexes.All(x => (x.Q, x.R) != h));+ // Strengths of 5 or more, above any loss in the table, so no unit is emptied: the ratio is the row's own min, or a+ // third for the first row.+ var (att, def) = cell.MinRatioPercent == 0 ? (10, 30) : (cell.MinRatioPercent / 10, 10);+ var s = With(c);+ s.Units.Clear();+ s.Units.Add(1, Attacking(new Unit(1, "veteran_soldier", q + 1, r, side: "israel", strength: att), q, r));+ s.Units.Add(2, new Unit(2, "egyptian_army", q, r, side: "egypt", strength: def));+ Assert.Equal(row, Combat.Preview(c, s, 1, q, r)!.Value.Row);+ ulong seed = 0;+ while ((int)(new Rng(seed).NextDouble() * faces) != face) seed++;+ s.RngState = seed;+ Resolve(c, s);+ Assert.Equal(att - cell.AttackerLoss[face], s.Units[1].Strength);+ var e = s.Units[2];+ Assert.Equal(def - cell.DefenderLoss[face], e.Strength);+ Assert.Equal(cell.DefenderRetreats[face] == 1, (e.Q, e.R) != (q, r));+ }++ // R-COMBAT-002, R-COMBAT-003: the loader refuses a combat value that is missing or out of range.+ [Theory]+ [InlineData("mvp.arms_per_attack", "arms_per_attack: 2", "arms_per_attack: -1", "must be >= 0")]+ [InlineData("mvp.combat_terrain_percent", "{ coastal_plain: 100, hills: 150, desert: 100 }", "{ coastal_plain: 100, desert: 100 }", "no percent for land biome 'hills'")]+ [InlineData("mvp.combat_terrain_percent.hills", "{ coastal_plain: 100, hills: 150, desert: 100 }", "{ coastal_plain: 100, hills: 0, desert: 100 }", "must be >= 1")]+ [InlineData("mvp.combat_table[0].min_ratio_percent", "- { min_ratio_percent: 0,", "- { min_ratio_percent: 10,", "the first row must start at 0")]+ [InlineData("mvp.combat_table[1].min_ratio_percent", "- { min_ratio_percent: 200,", "- { min_ratio_percent: 0,", "must be above the row before")]+ [InlineData("mvp.combat_table[1]", "attacker_loss: [0, 0]", "attacker_loss: [0]", "one entry per face")]+ [InlineData("mvp.combat_table[1]", "defender_loss: [1, 1], defender_retreats: [1, 1]", "defender_loss: [-1, 1], defender_retreats: [1, 1]", "a loss must be >= 0")]+ [InlineData("mvp.combat_table[1].defender_retreats", "defender_retreats: [1, 1]", "defender_retreats: [2, 1]", "must be 0 or 1")]+ public void TheLoaderRefusesABadCombatValue(string field, string from, string to, string message)+ {+ var files = Fixture.Gdd(new Dictionary<string, string> { ["unit_types.yaml"] = Types });+ Assert.Contains(from, files["rules.yaml"]);+ files["rules.yaml"] = files["rules.yaml"].Replace(from, to);+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(files)));+ Assert.Equal(("rules.yaml", field), (ex.File, ex.Field));+ Assert.Contains(message, ex.Message);+ }++ // A save and a scenario carry the attack's hex; fortify and hold carry none.+ [Fact]+ public void AnAttackOrderRoundTripsThroughASave()+ {+ var c = Load();+ var g = GameSession.New(c, 1, Mode.Historical);+ g.Step(new Command[] { new UnitOrder(1, Combat.Attack, 2, 0) }); // refused (unit 1 does not exist), and recorded+ g.Step(new Command[] { new UnitOrder(1, Orders.Hold) });+ var text = g.Save.Write();+ Assert.Contains("order 1 attack 2 0\n", text);+ Assert.Contains("order 1 hold\n", text);+ var back = GameSession.Load(c, text, out _).Save.Turns;+ var attack = (UnitOrder)back[0][0];+ Assert.Equal((1, Combat.Attack, (int?)2, (int?)0), (attack.Unit, attack.Order, attack.Q, attack.R));+ var hold = (UnitOrder)back[1][0];+ Assert.Equal(((int?)null, (int?)null), (hold.Q, hold.R));+ }+}diff --git a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs b/sim/Statecraft.Sim.Tests/DesignValuesTests.csindex 572c385a8..c2cc1831b 100644--- a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs+++ b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs@@ -15,7 +15,7 @@ public class DesignValuesTests/// <summary>Every design value: file, then the path of its key (a list item by its id). Adding one here and in content is/// a balance change for the owner to set or accept in review.</summary>- public static readonly (string File, string Key)[] Listed =+ public static readonly (string File, string Key)[] Listed = new (string File, string Key)[]{("rules.yaml", "attention_cost.assign_workers"),("rules.yaml", "attention_cost.train"),@@ -143,6 +143,15 @@ public class DesignValuesTests("rules.yaml", "mvp.move_cost.desert"),("rules.yaml", "mvp.move_cost.mountains"),("rules.yaml", "mvp.stack_limit"),+ // Combat (Phase 5 PR 8, #747; Q-COMBAT-1 to Q-COMBAT-4): agent-proposed, accepted by the owner as design values on 20 October 2026 (#747, https://github.com/eyalgolan/statecraft-israel/issues/747#issuecomment-6299184133). The table's cells are+ // listed by CombatTableCells below.+ ("rules.yaml", "mvp.arms_per_attack"),+ ("rules.yaml", "mvp.combat_terrain_percent.coastal_plain"),+ ("rules.yaml", "mvp.combat_terrain_percent.valley"),+ ("rules.yaml", "mvp.combat_terrain_percent.lowland"),+ ("rules.yaml", "mvp.combat_terrain_percent.hills"),+ ("rules.yaml", "mvp.combat_terrain_percent.desert"),+ ("rules.yaml", "mvp.combat_terrain_percent.mountains"),("rules.yaml", "mvp.road_move_cost"), // R-MOVE-007, #745 (Q-MOVE-2): agent-proposed("rules.yaml", "mvp.rail_move_cost"),("unit_types.yaml", "types[veteran_soldier].movement_points"),@@ -158,7 +167,19 @@ public class DesignValuesTests("rules.yaml", "mvp.arms_start"),("rules.yaml", "mvp.arms_price"),("rules.yaml", "mvp.arms_per_recruit_group"),- };+ }.Concat(CombatTableCells()).ToArray();++ /// <summary>rules.yaml mvp.combat_table, every cell: its five rows (below 1:2, 1:2, 1:1, 2:1, 3:1) with their start ratio+ /// and, for each of the draw's six faces, the two losses and the retreat (R-COMBAT-002, R-COMBAT-003; #747).</summary>+ static IEnumerable<(string File, string Key)> CombatTableCells()+ {+ for (int row = 0; row < 5; row++)+ {+ yield return ("rules.yaml", $"mvp.combat_table[{row}].min_ratio_percent");+ foreach (var list in new[] { "attacker_loss", "defender_loss", "defender_retreats" })+ for (int face = 0; face < 6; face++) yield return ("rules.yaml", $"mvp.combat_table[{row}].{list}[{face}]");+ }+ }/// <summary>Every number in the GDD files and blocks, as (file, key path, the line it is on). Scope: all of cities.yaml,@@ -249,6 +270,7 @@ public class DesignValuesTestsAssert.Equal((0.35, 0.15), (m.HousingStartCondition, m.OverflowConditionLoss)); // Q-START-3, Q-HOUSE-1 (D-D1)Assert.Equal((5, 0.5), (m.DelegationLoyaltyFloor, m.DisloyalEffectShare)); // R-EVT-003, #107 (D-H1)Assert.Equal((12, 1.0, 1, 1.0), (m.ArmsStart, m.ArmsPrice, m.ArmsPerRecruitGroup, c.Rules.AttentionCost["buy_arms"])); // #781 (D-G6)+ Assert.Equal((1, 5, 6), (m.ArmsPerAttack, m.CombatTable.Count, m.CombatTable[0].AttackerLoss.Count)); // #747 (D-G6, D-G3), accepted by the owner 20 Oct 2026Assert.Equal(12, c.Cities.Count);foreach (var x in c.Cities) // the listed housing and job values are the ones Cities.Init starts fromAssert.Equal(((int)x.Housing!.Value, (int)x.Jobs!.Value), (x.HousingCapacity, x.JobSlots));diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.csindex bdbc14ad6..ee044226b 100644--- a/sim/Statecraft.Sim.Tests/Fixture.cs+++ b/sim/Statecraft.Sim.Tests/Fixture.cs@@ -293,6 +293,11 @@ mvp:road_move_cost: 1rail_move_cost: 2enemy_held_localities: []+ arms_per_attack: 2+ combat_terrain_percent: { coastal_plain: 100, hills: 150, desert: 100 }+ combat_table:+ - { min_ratio_percent: 0, attacker_loss: [1, 1], defender_loss: [1, 1], defender_retreats: [0, 0] }+ - { min_ratio_percent: 200, attacker_loss: [0, 0], defender_loss: [1, 1], defender_retreats: [1, 1] }";public static readonly string GddCities = "\ncities:\n" + City("town_a", 12, 8, 10, 6, "[military_camp, hakhshara]");diff --git a/sim/Statecraft.Sim.Tests/MovementTests.cs b/sim/Statecraft.Sim.Tests/MovementTests.csindex f7dc1f921..91c2de4d3 100644--- a/sim/Statecraft.Sim.Tests/MovementTests.cs+++ b/sim/Statecraft.Sim.Tests/MovementTests.cs@@ -22,7 +22,7 @@ public class MovementTests/// <summary>A 6 x 3 board of coastal plain, q 0 to 5 and r 0 to 2, with <paramref name="biomes"/> replacing hexes (a/// "sea" or "lake" one is water). town_a stays on (1, 0) and site_a on (2, 0), as the fixture's other files need.</summary>- static string Board(params (int Q, int R, string Biome)[] biomes)+ internal static string Board(params (int Q, int R, string Biome)[] biomes){var rows = new List<string>();for (int r = 0; r < 3; r++)diff --git a/sim/Statecraft.Sim.Tests/OrdersTests.cs b/sim/Statecraft.Sim.Tests/OrdersTests.csindex 2b92c92bc..0ddf95935 100644--- a/sim/Statecraft.Sim.Tests/OrdersTests.cs+++ b/sim/Statecraft.Sim.Tests/OrdersTests.cs@@ -108,7 +108,7 @@ public class OrdersTests// R-ORDER-001: refusals leave the state as it was.[Theory][InlineData(9, "fortify", "There is no such unit")]- [InlineData(1, "attack", "That order is not known")]+ [InlineData(1, "advance", "That order is not known")] // attack is known since #747 (CombatTests)[InlineData(5, "hold", "Only a military unit takes that order")][InlineData(3, "hold", "That unit is not yours")][InlineData(2, "hold", "That unit already has that order")]diff --git a/sim/Statecraft.Sim.Tests/ReferencePlayerTests.cs b/sim/Statecraft.Sim.Tests/ReferencePlayerTests.csindex bd4db322e..711b27641 100644--- a/sim/Statecraft.Sim.Tests/ReferencePlayerTests.cs+++ b/sim/Statecraft.Sim.Tests/ReferencePlayerTests.cs@@ -32,8 +32,12 @@ public class ReferencePlayerTestsvar orders = ReferencePlayer.Commands(Mvp, s);var history = HistoricalAI.Commands(Mvp, s);Assert.Equal(history.Select(x => x.Kind), orders.Take(history.Count).Select(x => x.Kind));- Assert.Equal(history.Count + 1, orders.Count);+ Assert.Equal(history.Count + 2, orders.Count);Assert.DoesNotContain(orders, x => x is AssignWorkers);+ // The attack policy (#747): unit 0 (strength 5, on 10,9) meets the Syrian unit next to it (3, on the valley's 10,10)+ // at 166 percent, past the policy's 150.+ var attack = Assert.IsType<UnitOrder>(orders[history.Count]);+ Assert.Equal((0, Combat.Attack, (int?)10, (int?)10), (attack.Unit, attack.Order, attack.Q, attack.R));var train = Assert.IsType<Train>(orders.Last());Assert.Equal(("tel_aviv", "halutz", 1), (train.City, train.Track, train.Count)); // 152 civilians without workvar r = Simulation.Step(Mvp, s, orders);@@ -201,7 +205,9 @@ public class ReferencePlayerTestsAssert.DoesNotContain(ReferencePlayer.Commands(Mvp, full), x => x is AssignWorkers);var tired = s.Clone();tired.Attention = 0;- Assert.Empty(ReferencePlayer.Commands(Mvp, tired));+ Assert.All(ReferencePlayer.Commands(Mvp, tired), x => Assert.Equal(Combat.Attack, Assert.IsType<UnitOrder>(x).Order)); // unit orders are free (D-A6)+ tired.Arms = 0;+ Assert.Empty(ReferencePlayer.Commands(Mvp, tired)); // and the attack needs the Arms}/// <summary>With more jobs than civilians, the default (not the player) fills no more jobs than there are civilians.</summary>diff --git a/sim/Statecraft.Sim.Tests/golden/hash1950.txt b/sim/Statecraft.Sim.Tests/golden/hash1950.txtindex 951e82572..42941ac42 100644--- a/sim/Statecraft.Sim.Tests/golden/hash1950.txt+++ b/sim/Statecraft.Sim.Tests/golden/hash1950.txt@@ -1,4 +1,4 @@-1950-01-15;1948;Historical;20;+1950-01-15;8709371129873692656;Historical;20;ind{food_supply=0.8886718750000001 [3FEC700000000001]housing=0.106156810303452 [3FBB2D17BC8041AE]@@ -114,7 +114,7 @@ city{tiberias=6,2,8,2,1,c0.18928571428571433 [3FC83A83A83A83AA]zikhron_yaakov=2,1,2,1,1,c0.35 [3FD6666666666666]units[- 0:veteran_soldier@10,9|side=israel|strength=5+ 0:veteran_soldier@10,9|side=israel|strength=31:veteran_soldier@5,8|side=israel|strength=22:veteran_soldier@0,15|side=israel|strength=53:veteran_soldier@-3,19|side=israel|strength=1@@ -123,7 +123,6 @@ units[6:veteran_soldier@-9,27|side=israel|strength=27:egyptian_army@-11,27|side=egypt|strength=108:arab_legion@0,22|side=jordan|strength=5- 9:syrian_army@10,10|side=syria|strength=310:iraqi_army@9,11|side=iraq|strength=311:arab_liberation_army@12,4|side=ala|strength=413:veteran_halutz@-3,19/6@@ -136,4 +135,4 @@ cproj[15:housing@tel_aviv,-3,19/4,3FDB851EB851EB88next=16food=3003,1001,0-arms=12\ No newline at end of file+arms=8\ No newline at end of filediff --git a/sim/Statecraft.Sim.Tests/golden/hash1952.txt b/sim/Statecraft.Sim.Tests/golden/hash1952.txtindex b941a3912..d2b7210e9 100644--- a/sim/Statecraft.Sim.Tests/golden/hash1952.txt+++ b/sim/Statecraft.Sim.Tests/golden/hash1952.txt@@ -1,4 +1,4 @@-1952-01-15;1948;Historical;44;+1952-01-15;8709371129873692656;Historical;44;ind{food_supply=0.8555635490815091 [3FEB60C6CEDE8D7F]housing=0.08527449992708651 [3FB5D48CB45E9D83]@@ -135,7 +135,7 @@ city{tiberias=6,2,13,2,0,c0 [0000000000000000]zikhron_yaakov=2,1,4,1,0,c0 [0000000000000000]units[- 0:veteran_soldier@10,9|side=israel|strength=5+ 0:veteran_soldier@10,9|side=israel|strength=31:veteran_soldier@5,8|side=israel|strength=22:veteran_soldier@0,15|side=israel|strength=53:veteran_soldier@-3,19|side=israel|strength=1@@ -144,7 +144,6 @@ units[6:veteran_soldier@-9,27|side=israel|strength=27:egyptian_army@-11,27|side=egypt|strength=108:arab_legion@0,22|side=jordan|strength=5- 9:syrian_army@10,10|side=syria|strength=310:iraqi_army@9,11|side=iraq|strength=311:arab_liberation_army@12,4|side=ala|strength=413:veteran_halutz@-3,19/6@@ -168,4 +167,4 @@ obj{first_new_yishuv=1951-02-15score=100food=2734,1390,0-arms=12\ No newline at end of file+arms=8\ No newline at end of filediff --git a/sim/Statecraft.Sim.Tests/golden/manifest.txt b/sim/Statecraft.Sim.Tests/golden/manifest.txtindex 11caf130b..82a74ecd1 100644--- a/sim/Statecraft.Sim.Tests/golden/manifest.txt+++ b/sim/Statecraft.Sim.Tests/golden/manifest.txt@@ -2,11 +2,11 @@# Tests read this file. To accept a deliberate change: STATECRAFT_UPDATE_GOLDEN=1 dotnet test sim/Statecraft.sln# rewrites this file, the snapshots and the GoldenRun.cs constants; then update docs/determinism.md and tools/web_check.py# (GoldenManifestTests names any place that is out of date) and add a row to the rebaseline history.-hash1950 259133fc83a95471547be0cb1a317bae55c8324778864733b88957d7529c8585-hash1952 452c65ece470e844f6898151c4d9328aa0b2e59df82db4763214d43a8e8ea7f1+hash1950 73eb50db39dbc9ee569c18a5e0a68e55a2b88980d06da76e5f5bfffe22997675+hash1952 d9922fc9baaba3fcc5a6fbcd64de9317f787d7d3a8a0fb61f32a6b1b86462d91smoke5 e5a66f9c2c0c0718d7969289fcc8dd005dedddd37a7c25adfffdc45e2e8b29cdscenario-reckless 8d644f6eea2abe2d1fccafec82191994769c6c2feb480a3ca3bc045d6089c6a5scenario-cautious b4e5caa1fec69c7b8883226e01d40283aed0999e405f162d2f197f8943c64267scenario-mvp-absorb-first 7d37c0d0a4740bd3c74191feb138de24351bebca4682c27d6597373b8478091b-mvp-end 452c65ece470e844f6898151c4d9328aa0b2e59df82db4763214d43a8e8ea7f1+mvp-end d9922fc9baaba3fcc5a6fbcd64de9317f787d7d3a8a0fb61f32a6b1b86462d91scenario-mvp-defeat 7bd5158f52e0743533c930a583aed9e2cc146220016aa0532fdefef21f2e9905diff --git a/sim/Statecraft.Sim.Tests/golden/mvp-end.txt b/sim/Statecraft.Sim.Tests/golden/mvp-end.txtindex b941a3912..d2b7210e9 100644--- a/sim/Statecraft.Sim.Tests/golden/mvp-end.txt+++ b/sim/Statecraft.Sim.Tests/golden/mvp-end.txt@@ -1,4 +1,4 @@-1952-01-15;1948;Historical;44;+1952-01-15;8709371129873692656;Historical;44;ind{food_supply=0.8555635490815091 [3FEB60C6CEDE8D7F]housing=0.08527449992708651 [3FB5D48CB45E9D83]@@ -135,7 +135,7 @@ city{tiberias=6,2,13,2,0,c0 [0000000000000000]zikhron_yaakov=2,1,4,1,0,c0 [0000000000000000]units[- 0:veteran_soldier@10,9|side=israel|strength=5+ 0:veteran_soldier@10,9|side=israel|strength=31:veteran_soldier@5,8|side=israel|strength=22:veteran_soldier@0,15|side=israel|strength=53:veteran_soldier@-3,19|side=israel|strength=1@@ -144,7 +144,6 @@ units[6:veteran_soldier@-9,27|side=israel|strength=27:egyptian_army@-11,27|side=egypt|strength=108:arab_legion@0,22|side=jordan|strength=5- 9:syrian_army@10,10|side=syria|strength=310:iraqi_army@9,11|side=iraq|strength=311:arab_liberation_army@12,4|side=ala|strength=413:veteran_halutz@-3,19/6@@ -168,4 +167,4 @@ obj{first_new_yishuv=1951-02-15score=100food=2734,1390,0-arms=12\ No newline at end of file+arms=8\ No newline at end of filediff --git a/sim/Statecraft.Sim/Combat.cs b/sim/Statecraft.Sim/Combat.csnew file mode 100644index 000000000..19ce0772e--- /dev/null+++ b/sim/Statecraft.Sim/Combat.cs@@ -0,0 +1,231 @@+using System;+using System.Collections.Generic;+using System.Globalization;+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+ /// (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+ {+ public const string Attack = "attack";++ /// <summary>RNG values each engagement draws, whatever its outcome (docs/determinism.md, "Combat draws").</summary>+ public const int DrawsPerEngagement = 1;++ /// <summary>The player's team: Israel's units and the halutzim (no side). Every other side is the enemy, and the Arab+ /// sides fight on one team (Movement's reading of "the enemy").</summary>+ static bool Player(Unit u) => u.Side == "" || u.Side == Movement.PlayerSide;++ /// <summary>Only military units fight (R-UNIT-001): a halutz is never a target or an attacker.</summary>+ static bool Military(Unit u) => u.Side != "";++ static string Hex(int q, int r) => string.Format(CultureInfo.InvariantCulture, "{0},{1}", q, r);++ static bool Adjacent(Unit u, int q, int r) => Movement.Neighbours.Any(d => u.Q + d.Q == q && u.R + d.R == r);++ /// <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: 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, for an unknown unit, a halutz, an enemy unit, no hex, the attack+ /// it already has, a hex not next to it or with no enemy unit, or fewer Arms than one attack takes on top of the+ /// player's other attacks already ordered (Q-COMBAT-4). It costs no Attention (D-A6) and resolves in this turn's step 2.</summary>+ internal static string? Give(Content c, GameState s, int unitId, int? q, int? r, List<Cause> why)+ {+ 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";+ if (!Player(u)) return "That unit is not yours";+ if (q == null || r == null) return "An attack names a hex";+ var target = Hex(q.Value, r.Value);+ if (u.Order == Attack && u.OrderTarget == target) return "That unit already has that order";+ if (!Adjacent(u, q.Value, r.Value)) return "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";+ var need = c.RulesAt(s.Date).Mvp!.ArmsPerAttack!.Value;+ // 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 ordered = s.Units.Values.Count(x => x.Id != unitId && x.Order == Attack && Military(x) && Player(x));+ if (s.Arms < need * (ordered + 1)) return Short(need, s.Arms, ordered * need);+ s.Units[unitId] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, Attack, target);+ why.Add(new Cause("map", unitId.ToString(CultureInfo.InvariantCulture), 0, $"Unit {unitId} will attack hex {target}"));+ return 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>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, against the enemy units there after fortify and terrain, and the combat_table row it falls in. Null when (q, r)+ /// is not next to the unit or holds no enemy unit, or the unit is unknown or no military unit.</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) || !Adjacent(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) && Adjacent(x, q, r))).ToList();+ var mvp = c.RulesAt(s.Date).Mvp!;+ var ratio = Ratio(c, mvp, attackers, defenders, q, r);+ return (ratio, Row(mvp, ratio));+ }++ /// <summary>R-COMBAT-002: the attackers' summed strength over the defenders' summed strength, each defender's strength+ /// times its order's defence percent (Orders.DefencePercent) and its hex's biome percent, in whole percent rounded down.+ /// Integer arithmetic only, so it is the same on every runtime.</summary>+ static int Ratio(Content c, MvpRules mvp, List<Unit> attackers, List<Unit> defenders, int q, int r)+ {+ long attack = attackers.Sum(x => (long)x.Strength);+ var terrain = mvp.CombatTerrainPercent[c.HexAt(q, r)!.Biome]; // a unit stands on land, and the loader requires every land biome+ long defence = defenders.Sum(x => (long)x.Strength * Orders.DefencePercent(mvp, x) * terrain); // in 1/10,000 of a strength unit+ return defence == 0 ? int.MaxValue : (int)Math.Min(int.MaxValue, attack * 1_000_000 / defence); // 0: no real unit has no strength+ }++ /// <summary>The last combat_table row whose min_ratio_percent the ratio reaches (the first row starts at 0).</summary>+ static int Row(MvpRules mvp, int ratio)+ {+ var row = 0;+ for (int i = 1; i < mvp.CombatTable.Count; i++) if (ratio >= mvp.CombatTable[i].MinRatioPercent) row = i;+ return row;+ }++ /// <summary>Resolver step 2 (R-COMBAT-002 to R-COMBAT-006): 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, or whose hex holds no enemy unit, ends its attack; a player's unit pays mvp.arms_per_attack 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). 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)+ {+ var mvp = c.RulesAt(s.Date).Mvp!;+ var done = new HashSet<int>();+ foreach (var id in s.Units.Keys.ToList()) // Units is a SortedList: ascending id+ {+ if (done.Contains(id) || !s.Units.TryGetValue(id, out var lead) || lead.Order != Attack) continue;+ var (q, r) = Target(lead);+ var group = s.Units.Values.Where(x => !done.Contains(x.Id) && x.Order == Attack && x.OrderTarget == lead.OrderTarget && Player(x) == Player(lead)).ToList();+ var defenders = Defenders(s, lead, q, r);+ var attackers = new List<Unit>();+ foreach (var x in group)+ {+ done.Add(x.Id);+ if (defenders.Count == 0 || !Adjacent(x, q, r)) { End(s, x, $"Unit {x.Id}'s attack on hex {x.OrderTarget} ends: no enemy unit is there", why); continue; }+ if (Player(x))+ {+ var need = mvp.ArmsPerAttack!.Value;+ if (s.Arms < need)+ {+ End(s, x, $"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);+ continue;+ }+ s.Arms -= need;+ }+ attackers.Add(x);+ }+ if (attackers.Count > 0) Engage(c, s, mvp, attackers, defenders, q, r, why);+ }+ foreach (var u in s.Units.Values.ToList())+ if (u.Order == Attack)+ {+ var (q, r) = Target(u);+ if (Defenders(s, u, q, r).Count == 0 || !Adjacent(u, q, r))+ End(s, u, $"Unit {u.Id}'s attack on hex {u.OrderTarget} ends: no enemy unit is there", why);+ }+ }++ static (int Q, int R) Target(Unit u)+ {+ var parts = u.OrderTarget.Split(',');+ return (int.Parse(parts[0], CultureInfo.InvariantCulture), int.Parse(parts[1], CultureInfo.InvariantCulture));+ }++ static void End(GameState s, Unit u, string line, List<Cause> why)+ {+ s.Units[u.Id] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, "", "");+ why.Add(new Cause("map", u.Id.ToString(CultureInfo.InvariantCulture), 0, line));+ }++ /// <summary>R-COMBAT-002, R-COMBAT-003, R-COMBAT-006: one engagement. The face is the one draw; its row's losses fall on+ /// each side one population unit at a time on its strongest unit (a tie on the lower id), a unit at 0 leaves the state,+ /// and when the row says so each defender left retreats one hex, in id order, or surrenders when it has nowhere to go.+ /// The attackers stay where they are (no advance, Q-COMBAT-3).</summary>+ static void Engage(Content c, GameState s, MvpRules mvp, List<Unit> attackers, List<Unit> defenders, int q, int r, List<Cause> why)+ {+ var ratio = Ratio(c, mvp, attackers, defenders, q, r);+ var row = mvp.CombatTable[Row(mvp, ratio)];+ var rng = new Rng(s.RngState);+ var face = (int)(rng.NextDouble() * row.AttackerLoss.Count); // DrawsPerEngagement+ s.RngState = rng.State;+ var target = Hex(q, r);+ var ppu = mvp.PeoplePerUnit;+ var removed = new List<int>();+ var attackersLost = Take(s, attackers.Select(x => x.Id).ToList(), row.AttackerLoss[face], removed);+ var defendersLost = Take(s, defenders.Select(x => x.Id).ToList(), row.DefenderLoss[face], removed);+ why.Add(new Cause("map", target, 0, FormattableString.Invariant(+ $"The attack on hex {target} ({Ids(attackers)} against {Ids(defenders)}, strength ratio {ratio}%): the attackers lost {attackersLost * ppu:N0} people and the defenders lost {defendersLost * ppu:N0} people")));+ foreach (var id in removed)+ why.Add(new Cause("map", id.ToString(CultureInfo.InvariantCulture), 0, $"Unit {id} was destroyed"));+ if (row.DefenderRetreats[face] != 1) return;+ foreach (var d in defenders)+ {+ if (!s.Units.TryGetValue(d.Id, out var u)) continue;+ if (Retreat(c, s, mvp, u) is (int, int) to)+ {+ s.Units[u.Id] = new Unit(u.Id, u.Type, to.Item1, to.Item2, u.Service, u.Side, u.Strength, u.Order, u.OrderTarget);+ why.Add(new Cause("map", u.Id.ToString(CultureInfo.InvariantCulture), 0, $"Unit {u.Id} retreated to hex {Hex(to.Item1, to.Item2)}"));+ }+ else+ {+ // The only way a unit is captured (impact plan section 4.3 item 1); the prisoners themselves are Phase 5 PR 12.+ s.Units.Remove(u.Id);+ why.Add(new Cause("map", u.Id.ToString(CultureInfo.InvariantCulture), 0,+ FormattableString.Invariant($"Unit {u.Id} surrendered with {u.Strength * ppu:N0} people: it had no hex to retreat to")));+ }+ }+ }++ static string Ids(List<Unit> units) => (units.Count == 1 ? "unit " : "units ") + string.Join(", ", units.Select(x => x.Id.ToString(CultureInfo.InvariantCulture)));++ /// <summary>Takes up to <paramref name="loss"/> population units from <paramref name="ids"/>, one at a time from the+ /// strongest unit left (a tie on the lower id; the list is in id order), removing each that reaches 0 (its id is never+ /// reused: NextId is not touched) and adding it to <paramref name="removed"/>. Returns the units taken.</summary>+ static int Take(GameState s, List<int> ids, int loss, List<int> removed)+ {+ int taken = 0;+ for (; taken < loss; taken++)+ {+ Unit? top = null;+ foreach (var id in ids)+ if (s.Units.TryGetValue(id, out var x) && (top == null || x.Strength > top.Strength)) top = x;+ if (top == null) break;+ if (top.Strength <= 1) { s.Units.Remove(top.Id); removed.Add(top.Id); }+ else s.Units[top.Id] = new Unit(top.Id, top.Type, top.Q, top.R, top.Service, top.Side, top.Strength - 1, top.Order, top.OrderTarget);+ }+ return taken;+ }++ /// <summary>R-COMBAT-003: the first neighbour of the unit's hex, in the fixed order (R-MOVE-002), that is land, holds no+ /// unit of the other team, has room under mvp.stack_limit for the unit's side (R-MOVE-003) and, for the player's unit,+ /// is not an enemy-held locality (R-MOVE-005); null when there is none.</summary>+ static (int, int)? Retreat(Content c, GameState s, MvpRules mvp, Unit u)+ {+ var noEntry = Player(u) ? Movement.NoEntry(c, s) : new HashSet<(int Q, int R)>();+ foreach (var (dq, dr) in Movement.Neighbours)+ {+ int q = u.Q + dq, r = u.R + dr;+ if (!(c.HexAt(q, r) is MapHex hex) || !hex.Land || noEntry.Contains((q, r))) continue;+ var here = s.Units.Values.Where(x => x.Q == q && x.R == r).ToList();+ if (here.Any(x => Player(x) != Player(u)) || here.Count(x => x.Side == u.Side) >= mvp.StackLimit!.Value) continue;+ return (q, r);+ }+ return null;+ }+ }+}diff --git a/sim/Statecraft.Sim/Commands.cs b/sim/Statecraft.Sim/Commands.csindex 602112caf..f43698b8b 100644--- a/sim/Statecraft.Sim/Commands.cs+++ b/sim/Statecraft.Sim/Commands.cs@@ -103,13 +103,16 @@ namespace Statecraft.Simpublic StopWork(int unit) { Unit = unit; }}- /// <summary>Gives unit <see cref="Unit"/> the standing order <see cref="Order"/>, fortify or hold (Orders.Give, R-ORDER-001- /// to R-ORDER-003). GDD v0.1 loop only.</summary>+ /// <summary>Gives unit <see cref="Unit"/> the standing order <see cref="Order"/>: fortify or hold (Orders.Give, R-ORDER-001+ /// to R-ORDER-003), or attack, which names the hex (<see cref="Q"/>, <see cref="R"/>) (Combat.Give, R-COMBAT-001). GDD v0.1+ /// loop only.</summary>public sealed class UnitOrder : Command{public override string Kind => Orders.Kind;public int Unit { get; } public string Order { get; }- public UnitOrder(int unit, string order) { Unit = unit; Order = order; }+ /// <summary>The hex an attack names; null for fortify and hold.</summary>+ public int? Q { get; } public int? R { get; }+ public UnitOrder(int unit, string order, int? q = null, int? r = null) { Unit = unit; Order = order; Q = q; R = r; }}/// <summary>Starts city project <see cref="ProjectKind"/> (a projects.yaml id) for <see cref="City"/> on hex (<see cref="Q"/>,diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex 0780790f3..1b40802c9 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -615,11 +615,32 @@ namespace Statecraft.Sim/// <summary>The settlements (settlements_1948.yaml ids) whose hexes no player unit may enter or cross before Phase 6/// (R-MOVE-005; Q-CIV-1). The owner sets the list.</summary>public List<string> EnemyHeldLocalities { get; set; } = new List<string>();+ /// <summary>The Arms each of the player's units spends on an attack, paid when it resolves (R-COMBAT-004; D-G6,+ /// Q-COMBAT-4). Required in the GDD loop, >= 0.</summary>+ public int? ArmsPerAttack { get; set; }+ /// <summary>A defender's strength in percent for its hex's land biome (R-COMBAT-002; D-G3, Q-COMBAT-2: the defender's+ /// biome modifies the ratio). The loader requires one for every land biome in the GDD loop, each >= 1.</summary>+ public Dictionary<string, int> CombatTerrainPercent { get; set; } = new Dictionary<string, int>();+ /// <summary>The combat table (R-COMBAT-002, R-COMBAT-003; D-G3, Q-COMBAT-1): its rows in ascending+ /// <see cref="CombatRow.MinRatioPercent"/>, the first at 0. Required in the GDD loop.</summary>+ public List<CombatRow> CombatTable { get; set; } = new List<CombatRow>();/// <summary>The share of each numeric effect a delegated option applies when its minister is below the loyalty floor/// (R-EVT-003; #107). Required in the GDD loop, 0 to 1.</summary>public double? DisloyalEffectShare { get; set; }}+ /// <summary>One row of rules.yaml mvp.combat_table (R-COMBAT-002, R-COMBAT-003): it applies from an attack : defence+ /// ratio of <see cref="MinRatioPercent"/> percent up to the next row's. Each list has one entry per face of the+ /// engagement's one draw, all the same length: the population units the attackers and the defenders lose, and 1 where+ /// the defenders that are left retreat.</summary>+ public sealed class CombatRow+ {+ public int MinRatioPercent { get; set; }+ public List<int> AttackerLoss { get; set; } = new List<int>();+ public List<int> DefenderLoss { get; set; } = new List<int>();+ public List<int> DefenderRetreats { get; set; } = new List<int>();+ }+/// <summary>A kind of city project (projects.yaml; GDD "Cities and construction"; R-PROJ-001 to R-PROJ-003): permanent/// housing, the transit camp (D-D3, Q-HOUSE-3) or industry. Every number is a design value (Q-PROJ-1).</summary>public sealed class ProjectKinddiff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex d96190f14..d9627515f 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -1214,6 +1214,27 @@ namespace Statecraft.Sim// R-MOVE-003 (Q-MOVE-3): required, so a missing key is never read as no room at all.if (m.StackLimit == null) throw new ContentException(file, "mvp.stack_limit", "required when eras.yaml systems.loop is gdd");if (m.StackLimit < 1) throw new ContentException(file, "mvp.stack_limit", "must be >= 1");+ // R-COMBAT-002 to R-COMBAT-004 (Q-COMBAT-1 to Q-COMBAT-4): required, so a missing key is never read as a free+ // attack, a defender with no strength or an engagement with no outcome.+ if (m.ArmsPerAttack == null) throw new ContentException(file, "mvp.arms_per_attack", "required when eras.yaml systems.loop is gdd");+ if (m.ArmsPerAttack < 0) throw new ContentException(file, "mvp.arms_per_attack", "must be >= 0");+ foreach (var b in c.Hexes.Where(h => h.Land).Select(h => h.Biome).Distinct().OrderBy(b => b, StringComparer.Ordinal))+ if (!m.CombatTerrainPercent.ContainsKey(b)) throw new ContentException(file, "mvp.combat_terrain_percent", $"no percent for land biome '{b}' ({HexesFile})");+ foreach (var kv in m.CombatTerrainPercent)+ if (kv.Value < 1) throw new ContentException(file, "mvp.combat_terrain_percent." + kv.Key, "must be >= 1");+ if (m.CombatTable.Count == 0) throw new ContentException(file, "mvp.combat_table", "required when eras.yaml systems.loop is gdd");+ var faces = m.CombatTable[0].AttackerLoss.Count;+ for (int i = 0; i < m.CombatTable.Count; i++)+ {+ var row = m.CombatTable[i];+ var at = FormattableString.Invariant($"mvp.combat_table[{i}]");+ if (i == 0 ? row.MinRatioPercent != 0 : row.MinRatioPercent <= m.CombatTable[i - 1].MinRatioPercent)+ throw new ContentException(file, at + ".min_ratio_percent", i == 0 ? "the first row must start at 0" : "must be above the row before");+ if (faces < 1 || row.AttackerLoss.Count != faces || row.DefenderLoss.Count != faces || row.DefenderRetreats.Count != faces)+ throw new ContentException(file, at, "attacker_loss, defender_loss and defender_retreats need one entry per face, the same number in every row");+ if (row.AttackerLoss.Concat(row.DefenderLoss).Any(x => x < 0)) throw new ContentException(file, at, "a loss must be >= 0");+ if (row.DefenderRetreats.Any(x => x != 0 && x != 1)) throw new ContentException(file, at + ".defender_retreats", "must be 0 or 1");+ }// R-MOVE-007 (Q-MOVE-2): required, so a missing key is never read as a free step along a corridor.foreach (var (key, v) in new[] { ("road_move_cost", m.RoadMoveCost), ("rail_move_cost", m.RailMoveCost) }){diff --git a/sim/Statecraft.Sim/GoldenRun.cs b/sim/Statecraft.Sim/GoldenRun.csindex 310f285b9..257d34995 100644--- a/sim/Statecraft.Sim/GoldenRun.cs+++ b/sim/Statecraft.Sim/GoldenRun.cs@@ -16,13 +16,13 @@ namespace Statecraft.Sim/// <summary>Final hash of Play(content, Until1950). Changing it is a deliberate rules or content change: the value/// is pinned in sim/Statecraft.Sim.Tests/golden/manifest.txt, and STATECRAFT_UPDATE_GOLDEN=1 dotnet test rewrites/// both (docs/determinism.md). Say why in the commit message.</summary>- public const string Hash1950 = "259133fc83a95471547be0cb1a317bae55c8324778864733b88957d7529c8585";+ public const string Hash1950 = "73eb50db39dbc9ee569c18a5e0a68e55a2b88980d06da76e5f5bfffe22997675";public static readonly DateTime Until1950 = new DateTime(1950, 1, 1);/// <summary>Final hash of Play(content, Until1952): the M3 content range (to 31 December 1951). The GDD game ends on/// 15 January 1952 (R-LOOP-004), the first turn on or after Until1952, so this is also the mvp-end run.</summary>- public const string Hash1952 = "452c65ece470e844f6898151c4d9328aa0b2e59df82db4763214d43a8e8ea7f1";+ public const string Hash1952 = "d9922fc9baaba3fcc5a6fbcd64de9317f787d7d3a8a0fb61f32a6b1b86462d91";public static readonly DateTime Until1952 = new DateTime(1952, 1, 1);diff --git a/sim/Statecraft.Sim/Movement.cs b/sim/Statecraft.Sim/Movement.csindex 8464cbeec..1733adb67 100644--- a/sim/Statecraft.Sim/Movement.cs+++ b/sim/Statecraft.Sim/Movement.cs@@ -18,7 +18,7 @@ namespace Statecraft.Sim/// <summary>The six axial directions in tools/hexgrid.py's NEIGHBOURS order, the fixed order of hexes.json's layout/// (R-MOVE-002).</summary>- static readonly (int Q, int R)[] Neighbours = { (1, 0), (1, -1), (0, -1), (-1, 0), (-1, 1), (0, 1) };+ internal static readonly (int Q, int R)[] Neighbours = { (1, 0), (1, -1), (0, -1), (-1, 0), (-1, 1), (0, 1) };static bool IsEnemy(Unit u) => u.Side != "" && u.Side != PlayerSide;@@ -91,7 +91,7 @@ namespace Statecraft.Sim}/// <summary>R-MOVE-005: the hexes of mvp.enemy_held_localities.</summary>- static HashSet<(int Q, int R)> NoEntry(Content c, GameState s)+ internal static HashSet<(int Q, int R)> NoEntry(Content c, GameState s){var ids = c.RulesAt(s.Date).Mvp!.EnemyHeldLocalities;return new HashSet<(int Q, int R)>(c.SettlementHexes.Where(h => ids.Contains(h.Id)).Select(h => (h.Q, h.R)));diff --git a/sim/Statecraft.Sim/Reference/ReferencePlayer.cs b/sim/Statecraft.Sim/Reference/ReferencePlayer.csindex 0b1fbb93b..36a871d72 100644--- a/sim/Statecraft.Sim/Reference/ReferencePlayer.cs+++ b/sim/Statecraft.Sim/Reference/ReferencePlayer.cs@@ -5,7 +5,10 @@ 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 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,/// 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@@ -13,10 +16,14 @@ namespace Statecraft.Sim.Reference/// (ReferencePlayerTests.NoGameModeOrUiReachesIt).</summary>public static class ReferencePlayer{+ /// <summary>The attack policy's threshold: 3:2 (#747; test code, not a design value).</summary>+ public const int AttackRatioPercent = 150;+public static IReadOnlyList<Command> Commands(Content c, GameState s){var list = new List<Command>(HistoricalAI.Commands(c, s));var left = s.Attention - list.Sum(x => AttentionSystem.Cost(c, s, x.Kind));+ Attack(c, s, list, ref left);House(c, s, list, ref left);var halutz = c.UnitTypes.FirstOrDefault(t => t.Id == "halutz");if (halutz == null) return list;@@ -33,6 +40,28 @@ namespace Statecraft.Sim.Referencereturn list;}+ /// <summary>The attack policy in the class comment. Unit orders are free (D-A6), but the cost is still checked.</summary>+ static void Attack(Content c, GameState s, List<Command> list, ref double left)+ {+ if (!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))+ {+ if (cost > left + 1e-9 || s.Arms < per * (attacking + 1)) return;+ foreach (var (dq, dr) in Movement.Neighbours)+ {+ var preview = Combat.Preview(c, s, u.Id, u.Q + dq, u.R + dr);+ if (preview == null || preview.Value.RatioPercent < AttackRatioPercent) continue;+ list.Add(new UnitOrder(u.Id, Combat.Attack, u.Q + dq, u.R + dr));+ left -= cost;+ attacking++;+ break;+ }+ }+ }+/// <summary>Starts a housing project (R-PROJ-001) when none is being built, in the city with the most overflow (Cities.Overflow; the first/// in ordinal id order on a tie) that has a hex left for it, on the first hex in (q, r) order that Projects.CheckCity accepts, when the turn's/// Attention lasts. It borrows, as the other orders do.</summary>diff --git a/sim/Statecraft.Sim/SaveGame.cs b/sim/Statecraft.Sim/SaveGame.csindex 3ec323007..d16442080 100644--- a/sim/Statecraft.Sim/SaveGame.cs+++ b/sim/Statecraft.Sim/SaveGame.cs@@ -123,7 +123,7 @@ namespace Statecraft.SimCancelTraining t => $"untrain {Int(t.Cohort)}",PioneerWork p => $"pioneer {Int(p.Unit)} {Esc(p.Action)} {Esc(p.Site)}",StopWork w => $"stop {Int(w.Unit)}",- UnitOrder o => $"order {Int(o.Unit)} {Esc(o.Order)}",+ UnitOrder o => $"order {Int(o.Unit)} {Esc(o.Order)}" + (o.Q is int q && o.R is int r ? $" {Int(q)} {Int(r)}" : ""),StartProject p => $"project {Esc(p.ProjectKind)} {Esc(p.City)} {Int(p.Q)} {Int(p.R)}",CancelProject p => $"unproject {Int(p.Project)}",Move m => $"move {Int(m.Unit)} {Int(m.Q)} {Int(m.R)}",@@ -221,7 +221,9 @@ namespace Statecraft.Simcase "untrain": Arity(2); return new CancelTraining(I(f[1]));case "pioneer": Arity(4); return new PioneerWork(I(f[1]), Str(f[2]), Str(f[3]));case "stop": Arity(2); return new StopWork(I(f[1]));- case "order": Arity(3); return new UnitOrder(I(f[1]), Str(f[2]));+ case "order": // an attack carries its hex (R-COMBAT-001); fortify and hold none+ if (f.Length != 5) Arity(3);+ return f.Length == 5 ? new UnitOrder(I(f[1]), Str(f[2]), I(f[3]), I(f[4])) : new UnitOrder(I(f[1]), Str(f[2]));case "project": Arity(5); return new StartProject(Str(f[1]), Str(f[2]), I(f[3]), I(f[4]));case "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]));diff --git a/sim/Statecraft.Sim/Scenario.cs b/sim/Statecraft.Sim/Scenario.csindex 2404f884b..bcf00fbae 100644--- a/sim/Statecraft.Sim/Scenario.cs+++ b/sim/Statecraft.Sim/Scenario.cs@@ -22,7 +22,7 @@ namespace Statecraft.Sim/// Kinds: set_policy (policy, level), allocate_budget (shares: {office: share}), choose_event_option (event, option),/// set_mobilization (level), security_order (delta), appoint (office, person), map_action (action, q, r), assign_workers/// (city, role, count), train (city, track, count), cancel_training (cohort), pioneer_work (unit, action, site), stop_work- /// (unit), move (unit, q, r; GDD content only), unit_order (unit, order; GDD content only). A turn with no+ /// (unit), move (unit, q, r; GDD content only), unit_order (unit, order, and q, r for an attack; GDD content only). A turn with no/// scripted command passes; events nobody answered are delegated, as in the game. A command the sim rejects fails the run.</summary>public sealed class Scenario{@@ -65,7 +65,7 @@ namespace Statecraft.Sim["map_action"] = new[] { "action", "q", "r" }, ["assign_workers"] = new[] { "city", "role", "count" },["train"] = new[] { "city", "track", "count" }, ["cancel_training"] = new[] { "cohort" },["pioneer_work"] = new[] { "unit", "action", "site" }, ["stop_work"] = new[] { "unit" },- ["unit_order"] = new[] { "unit", "order" },+ ["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" },@@ -98,7 +98,7 @@ namespace Statecraft.Simcase "cancel_training": return new CancelTraining(Whole(c, "cohort"));case "pioneer_work": return new PioneerWork(Whole(c, "unit"), Str(c, "action"), Str(c, "site"));case "stop_work": return new StopWork(Whole(c, "unit"));- case "unit_order": return new UnitOrder(Whole(c, "unit"), Str(c, "order"));+ case "unit_order": return new UnitOrder(Whole(c, "unit"), Str(c, "order"), c.ContainsKey("q") ? Whole(c, "q") : (int?)null, c.ContainsKey("r") ? Whole(c, "r") : (int?)null);case "start_project": return new StartProject(Str(c, "project"), Str(c, "city"), Whole(c, "q"), Whole(c, "r"));case "cancel_project": return new CancelProject(Whole(c, "project"));case "move": return new Move(Whole(c, "unit"), Whole(c, "q"), Whole(c, "r"));@@ -142,7 +142,7 @@ namespace Statecraft.SimSecurityOrder o => o.Delta.ToString(CultureInfo.InvariantCulture), Appoint a => $"{a.Office} {a.Person}", MapAction m => $"{m.Action} {m.Q},{m.R}",AssignWorkers w => $"{w.City} {w.Role} {w.Count}", Train t => $"{t.City} {t.Track} {t.Count}", CancelTraining t => t.Cohort.ToString(CultureInfo.InvariantCulture),PioneerWork p => FormattableString.Invariant($"{p.Unit} {p.Action} {p.Site}"), StopWork w => w.Unit.ToString(CultureInfo.InvariantCulture),- UnitOrder o => FormattableString.Invariant($"{o.Unit} {o.Order}"),+ UnitOrder 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),diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.csindex ed06c52bf..3779453d5 100644--- a/sim/Statecraft.Sim/Simulation.cs+++ b/sim/Statecraft.Sim/Simulation.cs@@ -175,7 +175,8 @@ namespace Statecraft.Simcase StopWork w:return Projects.Stop(c, s, w.Unit, why);case UnitOrder o:- return Orders.Give(s, o.Unit, o.Order, why);+ if (o.Order == Combat.Attack) return Combat.Give(c, s, o.Unit, o.Q, o.R, why);+ return o.Q != null || o.R != null ? "That order names no hex" : Orders.Give(s, o.Unit, o.Order, why);case StartProject p:return Projects.StartCity(c, s, p.ProjectKind, p.City, p.Q, p.R, why);case CancelProject p:diff --git a/sim/Statecraft.Sim/TurnResolver.cs b/sim/Statecraft.Sim/TurnResolver.csindex d8124d567..7dff55dd6 100644--- a/sim/Statecraft.Sim/TurnResolver.cs+++ b/sim/Statecraft.Sim/TurnResolver.cs@@ -14,7 +14,9 @@ namespace Statecraft.Sim{if (!c.IsGdd) return;var r = c.RulesAt(s.Date).Mvp!; // the loader requires it in the GDD loop- // 1-3. Enemy orders, combat, capture: Phase 5.+ // 1. Enemy orders: Phase 5 PR 10.+ Combat.Resolve(c, s, why); // 2. combat, in ascending attacker id (R-COMBAT-002)+ // 3. Capture: Phase 6.Orders.Settle(s, why); // 3b. after combat: fortify given this turn is set, and lost where a unit left its hex (R-ORDER-002)Training.Progress(c, s, why); // 4. trainingProjects.Advance(c, s, next, why); // 5. constructiondiff --git a/tools/web_check.py b/tools/web_check.pyindex 56679babc..95e62b3ab 100644--- a/tools/web_check.py+++ b/tools/web_check.py@@ -8,7 +8,7 @@ fail on a failure line or a timeout. Uses Chrome for Testing from the Playwright--enable-logging=stderr --v=1 as INFO:CONSOLE... "text", source: ...Usage (from the repo root):- uv run tools/web_check.py unity/Builds/Web-disabled --query "golden" --expect "GOLDEN OK hash1950 259133fc83a95471547be0cb1a317bae55c8324778864733b88957d7529c8585" --expect "GOLDEN OK hash1952 452c65ece470e844f6898151c4d9328aa0b2e59df82db4763214d43a8e8ea7f1"+ uv run tools/web_check.py unity/Builds/Web-disabled --query "golden" --expect "GOLDEN OK hash1950 73eb50db39dbc9ee569c18a5e0a68e55a2b88980d06da76e5f5bfffe22997675" --expect "GOLDEN OK hash1952 d9922fc9baaba3fcc5a6fbcd64de9317f787d7d3a8a0fb61f32a6b1b86462d91"Options: --query Q (page URL query, without '?'), --expect TEXT (repeatable), --fail REGEX (default: GOLDEN FAIL|SMOKE FAIL|BOOT FAIL),--timeout SECONDS (default 300), --stall SECONDS (fail when no console message arrives for that long; 0 = off),--swiftshader (software WebGL when there is no GPU), --dpr N (default 1), --shots DIR (reassemble the player's