A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Player units may enter enemy-held target towns (R-MOVE-005, refs #1304) (#1314)
Berie562e5e615ff
diff --git a/changelog.d/1304.md b/changelog.d/1304.mdnew file mode 100644index 000000000..b39138ed6--- /dev/null+++ b/changelog.d/1304.md@@ -0,0 +1,4 @@+- Player units may enter enemy-held target towns, GDD Phase 6 (#1304; R-MOVE-005): a `Move` onto the hex of an+ enemy-held place on the curated target list is allowed, the unit card's Move preview lists it, and a unit that ends+ there with no enemy unit on it captures the place at turn end. Gaza, enemy-held but not a target, stays closed, and+ no path passes through it. Raid's withdrawal, combat retreat and the enemy's moves are unchanged.diff --git a/docs/determinism.md b/docs/determinism.mdindex e3f0c51ee..934174d82 100644--- a/docs/determinism.md+++ b/docs/determinism.md@@ -20,9 +20,10 @@ The simulation must produce the same state, bit for bit, on .NET, Unity Mono andonly; stored values, gameplay and completion dates are unchanged.- **Settlement control (resolver step 3):** targets resolve in ordinal id order, and the capture check reads only unitpositions, with no RNG draw (R-CTRL-004; `CaptureTests.SettlementsResolveInOrdinalOrder` and `NoRngDraw`). The shipped- list has six targets (#793), and no golden captures a place: the five enemy-held ones are no-entry hexes for player- units (R-MOVE-005), and the reference player's unit on Jaffa's hex (shared with Tel Aviv) captures nothing, since Jaffa- is not enemy-held at the start.+ list has six targets (#793), and no golden captures a place: player units may enter the five enemy-held ones since+ #1304 (R-MOVE-005), but the reference player sends no Move, so none of its units stands on one, and its unit on+ Jaffa's hex (shared with Tel Aviv) captures nothing, since Jaffa is not enemy-held at the start. The smoke-orders+ move skips the lit hexes of enemy-held places on purpose (`GoldenRun.SmokeMove`), so it stays a plain move.- **Answering a capture (Raid and withdraw):** the units on the place leave in ascending id, each to the first free hex inthe fixed neighbour order, and the captures still waiting at the game's end resolve in ordinal id order, with no RNGdraw (R-CTRL-008, R-CTRL-010; `RaidTests.RaidDrawsNothing`). No golden captures a place, so none answers one.@@ -69,8 +70,9 @@ uv run tools/web_check.py unity/Builds/Web-<compression> --query "golden&smoke=5`smoke-orders` (GDD Phase 5 PR 15, #754) is the same kind of browser run for the unit orders (`?smoke-orders`, desktop`-smoke-orders`: the golden seed, one turn). It hides the turn's event card (the events go to their ministers), clicks thehex of the unit `GoldenRun.SmokeMove` names (the lowest-id unit `Movement.Reachable` has a hex for: unit 0, Golani, on-10,9), presses the unit card's Move button, clicks the first lit hex in `Reachable`'s (q, r) order (7,11) and presses End-Turn: `SMOKE ORDERS OK 1948-06-15 ee6bfee561120532416c1aff2cd7cd741256aaafb443d19b414031356b680ae6`.+10,9), presses the unit card's Move button, clicks the first lit hex in `Reachable`'s (q, r) order that is no enemy-held+place (7,11; it skips Nazareth's 7,10, so the run captures nothing) and presses End Turn:+`SMOKE ORDERS OK 1948-06-15 ee6bfee561120532416c1aff2cd7cd741256aaafb443d19b414031356b680ae6`.`GoldenRun.PlaySmokeOrders` plays the same turn with that one `Move`, so the value is in the manifest (`SliceSmokeTests.TheSmokeOrdersRunMovesOneUnitAndEndsOnTheGolden`) and the player's golden checkprints it as `GOLDEN OK smoke-orders`. Re-record it when the sim or the order path on the card changes; the fortify, hold andattack slices can add their orders to it. Check a WebGL build with:diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex ee6e5feea..374e2772f 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -192,9 +192,9 @@ R-MOVE-003: A hex holds at most `mvp.stack_limit` units of one side (Q-MOVE-3; rR-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-005: A player unit cannot enter the hex of an enemy-held locality that is not a curated target (`settlement_targets.yaml`, R-CTRL-001), and no path passes through one: in Phase 6 only Gaza stays closed (Q-CIV-1, owner, 15 October 2026: "No entry until Phase 6"; Q-TGT-1 (a)). The hex of an enemy-held target is open, so a player unit may move onto it, or through it, and capture it in play (R-CTRL-004; the owner's ruling on #793, 21 October 2026, that the targets "can be captured in play", https://github.com/eyalgolan/statecraft-israel/issues/793#issuecomment-6322289565; #1304). Raid's withdrawal (R-CTRL-010) and combat retreat (R-COMBAT-003) still never end on any enemy-held locality, target or not, and the enemy's mirror (R-ENEMY-001) is unchanged. 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.+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 closed by R-MOVE-005 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.diff --git a/sim/Statecraft.Sim.Tests/CaptureTests.cs b/sim/Statecraft.Sim.Tests/CaptureTests.csindex 50d680461..389e9f18c 100644--- a/sim/Statecraft.Sim.Tests/CaptureTests.cs+++ b/sim/Statecraft.Sim.Tests/CaptureTests.cs@@ -181,4 +181,61 @@ public class CaptureTestsAssert.Equal(2, s.Settlements.Count);Assert.Equal(rng, s.RngState);}++ // R-MOVE-005 in Phase 6 (#1304; the owner's #793 ruling that the targets "can be captured in play"): a player unit may+ // move onto an enemy-held target's hex, Reachable lists it, a path may run through it, and the unit that ends its move+ // there with no enemy unit on it captures the place at turn end (R-CTRL-004), through the whole resolver.+ [Fact]+ public void APlayerUnitMayEnterAnEnemyHeldTargetAndCaptureIt()+ {+ var c = Load(AllTargets);+ var s = With(c, Soldier(1, 0, 0));+ Assert.Equal(1, Movement.Reachable(c, s, 1)[(1, 0)]);+ Assert.Equal(new[] { (1, 0), (2, 0) }, Movement.Path(c, s, 1, 2, 0)); // through town_a, not round it for 3+ var result = Simulation.Step(c, s, new Command[] { new Move(1, 1, 0) });+ Assert.Empty(result.Rejected);+ Assert.Equal((1, 0), (result.State.Units[1].Q, result.State.Units[1].R));+ var ctrl = Assert.Single(result.State.Settlements);+ Assert.Equal("town_a", ctrl.Key);+ Assert.Equal(SettlementControl.AwaitingChoice, ctrl.Value.State);+ }++ // R-MOVE-005 in Phase 6 (#1304): an enemy-held place that is not a target (Gaza's case, Q-TGT-1 (a)) stays closed:+ // Move is refused, Reachable leaves it out and no path runs through it.+ [Fact]+ public void AnEnemyHeldPlaceThatIsNotATargetStaysClosed()+ {+ var c = Load(AllTargets);+ var s = With(c, Soldier(1, 3, 2));+ var reach = Movement.Reachable(c, s, 1);+ Assert.False(reach.ContainsKey((4, 2)));+ Assert.Equal(3, reach[(5, 2)]); // round town_e by (4, 1) and (5, 1), not through it for 2+ Assert.DoesNotContain((4, 2), Movement.Path(c, s, 1, 5, 2));+ var result = Simulation.Step(c, s, new Command[] { new Move(1, 4, 2) });+ Assert.Equal("Units may not enter an enemy-held locality before its capture is possible", Assert.Single(result.Rejected).Reason);+ Assert.Equal((3, 2), (result.State.Units[1].Q, result.State.Units[1].R));+ Assert.Empty(result.State.Settlements);+ }++ // #1304's done-when on the shipped content, so a change to settlement_targets.yaml cannot quietly reopen Gaza or close Acre:+ // a player unit beside Acre (a target) can reach it, and none beside Gaza (not one) can.+ [Fact]+ public void RealContentGazaStaysClosedAndAcreIsReachable()+ {+ var c = ContentLoader.Load(RealContentTests.ContentRoot());+ var type = Simulation.NewGame(c, 1, Mode.Historical).Units.Values.First(u => u.Side == "israel").Type;+ (int Q, int R) Hex(string id) { var h = c.SettlementHexes.Single(x => x.Id == id); return (h.Q, h.R); }+ bool Reaches(string id) // from any of the six hexes around it (some are sea or too far on the real map)+ {+ var (q, r) = Hex(id);+ return new[] { (1, 0), (-1, 0), (0, 1), (0, -1), (1, -1), (-1, 1) }.Any(d =>+ {+ var s = With(c, new Unit(900, type, q + d.Item1, r + d.Item2, side: "israel", strength: 2));+ foreach (var uid in s.Units.Where(x => (x.Value.Q, x.Value.R) == (q, r)).Select(x => x.Key).ToList()) s.Units.Remove(uid); // an enemy unit's hex is refused first+ return Movement.Reachable(c, s, 900).ContainsKey((q, r));+ });+ }+ Assert.False(Reaches("gaza"));+ Assert.True(Reaches("acre"));+ }}diff --git a/sim/Statecraft.Sim.Tests/RaidTests.cs b/sim/Statecraft.Sim.Tests/RaidTests.csindex a841c5906..45276d81a 100644--- a/sim/Statecraft.Sim.Tests/RaidTests.cs+++ b/sim/Statecraft.Sim.Tests/RaidTests.cs@@ -42,7 +42,7 @@ public class RaidTestsAssert.Equal((2, 0), (result.State.Units[1].Q, result.State.Units[1].R));Assert.Equal((2, 0), (result.State.Units[2].Q, result.State.Units[2].R));Assert.Contains(result.Why, x => x.Target == "town_a" && x.Message.Contains("under enemy control again"));- Assert.Contains(Movement.NoEntry(c, result.State), h => h == (1, 0)); // the player may not walk back in (R-MOVE-005)+ Assert.Contains(Movement.NoEntry(c, result.State), h => h == (1, 0)); // no withdrawal ends on it (R-CTRL-010)}// R-CTRL-010 (Q-RAID-1 (a), "residents unchanged"): Raid changes the units' hexes and removes the record, and nothingdiff --git a/sim/Statecraft.Sim.Tests/SliceSmokeTests.cs b/sim/Statecraft.Sim.Tests/SliceSmokeTests.csindex 9abe5d3a7..8387fff54 100644--- a/sim/Statecraft.Sim.Tests/SliceSmokeTests.cs+++ b/sim/Statecraft.Sim.Tests/SliceSmokeTests.cs@@ -237,11 +237,15 @@ public class SliceSmokeTests{var start = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);var move = GoldenRun.SmokeMove(Real, start);- Assert.Equal(Movement.Reachable(Real, start, move.Unit).Keys.First(), (move.Q, move.R)); // a hex the card lights+ var reach = Movement.Reachable(Real, start, move.Unit).Keys;+ var places = Movement.NoEntry(Real, start);+ Assert.Contains(reach.First(), places); // the first lit hex, Nazareth, is a place (#1304) ...+ Assert.Equal(reach.First(h => !places.Contains(h)), (move.Q, move.R)); // ... so the move skips itvar end = GoldenRun.PlaySmokeOrders(Real);var expected = GoldenManifest.Expected("smoke-orders"); // read before an update rewrites the manifestif (GoldenManifest.UpdateRequested) GoldenManifest.Update("smoke-orders", end.Hash());Assert.Equal((move.Q, move.R), (end.Units[move.Unit].Q, end.Units[move.Unit].R)); // the order took effect+ Assert.Empty(end.Settlements); // a plain move: no golden captures a place (docs/determinism.md)Assert.NotEqual(Simulation.Step(Real, start, new List<Command>()).State.Hash(), end.Hash()); // and shows in the hashAssert.Equal(expected, end.Hash());}diff --git a/sim/Statecraft.Sim/GoldenRun.cs b/sim/Statecraft.Sim/GoldenRun.csindex fe4c6206d..97d63dbf6 100644--- a/sim/Statecraft.Sim/GoldenRun.cs+++ b/sim/Statecraft.Sim/GoldenRun.cs@@ -96,15 +96,16 @@ namespace Statecraft.Sim/// <summary>The smoke-orders golden's one order (GDD Phase 5 PR 15, #754), what the WebGL ?smoke-orders run's/// GameRoot.SmokeOrders gives through the unit card: Move for the lowest-id unit Movement.Reachable has a hex for,- /// to the first of those hexes in Reachable's (q, r) order. Here, so Unity's run and the tests pick the same order.</summary>+ /// to the first of those hexes in Reachable's (q, r) order that is not an enemy-held place (Movement.NoEntry), so the+ /// golden stays a plain move and captures nothing (#1304 opened the target towns). Here, so Unity's run and the tests+ /// pick the same order.</summary>public static Move SmokeMove(Content c, GameState s){if (c == null) throw new ArgumentNullException(nameof(c));+ var places = Movement.NoEntry(c, s);foreach (var id in s.Units.Keys) // a SortedList: in id order- {- var reach = Movement.Reachable(c, s, id);- if (reach.Count > 0) { var (q, r) = reach.Keys.First(); return new Move(id, q, r); }- }+ foreach (var (q, r) in Movement.Reachable(c, s, id).Keys)+ if (!places.Contains((q, r))) return new Move(id, q, r);throw new InvalidOperationException("the smoke-orders run needs a unit that can move");}diff --git a/sim/Statecraft.Sim/Movement.cs b/sim/Statecraft.Sim/Movement.csindex d03921d85..a8e33baad 100644--- a/sim/Statecraft.Sim/Movement.cs+++ b/sim/Statecraft.Sim/Movement.cs@@ -52,8 +52,8 @@ namespace Statecraft.Sim/// <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. With <paramref name="enemy"/>+ /// water or a hex off the map, an enemy unit's hex (entering it is an attack, Q-MOVE-3), an enemy-held locality that+ /// is not a target (R-MOVE-005), a hex full of the unit's side (R-MOVE-003), or a hex out of reach this turn. With <paramref name="enemy"/>/// the enemy AI orders its own unit through the same checks, the sides swapped (R-ENEMY-001).</summary>internal static string? Move(Content c, GameState s, int unitId, int q, int r, Dictionary<int, int> spent, List<Cause> why, bool enemy = false){@@ -64,7 +64,7 @@ namespace Statecraft.Simif (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) != enemy)) return "An enemy unit holds that hex";- if (NoEntry(c, s, enemy).Contains((q, r))) return "Units may not enter an enemy-held locality before its capture is possible";+ if (Closed(c, s, enemy).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);@@ -100,6 +100,18 @@ namespace Statecraft.Simreturn enemy ? new HashSet<(int Q, int R)>(c.SettlementHexes.Select(h => (h.Q, h.R)).Where(h => !held.Contains(h))) : held;}+ /// <summary>R-MOVE-005 in Phase 6 (#1304): the hexes a move and its path may not enter. For the player, those of+ /// mvp.enemy_held_localities that are not curated targets (settlement_targets.yaml), so a target can be captured in play+ /// (the owner's #793 ruling) while the rest, Gaza today, stay closed; for the enemy, <see cref="NoEntry"/>'s mirror+ /// unchanged. Raid's withdrawal and combat retreat still read <see cref="NoEntry"/>, so neither ends on an enemy-held+ /// place.</summary>+ static HashSet<(int Q, int R)> Closed(Content c, GameState s, bool enemy)+ {+ if (enemy) return NoEntry(c, s, true);+ var ids = c.RulesAt(s.Date).Mvp!.EnemyHeldLocalities.Except(c.SettlementTargets.Select(t => t.Id));+ return new HashSet<(int Q, int R)>(c.SettlementHexes.Where(h => ids.Contains(h.Id)).Select(h => (h.Q, h.R)));+ }+/// <summary>R-ENEMY-002: the furthest hex the unit can reach this turn on its cheapest path to (<paramref name="q"/>,/// <paramref name="r"/>), by the same search as Move, or null when no path leads there or its first step is out of reach.</summary>internal static (int Q, int R)? Toward(Content c, GameState s, Unit u, int q, int r)@@ -130,14 +142,14 @@ namespace Statecraft.Sim/// <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+ /// never an enemy unit's hex or a closed enemy-held locality's (<see cref="Closed"/>); 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, IsEnemy(u));+ var blocked = Closed(c, s, IsEnemy(u));var built = BuiltSegments(c, s);foreach (var x in s.Units.Values) if (IsEnemy(x) != IsEnemy(u)) blocked.Add((x.Q, x.R));var dist = new Dictionary<(int Q, int R), int> { [(u.Q, u.R)] = 0 };