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 experience from survived engagements under gdd-0.3 (R-UNIT-011), Refs #1707 (#2275)
Eyal Golanab4e2579cf50
diff --git a/changelog.d/1707-combat-xp.md b/changelog.d/1707-combat-xp.mdnew file mode 100644index 000000000..029d2da32--- /dev/null+++ b/changelog.d/1707-combat-xp.md@@ -0,0 +1,3 @@+- Under the gdd-0.3 rules only, units gain combat experience from the engagements they survive (Refs #1707): 1 for each+ engagement, up to 5, for both sides and for artillery firing alone. A recruit with 5 becomes a veteran soldier, and+ service time no longer promotes it. The game players play (gdd-0.1) is unchanged.diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex af123e2e0..f926ff610 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -242,11 +242,11 @@ Phase 5 PR 2 (#741) introduced the military record and types. PR 3 (#742, #1130)R-UNIT-001: A military unit is a group at formation scale, one token per formation (D-A1; Q-UNIT-1). It has a side, a type, a hex, a strength (an integer, in population units) and a standing order with its target. A military type in `unit_types.yaml` is a `unit` with a `side` (one of `units_1948.yaml`'s sides) and a `class` (infantry, artillery or armour); the loader refuses a type with only one of them, an unknown side or class, or a population type with either, naming the file and field. The MVP's military types are Israel's `recruit`, `veteran_soldier`, `artillery` and `armoured_car`.-R-UNIT-002: A unit's side, strength, order and order target are written into the state hash only when they are not at their default ("" or 0), after its service (R-LOOP-002's rule). Its housing home city is also written when nonempty (`|home=<city>`); an empty home adds nothing, preserving earlier units' canonical text. A halutz unit's canonical text remains unchanged when its home is empty.+R-UNIT-002: A unit's side, strength, order and order target are written into the state hash only when they are not at their default ("" or 0), after its service (R-LOOP-002's rule). Its housing home city is also written when nonempty (`|home=<city>`); an empty home adds nothing, preserving earlier units' canonical text. Its combat experience (R-UNIT-011) is written last, after `|full=`, only when it is not 0 (`|xp=<n>`), so no `gdd-0.1` unit's text changes. A halutz unit's canonical text remains unchanged when its home is empty.R-UNIT-003: A finished recruit cohort becomes exactly one Israeli infantry formation at its city's settlement hex, with `Strength` equal to the cohort's `Count` in population units, service 0 and the next id (Q-UNIT-1, Q-UNIT-4; owner, 15 October 2026). The cohort leaves the state: nobody is lost or duplicated. Its reserved Arms are neither charged again nor refunded on completion (R-ARMS-003). A cohort aimed at a unit adds to that unit instead of making a new one (R-TRAIN-004).-R-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-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. Under exact `gdd-0.3` service is a statistic only and never promotes: a recruit still gains its service turn, and veterancy comes from combat experience, R-UNIT-011 (owner, 1 November 2026, Q16: "Under gdd-0.3, yes: veterancy comes from combat experience. gdd-0.1 keeps R-UNIT-004.").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 waits for End turn and can be withdrawn until then, as Send home is not an instant order (R-TURN-004); when it runs, it 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).@@ -260,6 +260,8 @@ R-UNIT-009: A row of `map/units_1948.yaml` that meets R-UNIT-006 except that itsR-UNIT-010: In step 7, after production, Food consumption/imports and civilian upkeep, and before housing, each Israeli military formation pays `military_upkeep_per_turn` Money, including a formation that graduated this turn. The owner-accepted initial rate is IL 0.05m per formation per turn, independent of strength and turn length, a labelled design value under Q-GEN-1 (19 October 2026, https://github.com/eyalgolan/statecraft-israel/pull/1130#issuecomment-6269103829). Civilian, enemy and default records without a military side pay none. R-MONEY-003 borrows a shortfall; no strength is removed or Arms consumed for upkeep (Q-UNIT-3; owner, 15 October 2026). The loader requires a finite rate >= 0. R-ARMS-003 remains the training/refund rule; the Phase 5 plan's suggested reuse of that id is obsolete.+R-UNIT-011: Under exact `gdd-0.3` only, a military unit gains combat experience from the engagements it survives (#1707; owner, 2 November 2026: "Build it now (Recommended)", on today's aggregate units, `gdd-0.1` unchanged). After an engagement's one draw, its losses, retreats and surrenders (R-COMBAT-002, R-COMBAT-003), each attacker and defender still in the state, in ascending id, gains the Agreed catalogue `military.combat_xp_gain` (1), up to `military.combat_xp_full` (5): both sides, the player's instant attack and step 2's alike, a retreated defender included, and artillery firing alone too (owner, 1 November 2026, #1668 answers https://github.com/eyalgolan/statecraft-israel/pull/1668#issuecomment-6553884547: Q14 "Yes. Artillery fires alone from range, and it earns experience for each engagement it survives, like any unit."; Q15 "It stops."). A destroyed or surrendered unit gains nothing. Moves, orders, service and training give none. A `veteran_soldier` is a veteran already and gains none; a type with no veteran form stops at the full count (agent default, #1707 plan OQ1; enemy units count too, OQ2). An Israeli recruit that reaches the full count becomes a `veteran_soldier` with R-UNIT-004's promotion and its Why cause (no line for a single gain, OQ3), after the engagement, so it fought that engagement as a recruit. Every record change keeps the count (a refill too, R-TRAIN-004, OQ4), and a veteran stops accumulating service (OQ5). It draws nothing. The loader refuses either value when it is missing, Deferred or not a positive integer, with no fallback. The count is state, hashed as R-UNIT-002 says; a save replays its commands, so the save format is unchanged.+## CorridorsCorridor work is step 5 too, after the sites (Phase 4 PR 2, #786; owner, 17 October 2026, #782: the plan's Q-COR-1 to Q-COR-7 and Q-RAIL-1). `content/corridors.yaml` holds each corridor's kind (`road` or `rail`), names, map route and segments; a segment's hexes are derived from the route's traced line by `tools/corridor_hexes.py`. The Money and turns per segment are labelled design values in `rules.yaml` `mvp:` (Q-COR-6). On screen a segment is its corridor's name and its number ("Burma Road, segment 2"), never a waypoint's name (Q-SENS-1). The MVP's corridors are the Burma Road (four segments), the 1949 Haifa–Tel Aviv rail link (one) and the Tel Aviv–Netanya road (four, on straight draft lines between its five sourced places; owner, 18 October 2026, #786, Q-COR-3 (b)). A segment point in a hex the grid counts as sea (the coast) counts in its nearest land neighbour, as a shore town does.@@ -310,7 +312,7 @@ Phase 5 PR 8 (#747). Q-COMBAT-1 to Q-COMBAT-4 are the plan's recommendations (owR-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`. Under `gdd-0.3`, attacks and artillery fire use the same instant timing without an Arms affordability check or deduction; all other validity checks remain.-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. Under exact identity `gdd-0.3`, each defender instead counts once at `100 + biome defence_percent + permanent fort bonus + applicable settled Fortify bonus` percent, with bonuses read from the existing catalogue (#1668 military-combat.md:27, additive). Hold and unsettled/mismatched Fortify add nothing. Mountain + fort + settled Fortify is 225% of base defence (50 + 50 + 25); preview and resolution share this integer calculation. The older multiplicative formula remains unchanged.+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. Under exact identity `gdd-0.3`, each defender instead counts once at `100 + biome defence_percent + permanent fort bonus + applicable settled Fortify bonus` percent, with bonuses read from the existing catalogue (#1668 military-combat.md:27, additive). Hold and unsettled/mismatched Fortify add nothing. Mountain + fort + settled Fortify is 225% of base defence (50 + 50 + 25); preview and resolution share this integer calculation. The older multiplicative formula remains unchanged. Under exact `gdd-0.3`, after the draw and the losses, retreats and surrenders, the engagement's survivors gain combat experience (R-UNIT-011), drawing nothing more.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). A player's unit's first loss stores the strength it had as its `Full`; only replacements (R-TRAIN-004) restore lost strength.diff --git a/sim/Statecraft.Sim.Tests/ArtilleryTests.cs b/sim/Statecraft.Sim.Tests/ArtilleryTests.csindex eb4e886ff..bc2d1a9e0 100644--- a/sim/Statecraft.Sim.Tests/ArtilleryTests.cs+++ b/sim/Statecraft.Sim.Tests/ArtilleryTests.cs@@ -205,7 +205,7 @@ public class ArtilleryTestsAssert.Equal(arms, s.Arms);Assert.Equal(housed, Cities.Housed(s, s.Cities["town_a"]));Assert.Contains(why, w => w.Message.EndsWith("training and are " + noun, StringComparison.Ordinal));- for (int i = 0; i < 10; i++) Military.Serve(s, c.RulesAt(s.Date).Mvp!, why);+ for (int i = 0; i < 10; i++) Military.Serve(c, s, c.RulesAt(s.Date).Mvp!, why);Assert.Equal(track, s.Units[next].Type);}diff --git a/sim/Statecraft.Sim.Tests/Gdd03CombatXpTests.cs b/sim/Statecraft.Sim.Tests/Gdd03CombatXpTests.csnew file mode 100644index 000000000..546a6af43--- /dev/null+++ b/sim/Statecraft.Sim.Tests/Gdd03CombatXpTests.cs@@ -0,0 +1,362 @@+using System;+using System.Collections.Generic;+using System.IO;+using System.Linq;+using System.Text.RegularExpressions;+using Statecraft.Sim;++/// <summary>#1707, R-UNIT-011: combat experience from survived engagements under exact gdd-0.3, on today's aggregate units+/// (owner, 2 November 2026: "Build it now (Recommended)"). The owner's approved answers on #1668 (1 November 2026,+/// https://github.com/eyalgolan/statecraft-israel/pull/1668#issuecomment-6553884547): Q14 "Yes. Artillery fires alone from+/// range, and it earns experience for each engagement it survives, like any unit."; Q15 "It stops."; Q16 "Under gdd-0.3, yes:+/// veterancy comes from combat experience. gdd-0.1 keeps R-UNIT-004." Gdd03MovementFortTests' board and the real catalogue+/// (combat_xp_gain 1, combat_xp_full 5); the fixture's two-face table agrees on both faces, so no test depends on the draw:+/// below 2:1 both sides lose 1, from 2:1 the defenders lose 1 and retreat.</summary>+public class Gdd03CombatXpTests+{+ static Content Load() => Gdd03MovementFortTests.Load();+ static Content Legacy() => Gdd03MovementFortTests.Load(SaveGame.GddRuleset);++ static Unit Ours(int id, int q, int r, int strength, string type = "recruit", int xp = 0) =>+ new Unit(id, type, q, r, side: "israel", strength: strength, combatXp: xp);+ static Unit Theirs(int id, int q, int r, int strength, int xp = 0) =>+ new Unit(id, "enemy", q, r, side: "egypt", strength: strength, combatXp: xp);++ static GameState With(Content c, params Unit[] units) => CombatTests.With(c, units);++ static PreviewResult Attack(Content c, GameState s, int unit, int q, int r)+ {+ var now = Simulation.Preview(c, s, new Command[] { new UnitOrder(unit, Combat.Attack, q, r) });+ Assert.Empty(now.Rejected);+ return now;+ }++ // R-UNIT-011 (#1707 row 1): an attacker and a defender that both survive (6 against 6: both lose 1) each gain 1.+ [Fact]+ public void AttackerAndDefenderThatSurviveGainOne()+ {+ var c = Load();+ var now = Attack(c, With(c, Ours(1, 2, 1, 6), Theirs(2, 3, 1, 6)), 1, 3, 1);+ Assert.Equal((5, 1), (now.State.Units[1].Strength, now.State.Units[1].CombatXp));+ Assert.Equal((5, 1), (now.State.Units[2].Strength, now.State.Units[2].CombatXp));+ }++ // R-UNIT-011: a defender that loses and retreats has survived the engagement.+ [Fact]+ public void RetreatedDefenderGainsOne()+ {+ var c = Load();+ var now = Attack(c, With(c, Ours(1, 2, 1, 6), Theirs(2, 3, 1, 2)), 1, 3, 1);+ var d = now.State.Units[2];+ Assert.Equal((4, 1, 1, 1), (d.Q, d.R, d.Strength, d.CombatXp));+ Assert.Equal(1, now.State.Units[1].CombatXp);+ }++ // R-UNIT-011: a destroyed or surrendered unit gains nothing: its record is gone and no id is used. A unit that stood by gains nothing.+ [Fact]+ public void DestroyedAndSurrenderedGainNothing()+ {+ var c = Load();+ var s = With(c, Ours(1, 2, 1, 6), Theirs(2, 3, 1, 1));+ var now = Attack(c, s, 1, 3, 1);+ Assert.False(now.State.Units.ContainsKey(2));+ Assert.Equal(s.NextId, now.State.NextId);+ Assert.Equal(1, now.State.Units[1].CombatXp);++ // (5, 0) is a corner: its board neighbours (4, 0), (4, 1) and (5, 1) all hold Israeli units, so it surrenders.+ var t = With(c, Ours(1, 4, 0, 6), Ours(3, 4, 1, 1), Ours(4, 5, 1, 1), Theirs(2, 5, 0, 2));+ var held = Attack(c, t, 1, 5, 0);+ Assert.False(held.State.Units.ContainsKey(2));+ Assert.Contains(held.Why, w => w.Key == WhyKeys.SurrenderedPrisoners);+ Assert.Equal(t.NextId, held.State.NextId);+ Assert.Equal((1, 0, 0), (held.State.Units[1].CombatXp, held.State.Units[3].CombatXp, held.State.Units[4].CombatXp));+ }++ // R-UNIT-011, Q14: artillery that fires alone from range survives (the guns take no attacker loss) and gains 1.+ [Fact]+ public void ArtilleryFiringAloneGainsOne()+ {+ var c = Load();+ var now = Attack(c, With(c, Ours(1, 1, 1, 6, "gun"), Theirs(2, 3, 1, 6)), 1, 3, 1);+ Assert.Equal((6, 1), (now.State.Units[1].Strength, now.State.Units[1].CombatXp));+ Assert.Equal(1, now.State.Units[2].CombatXp);+ }++ // R-UNIT-011, R-COMBAT-002 (review of #2275, B1): the enemy's standing attack, fought in the resolver's step 2+ // (Combat.Resolve), gives XP as the player's attack does: the enemy attacker and our defender both survive (6 against 6:+ // both lose 1) and each gain 1. Pins that the award is made for every engagement, not only the player's Strike.+ [Fact]+ public void EnemyAttackInStepTwoGivesBothSidesOne()+ {+ var c = Load();+ var s = With(c, Ours(1, 2, 1, 6), Theirs(2, 3, 1, 6));+ var why = new List<Cause>();+ Assert.Null(Combat.Give(c, s, 2, 2, 1, why, enemy: true));+ Combat.Resolve(c, s, why);+ Assert.Contains(why, w => w.Key == WhyKeys.Engagement);+ Assert.Equal((5, 1), (s.Units[1].Strength, s.Units[1].CombatXp));+ Assert.Equal((5, 1), (s.Units[2].Strength, s.Units[2].CombatXp));+ }++ // R-UNIT-011, Q15: experience stops at combat_xp_full, for the guns and the enemy as for anyone. A veteran_soldier is a+ // veteran already (OQ1) and gains none.+ [Fact]+ public void XpStopsAtFullAndAVeteranGainsNone()+ {+ var c = Load();+ var now = Attack(c, With(c, Ours(1, 1, 1, 6, "gun", 5), Theirs(2, 3, 1, 6, 5)), 1, 3, 1);+ Assert.Equal((5, 5), (now.State.Units[1].CombatXp, now.State.Units[2].CombatXp));+ var vet = Attack(c, With(c, Ours(1, 2, 1, 6, "veteran_soldier"), Theirs(2, 3, 1, 6, 2)), 1, 3, 1);+ Assert.Equal((0, 3), (vet.State.Units[1].CombatXp, vet.State.Units[2].CombatXp));+ }++ // R-UNIT-011 (#1707: "service time and travel do not count"): moving, ordering and whole turns of service give no XP.+ [Fact]+ public void MovesOrdersAndServiceGiveNoXp()+ {+ var c = Load();+ var s = With(c, Ours(1, 0, 1, 6, xp: 2));+ var next = Simulation.Step(c, s, new Command[] { new Move(1, 1, 1), new UnitOrder(1, Orders.Fortify) }).State;+ next = Simulation.Step(c, next, new Command[0]).State;+ Assert.Equal((1, 2, 2), (next.Units[1].Q, next.Units[1].Service, next.Units[1].CombatXp));+ }++ // R-UNIT-011, R-COMBAT-002 (#1707 row 2): the experience draws nothing: the engagement draws its one face, as under gdd-0.1.+ [Fact]+ public void NoExtraDraw()+ {+ foreach (var c in new[] { Load(), Legacy() })+ {+ var s = With(c, Ours(1, 2, 1, 6), Theirs(2, 3, 1, 6));+ var rng = new Rng(s.RngState);+ rng.NextDouble();+ Assert.Equal(rng.State, Attack(c, s, 1, 3, 1).State.RngState);+ }+ }++ // R-UNIT-011, #1707 plan section 3.2: a unit's experience survives every change that rebuilds its record (13 sim sites+ // on main): a move, a go-to and its arrival, fortify and its setting, hold, an attack's own record, a loss, a retreat, an+ // enemy attack order and its end, a truce ending one, a turn of service and a promotion by service (gdd-0.1), a+ // replacement joining it, and a withdrawal by Raid. EverySimCopyOfAUnitPassesItsCombatXp covers the halutz-only sites.+ [Fact]+ public void XpSurvivesEveryUnitChange()+ {+ var c = Load();+ var spent = new Dictionary<int, int>(); var why = new List<Cause>();++ var s = With(c, Ours(1, 0, 1, 6, xp: 3));+ Assert.Null(Movement.Move(c, s, 1, 1, 1, spent, why)); // Movement.Move+ Assert.Equal(3, s.Units[1].CombatXp);+ Assert.Null(Movement.GiveGoTo(c, s, 1, 5, 1, spent, why)); // Movement.GiveGoTo+ Assert.Equal(3, s.Units[1].CombatXp);+ for (int turn = 0; turn < 3; turn++) { spent.Clear(); Movement.ContinueRoutes(c, s, spent, why); } // arrival: Stop+ Assert.Equal(("", 5, 3), (s.Units[1].Order, s.Units[1].Q, s.Units[1].CombatXp));+ Assert.Null(Orders.Give(c, s, 1, Orders.Fortify, why)); // Orders.With: fortifying+ Orders.Settle(s, why); // Orders.With: fortify+ Assert.Equal((Orders.Fortify, 3), (s.Units[1].Order, s.Units[1].CombatXp));+ Assert.Null(Orders.Give(c, s, 1, Orders.Hold, why));+ Assert.Equal((Orders.Hold, 3), (s.Units[1].Order, s.Units[1].CombatXp));++ // An attack (Strike's own record), its loss (Combat.Lose) and the defender's retreat each keep the old XP: 3 + 1.+ var fight = Attack(c, With(c, Ours(1, 2, 1, 6, xp: 3), Theirs(2, 3, 1, 6, 3)), 1, 3, 1).State;+ Assert.Equal((5, 4, 5, 4), (fight.Units[1].Strength, fight.Units[1].CombatXp, fight.Units[2].Strength, fight.Units[2].CombatXp));+ var rout = Attack(c, With(c, Ours(1, 2, 1, 6, xp: 3), Theirs(2, 3, 1, 2, 3)), 1, 3, 1).State;+ Assert.Equal((4, 4), (rout.Units[2].Q, rout.Units[2].CombatXp));++ // The enemy's standing attack (Combat.Give) and its end with no enemy there (Combat.End).+ var e = With(c, Theirs(2, 3, 1, 6, 3), Ours(1, 2, 1, 6));+ Assert.Null(Combat.Give(c, e, 2, 2, 1, why, enemy: true));+ Assert.Equal((Combat.Attack, 3), (e.Units[2].Order, e.Units[2].CombatXp));+ e.Units.Remove(1);+ Combat.Resolve(c, e, why);+ Assert.Equal(("", 3), (e.Units[2].Order, e.Units[2].CombatXp));++ // A turn of service under gdd-0.3 and, under gdd-0.1, the promotion by service (Military.Serve).+ var served = With(c, Ours(1, 0, 1, 6, xp: 3));+ Military.Serve(c, served, c.RulesAt(served.Date).Mvp!, why);+ Assert.Equal((1, 3), (served.Units[1].Service, served.Units[1].CombatXp));+ var old = Legacy();+ var promoted = With(old, new Unit(1, "recruit", 0, 1, 2, side: "israel", strength: 6, combatXp: 3));+ Military.Serve(old, promoted, old.RulesAt(promoted.Date).Mvp!, why);+ Assert.Equal(("veteran_soldier", 3), (promoted.Units[1].Type, promoted.Units[1].CombatXp));++ // A truce ends an enemy's standing attack (EnemyAI.Order), on the real content's 15 June 1948 truce turn.+ var real = Real.Value;+ var t = Simulation.NewGame(real, GoldenRun.Seed, Mode.Historical);+ var (id, u) = t.Units.First(kv => kv.Value.Side != "" && kv.Value.Side != Movement.PlayerSide);+ t.Units[id] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, Combat.Attack, $"{u.Q + 1},{u.R}", u.HomeCity, u.Full, 3);+ t.Date = new DateTime(1948, 6, 15);+ EnemyAI.Order(real, t, why, new DateTime(1948, 7, 15));+ Assert.Equal(3, t.Units[id].CombatXp);++ // A replacement cohort joining the unit (Training.Progress, R-TRAIN-004), on the real content's Tel Aviv camp.+ var r = Simulation.NewGame(real, GoldenRun.Seed, Mode.Historical);+ var tlv = real.SettlementHexes.Single(h => h.Id == "tel_aviv");+ var rid = r.NextId++;+ r.Units.Add(rid, new Unit(rid, "recruit", tlv.Q, tlv.R, side: "israel", strength: 2, homeCity: "tel_aviv", full: 5, combatXp: 3));+ r.Arms = 100;+ Assert.Null(Training.Reinforce(real, r, rid, "tel_aviv", 3, why));+ for (int turn = 0; turn < real.UnitTypes.Single(x => x.Id == "recruit").TrainingTurns; turn++) Training.Progress(real, r, why);+ Assert.Equal((5, 3), (r.Units[rid].Strength, r.Units[rid].CombatXp));++ // A withdrawal by Raid (SettlementControl's move out, R-CTRL-010), on RaidTests' fixture.+ var raid = CaptureTests.Load(CaptureTests.AllTargets);+ var w = CombatTests.With(raid, new Unit(1, "soldier", 1, 0, side: "israel", strength: 2, combatXp: 3));+ w.Settlements["town_a"] = new SettlementControl(Movement.PlayerSide, SettlementControl.AwaitingChoice, w.Date);+ var left = Simulation.Step(raid, w, new Command[] { new ResolveCapture("town_a", SettlementControl.Raid) }).State;+ Assert.Equal((2, 0, 3), (left.Units[1].Q, left.Units[1].R, left.Units[1].CombatXp));+ }++ static readonly Lazy<Content> Real = new Lazy<Content>(() => ContentLoader.Load(RealContentTests.ContentRoot()));++ // R-UNIT-011: the structural check behind XpSurvivesEveryUnitChange. Every sim site that rebuilds a unit from an existing+ // one, new Unit(x.Id, ...), passes x.CombatXp, the halutz sites (Corridors, Projects) included, so a new field is never+ // dropped by a copy. At least the 16 copy sites main had when #1707 started. The one exception is the award itself+ // (Combat.Experience), which writes the new count.+ [Fact]+ public void EverySimCopyOfAUnitPassesItsCombatXp()+ {+ var sim = Path.Combine(Path.GetDirectoryName(RealContentTests.ContentRoot())!, "sim", "Statecraft.Sim");+ int copies = 0, awards = 0;+ foreach (var file in Directory.GetFiles(sim, "*.cs"))+ {+ var source = File.ReadAllText(file);+ foreach (Match m in Regex.Matches(source, @"new Unit\((\w+)\.Id,"))+ {+ int depth = 0, end = m.Index + "new Unit".Length;+ for (; end < source.Length; end++)+ {+ if (source[end] == '(') depth++;+ else if (source[end] == ')' && --depth == 0) break;+ }+ var call = source.Substring(m.Index, end - m.Index + 1);+ if (Path.GetFileName(file) == "Combat.cs" && call.EndsWith("u.Full, xp)")) { awards++; continue; }+ Assert.True(call.Contains(m.Groups[1].Value + ".CombatXp"), Path.GetFileName(file) + " drops CombatXp: " + call);+ copies++;+ }+ }+ Assert.Equal(1, awards);+ Assert.True(copies >= 16, copies + " copy sites found");+ }++ // R-UNIT-011, R-UNIT-002: XP is hashed only when it is not 0, after |full=.+ [Fact]+ public void XpIsHashedOnlyWhenNotZero()+ {+ Assert.Equal("1:recruit@2,1|side=israel|strength=6", new Unit(1, "recruit", 2, 1, side: "israel", strength: 6).Canonical());+ Assert.Equal("1:recruit@2,1|side=israel|strength=5|full=6|xp=1",+ new Unit(1, "recruit", 2, 1, side: "israel", strength: 5, full: 6, combatXp: 1).Canonical());+ }++ // R-UNIT-011, R-UNIT-004: gdd-0.1 never writes XP: the same engagement leaves every unit's record free of it.+ [Fact]+ public void Gdd01NeverWritesXp()+ {+ var c = Legacy();+ var now = Attack(c, With(c, Ours(1, 2, 1, 6), Theirs(2, 3, 1, 6)), 1, 3, 1);+ Assert.All(now.State.Units.Values, u => Assert.Equal(0, u.CombatXp));+ Assert.DoesNotContain("|xp=", now.State.Describe());+ }++ // R-UNIT-011, R-TURN-004: the player's attack is fought in the preview and again in the turn, with the same XP.+ [Fact]+ public void PreviewAndStepAgree()+ {+ var c = Load();+ var s = With(c, Ours(1, 2, 1, 6), Theirs(2, 3, 1, 6));+ var cmd = new Command[] { new UnitOrder(1, Combat.Attack, 3, 1) };+ var preview = Simulation.Preview(c, s, cmd).State;+ var step = Simulation.Step(c, s, cmd).State;+ Assert.Equal((1, 1), (preview.Units[1].CombatXp, preview.Units[2].CombatXp));+ Assert.Equal((step.Units[1].CombatXp, step.Units[2].CombatXp), (preview.Units[1].CombatXp, preview.Units[2].CombatXp));+ }++ // R-UNIT-011: XP is derived from the commands, so a replay of the same commands from the same start gives the same hash.+ [Fact]+ public void ReplayKeepsXp()+ {+ var c = Load();+ GameState Play()+ {+ var s = With(c, Ours(1, 2, 1, 9), Theirs(2, 3, 1, 9)); // even, so the enemy never attacks back (R-ENEMY-003)+ for (int turn = 0; turn < 3; turn++) s = Simulation.Step(c, s, new Command[] { new UnitOrder(1, Combat.Attack, 3, 1) }).State;+ return s;+ }+ var first = Play();+ Assert.Equal((3, 3), (first.Units[1].CombatXp, first.Units[2].CombatXp));+ Assert.Contains("|xp=3", first.Describe());+ Assert.Equal(first.Hash(), Play().Hash());+ }++ // R-UNIT-011: gdd-0.3 reads both values from the catalogue at load, with no fallback: Deferred, missing or 0 is refused.+ [Theory]+ [InlineData("military.combat_xp_gain", "basis: Deferred, expression: pending, note: fixture")]+ [InlineData("military.combat_xp_full", "basis: Agreed, values: [0], note: fixture")]+ [InlineData("military.combat_xp_gain", null)]+ [InlineData("military.combat_xp_full", null)]+ public void CatalogueRefusal(string key, string? row)+ {+ var f = Gdd03MovementFortTests.Files();+ var catalogue = f[Gdd03BalanceCatalogue.FileName];+ f[Gdd03BalanceCatalogue.FileName] = row == null ? catalogue.Replace("\"" + key + "\":", "\"unused.fixture\":")+ : Regex.Replace(catalogue, "(?m)^ \"" + Regex.Escape(key) + "\":\\n(?: .*\\n)*", " \"" + key + "\": { " + row + " }\n");+ Assert.NotEqual(catalogue, f[Gdd03BalanceCatalogue.FileName]);+ Assert.Contains(key, Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(f))).Message);+ }++ // R-UNIT-011, R-UNIT-004, Q16: five survived engagements make a recruit a veteran_soldier, with R-UNIT-004's Why cause.+ [Fact]+ public void RecruitBecomesVeteranAfterFiveSurvivedEngagements()+ {+ var c = Load();+ var s = With(c, Ours(1, 2, 1, 9), Theirs(2, 3, 1, 30));+ for (int i = 1; i <= 5; i++)+ {+ var now = Attack(c, s, 1, 3, 1);+ s = now.State;+ Assert.Equal((i, i == 5 ? "veteran_soldier" : "recruit"), (s.Units[1].CombatXp, s.Units[1].Type));+ Assert.Equal(i == 5 ? 1 : 0, now.Why.Count(w => w.Key == CauseKeys.RecruitsVeteran));+ }+ var vet = s.Units[1];+ Assert.Equal((1, 2, 1, 0, "israel", 4, 9), (vet.Id, vet.Q, vet.R, vet.Service, vet.Side, vet.Strength, vet.Full));+ }++ // R-UNIT-011 (#1707: "New qualification applies from the next engagement"): the promoting engagement is fought at the+ // recruit's ratio. The fixture's veteran counts at 300% here so the two ratios differ.+ [Fact]+ public void PromotedInAnEngagementFoughtItAsARecruit()+ {+ var c = Load();+ c.UnitTypes.Single(t => t.Id == "veteran_soldier").CombatPercent = 300;+ var s = With(c, Ours(1, 2, 1, 9, xp: 4), Theirs(2, 3, 1, 30));+ var before = Combat.Preview(c, s, 1, 3, 1)!.Value.RatioPercent;+ var now = Attack(c, s, 1, 3, 1);+ Assert.Equal("veteran_soldier", now.State.Units[1].Type);+ Assert.Equal(before.ToString(System.Globalization.CultureInfo.InvariantCulture), now.Why.Single(w => w.Key == WhyKeys.Engagement).Args[1]);+ Assert.NotEqual(before, Combat.Preview(c, now.State, 1, 3, 1)!.Value.RatioPercent);+ }++ // R-UNIT-004 re-pointed, Q16: under gdd-0.3 service is a statistic only: a recruit with 20 turns and no XP stays one.+ [Fact]+ public void Gdd03ServiceNeverPromotes()+ {+ var c = Load();+ var s = With(c, new Unit(1, "recruit", 0, 1, 20, side: "israel", strength: 6));+ var why = new List<Cause>();+ Military.Serve(c, s, c.RulesAt(s.Date).Mvp!, why);+ Assert.Equal(("recruit", 21), (s.Units[1].Type, s.Units[1].Service));+ Assert.Empty(why);+ }++ // R-UNIT-004 unchanged under gdd-0.1: the fixture's veteran_soldier_service (3) still promotes, with its cause.+ [Fact]+ public void Gdd01ServiceStillPromotes()+ {+ var c = Legacy();+ var s = With(c, new Unit(1, "recruit", 0, 1, 2, side: "israel", strength: 6));+ var why = new List<Cause>();+ Military.Serve(c, s, c.RulesAt(s.Date).Mvp!, why);+ Assert.Equal(("veteran_soldier", 3), (s.Units[1].Type, s.Units[1].Service));+ Assert.Single(why, w => w.Key == CauseKeys.RecruitsVeteran);+ }+}diff --git a/sim/Statecraft.Sim.Tests/Gdd03MovementFortTests.cs b/sim/Statecraft.Sim.Tests/Gdd03MovementFortTests.csindex 41146a03e..5401d071d 100644--- a/sim/Statecraft.Sim.Tests/Gdd03MovementFortTests.cs+++ b/sim/Statecraft.Sim.Tests/Gdd03MovementFortTests.cs@@ -13,7 +13,7 @@ public class Gdd03MovementFortTests+ " - { id: enemy_car, kind: unit, side: egypt, class: armour, movement_points: 5 }\n"+ " - { id: gun, kind: unit, side: israel, class: artillery, movement_points: 2, range: 2, arms_per_fire: 2 }\n";- static Dictionary<string, string> Files(string identity = SaveGame.Gdd03Ruleset, string biome = "coastal_plain")+ internal static Dictionary<string, string> Files(string identity = SaveGame.Gdd03Ruleset, string biome = "coastal_plain"){var f = Fixture.Gdd(new Dictionary<string, string> {["unit_types.yaml"] = Types,@@ -29,7 +29,7 @@ public class Gdd03MovementFortTestsreturn f;}- static Content Load(string identity = SaveGame.Gdd03Ruleset, string biome = "coastal_plain") =>+ internal static Content Load(string identity = SaveGame.Gdd03Ruleset, string biome = "coastal_plain") =>ContentLoader.Load(Fixture.Write(Files(identity, biome)));static Unit Of(string type, int id = 1, int q = 2, int r = 1, string side = "israel", string order = "", string target = "") =>diff --git a/sim/Statecraft.Sim.Tests/MilitaryTrainingTests.cs b/sim/Statecraft.Sim.Tests/MilitaryTrainingTests.csindex e2f28b4c0..d72195b91 100644--- a/sim/Statecraft.Sim.Tests/MilitaryTrainingTests.cs+++ b/sim/Statecraft.Sim.Tests/MilitaryTrainingTests.cs@@ -80,7 +80,7 @@ public class MilitaryTrainingTestsvar rules = Mvp.RulesAt(s.Date).Mvp!;for (int turn = 0; turn < rules.VeteranSoldierService!.Value; turn++){- Military.Serve(s, rules, why);+ Military.Serve(Mvp, s, rules, why);Assert.Equal(city.Id, s.Units[unit.Id].HomeCity);Assert.Equal(3, Cities.Housed(s, city));}diff --git a/sim/Statecraft.Sim.Tests/NoShotArmsTests.cs b/sim/Statecraft.Sim.Tests/NoShotArmsTests.csindex 11632fc5e..b15b37e64 100644--- a/sim/Statecraft.Sim.Tests/NoShotArmsTests.cs+++ b/sim/Statecraft.Sim.Tests/NoShotArmsTests.cs@@ -205,7 +205,9 @@ public class NoShotArmsTestsvar normalized = y.State.Clone();normalized.Arms = x.State.Arms;static string Core(string text) => Regex.Replace(Regex.Replace(text, @"\npopulation-ledger\{(?:\n [^\n]*)*", "").Replace("ruleset=gdd-0.3;", ""), @"\natt=[^\n]*", "");- Assert.Equal(Core(x.State.Describe()), Core(normalized.Describe()));+ // R-UNIT-011 (#1707): gdd-0.3 also counts the survivors' combat experience; the losses, hexes and draw stay the same.+ Assert.Contains("|xp=1", normalized.Describe());+ Assert.Equal(Core(x.State.Describe()), Regex.Replace(Core(normalized.Describe()), @"\|xp=\d+", ""));Assert.Equal(x.Why.Select(w => w.Message), y.Why.Select(w => w.Message));}diff --git a/sim/Statecraft.Sim.Tests/PopulationLedgerBoundaryTests.cs b/sim/Statecraft.Sim.Tests/PopulationLedgerBoundaryTests.csindex 37b1f322c..65b02aa5c 100644--- a/sim/Statecraft.Sim.Tests/PopulationLedgerBoundaryTests.cs+++ b/sim/Statecraft.Sim.Tests/PopulationLedgerBoundaryTests.cs@@ -50,7 +50,7 @@ public class PopulationLedgerBoundaryTestscase "training.cancel": Training.Cancel(c,s,0,why); break;case "training.progress": Training.Progress(c,s,why); break;case "training.reinforce": Training.Reinforce(c,s,0,"missing",1,why); break;- case "military.serve": Military.Serve(s,rules,why); break;+ case "military.serve": Military.Serve(c,s,rules,why); break;case "military.upkeep": Military.PayUpkeep(c,s,rules,why); break;case "qualification.return": Qualification.ReturnCraftsmen(c,s,"missing",1,why); break;case "qualification.craftsmen": Qualification.ReassignCraftsmen(c,s,"missing",1,why); break;diff --git a/sim/Statecraft.Sim/Combat.cs b/sim/Statecraft.Sim/Combat.csindex 209114677..d8cf26d21 100644--- a/sim/Statecraft.Sim/Combat.cs+++ b/sim/Statecraft.Sim/Combat.cs@@ -126,7 +126,7 @@ namespace Statecraft.Simvar refused = Check(c, s, unitId, q, r, enemy);if (refused != null) return refused;var u = s.Units[unitId]; var target = Hex(q!.Value, r!.Value);- s.Units[unitId] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, Attack, target, u.HomeCity, u.Full);+ s.Units[unitId] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, Attack, target, u.HomeCity, u.Full, u.CombatXp);why.Add(UnitLines.Line(WhyKeys.AttackOrdered, $"Unit {unitId} will attack hex {target}", new[] { u }, target));return null;}@@ -142,7 +142,7 @@ namespace Statecraft.Simvar mvp = c.RulesAt(s.Date).Mvp!;var u = s.Units[unitId];if (SpendsArms(c)) 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, u.Full);+ var attacker = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, "", "", u.HomeCity, u.Full, u.CombatXp);s.Units[unitId] = attacker;if (u.Order == Orders.Fortify)why.Add(UnitLines.Line(WhyKeys.FortifyLost,@@ -276,15 +276,41 @@ namespace Statecraft.Simstatic void End(GameState s, Unit u, string key, string line, List<Cause> why, params string[] args){- s.Units[u.Id] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, "", "", u.HomeCity, u.Full);+ s.Units[u.Id] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, "", "", u.HomeCity, u.Full, u.CombatXp);why.Add(UnitLines.Line(key, line, new[] { u }, args));}+ /// <summary>One engagement (<see cref="Fight"/>), then, under exact gdd-0.3, its survivors' combat experience+ /// (R-UNIT-011). Every engagement, the player's instant attack and step 2's alike, runs through here.</summary>+ static void Engage(Content c, GameState s, MvpRules mvp, List<Unit> attackers, List<Unit> defenders, int q, int r, List<Cause> why)+ {+ Fight(c, s, mvp, attackers, defenders, q, r, why);+ if (Gdd03Military.Applies(c)) Experience(c, s, attackers, defenders, why);+ }++ /// <summary>R-UNIT-011 (owner, 1 November 2026, #1668 Q14 to Q16): after the engagement's one draw, its losses, retreats+ /// and surrenders, each attacker and defender still in the state, in ascending id, gains military.combat_xp_gain combat+ /// experience, up to military.combat_xp_full. A destroyed or surrendered unit has left the state and gains nothing; a+ /// veteran_soldier is a veteran already and gains none. A recruit that reaches the full count becomes a veteran_soldier+ /// (R-UNIT-004's promotion), so it fought this engagement as a recruit. Draws nothing.</summary>+ static void Experience(Content c, GameState s, List<Unit> attackers, List<Unit> defenders, List<Cause> why)+ {+ var gain = Gdd03Military.Scalar(c, "military.combat_xp_gain");+ var full = Gdd03Military.Scalar(c, "military.combat_xp_full");+ foreach (var id in attackers.Concat(defenders).Select(x => x.Id).OrderBy(x => x))+ {+ if (!s.Units.TryGetValue(id, out var u) || u.Type == Statecraft.Sim.Military.VeteranSoldier) continue;+ var xp = (int)Math.Min(full, (long)u.CombatXp + gain);+ var gained = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full, xp);+ s.Units[id] = xp == full && Statecraft.Sim.Military.Promotes(u) ? Statecraft.Sim.Military.Promote(gained, why) : gained;+ }+ }+/// <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)+ static void Fight(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)];@@ -314,7 +340,7 @@ namespace Statecraft.Simif (!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, u.HomeCity, u.Full);+ s.Units[u.Id] = new Unit(u.Id, u.Type, to.Item1, to.Item2, u.Service, u.Side, u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full, u.CombatXp);var hex = Hex(to.Item1, to.Item2);why.Add(UnitLines.Line(WhyKeys.Retreated, $"Unit {u.Id} retreated to hex {hex}", new[] { u }, hex));}@@ -357,7 +383,7 @@ namespace Statecraft.Sim/// strength it had as its Full, the most replacements refill it to; no rule reads an enemy's, so it stores none.</summary>internal static Unit Lose(Unit u) =>new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength - 1, u.Order, u.OrderTarget, u.HomeCity,- u.Full == 0 && u.Side == Movement.PlayerSide ? u.Strength : u.Full);+ u.Full == 0 && u.Side == Movement.PlayerSide ? u.Strength : u.Full, u.CombatXp);/// <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,diff --git a/sim/Statecraft.Sim/Corridors.cs b/sim/Statecraft.Sim/Corridors.csindex bda92c408..887adf059 100644--- a/sim/Statecraft.Sim/Corridors.cs+++ b/sim/Statecraft.Sim/Corridors.cs@@ -114,7 +114,7 @@ namespace Statecraft.Simif (u.Type != "halutz") continue;var service = u.Service + 1;var promoted = service >= r.VeteranHalutzService!.Value;- s.Units[u.Id] = new Unit(u.Id, promoted ? Projects.VeteranType : u.Type, u.Q, u.R, service, u.Side, u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full);+ s.Units[u.Id] = new Unit(u.Id, promoted ? Projects.VeteranType : u.Type, u.Q, u.R, service, u.Side, u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full, u.CombatXp);if (promoted) why.Add(new Cause("map", w.Id, 1, "A group of halutzim became veteran pioneers", key: CauseKeys.PioneersVeteran));}s.Corridors[w.Id] = cur;diff --git a/sim/Statecraft.Sim/EnemyAI.cs b/sim/Statecraft.Sim/EnemyAI.csindex 9d2c8c44a..9284dd088 100644--- a/sim/Statecraft.Sim/EnemyAI.cs+++ b/sim/Statecraft.Sim/EnemyAI.cs@@ -55,7 +55,7 @@ namespace Statecraft.Sim// fortify (Movement.Move), and step 2 would resolve it inside the truce (owner, #1263).if (truce && u.Order == Combat.Attack){- s.Units[id] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, "", "", u.HomeCity, u.Full);+ s.Units[id] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, "", "", u.HomeCity, u.Full, u.CombatXp);why.Add(UnitLines.Line(WhyKeys.AttackEndedTruce,$"Unit {id}'s attack on hex {u.OrderTarget} ends: a truce is on", new[] { u }, u.OrderTarget));}diff --git a/sim/Statecraft.Sim/Gdd03Military.cs b/sim/Statecraft.Sim/Gdd03Military.csindex 5d47b08e7..18f051bb3 100644--- a/sim/Statecraft.Sim/Gdd03Military.cs+++ b/sim/Statecraft.Sim/Gdd03Military.cs@@ -151,6 +151,7 @@ namespace Statecraft.SimScalar(c, "military.fort_bonus", false);EnemyAttackRatioPercent(c);Scalar(c, "military.fortify_bonus", false);+ Scalar(c, "military.combat_xp_gain"); Scalar(c, "military.combat_xp_full"); // R-UNIT-011if (Scalar(c, "military.fortify_turns") != 1) throw Invalid("military.fortify_turns", "only the existing one-turn settlement is implemented");foreach (var biome in new[] { "coastal_plain", "lowland", "valley", "hills", "mountains", "desert" }){diff --git a/sim/Statecraft.Sim/GddState.cs b/sim/Statecraft.Sim/GddState.csindex 96f829765..19cf438b7 100644--- a/sim/Statecraft.Sim/GddState.cs+++ b/sim/Statecraft.Sim/GddState.cs@@ -200,10 +200,13 @@ namespace Statecraft.Sim/// <summary>The strength the formation had before its first loss, the most replacements refill it to (R-TRAIN-004), or/// 0 while it has lost none: combat sets it (R-COMBAT-003) and a refill to full clears it.</summary>public int Full { get; }+ /// <summary>Combat experience under exact gdd-0.3 (R-UNIT-011): survived engagements, up to military.combat_xp_full.+ /// Always 0 under every other ruleset.</summary>+ public int CombatXp { get; }- public Unit(int id, string type, int q, int r, int service = 0, string side = "", int strength = 0, string order = "", string orderTarget = "", string homeCity = "", int full = 0)+ public Unit(int id, string type, int q, int r, int service = 0, string side = "", int strength = 0, string order = "", string orderTarget = "", string homeCity = "", int full = 0, int combatXp = 0){- Id = id; Type = type; Q = q; R = r; Service = service; Side = side; Strength = strength; Order = order; OrderTarget = orderTarget; HomeCity = homeCity; Full = full;+ Id = id; Type = type; Q = q; R = r; Service = service; Side = side; Strength = strength; Order = order; OrderTarget = orderTarget; HomeCity = homeCity; Full = full; CombatXp = combatXp;}/// <summary>The record as the state hash writes it. Each field after the hex is written only when it is not at its@@ -216,7 +219,8 @@ namespace Statecraft.Sim+ (Order == "" ? "" : "|order=" + Order)+ (OrderTarget == "" ? "" : "|target=" + OrderTarget)+ (HomeCity == "" ? "" : "|home=" + HomeCity)- + (Full == 0 ? "" : "|full=" + Full.ToString(CultureInfo.InvariantCulture));+ + (Full == 0 ? "" : "|full=" + Full.ToString(CultureInfo.InvariantCulture))+ + (CombatXp == 0 ? "" : "|xp=" + CombatXp.ToString(CultureInfo.InvariantCulture));}/// <summary>A group of a city's people in training (GDD "Progression"; R-TRAIN-001): <see cref="Count"/> population unitsdiff --git a/sim/Statecraft.Sim/Military.cs b/sim/Statecraft.Sim/Military.csindex b248d5d08..7f0f18c2a 100644--- a/sim/Statecraft.Sim/Military.cs+++ b/sim/Statecraft.Sim/Military.cs@@ -7,21 +7,34 @@ namespace Statecraft.Simpublic static class Military{/// <summary>R-UNIT-004: recruits already in play serve this turn. Run before training completes, so training time- /// never counts as service. Promotion preserves the formation and its standing order; combat adds no service.</summary>- public static void Serve(GameState s, MvpRules r, List<Cause> why)+ /// never counts as service. Promotion preserves the formation and its standing order; combat adds no service. Under+ /// exact gdd-0.3 service is a statistic only and never promotes: veterancy comes from combat experience (R-UNIT-011, Q16).</summary>+ public static void Serve(Content c, GameState s, MvpRules r, List<Cause> why){PopulationLedger.RefuseAggregate(s);+ var byService = !Gdd03Military.Applies(c);foreach (var u in s.Units.Values.ToList()){- if (u.Type != "recruit" || u.Side != "israel") continue;- var service = u.Service + 1;- var veteran = service >= r.VeteranSoldierService!.Value;- s.Units[u.Id] = new Unit(u.Id, veteran ? "veteran_soldier" : u.Type, u.Q, u.R, service,- u.Side, u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full);- if (veteran) why.Add(new Cause("city", "units", u.Strength, "Recruits became veteran soldiers", key: CauseKeys.RecruitsVeteran));+ if (!Promotes(u)) continue;+ var served = new Unit(u.Id, u.Type, u.Q, u.R, u.Service + 1, u.Side, u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full, u.CombatXp);+ s.Units[u.Id] = byService && served.Service >= r.VeteranSoldierService!.Value ? Promote(served, why) : served;}}+ /// <summary>R-UNIT-004, R-UNIT-011: an Israeli recruit formation is the one unit that becomes a veteran_soldier.</summary>+ internal static bool Promotes(Unit u) => u.Type == "recruit" && u.Side == "israel";++ /// <summary>R-UNIT-004, R-UNIT-011: the recruit <paramref name="u"/> as a veteran_soldier, keeping id, hex, service, side,+ /// strength, standing order, home, Full and combat experience, with the Why cause.</summary>+ internal static Unit Promote(Unit u, List<Cause> why)+ {+ why.Add(new Cause("city", "units", u.Strength, "Recruits became veteran soldiers", key: CauseKeys.RecruitsVeteran));+ return new Unit(u.Id, VeteranSoldier, u.Q, u.R, u.Service, u.Side, u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full, u.CombatXp);+ }++ /// <summary>The Israeli veteran infantry type the loader requires when recruits exist (R-UNIT-004).</summary>+ internal const string VeteranSoldier = "veteran_soldier";+/// <summary>R-UNIT-010: step 7 pays per Israeli military formation, including this turn's graduates. The national/// Treasury borrows a shortfall (R-MONEY-003); upkeep never consumes Arms (Q-UNIT-3).</summary>public static void PayUpkeep(Content c, GameState s, MvpRules r, List<Cause> why)diff --git a/sim/Statecraft.Sim/Movement.cs b/sim/Statecraft.Sim/Movement.csindex 5a7c140cc..169c4f1c0 100644--- a/sim/Statecraft.Sim/Movement.cs+++ b/sim/Statecraft.Sim/Movement.cs@@ -122,7 +122,7 @@ namespace Statecraft.Simstatic void Stop(GameState s, Unit u, string key, string line, string hex, List<Cause> why){- s.Units[u.Id] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, "", "", u.HomeCity, u.Full);+ s.Units[u.Id] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, "", "", u.HomeCity, u.Full, u.CombatXp);why.Add(UnitLines.Line(key, line, new[] { u }, hex));}@@ -141,7 +141,7 @@ namespace Statecraft.Simif (Closed(c, s, false).Contains((q.Value, r.Value))) return "Units may not enter an enemy-held locality before its capture is possible";if (Route(c, s, unitId, q.Value, r.Value, spent).Count == 0) return "No route reaches that hex";var target = HexText(q.Value, r.Value);- var given = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, GoTo, target, u.HomeCity, u.Full);+ var given = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, GoTo, target, u.HomeCity, u.Full, u.CombatXp);s.Units[unitId] = given;why.Add(UnitLines.Line(WhyKeys.OnItsWay, $"Unit {unitId} is on its way to hex {target}", new[] { given }, target));if (u.Order == "fortify")@@ -223,7 +223,7 @@ namespace Statecraft.Sim// is given, with the hex it names), so a unit that goes out and comes back the same turn is not fortified; hold moves with// the unit. The order step at the end of the turn only sees the final hex.var fortified = u.Order == "fortify" || u.Order == "fortifying";- s.Units[unitId] = new Unit(u.Id, u.Type, q, r, u.Service, u.Side, u.Strength, fortified ? "" : u.Order, fortified ? "" : u.OrderTarget, u.HomeCity, u.Full);+ s.Units[unitId] = new Unit(u.Id, u.Type, q, r, u.Service, u.Side, u.Strength, fortified ? "" : u.Order, fortified ? "" : u.OrderTarget, u.HomeCity, u.Full, u.CombatXp);spent[unitId] = used + cost;why.Add(new Cause("map", unitId.ToString(CultureInfo.InvariantCulture), cost,FormattableString.Invariant($"Unit {unitId} moved to hex {q},{r} for {cost} movement points"), enemy ? Kind : "",diff --git a/sim/Statecraft.Sim/Orders.cs b/sim/Statecraft.Sim/Orders.csindex 26c7d3971..df9454b6d 100644--- a/sim/Statecraft.Sim/Orders.cs+++ b/sim/Statecraft.Sim/Orders.cs@@ -33,7 +33,7 @@ namespace Statecraft.Simstatic string Hex(Unit u) => string.Format(CultureInfo.InvariantCulture, "{0},{1}", u.Q, u.R);static Unit With(Unit u, string order, string target) =>- new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, order, target, u.HomeCity, u.Full);+ new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, order, target, u.HomeCity, u.Full, u.CombatXp);/// <summary>R-ORDER-001's refusals: null when <see cref="Give"/> takes the order, else the reason shown to the player./// Changes nothing: the unit card asks it before it offers fortify or hold (#754). Refused for an unknown order ordiff --git a/sim/Statecraft.Sim/Projects.cs b/sim/Statecraft.Sim/Projects.csindex e1b52ed97..4c755fd53 100644--- a/sim/Statecraft.Sim/Projects.cs+++ b/sim/Statecraft.Sim/Projects.cs@@ -91,7 +91,7 @@ namespace Statecraft.Simif (u.Type == "halutz"){var service = u.Service + 1;- u = new Unit(u.Id, service >= r.VeteranHalutzService!.Value ? VeteranType : u.Type, u.Q, u.R, service, u.Side, u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full);+ u = new Unit(u.Id, service >= r.VeteranHalutzService!.Value ? VeteranType : u.Type, u.Q, u.R, service, u.Side, u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full, u.CombatXp);}}}@@ -235,7 +235,7 @@ namespace Statecraft.Simif (u.Type != "halutz") continue;var service = u.Service + 1;var promoted = service >= r.VeteranHalutzService!.Value;- s.Units[u.Id] = new Unit(u.Id, promoted ? VeteranType : u.Type, u.Q, u.R, service, u.Side, u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full);+ s.Units[u.Id] = new Unit(u.Id, promoted ? VeteranType : u.Type, u.Q, u.R, service, u.Side, u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full, u.CombatXp);if (promoted) why.Add(new Cause("map", w.Site, 1, "A group of halutzim became veteran pioneers", key: CauseKeys.PioneersVeteran));}Corridors.Advance(c, s, next, why); // R-COR-002: after the sites (Phase 4 PR 2)diff --git a/sim/Statecraft.Sim/SettlementControl.cs b/sim/Statecraft.Sim/SettlementControl.csindex 0724633c9..d25f61911 100644--- a/sim/Statecraft.Sim/SettlementControl.cs+++ b/sim/Statecraft.Sim/SettlementControl.cs@@ -259,7 +259,7 @@ namespace Statecraft.Simmoved.Clear();return new CaptureRefusal(CaptureRefusal.NoFreeHex, $"A unit has no free hex next to {name} to withdraw to");}- var w = new Unit(u.Id, u.Type, to.Value.Q, to.Value.R, u.Service, u.Side, u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full);+ var w = new Unit(u.Id, u.Type, to.Value.Q, to.Value.R, u.Service, u.Side, u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full, u.CombatXp);s.Units[u.Id] = w;moved.Add((u, w));}diff --git a/sim/Statecraft.Sim/Training.cs b/sim/Statecraft.Sim/Training.csindex cef30f47a..a2fc301e7 100644--- a/sim/Statecraft.Sim/Training.cs+++ b/sim/Statecraft.Sim/Training.cs@@ -225,7 +225,7 @@ namespace Statecraft.Sim// The unit keeps its type, service and order (a veteran stays one); full again, it forgets its Full.var strength = target.Strength + k.Count;s.Units[target.Id] = new Unit(target.Id, target.Type, target.Q, target.R, target.Service, target.Side, strength,- target.Order, target.OrderTarget, target.HomeCity, strength >= target.Full ? 0 : target.Full);+ target.Order, target.OrderTarget, target.HomeCity, strength >= target.Full ? 0 : target.Full, target.CombatXp);why.Add(new Cause("city", k.City, k.Count, FormattableString.Invariant($"{name}: {Groups(k.Count)} finished {Course(type)} and joined unit {target.Id}"), key: CauseKeys.ReplacementsJoined, args: new[] { CauseKeys.Number(k.Count), CourseId(type), CauseKeys.Number(target.Id) }));}else if (type.Side != "")diff --git a/sim/Statecraft.Sim/TurnResolver.cs b/sim/Statecraft.Sim/TurnResolver.csindex 1e29d2708..fba67e569 100644--- a/sim/Statecraft.Sim/TurnResolver.cs+++ b/sim/Statecraft.Sim/TurnResolver.cs@@ -20,7 +20,7 @@ namespace Statecraft.SimCombat.Resolve(c, s, why); // 2. combat, in ascending attacker id (R-COMBAT-002)SettlementControl.Capture(c, s, next, why); // 3. capture, in ordinal settlement id (R-CTRL-004, R-CTRL-005)Orders.Settle(s, why); // 3b. after combat: fortify given this turn is set, and lost where a unit left its hex (R-ORDER-002)- Military.Serve(s, r, why); // service by formations already in play, before graduation+ Military.Serve(c, s, r, why); // service by formations already in play, before graduationTraining.Progress(c, s, why); // 4. trainingProjects.Advance(c, s, next, why); // 5. constructionProjects.AdvanceCity(c, s, next, why); // and the city projects (R-PROJ-003)