Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

sim: unit movement, Move and the Reachable preview (GDD Phase 5 PR 5, R-MOVE-001 to R-MOVE-006; fixes #744) (#1073)

Beric1cc8c3ce4fd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ffc6bc6df..00f71fcfe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -83,6 +83,14 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
- The Cabinet, Budget, Defence, Why, How to play and Settings screens each gain an X in the header that closes
them (the same close as Escape): a phone has no Escape key, and re-tapping the lit rail button was the only way
out (v0.1.1 playtest feedback).
+- Unit movement (GDD Phase 5 PR 5): `Move(unit, q, r)` moves a player unit at command time along the cheapest path
+ within the movement points it has left this turn, and `Movement.Reachable` and `Movement.Path` give the preview.
+ Movement points per military type and a cost per land biome are owner-accepted design values (Q-MOVE-1, 19 October 2026); lake and sea are
+ impassable; a hex holds at most three units of a side (Q-MOVE-3); no zone of control, and no entry to an enemy unit's
+ hex or to an enemy-held locality (Q-MOVE-4, Q-CIV-1; the list is an owner-accepted draft: acre, nazareth, lod, ramla, gaza, beersheba, unchecked until research task #1096). Orders are free (D-A6).
+ A Move that goes through clears fortify (set or given this turn) at once, even out and back to the same hex; hold
+ moves with the unit (Q-HOLD-1).
+ No golden moves: nothing issues a Move yet (R-MOVE-001 to R-MOVE-006; fixes #744, refs #385).
- The national Arms pool in the GDD loop (R-ARMS-001 to R-ARMS-003; fixes #781): one Arms is the equipment package for a
1,000-person recruit group, and the state holds 12 on 15 May 1948. A `BuyArms(count)` order pays IL 1m an Arms,
borrows a short Treasury and costs 1 Attention whatever the count; recruit training takes 1 Arms a group when it
diff --git a/content/rules.yaml b/content/rules.yaml
index 467908968..7eeb86694 100644
--- a/content/rules.yaml
+++ b/content/rules.yaml
@@ -20,6 +20,7 @@ attention_cost:
unit_order: 0 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6: unit orders are free; R-ORDER-001, #746)
start_project: 1 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6, D-C5, Q-PROJ-5: the map action's cost)
cancel_project: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6, D-C5, Q-PROJ-5: cancel_training's cost)
+ move: 0 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6: unit orders are free)
buy_arms: 1 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6, D-G6, #781: one order, whatever the quantity)
# Turn length on each security rung, rungs 1 to 5 (R-TURN-001). The GDD MVP plays monthly turns on every rung (D-B1), so
# turns from 15 May 1948 end on the 15th of each month.
@@ -126,6 +127,23 @@ mvp:
# the deputies 5 as a neutral rating, so neutral is not disloyal. Agent-proposed; the owner may override them.
delegation_loyalty_floor: 5 # DESIGN VALUE: owner-set balance, not a historical figure (D-H1, #107: loyalty below which a delegated decision is half-done)
disloyal_effect_share: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-H1, #107: share of each numeric effect a disloyal minister delivers)
+ # Movement (R-MOVE-001, R-MOVE-003; Q-MOVE-1, Q-MOVE-3, owner, 15 October 2026, #375: "Take all recommendations").
+ # The numbers below were proposed in PR #1073 (#744) and accepted by the owner as design values on 19 October 2026:
+ # https://github.com/eyalgolan/statecraft-israel/pull/1073#issuecomment-6259021508
+ # The smallest integer spread that separates the plain from the hills from the mountains; lake and sea have no cost,
+ # so they are impassable. Three units of a side per hex: a brigade of battalion-size formations.
+ move_cost:
+ coastal_plain: 1 # DESIGN VALUE: owner-set balance, not a historical figure (D-G2, Q-MOVE-1: movement points to enter the hex)
+ valley: 1 # DESIGN VALUE: owner-set balance, not a historical figure (D-G2, Q-MOVE-1: movement points to enter the hex)
+ lowland: 1 # DESIGN VALUE: owner-set balance, not a historical figure (D-G2, Q-MOVE-1: movement points to enter the hex)
+ hills: 2 # DESIGN VALUE: owner-set balance, not a historical figure (D-G2, Q-MOVE-1: movement points to enter the hex)
+ desert: 2 # DESIGN VALUE: owner-set balance, not a historical figure (D-G2, Q-MOVE-1: movement points to enter the hex)
+ mountains: 3 # DESIGN VALUE: owner-set balance, not a historical figure (D-G2, Q-MOVE-1: movement points to enter the hex)
+ stack_limit: 3 # DESIGN VALUE: owner-set balance, not a historical figure (D-G2, Q-MOVE-3: units of one side a hex holds)
+ # R-MOVE-005 (Q-CIV-1, owner, 15 October 2026: "No entry until Phase 6"): the settlements no player unit may enter or
+ # 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]
# 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.06
diff --git a/content/unit_types.yaml b/content/unit_types.yaml
index 88753bce2..c11315e4a 100644
--- a/content/unit_types.yaml
+++ b/content/unit_types.yaml
@@ -22,8 +22,23 @@ types:
training_turns: 3 # DESIGN VALUE: owner-set balance, not a historical figure (D-A3, D-D4: Q-CRAFT-3)
training_cost: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-A3, D-D4: Q-CRAFT-3, IL millions per group)
# Phase 5's military types (R-UNIT-001; Q-UNIT-1, owner, 15 October 2026; #741, owner, 18 October 2026: "all defaults").
-# A side and a class only: movement points come with movement (Phase 5 PR 5), strength from the unit's sourced row or
-# its cohort (Q-UNIT-4) and upkeep with Phase 5 PR 3. The recruit stays a count per city until PR 3; the enemy types come in PR 4.
- - { id: veteran_soldier, kind: unit, side: israel, class: infantry }
- - { id: artillery, kind: unit, side: israel, class: artillery }
- - { id: armoured_car, kind: unit, side: israel, class: armour }
+# A side, a class and movement points (Phase 5 PR 5, R-MOVE-001); strength comes from the unit's sourced row or its cohort
+# (Q-UNIT-4) and upkeep with Phase 5 PR 3. The recruit stays a count per city until PR 3; the enemy types come in PR 4.
+# Movement points were proposed in PR #1073 (#744; Q-MOVE-1, owner, 15 October 2026: "Take all recommendations") and
+# accepted by the owner as design values on 19 October 2026 (https://github.com/eyalgolan/statecraft-israel/pull/1073#issuecomment-6259021508). At about 8.7 km between hex centres, 3 plain hexes is about 26 km a monthly turn, an operational pace; the
+# armoured car carries more (Q-ARTY-2) and the guns fewer.
+ - id: veteran_soldier
+ kind: unit
+ side: israel
+ class: infantry
+ movement_points: 3 # DESIGN VALUE: owner-set balance, not a historical figure (D-G2, Q-MOVE-1: points a turn)
+ - id: artillery
+ kind: unit
+ side: israel
+ class: artillery
+ movement_points: 2 # DESIGN VALUE: owner-set balance, not a historical figure (D-G2, Q-MOVE-1: points a turn)
+ - id: armoured_car
+ kind: unit
+ side: israel
+ class: armour
+ movement_points: 5 # DESIGN VALUE: owner-set balance, not a historical figure (D-G2, Q-MOVE-1, Q-ARTY-2: points a turn)
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 2bb6b0692..e819531da 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -142,6 +142,22 @@ R-UNIT-001: A military unit is a group at formation scale, one token per formati
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), so a halutz unit's hash text, and every golden, is unchanged.
+## Movement
+
+Phase 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: 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-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.
+
+R-MOVE-004: There is no zone of control (Q-MOVE-4): a unit passes next to an enemy unit at the terrain's cost, but no path enters or passes through an enemy unit's hex. Units may enter any land hex on the board; the 1948 control layer stays display-only. There is no transport (Q-MOVE-5).
+
+R-MOVE-005: Before Phase 6 a player unit cannot enter the hex of an enemy-held locality, and no path passes through one (Q-CIV-1, owner, 15 October 2026: "No entry until Phase 6"). The localities are the settlements listed in `rules.yaml` `mvp.enemy_held_localities` (`settlements_1948.yaml` ids; the loader refuses an unknown one). The real list is the owner-accepted DRAFT (19 October 2026, https://github.com/eyalgolan/statecraft-israel/pull/1073#issuecomment-6259083180): acre, nazareth, lod, ramla, gaza, beersheba. It is unchecked: no person has yet checked each place's control on 15 May 1948; research task #1096 will check it.
+
+R-MOVE-006: `Move` is refused with the state unchanged and a reason when the unit does not exist, is not the player's (a unit of a side other than Israel), cannot move or is already on the hex, when the hex is water or off the board, holds an enemy unit, is an enemy-held locality or is full of the unit's side, or when no path reaches it within the points the unit has left this turn. It costs no Attention (D-A6). A Move that goes through clears a fortify order (`fortify`, or `fortifying` the turn it is given) and the hex it names at once, so a unit that leaves its hex and comes back in the same turn is not fortified (Q-HOLD-1, "lost on move"); hold moves with the unit; a refused Move changes nothing.
+
## Standing orders
Phase 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/CommandGuardTests.cs b/sim/Statecraft.Sim.Tests/CommandGuardTests.cs
index 6a36cc651..a35cb8659 100644
--- a/sim/Statecraft.Sim.Tests/CommandGuardTests.cs
+++ b/sim/Statecraft.Sim.Tests/CommandGuardTests.cs
@@ -26,6 +26,7 @@ public class CommandGuardTests
[typeof(UnitOrder)] = new UnitOrder(1, "fortify"),
[typeof(StartProject)] = new StartProject("housing", "tel_aviv", 1, 0),
[typeof(CancelProject)] = new CancelProject(1),
+ [typeof(Move)] = new Move(1, 2, 0),
[typeof(BuyArms)] = new BuyArms(0), // refused (fewer than one unit), as GovernmentTests.ARefusedGddOrderRefundsItsAttention needs
};
diff --git a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs
index cec5cf1f6..d5c7e2bff 100644
--- a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs
+++ b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs
@@ -125,6 +125,18 @@ public class DesignValuesTests
("projects.yaml", "projects[industry].capacity"),
("projects.yaml", "projects[industry].condition"),
("projects.yaml", "projects[industry].job_slots"),
+ // Movement (Phase 5 PR 5, #744; Q-MOVE-1, Q-MOVE-3): agent-proposed under "Take all recommendations" (#375).
+ ("rules.yaml", "attention_cost.move"),
+ ("rules.yaml", "mvp.move_cost.coastal_plain"),
+ ("rules.yaml", "mvp.move_cost.valley"),
+ ("rules.yaml", "mvp.move_cost.lowland"),
+ ("rules.yaml", "mvp.move_cost.hills"),
+ ("rules.yaml", "mvp.move_cost.desert"),
+ ("rules.yaml", "mvp.move_cost.mountains"),
+ ("rules.yaml", "mvp.stack_limit"),
+ ("unit_types.yaml", "types[veteran_soldier].movement_points"),
+ ("unit_types.yaml", "types[artillery].movement_points"),
+ ("unit_types.yaml", "types[armoured_car].movement_points"),
// The national Arms pool (Phase 2 PR 3b; #781, owner 18 October 2026: "Approve as drafted").
("rules.yaml", "attention_cost.buy_arms"),
("rules.yaml", "mvp.arms_start"),
diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.cs
index 044a0a46b..7f20c1a1d 100644
--- a/sim/Statecraft.Sim.Tests/Fixture.cs
+++ b/sim/Statecraft.Sim.Tests/Fixture.cs
@@ -240,7 +240,7 @@ series:
}
/// <summary>The fixture's attention_cost line with the GDD command kinds added (replaces "map_action: 1 }").</summary>
- public const string GddCosts = "map_action: 1, assign_workers: 1, train: 1, cancel_training: 1, pioneer_work: 0, stop_work: 0, unit_order: 0, start_project: 1, cancel_project: 0.5, buy_arms: 1 }";
+ public const string GddCosts = "map_action: 1, assign_workers: 1, train: 1, cancel_training: 1, pioneer_work: 0, stop_work: 0, start_project: 1, cancel_project: 0.5, buy_arms: 1, move: 0, unit_order: 0 }";
public const string GddRules = @"
mvp:
@@ -281,6 +281,9 @@ mvp:
hold_defence_percent: 120
delegation_loyalty_floor: 5
disloyal_effect_share: 0.5
+ move_cost: { coastal_plain: 1, hills: 2, desert: 3 }
+ stack_limit: 2
+ enemy_held_localities: []
";
public static readonly string GddCities = "\ncities:\n" + City("town_a", 12, 8, 10, 6, "[military_camp, hakhshara]");
diff --git a/sim/Statecraft.Sim.Tests/MilitaryUnitTests.cs b/sim/Statecraft.Sim.Tests/MilitaryUnitTests.cs
index 32a9ab346..d5b8c8630 100644
--- a/sim/Statecraft.Sim.Tests/MilitaryUnitTests.cs
+++ b/sim/Statecraft.Sim.Tests/MilitaryUnitTests.cs
@@ -59,7 +59,7 @@ public class MilitaryUnitTests
[Fact]
public void AMilitaryTypeLoadsAndAPopulationTypeNeedsNeither()
{
- var c = Load(Fixture.GddUnitTypes + " - { id: soldier, kind: unit, side: egypt, class: armour }\n");
+ var c = Load(Fixture.GddUnitTypes + " - { id: soldier, kind: unit, side: egypt, class: armour, movement_points: 4 }\n");
var t = c.UnitTypes.Single(x => x.Id == "soldier");
Assert.Equal(("egypt", "armour"), (t.Side, t.Class));
Assert.Equal(("", ""), (c.UnitTypes.Single(x => x.Id == "civilian").Side, c.UnitTypes.Single(x => x.Id == "civilian").Class));
diff --git a/sim/Statecraft.Sim.Tests/MovementTests.cs b/sim/Statecraft.Sim.Tests/MovementTests.cs
new file mode 100644
index 000000000..5724f6f47
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/MovementTests.cs
@@ -0,0 +1,312 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Globalization;
+using System.Linq;
+using Statecraft.Sim;
+using Xunit.Abstractions;
+
+/// <summary>Movement (GDD Phase 5 PR 5, #744): Move(unit, q, r) and the Reachable preview. Q-MOVE-1, Q-MOVE-3, Q-MOVE-4 and
+/// Q-MOVE-5 are the plan's recommendations, taken by the owner on 15 October 2026 ("Take all recommendations", #375); Q-CIV-1
+/// is the owner's "No entry until Phase 6". The fixture's numbers are fixture values: coastal plain 1, hills 2, desert 3,
+/// two units of a side per hex, and a soldier with 3 movement points.</summary>
+public class MovementTests
+{
+ readonly ITestOutputHelper _out;
+ public MovementTests(ITestOutputHelper output) { _out = output; }
+
+ /// <summary>A soldier, an Egyptian unit (an enemy side) and the fixture's halutz types.</summary>
+ 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";
+
+ /// <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)
+ {
+ var rows = new List<string>();
+ for (int r = 0; r < 3; r++)
+ for (int q = 0; q < 6; q++)
+ {
+ var b = biomes.Where(x => x.Q == q && x.R == r).Select(x => x.Biome).DefaultIfEmpty("coastal_plain").First();
+ var land = b != "sea" && b != "lake";
+ rows.Add(FormattableString.Invariant($"{{\"q\":{q},\"r\":{r},\"lon\":{34.3 + 0.1 * q},\"lat\":{33.3 - 0.1 * r},\"elev_m\":0.0,\"land\":{(land ? "true" : "false")},\"biome\":\"{b}\"}}"));
+ }
+ return "{\"attribution\":[\"test\"],\"bounds\":{\"lon0\":34.2,\"lon1\":35.9,\"lat0\":29.45,\"lat1\":33.35},\"hex_size_km\":5.0,\"layout\":\"pointy\",\"hexes\":[\n"
+ + string.Join(",\n", rows) + "]}\n";
+ }
+
+ static Content Load(string board, params (string From, string To)[] edits)
+ {
+ var files = Fixture.Gdd(new Dictionary<string, string> { ["unit_types.yaml"] = Types, ["map/hexes.json"] = board });
+ foreach (var (from, to) in edits) files["rules.yaml"] = files["rules.yaml"].Replace(from, to);
+ return ContentLoader.Load(Fixture.Write(files));
+ }
+
+ static Content Plain(params (string From, string To)[] edits) => Load(Board(), edits);
+
+ /// <summary>A new game with each of <paramref name="units"/> added in the order given.</summary>
+ 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;
+ }
+
+ static Unit Soldier(int id, int q, int r) => new Unit(id, "soldier", q, r, side: "israel");
+ static Unit Enemy(int id, int q, int r) => new Unit(id, "enemy", q, r, side: "egypt");
+
+ static StepResult Step(Content c, GameState s, params Command[] commands) => Simulation.Step(c, s, commands);
+
+ // R-MOVE-001: the cost of entering one hex is its biome's.
+ [Theory]
+ [InlineData("coastal_plain", 1)]
+ [InlineData("hills", 2)]
+ [InlineData("desert", 3)]
+ public void TerrainCosts(string biome, int cost)
+ {
+ var c = Load(Board((3, 1, biome)));
+ var s = With(c, Soldier(1, 2, 1));
+ Assert.Equal(cost, Movement.Reachable(c, s, 1)[(3, 1)]);
+ }
+
+ // R-MOVE-001: the real game's numbers, design values this PR proposes (Q-MOVE-1): one cost per land biome of hexes.json,
+ // none for lake and sea, and the movement points of the three military types.
+ [Fact]
+ public void TheRealGameHasACostForEveryLandBiomeAndPointsForEveryMilitaryType()
+ {
+ var c = ContentLoader.Load(RealContentTests.ContentRoot());
+ var costs = c.Rules.Mvp!.MoveCost;
+ Assert.Equal(new SortedDictionary<string, int> { ["coastal_plain"] = 1, ["desert"] = 2, ["hills"] = 2, ["lowland"] = 1, ["mountains"] = 3, ["valley"] = 1 },
+ new SortedDictionary<string, int>(costs));
+ Assert.Equal(new SortedSet<string>(costs.Keys), new SortedSet<string>(c.Hexes.Where(h => h.Land).Select(h => h.Biome)));
+ Assert.DoesNotContain(c.Hexes, h => h.Land && (h.Biome == "sea" || h.Biome == "lake"));
+ Assert.Equal(new[] { ("veteran_soldier", 3), ("artillery", 2), ("armoured_car", 5) },
+ c.UnitTypes.Where(t => t.Side != "").Select(t => (t.Id, t.MovementPoints)));
+ }
+
+ // R-MOVE-001: a path's cost is the sum of the hexes it enters, not of the one it leaves.
+ [Fact]
+ public void APathCostsTheSumOfTheHexesItEnters()
+ {
+ var c = Load(Board((0, 1, "desert"), (1, 1, "hills")));
+ var s = With(c, Soldier(1, 0, 1));
+ var reach = Movement.Reachable(c, s, 1);
+ Assert.Equal(2, reach[(1, 1)]); // hills; leaving the desert costs nothing
+ Assert.Equal(3, reach[(2, 1)]); // hills then coastal plain, or three plain hexes: both 3
+ Assert.Equal(new[] { (1, 1), (2, 1) }, Movement.Path(c, s, 1, 2, 1)); // (1, 1) comes first in (cost, q, r) order
+ Assert.False(reach.ContainsKey((0, 1))); // the unit's own hex is not a move
+ }
+
+ // R-MOVE-002: the same state, built twice and with its units added in another order, gives the same path and preview.
+ [Fact]
+ public void ThePathIsTheSameEveryRun()
+ {
+ var c = Load(Board((2, 1, "hills"), (3, 0, "desert")));
+ var a = With(c, Soldier(1, 0, 1), Soldier(2, 1, 2), Enemy(3, 2, 2));
+ var b = With(c, Enemy(3, 2, 2), Soldier(2, 1, 2), Soldier(1, 0, 1));
+ Assert.Equal(a.Hash(), b.Hash());
+ var path = Movement.Path(c, a, 1, 2, 1);
+ Assert.NotEmpty(path);
+ Assert.Equal(path, Movement.Path(c, b, 1, 2, 1));
+ Assert.Equal(path, Movement.Path(c, a, 1, 2, 1));
+ Assert.Equal(Movement.Reachable(c, a, 1).ToList(), Movement.Reachable(c, b, 1).ToList());
+ Assert.Equal(Step(c, a, new Move(1, 2, 1)).State.Hash(), Step(c, b, new Move(1, 2, 1)).State.Hash());
+ }
+
+ // R-MOVE-002: of two paths of equal cost, a hex is reached from the neighbour that comes first in (cost, q, r) order:
+ // (0, 1) to (2, 0) goes by (1, 0), not by (1, 1) (r decides); (0, 1) to (1, 2) goes by (0, 2), not by (1, 1) (q decides);
+ // and (2, 1) to (0, 2) goes by (1, 1), not by (1, 2).
+ [Fact]
+ public void EqualCostPathsBreakTiesByTheStatedOrder()
+ {
+ var c = Plain();
+ var s = With(c, Soldier(1, 0, 1), Soldier(2, 2, 1));
+ Assert.Equal(new[] { (1, 0), (2, 0) }, Movement.Path(c, s, 1, 2, 0));
+ Assert.Equal(new[] { (0, 2), (1, 2) }, Movement.Path(c, s, 1, 1, 2));
+ Assert.Equal(new[] { (1, 1), (0, 2) }, Movement.Path(c, s, 2, 0, 2));
+ }
+
+ // R-MOVE-003: a hex holds at most stack_limit units of one side; a full hex is refused as a target and not previewed,
+ // and a path may still pass through it.
+ [Fact]
+ public void StackingLimit()
+ {
+ var c = Load(Board((0, 1, "sea"), (1, 1, "sea"), (2, 1, "sea")));
+ // With row 1 at sea, (0, 2) - (1, 2) - (2, 2) is a corridor; two soldiers hold (1, 2), the limit.
+ var s = With(c, Soldier(1, 0, 2), Soldier(2, 1, 2), Soldier(3, 1, 2));
+ Assert.False(Movement.Reachable(c, s, 1).ContainsKey((1, 2)));
+ var r = Step(c, s, new Move(1, 1, 2));
+ Assert.Equal("That hex already holds 2 units of that side, the most one hex can hold", Assert.Single(r.Rejected).Reason);
+ Assert.Equal((0, 2), (r.State.Units[1].Q, r.State.Units[1].R));
+ Assert.Equal(new[] { (1, 2), (2, 2) }, Movement.Path(c, s, 1, 2, 2)); // passing through is not stacking
+ Assert.Empty(Step(c, s, new Move(1, 2, 2)).Rejected);
+ var one = With(c, Soldier(1, 0, 2), Soldier(2, 1, 2));
+ var moved = Step(c, one, new Move(1, 1, 2));
+ Assert.Empty(moved.Rejected);
+ Assert.Equal((1, 2), (moved.State.Units[1].Q, moved.State.Units[1].R));
+ // Only the unit's own side counts: two halutzim (no side) on the hex leave room for soldiers.
+ Assert.True(Movement.Reachable(c, With(c, Soldier(1, 0, 2), new Unit(2, "halutz", 1, 2), new Unit(3, "halutz", 1, 2)), 1).ContainsKey((1, 2)));
+ }
+
+ // R-MOVE-004: no zone of control, so a unit passes next to an enemy at the terrain's cost; it never enters or passes
+ // through an enemy unit's hex (entering one is an attack, Q-MOVE-3).
+ [Fact]
+ public void EnemyGround()
+ {
+ var c = Plain();
+ var s = With(c, Soldier(1, 0, 1), Enemy(2, 2, 1));
+ var reach = Movement.Reachable(c, s, 1);
+ Assert.False(reach.ContainsKey((2, 1)));
+ Assert.Equal(1, reach[(1, 1)]); // next to the enemy, at the plain's cost
+ Assert.Equal(new[] { (1, 0), (2, 0), (3, 0) }, Movement.Path(c, s, 1, 3, 0)); // past it, not through it
+ Assert.False(reach.ContainsKey((3, 1))); // the straight line runs through it, and the way round costs 4
+ var r = Step(c, s, new Move(1, 2, 1));
+ Assert.Equal("An enemy unit holds that hex", Assert.Single(r.Rejected).Reason);
+ Assert.Equal((0, 1), (r.State.Units[1].Q, r.State.Units[1].R));
+ }
+
+ // R-MOVE-005 (Q-CIV-1, "No entry until Phase 6"): a player unit cannot enter the hex of a locality listed in
+ // mvp.enemy_held_localities, and no path passes through one. The real list is the owner-accepted DRAFT (19 October 2026,
+ // #1073): unchecked until research task #1096 checks each place's 15 May 1948 control.
+ [Fact]
+ public void NoEntryToEnemyHeldLocalities()
+ {
+ var c = Plain(("enemy_held_localities: []", "enemy_held_localities: [town_a]"));
+ var s = With(c, Soldier(1, 0, 0));
+ var reach = Movement.Reachable(c, s, 1);
+ Assert.False(reach.ContainsKey((1, 0)));
+ Assert.Equal(3, reach[(2, 0)]); // around town_a's hex, by (0, 1) and (1, 1), not through it for 2
+ Assert.DoesNotContain((1, 0), Movement.Path(c, s, 1, 2, 0));
+ var r = Step(c, s, new Move(1, 1, 0));
+ Assert.Equal("Units may not enter an enemy-held locality before its capture is possible", Assert.Single(r.Rejected).Reason);
+ Assert.Equal((0, 0), (r.State.Units[1].Q, r.State.Units[1].R));
+ var real = ContentLoader.Load(RealContentTests.ContentRoot());
+ var draft = real.Rules.Mvp!.EnemyHeldLocalities;
+ Assert.Equal(new[] { "acre", "nazareth", "lod", "ramla", "gaza", "beersheba" }, draft);
+ Assert.All(draft, id => Assert.Contains(real.SettlementHexes, h => h.Id == id));
+ }
+
+ // R-MOVE-006 and the preview: every hex Reachable lists can be reached with Move, at the listed cost, and no other hex
+ // can, on a board with water, terrain, an enemy, a full hex and an enemy-held locality.
+ [Fact]
+ public void ReachableMatchesMove()
+ {
+ var c = Load(Board((2, 1, "hills"), (3, 1, "desert"), (4, 0, "sea"), (0, 2, "lake"), (3, 2, "hills")),
+ ("enemy_held_localities: []", "enemy_held_localities: [town_a]"));
+ var s = With(c, Soldier(1, 1, 1), Enemy(2, 3, 0), Soldier(3, 2, 2), Soldier(4, 2, 2));
+ var reach = Movement.Reachable(c, s, 1);
+ Assert.NotEmpty(reach);
+ foreach (var h in c.Hexes)
+ {
+ var r = Step(c, s, new Move(1, h.Q, h.R));
+ if (reach.ContainsKey((h.Q, h.R)))
+ {
+ Assert.Empty(r.Rejected);
+ Assert.Equal((h.Q, h.R), (r.State.Units[1].Q, r.State.Units[1].R));
+ }
+ else
+ {
+ Assert.Single(r.Rejected);
+ Assert.Equal((1, 1), (r.State.Units[1].Q, r.State.Units[1].R));
+ }
+ }
+ }
+
+ // R-MOVE-006: refused with the state unchanged, with the reason, for each case.
+ [Theory]
+ [InlineData(9, 2, 1, "There is no such unit")]
+ [InlineData(2, 3, 1, "That unit is not yours")]
+ [InlineData(3, 1, 1, "That unit cannot move")]
+ [InlineData(1, 0, 1, "That unit is already there")]
+ [InlineData(1, 0, 0, "Units cannot enter water or leave the map")]
+ [InlineData(1, 9, 9, "Units cannot enter water or leave the map")]
+ [InlineData(1, 5, 1, "That hex is out of reach this turn")]
+ public void AMoveThatBreaksARuleIsRefusedWithTheStateUnchanged(int unit, int q, int r, string reason)
+ {
+ var c = Load(Board((0, 0, "sea")));
+ var s = With(c, Soldier(1, 0, 1), Enemy(2, 4, 2), new Unit(3, "halutz", 1, 2));
+ var before = Step(c, s).State.Hash();
+ var result = Step(c, s, new Move(unit, q, r));
+ Assert.Equal(reason, Assert.Single(result.Rejected).Reason);
+ Assert.Equal(before, result.State.Hash());
+ }
+
+ // R-MOVE-001: the allowance is per turn. A second Move of the same unit in one turn has only what the first left, and
+ // the next turn has the full allowance again.
+ [Fact]
+ public void MovementPointsArePerTurn()
+ {
+ var c = Plain();
+ var s = With(c, Soldier(1, 0, 1));
+ var r = Step(c, s, new Move(1, 2, 1), new Move(1, 3, 1), new Move(1, 5, 1));
+ Assert.Equal("That hex is out of reach this turn", Assert.Single(r.Rejected).Reason);
+ Assert.Equal((3, 1), (r.State.Units[1].Q, r.State.Units[1].R));
+ Assert.Contains(r.Why, x => x.System == "map" && x.Message == "Unit 1 moved to hex 2,1 for 2 movement points");
+ Assert.Empty(Step(c, r.State, new Move(1, 5, 1)).Rejected);
+ }
+
+ // 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.
+ [Theory]
+ [InlineData("fortify", "0,1", "", "")]
+ [InlineData("fortifying", "0,1", "", "")]
+ [InlineData("hold", "", "hold", "")]
+ public void AMoveOutAndBackClearsFortifyAndKeepsHold(string order, string target, string afterOrder, string afterTarget)
+ {
+ var c = Plain();
+ var s = With(c, new Unit(1, "soldier", 0, 1, side: "israel", order: order, orderTarget: target));
+ var r = Step(c, s, new Move(1, 1, 1), new Move(1, 0, 1));
+ Assert.Empty(r.Rejected);
+ Assert.Equal((0, 1, afterOrder, afterTarget), (r.State.Units[1].Q, r.State.Units[1].R, r.State.Units[1].Order, r.State.Units[1].OrderTarget));
+ Assert.Equal(order == "fortify" ? 1 : 0, r.Why.Count(x => x.System == "map" && x.Message == "Unit 1 left hex 0,1 and is no longer fortified"));
+
+ var refused = Step(c, s, new Move(1, 5, 1)); // refused by the last check before the move
+ Assert.Equal("That hex is out of reach this turn", Assert.Single(refused.Rejected).Reason);
+ Assert.Equal(Step(c, s).State.Hash(), refused.State.Hash()); // as a turn with no Move: the order is the turn's own
+ }
+
+ // R-MOVE-001: the loader refuses a military type with no movement points, a population type with some, a land biome
+ // with no cost, a cost for water, a stack limit below 1 and an unknown locality.
+ [Theory]
+ [InlineData("unit_types.yaml", "types[soldier].movement_points", " - { id: soldier, kind: unit, side: israel, class: infantry, movement_points: 3 }", " - { id: soldier, kind: unit, side: israel, class: infantry }", "required for a military type, at least 1")]
+ [InlineData("unit_types.yaml", "types[civilian].movement_points", " - { id: civilian, kind: population }", " - { id: civilian, kind: population, movement_points: 2 }", "only a unit moves")]
+ [InlineData("rules.yaml", "mvp.move_cost", "move_cost: { coastal_plain: 1, hills: 2, desert: 3 }", "move_cost: { coastal_plain: 1, desert: 3 }", "no cost for land biome 'hills'")]
+ [InlineData("rules.yaml", "mvp.move_cost.sea", "move_cost: { coastal_plain: 1, hills: 2, desert: 3 }", "move_cost: { coastal_plain: 1, hills: 2, desert: 3, sea: 1 }", "is water in map/hexes.json: lake and sea are impassable")]
+ [InlineData("rules.yaml", "mvp.move_cost.hills", "move_cost: { coastal_plain: 1, hills: 2, desert: 3 }", "move_cost: { coastal_plain: 1, hills: 0, desert: 3 }", "must be >= 1")]
+ [InlineData("rules.yaml", "mvp.stack_limit", "stack_limit: 2", "stack_limit: 0", "must be >= 1")]
+ [InlineData("rules.yaml", "mvp.enemy_held_localities", "enemy_held_localities: []", "enemy_held_localities: [atlantis]", "unknown settlement 'atlantis'")]
+ public void TheLoaderRefusesABadMovementValue(string file, string field, string from, string to, string message)
+ {
+ var files = Fixture.Gdd(new Dictionary<string, string> { ["unit_types.yaml"] = Types });
+ Assert.Contains(from, files[file]);
+ files[file] = files[file].Replace(from, to);
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(files)));
+ Assert.Equal((file, field), (ex.File, ex.Field));
+ Assert.Contains(message, ex.Message);
+ }
+
+ // Performance (spec §2.5): a Reachable for a fast unit on each of the real game's 25 settlement hexes, on the 870-hex
+ // board, stays under one Step's 16 ms WebGL budget. Measured on .NET, best of five runs; the margin is printed.
+ [Fact]
+ public void AFullTurnOfMovesIsFast()
+ {
+ var c = ContentLoader.Load(RealContentTests.ContentRoot());
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ foreach (var h in c.SettlementHexes) { var id = s.NextId++; s.Units.Add(id, new Unit(id, "armoured_car", h.Q, h.R, side: "israel")); }
+ Assert.Equal(25, s.Units.Count);
+ var best = double.MaxValue;
+ var listed = 0;
+ for (int run = 0; run < 5; run++)
+ {
+ var w = Stopwatch.StartNew();
+ listed = s.Units.Keys.Sum(id => Movement.Reachable(c, s, id).Count);
+ best = Math.Min(best, w.Elapsed.TotalMilliseconds);
+ }
+ _out.WriteLine(string.Format(CultureInfo.InvariantCulture, "25 Reachable calls, {0} hexes listed: {1:F2} ms (budget 16 ms, {2:F1}x margin)", listed, best, 16 / best));
+ Assert.True(listed > 25);
+ Assert.True(best < 16, string.Format(CultureInfo.InvariantCulture, "{0:F2} ms", best));
+ }
+}
diff --git a/sim/Statecraft.Sim.Tests/OrdersTests.cs b/sim/Statecraft.Sim.Tests/OrdersTests.cs
index 3486dc823..2b92c92bc 100644
--- a/sim/Statecraft.Sim.Tests/OrdersTests.cs
+++ b/sim/Statecraft.Sim.Tests/OrdersTests.cs
@@ -9,8 +9,8 @@ public class OrdersTests
{
/// <summary>An Israeli soldier, an Egyptian unit (an enemy side) and the fixture's halutz types.</summary>
const string Types = Fixture.GddUnitTypes
- + " - { id: soldier, kind: unit, side: israel, class: infantry }\n"
- + " - { id: enemy, kind: unit, side: egypt, class: infantry }\n";
+ + " - { id: soldier, kind: unit, side: israel, class: infantry, movement_points: 3 }\n"
+ + " - { id: enemy, kind: unit, side: egypt, class: infantry, movement_points: 3 }\n";
static Content Load() =>
ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string> { ["unit_types.yaml"] = Types })));
diff --git a/sim/Statecraft.Sim.Tests/SaveGameTests.cs b/sim/Statecraft.Sim.Tests/SaveGameTests.cs
index 286056fad..01286c14b 100644
--- a/sim/Statecraft.Sim.Tests/SaveGameTests.cs
+++ b/sim/Statecraft.Sim.Tests/SaveGameTests.cs
@@ -29,7 +29,7 @@ public class SaveGameTests
new Command[] { new SetPolicy("odd id with spaces%", 0.5), new MapAction("transit_camp", 4, 0) },
new Command[] { new AssignWorkers("town_a", "job", 1), new UnitOrder(1, "hold") }, // GDD orders: the legacy fixture refuses them
new Command[] { new Train("town_a", "halutz", 1), new CancelTraining(1) }, // GDD orders too
- new Command[] { new PioneerWork(1, "build_yishuv", "site_a"), new StopWork(1), new StartProject("housing", "town_a", 1, 1), new CancelProject(1), new BuyArms(2) },
+ new Command[] { new PioneerWork(1, "build_yishuv", "site_a"), new StopWork(1), new StartProject("housing", "town_a", 1, 1), new CancelProject(1), new BuyArms(2), new Move(1, -2, 3) },
new Command[] { new SecurityOrder(1) }, new Command[0],
};
foreach (var o in orders) g.Step(o);
diff --git a/sim/Statecraft.Sim/AttentionSystem.cs b/sim/Statecraft.Sim/AttentionSystem.cs
index ecc4bbac0..bd9c8b877 100644
--- a/sim/Statecraft.Sim/AttentionSystem.cs
+++ b/sim/Statecraft.Sim/AttentionSystem.cs
@@ -8,11 +8,11 @@ namespace Statecraft.Sim
public static class AttentionSystem
{
static readonly HashSet<string> Kinds = new HashSet<string>
- { "set_policy", "allocate_budget", "choose_event_option", "set_mobilization", "security_order", "appoint", "map_action", "assign_workers", "train", "cancel_training", "pioneer_work", "stop_work", "start_project", "cancel_project", "buy_arms", "unit_order" };
+ { "set_policy", "allocate_budget", "choose_event_option", "set_mobilization", "security_order", "appoint", "map_action", "assign_workers", "train", "cancel_training", "pioneer_work", "stop_work", "start_project", "cancel_project", "buy_arms", "move", "unit_order" };
/// <summary>The kinds only the GDD v0.1 loop runs. Rules price them only when systems.loop is gdd, and the legacy loop
/// refuses them before charging Attention.</summary>
- static readonly HashSet<string> GddKinds = new HashSet<string> { "assign_workers", "train", "cancel_training", "pioneer_work", "stop_work", "start_project", "cancel_project", "buy_arms", "unit_order" };
+ static readonly HashSet<string> GddKinds = new HashSet<string> { "assign_workers", "train", "cancel_training", "pioneer_work", "stop_work", "start_project", "cancel_project", "buy_arms", "move", "unit_order" };
public static IReadOnlyCollection<string> CommandKinds => Kinds;
diff --git a/sim/Statecraft.Sim/Commands.cs b/sim/Statecraft.Sim/Commands.cs
index c164429c1..602112caf 100644
--- a/sim/Statecraft.Sim/Commands.cs
+++ b/sim/Statecraft.Sim/Commands.cs
@@ -130,6 +130,15 @@ namespace Statecraft.Sim
public CancelProject(int project) { Project = project; }
}
+ /// <summary>Moves unit <see cref="Unit"/> to hex (<see cref="Q"/>, <see cref="R"/>) along the cheapest path, within the
+ /// movement points it has left this turn (Movement.Move, R-MOVE-001 to R-MOVE-006). GDD v0.1 loop only.</summary>
+ public sealed class Move : Command
+ {
+ public override string Kind => Movement.Kind;
+ public int Unit { get; } public int Q { get; } public int R { get; }
+ public Move(int unit, int q, int r) { Unit = unit; Q = q; R = r; }
+ }
+
/// <summary>Buys <see cref="Count"/> Arms with Money (Pools.BuyArms, R-ARMS-002, D-G6). GDD v0.1 loop only.</summary>
public sealed class BuyArms : Command
{
@@ -174,6 +183,7 @@ namespace Statecraft.Sim
case UnitOrder o: Text(o.Order, "Order"); break;
case StartProject p: Text(p.ProjectKind, "ProjectKind"); Text(p.City, "City"); break;
case CancelProject _: break;
+ case Move _: break;
case BuyArms _: break;
case SetMobilization _: case SecurityOrder _: break;
default: throw new ArgumentException("unknown command type " + cmd.GetType().Name, "commands");
diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.cs
index 982583797..42cd92f76 100644
--- a/sim/Statecraft.Sim/Content.cs
+++ b/sim/Statecraft.Sim/Content.cs
@@ -594,6 +594,14 @@ namespace Statecraft.Sim
/// <summary>A minister whose loyalty is below this carries a delegated decision out half-heartedly (R-EVT-003; #107,
/// owner, 18 October 2026). Required in the GDD loop, 0 to 10 (0: nobody is below it).</summary>
public int? DelegationLoyaltyFloor { get; set; }
+ /// <summary>The movement points it costs to enter a hex of each land biome of map/hexes.json (R-MOVE-001; Q-MOVE-1).
+ /// Lake and sea have none: they are impassable. The loader requires one for every land biome in the GDD loop.</summary>
+ public Dictionary<string, int> MoveCost { get; set; } = new Dictionary<string, int>();
+ /// <summary>The most units of one side a hex holds (R-MOVE-003; Q-MOVE-3). Required in the GDD loop, at least 1.</summary>
+ public int? StackLimit { get; set; }
+ /// <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 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; }
@@ -724,6 +732,9 @@ namespace Statecraft.Sim
public string Side { get; set; } = "";
/// <summary>A military type's class: infantry, artillery or armour, or "" for a type that is not military (R-UNIT-001).</summary>
public string Class { get; set; } = "";
+ /// <summary>The movement points a unit of this type has each turn (R-MOVE-001; Q-MOVE-1), or 0 for a type that does not
+ /// move. Required on a military type.</summary>
+ public int MovementPoints { get; set; }
}
/// <summary>One stretch of a budget line's ownership (rules.yaml budget_owners): from this day (inclusive) the office owns the line.</summary>
diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.cs
index c76971924..a654317dd 100644
--- a/sim/Statecraft.Sim/ContentLoader.cs
+++ b/sim/Statecraft.Sim/ContentLoader.cs
@@ -1087,6 +1087,10 @@ namespace Statecraft.Sim
if (!Sides.Contains(x.Side)) throw new ContentException(uf, at + ".side", $"unknown side '{x.Side}' ({string.Join(", ", Sides)})");
if (!Classes.Contains(x.Class)) throw new ContentException(uf, at + ".class", $"unknown class '{x.Class}' (infantry, artillery or armour)");
}
+ // R-MOVE-001 (Q-MOVE-1): a military type has its movement points; a population count is not on the map.
+ if (x.Kind == "population" && x.MovementPoints != 0) throw new ContentException(uf, at + ".movement_points", "only a unit moves");
+ if (x.Side != "" && x.MovementPoints < 1) throw new ContentException(uf, at + ".movement_points", "required for a military type, at least 1");
+ if (x.MovementPoints < 0) throw new ContentException(uf, at + ".movement_points", "must be >= 0");
if (x.Facility == "")
{
// Training (R-TRAIN-001) needs a place to train; values without one would be read by nothing.
@@ -1189,6 +1193,21 @@ namespace Statecraft.Sim
if (m.DelegationLoyaltyFloor < 0 || m.DelegationLoyaltyFloor > 10) throw new ContentException(file, "mvp.delegation_loyalty_floor", "must be 0-10");
if (m.DisloyalEffectShare == null) throw new ContentException(file, "mvp.disloyal_effect_share", "required when eras.yaml systems.loop is gdd");
Unit(file, "mvp.disloyal_effect_share", m.DisloyalEffectShare.Value);
+ // R-MOVE-001 (Q-MOVE-1): a cost for every land biome of the map, so no hex is read as free, and none for a water
+ // biome, so lake and sea stay impassable.
+ foreach (var b in c.Hexes.Where(h => h.Land).Select(h => h.Biome).Distinct().OrderBy(b => b, StringComparer.Ordinal))
+ if (!m.MoveCost.ContainsKey(b)) throw new ContentException(file, "mvp.move_cost", $"no cost for land biome '{b}' ({HexesFile})");
+ foreach (var kv in m.MoveCost)
+ {
+ if (c.Hexes.Any(h => !h.Land && h.Biome == kv.Key)) throw new ContentException(file, "mvp.move_cost." + kv.Key, $"is water in {HexesFile}: lake and sea are impassable");
+ if (kv.Value < 1) throw new ContentException(file, "mvp.move_cost." + kv.Key, "must be >= 1");
+ }
+ // 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-MOVE-005 (Q-CIV-1)
+ foreach (var id in m.EnemyHeldLocalities)
+ if (c.SettlementHexes.All(h => h.Id != id)) throw new ContentException(file, "mvp.enemy_held_localities", $"unknown settlement '{id}' ({SettlementHexesFileName})");
if (c.Indicators.All(i => i.Id != Pools.FoodIndicator))
throw new ContentException(file, "mvp.k_food", "the Food stock feeds the food_supply indicator, which model.yaml must define");
// One game has one last day (R-LOOP-004): an era cannot move it.
diff --git a/sim/Statecraft.Sim/Movement.cs b/sim/Statecraft.Sim/Movement.cs
new file mode 100644
index 000000000..31dd9804d
--- /dev/null
+++ b/sim/Statecraft.Sim/Movement.cs
@@ -0,0 +1,133 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+
+namespace Statecraft.Sim
+{
+ /// <summary>Unit movement in the GDD v0.1 loop (Phase 5 PR 5; docs/rules/mvp.md R-MOVE-001 to R-MOVE-006). A Move goes at
+ /// command time along the cheapest path within the unit's movement points (spec 2026-10-12 section 2.3); Reachable and
+ /// Path are the preview the UI reads (spec section 2.6), from the same search.</summary>
+ public static class Movement
+ {
+ public const string Kind = "move";
+
+ /// <summary>The player's side (units_1948.yaml's id). A unit of any other side is the enemy's; a halutz has no side and
+ /// is the player's.</summary>
+ public const string PlayerSide = "israel";
+
+ /// <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) };
+
+ 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;
+
+ /// <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)
+ {
+ 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));
+ 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;
+ }
+
+ /// <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)
+ {
+ if (!Reachable(c, s, unitId).ContainsKey((q, r))) return Array.Empty<(int, int)>();
+ var u = s.Units[unitId];
+ var (_, prev) = Search(c, s, u, Points(c, u));
+ 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-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
+ /// (R-MOVE-005), a hex full of the unit's side (R-MOVE-003), or a hex out of reach this turn.</summary>
+ internal static string? Move(Content c, GameState s, int unitId, int q, int r, Dictionary<int, int> spent, List<Cause> why)
+ {
+ if (!s.Units.TryGetValue(unitId, out var u)) return "There is no such unit";
+ if (IsEnemy(u)) return "That unit is not yours";
+ var points = Points(c, u);
+ if (points == 0) return "That unit cannot move";
+ if (u.Q == q && u.R == r) return "That unit is already there";
+ if (!(c.HexAt(q, r) is MapHex hex) || !hex.Land) return "Units cannot enter water or leave the map";
+ if (s.Units.Values.Any(x => x.Q == q && x.R == r && IsEnemy(x))) return "An enemy unit holds that hex";
+ if (NoEntry(c, s).Contains((q, r))) return "Units may not enter an enemy-held locality before its capture is possible";
+ if (Full(c, s, u, q, r) is string full) return full;
+ spent.TryGetValue(unitId, out var used);
+ var (dist, _) = Search(c, s, u, points - used);
+ if (!dist.TryGetValue((q, r), out var cost)) return "That hex is out of reach this turn";
+ // Moving clears fortify at once (Q-HOLD-1, "lost on move"; the standing orders' "fortify", or "fortifying" the turn it
+ // 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);
+ 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")));
+ if (u.Order == "fortify")
+ why.Add(new Cause("map", unitId.ToString(CultureInfo.InvariantCulture), 0,
+ $"Unit {unitId} left hex {u.OrderTarget} and is no longer fortified"));
+ return null;
+ }
+
+ /// <summary>R-MOVE-003: the refusal when (q, r) already holds stack_limit units of <paramref name="u"/>'s side, else null.</summary>
+ static string? Full(Content c, GameState s, Unit u, int q, int r)
+ {
+ var limit = c.RulesAt(s.Date).Mvp!.StackLimit!.Value; // the loader requires it in the GDD loop
+ var held = s.Units.Values.Count(x => x.Id != u.Id && x.Side == u.Side && x.Q == q && x.R == r);
+ return held >= limit ? FormattableString.Invariant($"That hex already holds {held} units of that side, the most one hex can hold") : null;
+ }
+
+ /// <summary>R-MOVE-005: the hexes of mvp.enemy_held_localities.</summary>
+ 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)));
+ }
+
+ /// <summary>R-MOVE-001, R-MOVE-002, R-MOVE-004, R-MOVE-005: the cheapest cost of every hex within <paramref name="budget"/>
+ /// points from the unit's hex, and the hex each is entered from. A path enters only land hexes, at their biome's cost,
+ /// and never an enemy unit's hex or an enemy-held locality's; passing next to either costs nothing extra (no zone of
+ /// control, Q-MOVE-4). Hexes leave the frontier in (cost, q, r) order and neighbours are tried in the fixed
+ /// <see cref="Neighbours"/> order, so a hex reached at the same cost twice keeps the first, and the path is the same
+ /// every run. Stacking limits only where a move ends, so it is not checked here.</summary>
+ static (Dictionary<(int Q, int R), int> Dist, Dictionary<(int Q, int R), (int Q, int R)> Prev) Search(Content c, GameState s, Unit u, int budget)
+ {
+ var costs = c.RulesAt(s.Date).Mvp!.MoveCost; // the loader requires a cost for every land biome in the GDD loop
+ var blocked = NoEntry(c, s);
+ foreach (var x in s.Units.Values) if (IsEnemy(x)) blocked.Add((x.Q, x.R));
+ var dist = new Dictionary<(int Q, int R), int> { [(u.Q, u.R)] = 0 };
+ var prev = new Dictionary<(int Q, int R), (int Q, int R)>();
+ var frontier = new SortedSet<(int Cost, int Q, int R)> { (0, u.Q, u.R) };
+ while (frontier.Count > 0)
+ {
+ var (cost, q, r) = frontier.Min;
+ frontier.Remove(frontier.Min);
+ foreach (var (dq, dr) in Neighbours)
+ {
+ var next = (q + dq, r + dr);
+ if (!(c.HexAt(next.Item1, next.Item2) is MapHex hex) || !hex.Land || blocked.Contains(next)) continue;
+ var total = cost + costs[hex.Biome];
+ if (total > budget || (dist.TryGetValue(next, out var known) && known <= total)) continue;
+ if (dist.ContainsKey(next)) frontier.Remove((known, next.Item1, next.Item2));
+ dist[next] = total;
+ prev[next] = (q, r);
+ frontier.Add((total, next.Item1, next.Item2));
+ }
+ }
+ return (dist, prev);
+ }
+ }
+}
diff --git a/sim/Statecraft.Sim/SaveGame.cs b/sim/Statecraft.Sim/SaveGame.cs
index 5b64cd1b5..3ec323007 100644
--- a/sim/Statecraft.Sim/SaveGame.cs
+++ b/sim/Statecraft.Sim/SaveGame.cs
@@ -126,6 +126,7 @@ namespace Statecraft.Sim
UnitOrder o => $"order {Int(o.Unit)} {Esc(o.Order)}",
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)}",
BuyArms a => $"arms {Int(a.Count)}",
_ => throw new ArgumentException($"Cannot save command kind '{cmd.Kind}'", nameof(cmd)),
};
@@ -223,6 +224,7 @@ namespace Statecraft.Sim
case "order": Arity(3); return 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]));
case "arms": Arity(2); return new BuyArms(I(f[1]));
default: throw new SaveException(line, $"unknown command '{f[0]}'");
}
diff --git a/sim/Statecraft.Sim/Scenario.cs b/sim/Statecraft.Sim/Scenario.cs
index c445c34de..2404f884b 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), unit_order (unit, order; GDD content only). A turn with no
+ /// (unit), move (unit, q, r; GDD content only), unit_order (unit, order; 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
{
@@ -67,6 +67,7 @@ namespace Statecraft.Sim
["pioneer_work"] = new[] { "unit", "action", "site" }, ["stop_work"] = new[] { "unit" },
["unit_order"] = new[] { "unit", "order" },
["start_project"] = new[] { "project", "city", "q", "r" }, ["cancel_project"] = new[] { "project" },
+ ["move"] = new[] { "unit", "q", "r" },
["buy_arms"] = new[] { "count" },
};
@@ -100,6 +101,7 @@ namespace Statecraft.Sim
case "unit_order": return new UnitOrder(Whole(c, "unit"), Str(c, "order"));
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"));
case "buy_arms": return new BuyArms(Whole(c, "count"));
default: throw new InvalidDataException($"command kind '{kind}' has no builder");
}
@@ -142,6 +144,7 @@ namespace Statecraft.Sim
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}"),
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),
_ => c.Kind,
};
diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.cs
index b9d377f0b..fb8df9d69 100644
--- a/sim/Statecraft.Sim/Simulation.cs
+++ b/sim/Statecraft.Sim/Simulation.cs
@@ -99,13 +99,14 @@ namespace Statecraft.Sim
static void RunOrders(Content c, GameState s, IReadOnlyList<Command> commands, 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; }
// A GDD order has no price in the legacy rules: refuse it before charging (R-CITY-001).
if (AttentionSystem.IsGddKind(cmd.Kind) && !c.IsGdd) { rejected.Add(new Rejection(cmd, "That order is not available in this game")); continue; }
var before = s.Attention;
- var error = AttentionSystem.TrySpend(c, s, cmd.Kind, priceRung) ?? Execute(c, s, cmd, why);
+ var error = AttentionSystem.TrySpend(c, s, cmd.Kind, priceRung) ?? Execute(c, s, cmd, spent, why);
if (error != null) { s.Attention = before; rejected.Add(new Rejection(cmd, error)); }
}
}
@@ -113,7 +114,7 @@ namespace Statecraft.Sim
/// <summary>Returns null when the command was carried out (a lost vote counts: it consumes the RNG draw and is
/// reported as a politics cause), or the reason it failed validation. A command that fails validation leaves
/// the state as it found it (attention is refunded by the caller).</summary>
- static string? Execute(Content c, GameState s, Command cmd, List<Cause> why)
+ static string? Execute(Content c, GameState s, Command cmd, Dictionary<int, int> spent, List<Cause> why)
{
switch (cmd)
{
@@ -178,6 +179,8 @@ namespace Statecraft.Sim
return Projects.StartCity(c, s, p.ProjectKind, p.City, p.Q, p.R, why);
case CancelProject p:
return Projects.CancelCity(c, s, p.Project, why);
+ case Move m:
+ return Movement.Move(c, s, m.Unit, m.Q, m.R, spent, why);
case BuyArms a:
return Pools.BuyArms(c, s, a.Count, why);
case SecurityOrder o:
diff --git a/unity/Assets/Scripts/UI/SimBridge.cs b/unity/Assets/Scripts/UI/SimBridge.cs
index a95145814..9694716c1 100644
--- a/unity/Assets/Scripts/UI/SimBridge.cs
+++ b/unity/Assets/Scripts/UI/SimBridge.cs
@@ -62,6 +62,7 @@ namespace Statecraft.Game.UI
UnitOrder o => FormattableString.Invariant($"order:{o.Unit}"),
StartProject p => FormattableString.Invariant($"project:{p.Q},{p.R}"),
CancelProject x => FormattableString.Invariant($"unproject:{x.Project}"),
+ Move m => FormattableString.Invariant($"move:{m.Unit}"),
_ => c.Kind,
};
@@ -128,6 +129,9 @@ namespace Statecraft.Game.UI
return Unknown("unit", w.Unit.ToString(System.Globalization.CultureInfo.InvariantCulture), State.Units.Keys.Select(k => k.ToString(System.Globalization.CultureInfo.InvariantCulture)))
?? Unknown("pioneer_work", w.Action, new[] { Projects.BuildYishuv }) ?? Unknown("site", w.Site, Content.Sites.Select(x => x.Id));
case StopWork w: return Unknown("unit", w.Unit.ToString(System.Globalization.CultureInfo.InvariantCulture), State.Units.Keys.Select(k => k.ToString(System.Globalization.CultureInfo.InvariantCulture)));
+ // Movement (#744): the unit id only; the sim refuses an unreachable, full or forbidden hex with its own reason.
+ case Move m: return Unknown("unit", m.Unit.ToString(System.Globalization.CultureInfo.InvariantCulture), State.Units.Keys.Select(k => k.ToString(System.Globalization.CultureInfo.InvariantCulture)));
+
// Standing orders (#746): the unit id only; the sim refuses an unknown order, a halutz or an enemy unit itself.
case UnitOrder o: return Unknown("unit", o.Unit.ToString(System.Globalization.CultureInfo.InvariantCulture), State.Units.Keys.Select(k => k.ToString(System.Globalization.CultureInfo.InvariantCulture)));
// City projects (#735): ids only; the sim refuses a far or taken hex, the policy gate and the turn's limit itself.
diff --git a/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs b/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs
index 4c643750e..d24c5fe7e 100644
--- a/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs
+++ b/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs
@@ -34,6 +34,7 @@ public class SimBridgeGuardTests
[typeof(UnitOrder)] = new UnitOrder(1, "fortify"),
[typeof(StartProject)] = new StartProject("housing", "tel_aviv", 1, 0),
[typeof(CancelProject)] = new CancelProject(1),
+ [typeof(Move)] = new Move(1, 2, 0),
[typeof(BuyArms)] = new BuyArms(0),
};