A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: roads and rail lower the movement cost (GDD Phase 5 PR 6, refs #745) (#1193)
Beri6119ad1a9ca2
diff --git a/changelog.d/745.md b/changelog.d/745.mdnew file mode 100644index 000000000..55bfe3451--- /dev/null+++ b/changelog.d/745.md@@ -0,0 +1,4 @@+- Roads and rail lower the movement cost (GDD Phase 5 PR 6, refs #745): a unit stepping between two hexes of one built+ corridor segment pays `road_move_cost` or `rail_move_cost` instead of the terrain's cost, when that is lower+ (R-MOVE-007). Only the corridors the pioneers build count (Q-MOVE-2). Both values are 1, labelled design values the+ owner may override; a segment not yet built costs the terrain.diff --git a/content/rules.yaml b/content/rules.yamlindex a025c5a51..be402a2e3 100644--- a/content/rules.yaml+++ b/content/rules.yaml@@ -147,6 +147,12 @@ mvp: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)+ # Roads and rail (R-MOVE-007; Q-MOVE-2, owner, 15 October 2026, #375: option (a), only the corridors Phase 4 builds).+ # Proposed in Phase 5 PR 6 (#745) under "Agents propose design values"; the owner may override them. 1 is the lowest+ # whole cost, so a built segment halves a hills step and thirds a mountain one, but on the coastal plain, valley and+ # lowland (already 1) it saves nothing. Not historical figures.+ road_move_cost: 1 # DESIGN VALUE: owner-set balance, not a historical figure (D-G2, Q-MOVE-2: movement points for a step along a built road segment)+ rail_move_cost: 1 # DESIGN VALUE: owner-set balance, not a historical figure (D-G2, Q-MOVE-2: movement points for a step along a built rail segment)# 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.diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex bb30977f2..ceee45552 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -168,6 +168,8 @@ R-MOVE-005: Before Phase 6 a player unit cannot enter the hex of an enemy-held lR-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.+R-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.+## 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/DesignValuesTests.cs b/sim/Statecraft.Sim.Tests/DesignValuesTests.csindex 82725cab2..89c534449 100644--- a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs+++ b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs@@ -138,6 +138,8 @@ public class DesignValuesTests("rules.yaml", "mvp.move_cost.desert"),("rules.yaml", "mvp.move_cost.mountains"),("rules.yaml", "mvp.stack_limit"),+ ("rules.yaml", "mvp.road_move_cost"), // R-MOVE-007, #745 (Q-MOVE-2): agent-proposed+ ("rules.yaml", "mvp.rail_move_cost"),("unit_types.yaml", "types[veteran_soldier].movement_points"),("unit_types.yaml", "types[artillery].movement_points"),("unit_types.yaml", "types[armoured_car].movement_points"),diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.csindex 3db359faa..6603574dd 100644--- a/sim/Statecraft.Sim.Tests/Fixture.cs+++ b/sim/Statecraft.Sim.Tests/Fixture.cs@@ -288,6 +288,8 @@ mvp:disloyal_effect_share: 0.5move_cost: { coastal_plain: 1, hills: 2, desert: 3 }stack_limit: 2+ road_move_cost: 1+ rail_move_cost: 2enemy_held_localities: []";diff --git a/sim/Statecraft.Sim.Tests/MovementTests.cs b/sim/Statecraft.Sim.Tests/MovementTests.csindex 045ea2229..c699689ad 100644--- a/sim/Statecraft.Sim.Tests/MovementTests.cs+++ b/sim/Statecraft.Sim.Tests/MovementTests.cs@@ -36,12 +36,14 @@ public class MovementTests+ string.Join(",\n", rows) + "]}\n";}- static Content Load(string board, params (string From, string To)[] edits)+ static Content Load(string board, params (string From, string To)[] edits) => Load(board, "corridors: []\n", edits);++ static Content Load(string board, string corridors, params (string From, string To)[] edits){- // This custom movement board has no buildable corridors; the shared fixture's corridors belong to its own map.+ // The shared fixture's corridors belong to its own map, so this custom board has only the corridors given.var files = Fixture.Gdd(new Dictionary<string, string>{- ["unit_types.yaml"] = Types, ["map/hexes.json"] = board, ["corridors.yaml"] = "corridors: []\n"+ ["unit_types.yaml"] = Types, ["map/hexes.json"] = board, ["corridors.yaml"] = corridors});foreach (var (from, to) in edits) files["rules.yaml"] = files["rules.yaml"].Replace(from, to);return ContentLoader.Load(Fixture.Write(files));@@ -272,8 +274,71 @@ public class MovementTestsAssert.Equal(Step(c, s).State.Hash(), refused.State.Hash()); // as a turn with no Move: the order is the turn's own}+ /// <summary>One corridor of <paramref name="kind"/> on the desert row r = 1: segment 1 over (1, 1) and (2, 1), segment 2+ /// over (2, 1) and (3, 1). Fixture values, not history.</summary>+ static string DesertCorridor(string kind) => "corridors:\n - id: cor_a\n kind: " + kind + "\n name: Cor A\n name_he: מסלול א\n"+ + " route: cor_a\n segments:\n - { to: X, hexes: [[1, 1], [2, 1]] }\n - { to: Y, hexes: [[2, 1], [3, 1]] }\n"+ + " sources:\n - { url: \"https://example.org/cor_a\", checked: 2026-10-15 }\n status: draft\n";++ static Content DesertRow(string kind) => Load(Board((1, 1, "desert"), (2, 1, "desert"), (3, 1, "desert"), (4, 1, "desert")), DesertCorridor(kind));++ static readonly DateTime Built = new DateTime(1948, 6, 15);++ // R-MOVE-007: a step from one hex of a built segment to another hex of the same segment costs the kind's cost (the+ // fixture's road 1, rail 2) instead of the desert's 3, and Move charges it; the step onto the unbuilt segment 2 costs+ // the terrain again.+ [Theory]+ [InlineData("road", 1)]+ [InlineData("rail", 2)]+ public void RoadsAreCheaper(string kind, int cost)+ {+ var c = DesertRow(kind);+ var s = With(c, Soldier(1, 1, 1));+ s.Corridors["cor_a"] = new CorridorWork("cor_a", new SegmentWork?[] { new SegmentWork(null, 6, Built), null });+ var reach = Movement.Reachable(c, s, 1);+ Assert.Equal(cost, reach[(2, 1)]);+ Assert.False(reach.ContainsKey((3, 1))); // cost + the desert's 3 is more than 3 points+ var r = Step(c, s, new Move(1, 2, 1));+ Assert.Empty(r.Rejected);+ Assert.Contains(r.Why, x => x.System == "map" && x.Message == $"Unit 1 moved to hex 2,1 for {cost} movement points");+ }++ // R-MOVE-007: a kind's cost applies only when it is lower than the terrain's, so the fixture's rail (2) on coastal plain+ // (1) costs the plain's 1.+ [Fact]+ public void ACorridorNeverCostsMoreThanTheTerrain()+ {+ var c = Load(Board(), DesertCorridor("rail"));+ var s = With(c, Soldier(1, 1, 1));+ s.Corridors["cor_a"] = new CorridorWork("cor_a", new SegmentWork?[] { new SegmentWork(null, 6, Built), null });+ Assert.Equal(1, Movement.Reachable(c, s, 1)[(2, 1)]);+ }++ // R-MOVE-007: a segment not started, or being built, is no corridor yet: the step costs the terrain.+ [Theory]+ [InlineData(false)]+ [InlineData(true)]+ public void AnUnbuiltSegmentCostsTerrain(bool started)+ {+ var c = DesertRow("road");+ var s = With(c, Soldier(1, 1, 1));+ if (started) s.Corridors["cor_a"] = new CorridorWork("cor_a", new SegmentWork?[] { new SegmentWork(9, 5, null), null });+ Assert.Equal(3, Movement.Reachable(c, s, 1)[(2, 1)]);+ }++ // R-MOVE-007: a kind's cost needs BOTH ends on the segment: a step from a hex off the built segment onto one of its hexes+ // costs the terrain's 3, not the road's 1.+ [Fact]+ public void AStepOntoABuiltSegmentFromOutsideItCostsTerrain()+ {+ var c = DesertRow("road");+ var s = With(c, Soldier(1, 1, 2));+ s.Corridors["cor_a"] = new CorridorWork("cor_a", new SegmentWork?[] { new SegmentWork(null, 6, Built), null });+ Assert.Equal(3, Movement.Reachable(c, s, 1)[(1, 1)]);+ }+// 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.+ // with no cost, a cost for water, a stack limit below 1, a missing or zero corridor cost 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")]@@ -281,6 +346,8 @@ public class MovementTests[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.road_move_cost", " road_move_cost: 1\n", "", "required when eras.yaml systems.loop is gdd")]+ [InlineData("rules.yaml", "mvp.rail_move_cost", "rail_move_cost: 2", "rail_move_cost: 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){diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex 90ba6c397..c4f8df35d 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -607,6 +607,11 @@ namespace Statecraft.Simpublic 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 movement points a step costs between two hexes of one built road segment, or of one built rail segment,+ /// when lower than the terrain's (R-MOVE-007; Q-MOVE-2). Required in the GDD loop, at least 1.</summary>+ public int? RoadMoveCost { get; set; }+ /// <inheritdoc cref="RoadMoveCost"/>+ public int? RailMoveCost { 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>();diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex 44644a0b4..dc030e715 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -1212,6 +1212,12 @@ namespace Statecraft.Sim// R-MOVE-003 (Q-MOVE-3): required, so a missing key is never read as no room at all.if (m.StackLimit == null) throw new ContentException(file, "mvp.stack_limit", "required when eras.yaml systems.loop is gdd");if (m.StackLimit < 1) throw new ContentException(file, "mvp.stack_limit", "must be >= 1");+ // R-MOVE-007 (Q-MOVE-2): required, so a missing key is never read as a free step along a corridor.+ foreach (var (key, v) in new[] { ("road_move_cost", m.RoadMoveCost), ("rail_move_cost", m.RailMoveCost) })+ {+ if (v == null) throw new ContentException(file, "mvp." + key, "required when eras.yaml systems.loop is gdd");+ if (v < 1) throw new ContentException(file, "mvp." + key, "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})");diff --git a/sim/Statecraft.Sim/Movement.cs b/sim/Statecraft.Sim/Movement.csindex 31dd9804d..8464cbeec 100644--- a/sim/Statecraft.Sim/Movement.cs+++ b/sim/Statecraft.Sim/Movement.cs@@ -5,9 +5,9 @@ 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>+ /// <summary>Unit movement in the GDD v0.1 loop (Phase 5 PRs 5 and 6; docs/rules/mvp.md R-MOVE-001 to R-MOVE-007). 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";@@ -97,9 +97,25 @@ namespace Statecraft.Simreturn 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+ /// <summary>R-MOVE-007: the hexes of each built corridor segment (a segment not started or being built is no road yet),+ /// with its kind's mvp.road_move_cost or mvp.rail_move_cost.</summary>+ static List<(HashSet<(int Q, int R)> Hexes, int Cost)> BuiltSegments(Content c, GameState s)+ {+ var m = c.RulesAt(s.Date).Mvp!; // the loader requires both costs in the GDD loop+ var built = new List<(HashSet<(int Q, int R)>, int)>();+ foreach (var d in c.Corridors)+ if (s.Corridors.TryGetValue(d.Id, out var w))+ for (int i = 0; i < d.Segments.Count; i++)+ if (w.Segments[i]?.BuiltOn != null)+ built.Add((new HashSet<(int Q, int R)>(d.Segments[i].Hexes.Select(h => (h[0], h[1]))),+ d.Kind == Corridors.Rail ? m.RailMoveCost!.Value : m.RoadMoveCost!.Value));+ return built;+ }++ /// <summary>R-MOVE-001, R-MOVE-002, R-MOVE-004, R-MOVE-005, R-MOVE-007: 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 or, from a hex of the same built corridor segment, at the kind's cost when that is lower, 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>@@ -107,6 +123,7 @@ namespace Statecraft.Sim{var costs = c.RulesAt(s.Date).Mvp!.MoveCost; // the loader requires a cost for every land biome in the GDD loopvar blocked = NoEntry(c, s);+ var built = BuiltSegments(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)>();@@ -119,7 +136,10 @@ namespace Statecraft.Sim{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];+ var step = costs[hex.Biome];+ foreach (var (hexes, kindCost) in built)+ if (kindCost < step && hexes.Contains((q, r)) && hexes.Contains(next)) step = kindCost;+ var total = cost + step;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;