A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Civ movement S1: the turn preview, points left and units that need orders (Refs #1398) (#1439)
Eyal Golanbfffff38ab6a
diff --git a/changelog.d/1398-s1.md b/changelog.d/1398-s1.mdnew file mode 100644index 000000000..6fc28ea83--- /dev/null+++ b/changelog.d/1398-s1.md@@ -0,0 +1,3 @@+- Sim groundwork for Civ-style movement (#1398): `Simulation.Preview` runs the turn's committed orders as End turn will,+ `Movement.PointsLeft` and the spent-aware `Reachable`/`Path` count the points a unit has left this turn, and+ `Movement.NeedsOrders` lists the units that still need orders (R-MOVE-010). Nothing changes on screen yet.diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex 591e5ffde..5aaf20f0f 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -186,9 +186,9 @@ R-COR-003: A corridor is complete when every one of its segments is built, in anPhase 5 PR 5 (#744). The numbers are design values this PR proposed (Q-MOVE-1, Q-MOVE-3; owner, 15 October 2026, #375: "Take all recommendations") and the owner accepted them on 19 October 2026 (https://github.com/eyalgolan/statecraft-israel/pull/1073#issuecomment-6259021508).-R-MOVE-001: Each unit type that moves has an integer `movement_points` a turn (`unit_types.yaml`; required, at least 1, on a military type; refused on a population type), and each land biome of `map/hexes.json` an integer cost to enter (`rules.yaml` `mvp.move_cost`, at least 1; the loader refuses a land biome with no cost and a cost for a water biome, so lake and sea are impassable). A path's cost is the sum of the costs of the hexes it enters. A unit's Moves in one turn share its points: a second Move has what the first left, and the next turn has them all again. A type with no movement points (the halutz types) cannot move. Real values: recruit 3 (owner, 19 October 2026, https://github.com/eyalgolan/statecraft-israel/pull/1130#issuecomment-6269103829), veteran soldier 3, artillery 2, armoured car 5; coastal plain, valley and lowland 1, hills and desert 2, mountains 3.+R-MOVE-001: Each unit type that moves has an integer `movement_points` a turn (`unit_types.yaml`; required, at least 1, on a military type; refused on a population type), and each land biome of `map/hexes.json` an integer cost to enter (`rules.yaml` `mvp.move_cost`, at least 1; the loader refuses a land biome with no cost and a cost for a water biome, so lake and sea are impassable). A path's cost is the sum of the costs of the hexes it enters. A unit's Moves in one turn share its points: a second Move has what the first left, and the next turn has them all again. The points left are the type's points less those the unit spent this turn (`Movement.PointsLeft`). A type with no movement points (the halutz types) cannot move. Real values: recruit 3 (owner, 19 October 2026, https://github.com/eyalgolan/statecraft-israel/pull/1130#issuecomment-6269103829), veteran soldier 3, artillery 2, armoured car 5; coastal plain, valley and lowland 1, hills and desert 2, mountains 3.-R-MOVE-002: `Move(unit, q, r)` takes the cheapest path, at command time (spec §2.3). Hexes leave the search in (cost, q, r) ordinal order, neighbours are tried in `tools/hexgrid.py`'s `NEIGHBOURS` order, and a hex reached again at the same cost keeps the hex it was first entered from, so of two equal paths the one through the hex first in that order wins, and the path is the same every run. `Movement.Reachable(c, s, unit)` lists the hexes a Move can end on this turn with their costs, and `Movement.Path` the hexes a path enters; both come from the same search Move uses (spec §2.6).+R-MOVE-002: `Move(unit, q, r)` takes the cheapest path, at command time (spec §2.3). Hexes leave the search in (cost, q, r) ordinal order, neighbours are tried in `tools/hexgrid.py`'s `NEIGHBOURS` order, and a hex reached again at the same cost keeps the hex it was first entered from, so of two equal paths the one through the hex first in that order wins, and the path is the same every run. `Movement.Reachable(c, s, unit, spent)` and `Movement.Path(c, s, unit, q, r, spent)` search with the points left; without `spent`, with all of them. `Movement.Reachable` lists the hexes a Move can end on this turn with their costs, and `Movement.Path` the hexes a path enters; both come from the same search Move uses (spec §2.6).R-MOVE-003: A hex holds at most `mvp.stack_limit` units of one side (Q-MOVE-3; real value 3). The limit counts the moving unit's side only and applies where a move ends; a path may pass through a full hex. A hex never holds both sides' units: entering an enemy unit's hex is an attack (Phase 5 PR 8), so Move refuses it.@@ -200,6 +200,8 @@ R-MOVE-006: `Move` is refused with the state unchanged and a reason when the uniR-MOVE-007: Roads and rail are cheaper (D-G2; Phase 5 PR 6, #745). A step into a hex from a hex of the same built corridor segment (`corridors.yaml`, R-COR-002) costs the kind's `mvp.road_move_cost` or `mvp.rail_move_cost` (at least 1; the loader requires both in the GDD loop) when that is lower than the terrain's cost; otherwise it costs the terrain's. Only the corridors Phase 4 builds count, not the 1948 roads of `map/routes_1948.yaml` (Q-MOVE-2, owner, 15 October 2026, #375: option (a)). A segment not started or still being built costs the terrain, and a step from one segment onto another costs the terrain unless both hexes lie on one built segment. Real values: road 1, rail 1, design values Phase 5 PR 6 proposes; the owner may override them. A cost of 1 saves nothing on the coastal plain, valley or lowland, which already cost 1.+R-MOVE-010: A unit needs orders when it is one of the player's military units, its type has movement points, it has neither moved nor attacked this turn, and it has no order (`fortify`, `fortifying`, `hold` and `go_to` are orders) (`Movement.NeedsOrders`, ascending id). End turn waits until no unit needs orders, apart from those the player skips this turn (the owner, 23 October 2026: "Block like Civ"; spec 2026-10-23 section 7). Skipping is not an order and changes nothing in the game.+## Standing ordersPhase 5 PR 7 (#746). Q-HOLD-1, "(a) 1 turn, free, lost on move", and Q-HOLD-2, "(a) Own hex, no interception" (owner, 15 October 2026, #375). The two percents are design values this PR proposes from avlco's option 1 on #746; the owner may override them.diff --git a/sim/Statecraft.Sim.Tests/MovementTests.cs b/sim/Statecraft.Sim.Tests/MovementTests.csindex 95f281db7..c6c314bfc 100644--- a/sim/Statecraft.Sim.Tests/MovementTests.cs+++ b/sim/Statecraft.Sim.Tests/MovementTests.cs@@ -255,6 +255,78 @@ public class MovementTestsAssert.Empty(Step(c, r.State, new Move(1, 5, 1)).Rejected);}+ // R-MOVE-002: Reachable with the turn's spent points searches with the points left (R-MOVE-001); without them, with all.+ [Fact]+ public void ReachableUsesOnlyTheMovementPointsLeftAfterAFirstMove()+ {+ var c = Plain();+ var s = With(c, Soldier(1, 0, 1));+ var spent = new Dictionary<int, int>();+ Assert.Null(Movement.Move(c, s, 1, 2, 1, spent, new List<Cause>()));++ Assert.True(Movement.Reachable(c, s, 1).ContainsKey((5, 1))); // three points from the unit's new hex+ var left = Movement.Reachable(c, s, 1, spent);+ Assert.True(left.ContainsKey((3, 1)));+ Assert.False(left.ContainsKey((4, 1))); // two points, but only one remains+ Assert.True(left.Count < Movement.Reachable(c, s, 1).Count);+ }++ // R-MOVE-002: Path with the turn's spent points finds only paths the points left can pay for.+ [Fact]+ public void PathUsesOnlyTheMovementPointsLeftAfterAFirstMove()+ {+ var c = Plain();+ var s = With(c, Soldier(1, 0, 1));+ var spent = new Dictionary<int, int>();+ Assert.Null(Movement.Move(c, s, 1, 2, 1, spent, new List<Cause>()));++ Assert.Equal(new[] { (3, 1), (4, 1) }, Movement.Path(c, s, 1, 4, 1));+ Assert.Empty(Movement.Path(c, s, 1, 4, 1, spent));+ Assert.Equal(new[] { (3, 1) }, Movement.Path(c, s, 1, 3, 1, spent));+ }++ // Spec 2026-10-23 section 3: the preview runs the same orders as Step's RunOrders and stops before the resolver.+ [Fact]+ public void PreviewRunsTheSameMoveOrdersWithoutResolvingTheTurn()+ {+ var c = Plain();+ var s = With(c, Soldier(1, 0, 1));+ Command[] commands = { new Move(1, 2, 1), new Move(1, 3, 1), new Move(1, 5, 1) };++ var preview = Simulation.Preview(c, s, commands);+ var expected = s.Clone();+ var spent = new Dictionary<int, int>();+ var why = new List<Cause>();+ Assert.Null(Movement.Move(c, expected, 1, 2, 1, spent, why));+ Assert.Null(Movement.Move(c, expected, 1, 3, 1, spent, why));+ Assert.Equal("That hex is out of reach this turn", Movement.Move(c, expected, 1, 5, 1, spent, why));++ Assert.Equal(expected.Hash(), preview.State.Hash());+ Assert.Equal(3, preview.Spent[1]);+ // Step continues through TurnResolver and the rest of the turn, so its full hash is not comparable. This fixture+ // has no enemy units, and resolution does not move the player's unit: its final position remains comparable.+ var stepped = Step(c, s, commands);+ Assert.Equal((stepped.State.Units[1].Q, stepped.State.Units[1].R),+ (preview.State.Units[1].Q, preview.State.Units[1].R));+ }++ // Spec 2026-10-23 section 3: the preview works on a clone; the turn's start state and its RNG are untouched.+ [Fact]+ public void PreviewLeavesTheInputStateAndItsRngUnchanged()+ {+ var c = Plain();+ var s = With(c, Soldier(1, 0, 1));+ s.CoalitionStability = 0.4; // below the automatic-pass threshold, so the policy vote consumes a draw+ var beforeHash = s.Hash();+ var beforeRng = s.RngState;++ var preview = Simulation.Preview(c, s, new Command[] { new SetPolicy("rationing", 0.5), new Move(1, 1, 1) });++ Assert.Equal(beforeHash, s.Hash());+ Assert.Equal(beforeRng, s.RngState);+ Assert.NotEqual(beforeRng, preview.State.RngState); // the vote consumed only the clone's draw+ }+// R-MOVE-006, Q-HOLD-1 ("lost on move"): a move that goes through clears fortify, set or given this turn, and the hex it// names, even when the unit comes back to that hex in the same turn; hold moves with the unit; a refused move changes// nothing. The order values are the standing orders' (Phase 5 PR 7, #746), written here as records.diff --git a/sim/Statecraft.Sim.Tests/TurnPreviewTests.cs b/sim/Statecraft.Sim.Tests/TurnPreviewTests.csnew file mode 100644index 000000000..b477f50dd--- /dev/null+++ b/sim/Statecraft.Sim.Tests/TurnPreviewTests.cs@@ -0,0 +1,96 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;+using Xunit;++/// <summary>Spec 2026-10-23 section 3: the screen shows Simulation.Preview(turn start, committed orders), the same RunOrders+/// Step runs (R-MOVE-001, R-MOVE-002).</summary>+public class TurnPreviewTests+{+ 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";++ internal static Content Plain() => ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>+ {+ ["unit_types.yaml"] = Types, ["map/hexes.json"] = MovementTests.Board(), ["corridors.yaml"] = "corridors: []\n"+ })));++ internal static GameState With(Content c, params Unit[] units) => CombatTests.With(c, units);+ internal static Unit Soldier(int id, int q, int r) => new Unit(id, "soldier", q, r, side: "israel", strength: 3);++ // Spec 2026-10-23 section 3: the preview's Why lines are the start of End turn's: what the player saw is what End turn ran.+ [Fact]+ public void ThePreviewsLinesStartEndTurnsLines()+ {+ var c = Plain();+ var s = With(c, Soldier(1, 0, 1));+ var orders = new Command[] { new Move(1, 1, 1), new Move(1, 2, 1) };+ var now = Simulation.Preview(c, s, orders);+ var ended = Simulation.Step(c, s, orders);+ Assert.Equal(now.Why.Select(w => w.Message), ended.Why.Take(now.Why.Count).Select(w => w.Message));+ Assert.Equal(2, now.Spent[1]);+ Assert.Empty(now.Rejected);+ }++ // Spec 2026-10-23 section 3: a refused order is in Rejected with the sim's reason, and the state is as it was.+ [Fact]+ public void ARefusedOrderIsRejectedAndChangesNothing()+ {+ var c = Plain();+ var s = With(c, Soldier(1, 0, 1));+ var now = Simulation.Preview(c, s, new Command[] { new Move(1, 5, 1) });+ Assert.Equal("That hex is out of reach this turn", Assert.Single(now.Rejected).Reason);+ Assert.Equal(s.Hash(), now.State.Hash());+ }++ // A game that is over takes no order, as Step (Simulation.cs:42-46).+ [Fact]+ public void AGameThatIsOverTakesNoOrder()+ {+ var c = Plain();+ var s = With(c, Soldier(1, 0, 1));+ s.GameOver = GameOverCodes.MvpEnded;+ var now = Simulation.Preview(c, s, new Command[] { new Move(1, 1, 1) });+ Assert.StartsWith("The game is over", Assert.Single(now.Rejected).Reason);+ }++ // Spec 2026-10-23 section 3.2: moves, go-to, attacks, fortify and hold are instant; Send home and the rest wait for End turn.+ [Fact]+ public void WhichOrdersAreInstant()+ {+ Assert.True(Simulation.IsInstant(new Move(1, 1, 1)));+ Assert.True(Simulation.IsInstant(new UnitOrder(1, Orders.Fortify)));+ Assert.True(Simulation.IsInstant(new UnitOrder(1, Orders.Hold)));+ Assert.True(Simulation.IsInstant(new UnitOrder(1, Combat.Attack, 2, 2)));+ Assert.False(Simulation.IsInstant(new UnitOrder(1, Demobilization.SendHome)));+ Assert.False(Simulation.IsInstant(new BuyArms(1)));+ Assert.False(Simulation.IsInstant(new ResolveCapture("lod", SettlementControl.Raid)));+ Assert.False(Simulation.IsInstant(new SetPolicy("rationing", 0.5)));+ }++ // R-MOVE-001: the points left are the type's less what the unit spent this turn.+ [Fact]+ public void PointsLeftCountTheTurnsMoves()+ {+ var c = Plain();+ var s = With(c, Soldier(1, 0, 1));+ var now = Simulation.Preview(c, s, new Command[] { new Move(1, 2, 1) });+ Assert.Equal(1, Movement.PointsLeft(c, now.State, 1, now.Spent));+ Assert.Equal(3, Movement.PointsLeft(c, s, 1, new Dictionary<int, int>()));+ }++ // R-MOVE-010: the player's military units with points that have neither moved nor attacked this turn and have no order.+ [Fact]+ public void NeedsOrdersListsIdleUnitsThatHaveNotMoved()+ {+ var c = Plain();+ var fortified = new Unit(3, "soldier", 4, 1, side: "israel", strength: 3, order: Orders.Fortify, orderTarget: "4,1");+ var held = new Unit(4, "soldier", 5, 1, side: "israel", strength: 3, order: Orders.Hold);+ var s = With(c, Soldier(1, 0, 1), Soldier(2, 0, 2), fortified, held,+ new Unit(5, "enemy", 5, 2, side: "egypt", strength: 3), new Unit(6, "halutz", 3, 2));+ var now = Simulation.Preview(c, s, new Command[] { new Move(2, 1, 2) });+ Assert.Equal(new[] { 1 }, Movement.NeedsOrders(c, now.State, now.Spent));+ }+}diff --git a/sim/Statecraft.Sim/Commands.cs b/sim/Statecraft.Sim/Commands.csindex c92da888a..52cea8c0a 100644--- a/sim/Statecraft.Sim/Commands.cs+++ b/sim/Statecraft.Sim/Commands.cs@@ -174,6 +174,18 @@ namespace Statecraft.Simpublic StepResult(GameState state, IReadOnlyList<Cause> why, IReadOnlyList<Rejection> rejected) { State = state; Why = why; Rejected = rejected; }}+ /// <summary>The state after the turn's committed orders (spec 2026-10-23 section 3), before End turn: what+ /// the screen shows, the movement points each unit has spent, the turn's Why lines so far and the refused orders.</summary>+ public sealed class PreviewResult+ {+ public GameState State { get; }+ public IReadOnlyDictionary<int, int> Spent { get; }+ public IReadOnlyList<Cause> Why { get; }+ public IReadOnlyList<Rejection> Rejected { get; }+ public PreviewResult(GameState state, IReadOnlyDictionary<int, int> spent, IReadOnlyList<Cause> why, IReadOnlyList<Rejection> rejected)+ { State = state; Spent = spent; Why = why; Rejected = rejected; }+ }+/// <summary>Checks that every text an order carries can be saved: a null id or a lone surrogate would make the save/// unwritable or lossy, so Step refuses the whole batch before anything happens (a programmer error, like a null Command).</summary>static class CommandTextdiff --git a/sim/Statecraft.Sim/Movement.cs b/sim/Statecraft.Sim/Movement.csindex a8e33baad..d6ebd048e 100644--- a/sim/Statecraft.Sim/Movement.cs+++ b/sim/Statecraft.Sim/Movement.cs@@ -16,22 +16,30 @@ namespace Statecraft.Sim/// is the player's.</summary>public const string PlayerSide = "israel";+ static readonly IReadOnlyDictionary<int, int> NothingSpent = new Dictionary<int, int>();+/// <summary>The six axial directions in tools/hexgrid.py's NEIGHBOURS order, the fixed order of hexes.json's layout/// (R-MOVE-002).</summary>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;- static int Points(Content c, Unit u) => c.UnitTypes.FirstOrDefault(t => t.Id == u.Type)?.MovementPoints ?? 0;+ internal static int Points(Content c, Unit u) => c.UnitTypes.FirstOrDefault(t => t.Id == u.Type)?.MovementPoints ?? 0;/// <summary>The hexes unit <paramref name="unitId"/> can move to this turn, each with its path's cost, in (q, r) order:/// what Move accepts on a turn the unit has not moved yet (R-MOVE-001 to R-MOVE-005). Empty for an unknown unit, an/// enemy unit or one that cannot move.</summary>- public static IReadOnlyDictionary<(int Q, int R), int> Reachable(Content c, GameState s, int unitId)+ public static IReadOnlyDictionary<(int Q, int R), int> Reachable(Content c, GameState s, int unitId) =>+ Reachable(c, s, unitId, NothingSpent);++ /// <summary>The hexes unit <paramref name="unitId"/> can move to with the points left after <paramref name="spent"/>,+ /// each with its path's cost, in (q, r) order. Empty for an unknown unit, an enemy unit or one that cannot move.</summary>+ public static IReadOnlyDictionary<(int Q, int R), int> Reachable(Content c, GameState s, int unitId, IReadOnlyDictionary<int, int> spent){var result = new SortedDictionary<(int Q, int R), int>();if (!s.Units.TryGetValue(unitId, out var u) || IsEnemy(u)) return result;- var (dist, _) = Search(c, s, u, Points(c, u));+ spent.TryGetValue(unitId, out var used);+ var (dist, _) = Search(c, s, u, Points(c, u) - used);foreach (var kv in dist)if (kv.Key != (u.Q, u.R) && Full(c, s, u, kv.Key.Q, kv.Key.R) == null) result[kv.Key] = kv.Value;return result;@@ -39,17 +47,39 @@ namespace Statecraft.Sim/// <summary>The hexes the unit's cheapest path to (<paramref name="q"/>, <paramref name="r"/>) enters, in order, within/// this turn's movement points (R-MOVE-002); empty when the hex is out of reach.</summary>- public static IReadOnlyList<(int Q, int R)> Path(Content c, GameState s, int unitId, int q, int r)+ public static IReadOnlyList<(int Q, int R)> Path(Content c, GameState s, int unitId, int q, int r) =>+ Path(c, s, unitId, q, r, NothingSpent);++ /// <summary>The hexes the unit's cheapest path to (<paramref name="q"/>, <paramref name="r"/>) enters, in order, within+ /// the points left after <paramref name="spent"/>; empty when the hex is out of reach.</summary>+ public static IReadOnlyList<(int Q, int R)> Path(Content c, GameState s, int unitId, int q, int r, IReadOnlyDictionary<int, int> spent){- if (!Reachable(c, s, unitId).ContainsKey((q, r))) return Array.Empty<(int, int)>();+ if (!Reachable(c, s, unitId, spent).ContainsKey((q, r))) return Array.Empty<(int, int)>();var u = s.Units[unitId];- var (_, prev) = Search(c, s, u, Points(c, u));+ spent.TryGetValue(unitId, out var used);+ var (_, prev) = Search(c, s, u, Points(c, u) - used);var path = new List<(int Q, int R)>();for (var h = (q, r); h != (u.Q, u.R); h = prev[h]) path.Add(h);path.Reverse();return path;}+ /// <summary>R-MOVE-001: the movement points unit <paramref name="unitId"/> has left this turn; 0 for an unknown unit.</summary>+ public static int PointsLeft(Content c, GameState s, int unitId, IReadOnlyDictionary<int, int> spent)+ {+ if (!s.Units.TryGetValue(unitId, out var u)) return 0;+ spent.TryGetValue(unitId, out var used);+ return Math.Max(0, Points(c, u) - used);+ }++ /// <summary>R-MOVE-010: the player's military units, in ascending id, that have movement points, have neither moved nor+ /// attacked this turn (nothing in <paramref name="spent"/>) and have no order (fortify, fortifying, hold and go-to are+ /// orders). End turn waits for them (spec 2026-10-23 section 7); Skip is the UI's and not in the sim.</summary>+ public static IReadOnlyList<int> NeedsOrders(Content c, GameState s, IReadOnlyDictionary<int, int> spent) =>+ s.Units.Values.Where(u => u.Side == PlayerSide && Points(c, u) > 0 && u.Order == ""+ && !(spent.TryGetValue(u.Id, out var used) && used > 0))+ .Select(u => u.Id).ToList();+/// <summary>R-MOVE-006: moves the unit, spending the path's cost from what <paramref name="spent"/> says it has used this/// turn (R-MOVE-001). Refused, state untouched, for an unknown or enemy unit, one that cannot move or is already there,/// water or a hex off the map, an enemy unit's hex (entering it is an attack, Q-MOVE-3), an enemy-held locality thatdiff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.csindex b9afd0399..90fc1a93f 100644--- a/sim/Statecraft.Sim/Simulation.cs+++ b/sim/Statecraft.Sim/Simulation.cs@@ -45,7 +45,7 @@ namespace Statecraft.Simreturn new StepResult(s, why, rejected);}- RunOrders(c, s, commands, why, rejected);+ RunOrders(c, s, commands, new Dictionary<int, int>(), why, rejected);EventSystem.Delegate(c, s, why);var len = SecuritySystem.TurnLengthFor(c, s.Date, s.Rung);@@ -91,16 +91,37 @@ namespace Statecraft.Simif (commands.Any(x => x == null)) throw new ArgumentException("Commands cannot contain null.", nameof(commands));CommandText.Validate(commands);var s = state.Clone();- if (s.GameOver == null) RunOrders(c, s, commands, new List<Cause>(), new List<Rejection>());+ if (s.GameOver == null) RunOrders(c, s, commands, new Dictionary<int, int>(), new List<Cause>(), new List<Rejection>());return EventSystem.DelegatedTo(c, s, c.Events.First(e => e.Id == eventId));}+ /// <summary>The state after <paramref name="commands"/> run as End turn would run them first (spec 2026-10-23 section 3;+ /// RunOrders, shared with Step), on a clone. Never mutates <paramref name="state"/>.</summary>+ public static PreviewResult Preview(Content c, GameState state, IReadOnlyList<Command> commands)+ {+ if (c == null) throw new ArgumentNullException(nameof(c));+ if (state == null) throw new ArgumentNullException(nameof(state));+ if (commands == null) throw new ArgumentNullException(nameof(commands));+ if (commands.Any(x => x == null)) throw new ArgumentException("Commands cannot contain null.", nameof(commands));+ CommandText.Validate(commands);+ var s = state.Clone();+ var why = new List<Cause>(); var rejected = new List<Rejection>(); var spent = new Dictionary<int, int>();+ if (s.GameOver != null)+ foreach (var cmd in commands) rejected.Add(new Rejection(cmd, $"The game is over: {PlayerText.GameOver(s.GameOver)}"));+ else RunOrders(c, s, commands, spent, why, rejected);+ return new PreviewResult(s, spent, why, rejected);+ }++ /// <summary>A move, a go-to, an attack, fortify or hold takes effect at once; Send home and every other order waits+ /// for End turn (spec 2026-10-23 section 3.2).</summary>+ public static bool IsInstant(Command cmd) => cmd is Move || (cmd is UnitOrder o && o.Order != Demobilization.SendHome);+/// <summary>The turn's orders in order: each pays Attention first; one that fails validation is refunded and- /// rejected with its reason. Step and DelegatedTo share it, so the dry run sees what End Turn will.</summary>- static void RunOrders(Content c, GameState s, IReadOnlyList<Command> commands, List<Cause> why, List<Rejection> rejected)+ /// rejected with its reason. Step, DelegatedTo and Preview share it, so every dry run sees what End Turn will.</summary>+ static void RunOrders(Content c, GameState s, IReadOnlyList<Command> commands, Dictionary<int, int> spent,+ List<Cause> why, List<Rejection> rejected){var priceRung = s.Rung; // every command this turn is priced at the rung the turn started at- var spent = new Dictionary<int, int>(); // movement points each unit has used this turn (R-MOVE-001)foreach (var cmd in commands){if (!AttentionSystem.IsCommandKind(cmd.Kind)) { rejected.Add(new Rejection(cmd, "That order is not known")); continue; }