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.

Enemy rules: no enemy force may arrive after the start; scripted moves get the full-points first step in every ruleset (Fixes #2587) (#2592)

Eyal Golan8b2550f01106
diff --git a/changelog.d/2587-enemy-rules.md b/changelog.d/2587-enemy-rules.md
new file mode 100644
index 000000000..077800e16
--- /dev/null
+++ b/changelog.d/2587-enemy-rules.md
@@ -0,0 +1,3 @@
+### Fixed
+
+- Enforce the no-enemy-reinforcements rule and let a scripted unit spend all its points on an otherwise too-costly first step, with no change in play with today's content.
diff --git a/sim/Statecraft.Sim.Tests/EnemyAITests.cs b/sim/Statecraft.Sim.Tests/EnemyAITests.cs
index 645b6c1bf..5525eed4c 100644
--- a/sim/Statecraft.Sim.Tests/EnemyAITests.cs
+++ b/sim/Statecraft.Sim.Tests/EnemyAITests.cs
@@ -217,6 +217,33 @@ public class EnemyAITests
Assert.Equal(scripted ? new[] { (3, 2, new DateTime(1948, 7, 8)) } : Array.Empty<(int, int, DateTime)>(), f.Script);
}
+ // R-ENEMY-002, R-MOVE-001: under gdd-0.1 too, a scripted unit that has not moved this turn may enter one neighbouring
+ // land hex whose cost exceeds its full allowance, spending all its points. Fixture: two points, adjacent desert costs 3.
+ [Fact]
+ public void AScriptedFirstStepMayCostMoreThanTheUnitsFullPoints()
+ {
+ const string SlowTypes = Fixture.GddUnitTypes
+ + " - { id: soldier, kind: unit, side: israel, class: infantry, movement_points: 3 }\n"
+ + " - { id: enemy, kind: unit, side: egypt, class: infantry, movement_points: 2 }\n";
+ const string Two = "[{ url: 'https://example.org/a', checked: '2026-10-13' }, { url: 'https://example.org/b', checked: '2026-10-13' }]";
+ var row = "- id: force\n service: army\n side: egypt\n status: draft\n strength: { value: 30, as_of: '1948-05-15' }\n anchors:\n"
+ + " - { place: Start, lon: 34.29, lat: 33.35, from: '1948-05-15', to: '1948-06-11' }\n"
+ + " - { place: June, lon: 34.29, lat: 33.35, from: '1948-06-11', to: '1948-07-08', sources: " + Two + " }\n";
+ var c = ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>
+ {
+ ["unit_types.yaml"] = SlowTypes,
+ ["map/hexes.json"] = MovementTests.Board((3, 1, "desert")),
+ ["corridors.yaml"] = "corridors: []\n",
+ ["map/units_1948.yaml"] = "units:\n" + row,
+ ["map/unit_anchor_hexes.yaml"] = "anchors:\n - { id: force, anchor: 0, q: 2, r: 1 }\n - { id: force, anchor: 1, q: 3, r: 1 }\n",
+ })));
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ var why = new List<Cause>();
+ EnemyAI.Order(c, s, why);
+ Assert.Equal((3, 1), (s.Units[0].Q, s.Units[0].R));
+ Assert.Contains(why, x => x.Message == "Unit 0 moved to hex 3,1 for 2 movement points");
+ }
+
// R-ENEMY-002 past the first truce (#1270; owner, 31 October 2026, ruling a: "First listed (as today)"): the script is
// every anchor from 11 June 1948 on two non-wiki sources, in the file's order, and on each turn the unit marches on the
// first of them whose window has not ended. Fixture: a later anchor on one source is skipped; of two that overlap from
@@ -421,7 +448,7 @@ public class EnemyAITests
for (int i = 0; i < 8 && s.GameOver == null; i++)
{
s = Simulation.Step(Real, s, Array.Empty<Command>()).State;
- Assert.Subset(ids, s.Units.Values.Where(IsEnemy).Select(u => u.Id).ToHashSet());
+ Assert.Subset(ids, s.Units.Values.Where(IsEnemy).Select(u => u.Id).ToHashSet()); // xUnit: every id now is a starting one (B ⊆ A), so none arrived
}
}
diff --git a/sim/Statecraft.Sim.Tests/StartingForcesTests.cs b/sim/Statecraft.Sim.Tests/StartingForcesTests.cs
index 459042d13..618545fae 100644
--- a/sim/Statecraft.Sim.Tests/StartingForcesTests.cs
+++ b/sim/Statecraft.Sim.Tests/StartingForcesTests.cs
@@ -193,6 +193,37 @@ public class StartingForcesTests
Assert.False(s.Units.ContainsKey(1));
}
+ // R-ENEMY-004: no enemy-side starting force may be authored to arrive after the game starts. The loader names the
+ // units_1948.yaml row and field, before a turn can add the unit.
+ [Fact]
+ public void AnEnemyRowDatedAfterTheStartIsRefused()
+ {
+ var ex = Assert.Throws<ContentException>(() =>
+ Load(Row("late_enemy", "egypt", 20, from: "1948-06-20", asOf: "1948-06-20")));
+ Assert.Equal("map/units_1948.yaml", ex.File);
+ Assert.Equal("units[late_enemy].strength.as_of", ex.Field);
+ Assert.Contains("enemy-side force may not arrive after the game starts", ex.Message);
+ }
+
+ // R-ENEMY-004: Arrive is a second boundary for in-memory or otherwise unvalidated content. It refuses before adding
+ // anything, so an Israeli brigade due the same turn, listed before the enemy, is not added either.
+ [Fact]
+ public void ArriveRefusesAnEnemyForceThatBypassedTheLoader()
+ {
+ var c = Load(Row("late", "israel", 20, q: 3, from: "1948-06-15", asOf: "1948-06-15"), Row("first", "israel", 20));
+ c.StartingForces.Add(new StartingForce
+ {
+ Row = "late_enemy", Type = "egyptian_army", Side = "egypt", Strength = 2, Q = 2, R = 0,
+ Arrives = new DateTime(1948, 6, 15),
+ });
+ Assert.Equal(new[] { "first", "late", "late_enemy" }, c.StartingForces.Select(f => f.Row));
+ var s = Simulation.NewGame(c, GoldenRun.Seed, Mode.Historical);
+ var before = s.Hash();
+ Assert.Throws<InvalidOperationException>(() => StartingForces.Arrive(c, s, new DateTime(1948, 6, 15)));
+ Assert.Equal(new[] { 0 }, s.Units.Keys);
+ Assert.Equal(before, s.Hash());
+ }
+
// R-UNIT-009: a strength's as_of that is not a 'YYYY-MM-DD' date is a load error naming the file and the row.
[Fact]
public void AStrengthDateMustBeADate()
diff --git a/sim/Statecraft.Sim/Movement.cs b/sim/Statecraft.Sim/Movement.cs
index 2fac1d353..2fc8e9dd5 100644
--- a/sim/Statecraft.Sim/Movement.cs
+++ b/sim/Statecraft.Sim/Movement.cs
@@ -310,7 +310,8 @@ namespace Statecraft.Sim
}
/// <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>
+ /// <paramref name="r"/>), by the same search as Move, including R-MOVE-001's full-points first-step exception; null
+ /// when no path leads there or the unit is already there.</summary>
internal static (int Q, int R)? Toward(Content c, GameState s, Unit u, int q, int r)
{
var points = Points(c, u);
@@ -319,7 +320,6 @@ namespace Statecraft.Sim
if (!dist.ContainsKey((q, r)) || (u.Q, u.R) == (q, r)) return null;
var h = (q, r);
while (dist[h] > points && prev[h] != (u.Q, u.R)) h = prev[h];
- if (dist[h] > points && !Gdd03Military.Applies(c)) h = prev[h];
return h == (u.Q, u.R) ? ((int, int)?)null : h;
}
diff --git a/sim/Statecraft.Sim/StartingForces.cs b/sim/Statecraft.Sim/StartingForces.cs
index d763a5ea0..59e5c71b7 100644
--- a/sim/Statecraft.Sim/StartingForces.cs
+++ b/sim/Statecraft.Sim/StartingForces.cs
@@ -85,6 +85,8 @@ namespace Statecraft.Sim
if (people < 0 || people != decimal.Truncate(people)) throw new ContentException(FileName, $"{at}.strength.value", "must be a whole number >= 0");
var units = Cities.StartUnits(people, ppu); // the nearest unit, a half up, at least 1 for a force with people
if (units == 0) continue; // a strength of nobody starts nothing
+ if (asOf > c.Rules.Start && side != Movement.PlayerSide)
+ throw new ContentException(FileName, $"{at}.strength.as_of", "an enemy-side force may not arrive after the game starts (R-ENEMY-004)");
if (!hexes.TryGetValue((id, k), out var qr))
throw new ContentException(HexesFileName, "anchors", $"no hex for {at}.anchors[{k}] ({FileName}); rerun tools/unit_anchor_hexes.py");
var (q, r) = qr;
@@ -147,11 +149,15 @@ namespace Statecraft.Sim
public static void Arrive(Content c, GameState s, DateTime next)
{
PopulationLedger.RefuseAggregate(s);
+ bool Due(StartingForce f) => f.Arrives is DateTime day && s.Date < day && day <= next;
+ // Every due force is checked before any is added, so a refusal leaves the state unchanged.
+ foreach (var f in c.StartingForces)
+ if (Due(f) && f.Side != Movement.PlayerSide)
+ throw new InvalidOperationException($"Enemy-side starting force '{f.Row}' may not arrive after the game starts (R-ENEMY-004)");
for (int i = 0; i < c.StartingForces.Count; i++)
{
var f = c.StartingForces[i];
- if (f.Arrives is DateTime day && s.Date < day && day <= next)
- s.Units.Add(i, new Unit(i, f.Type, f.Q, f.R, side: f.Side, strength: f.Strength));
+ if (Due(f)) s.Units.Add(i, new Unit(i, f.Type, f.Q, f.R, side: f.Side, strength: f.Strength));
}
}