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.

Combat: an enemy retreat no longer ends on a player's locality (Fixes #2932) (#2934)

Berif3a36da3583c
diff --git a/changelog.d/2932-enemy-retreat.md b/changelog.d/2932-enemy-retreat.md
new file mode 100644
index 000000000..c7b7a653c
--- /dev/null
+++ b/changelog.d/2932-enemy-retreat.md
@@ -0,0 +1,6 @@
+### Fixed
+
+- An enemy unit beaten back in combat no longer retreats onto an empty Israeli town or city. It obeys the same limit
+ as an enemy move, and with no other hex to go to it surrenders. Before, under gdd-0.1 such a retreat onto a city
+ ended the game at once with "The enemy holds a city". A save in which that retreat happened replays differently
+ (Fixes #2932).
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index bd7490d03..6715b9724 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -334,7 +334,7 @@ R-COMBAT-001: `UnitOrder(unit, attack, q, r)` makes one of the player's military
R-COMBAT-002: Resolver step 2 resolves the enemy's attacks in ascending attacker id: the lowest-id unit with an attack not yet in an engagement leads one, with every enemy unit attacking the same hex. A player's attack is fought when its order runs (R-COMBAT-001), as one engagement with that unit alone and one draw. Each unit's strength is first multiplied by its type's `combat_percent` (R-COMBAT-007, R-COMBAT-008). The attackers' strengths are summed; each defender's strength is multiplied by its order's defence percent (`Orders.DefencePercent`: fortify 125, R-ORDER-002) and by `mvp.combat_terrain_percent` for its hex's biome (real values: hills 125, mountains 150, every other land biome 100). The ratio is attack over defence in whole percent, rounded down, in integers only; the row of `mvp.combat_table` is the last whose `min_ratio_percent` it reaches (real rows: below 1:2, 1:2, 1:1, 2:1, 3:1). Each engagement draws exactly one RNG value, a face of the row (six in the real table), whatever its outcome; a step 2 with no engagement draws nothing (docs/determinism.md, "Combat draws"). `Combat.Preview(c, s, unit, q, r)` gives the ratio and row the UI shows (Q-UI-1; spec §2.6), counting that unit alone for a player's attack. Under exact identity `gdd-0.3`, each defender instead counts once at `100 + biome defence_percent + permanent fort bonus + applicable settled Fortify bonus` percent, with bonuses read from the existing catalogue (#1668 military-combat.md:27, additive). Hold and unsettled/mismatched Fortify add nothing. Mountain + fort + settled Fortify is 225% of base defence (50 + 50 + 25); preview and resolution share this integer calculation. The older multiplicative formula remains unchanged. Under exact `gdd-0.3`, after the draw and the losses, retreats and surrenders, the engagement's survivors gain combat experience (R-UNIT-011), drawing nothing more.
-R-COMBAT-003: The face gives the population units each side loses and whether the defenders retreat. Losses fall one unit at a time on the side's strongest unit in the engagement (a tie on the lower id; the attackers' losses spare their artillery, R-COMBAT-007); a unit at 0 is destroyed and leaves the state, and its id is never reused (`NextId` does not move). When the face says retreat, each defender left, in id order, moves one hex to the first neighbour in the fixed order (R-MOVE-002) that is land, holds no unit of the other side, has room for its side under `mvp.stack_limit`, and, for a player's unit, is not an enemy-held locality (R-MOVE-005). A defender with no such hex surrenders and leaves the state: the only way a unit is captured (impact plan §4.3 item 1; its people are counted as prisoners or as the player's soldiers held, R-POW-001, R-POW-005). The attackers never advance into the hex (Q-COMBAT-3). A player's unit's first loss stores the strength it had as its `Full`; only replacements (R-TRAIN-004) restore lost strength.
+R-COMBAT-003: The face gives the population units each side loses and whether the defenders retreat. Losses fall one unit at a time on the side's strongest unit in the engagement (a tie on the lower id; the attackers' losses spare their artillery, R-COMBAT-007); a unit at 0 is destroyed and leaves the state, and its id is never reused (`NextId` does not move). When the face says retreat, each defender left, in id order, moves one hex to the first neighbour in the fixed order (R-MOVE-002) that is land, holds no unit of the other side, has room for its side under `mvp.stack_limit`, and is not a locality closed to its side: for a player's unit an enemy-held locality (R-MOVE-005), for an enemy unit a player's locality (R-ENEMY-001, #2932). A defender with no such hex surrenders and leaves the state: the only way a unit is captured (impact plan §4.3 item 1; its people are counted as prisoners or as the player's soldiers held, R-POW-001, R-POW-005). The attackers never advance into the hex (Q-COMBAT-3). A player's unit's first loss stores the strength it had as its `Full`; only replacements (R-TRAIN-004) restore lost strength.
R-COMBAT-004: Each of the player's units pays `mvp.arms_per_attack` (real value 1; artillery pays its `arms_per_fire` instead, R-COMBAT-007) from the Arms stock when the attack is given; an attack the stock cannot pay for is refused. Enemy units pay nothing (Q-ENEMY-4: no supply). This price rule remains for `gdd-0.1`; under `gdd-0.3`, player attacks and artillery fire neither read nor spend these shot prices (#1706; owner ruling, 25 October 2026, on #1668). Arms stock, purchases, equipment, replacements and training refunds remain governed by their existing rules.
diff --git a/sim/Statecraft.Sim.Tests/CombatTests.cs b/sim/Statecraft.Sim.Tests/CombatTests.cs
index ae4c83537..2a5aee2c7 100644
--- a/sim/Statecraft.Sim.Tests/CombatTests.cs
+++ b/sim/Statecraft.Sim.Tests/CombatTests.cs
@@ -501,7 +501,8 @@ public class CombatTests
}
// R-COMBAT-003: a defender the row sends back retreats to the first free neighbour in the fixed order: (3, 0) holds the
- // attacker, so (1, 0)... is town_a's hex, free to an enemy unit (R-MOVE-005 binds the player's units only).
+ // attacker, (3, -1) and (2, -1) are off the board and (1, 0) is town_a's, closed to an enemy unit (R-ENEMY-001, #2932),
+ // so (1, 1).
[Fact]
public void ALosingDefenderRetreatsOneHex()
{
@@ -509,8 +510,8 @@ public class CombatTests
var s = With(c, Attacking(Soldier(1, 3, 0, 6), 2, 0), Enemy(2, 2, 0, 3));
var why = Resolve(c, s);
var e = s.Units[2];
- Assert.Equal((2, 1, 0), (e.Strength, e.Q, e.R));
- Assert.Contains(why, x => x.Message == "Unit 2 retreated to hex 1,0");
+ Assert.Equal((2, 1, 1), (e.Strength, e.Q, e.R));
+ Assert.Contains(why, x => x.Message == "Unit 2 retreated to hex 1,1");
Assert.Equal((3, 0), (s.Units[1].Q, s.Units[1].R)); // the attacker does not advance
// The attack ends: no enemy unit is on the hex now.
Assert.Equal(("", ""), (s.Units[1].Order, s.Units[1].OrderTarget));
@@ -530,6 +531,23 @@ public class CombatTests
Assert.Equal(next, s.NextId);
}
+ // R-COMBAT-003 with R-ENEMY-001 (#2932): an enemy unit's retreat may not end on a player's locality, as its move may not.
+ // (0, 0)'s neighbours on the board are town_a's (1, 0) and the attacker's (0, 1), so the enemy surrenders. Before the fix it
+ // retreated onto town_a, a city, and under gdd-0.1 the turn ended in defeat_war (R-END-003); gdd-0.3 holds the same.
+ [Theory]
+ [InlineData(SaveGame.GddRuleset)]
+ [InlineData(SaveGame.Gdd03Ruleset)]
+ public void AnEnemyRetreatNeverEndsOnAPlayersLocality(string ruleset)
+ {
+ var c = Gdd03MovementFortTests.Load(ruleset);
+ var s = With(c, new Unit(1, "recruit", 0, 1, side: "israel", strength: 6), Enemy(2, 0, 0, 2));
+ var r = Step(c, s, new UnitOrder(1, Combat.Attack, 0, 0));
+ Assert.Empty(r.Rejected);
+ Assert.False(r.State.Units.ContainsKey(2));
+ Assert.Contains(r.Why, x => x.Key == WhyKeys.SurrenderedPrisoners);
+ Assert.Null(r.State.GameOver);
+ }
+
// Review focus 4: a unit at 0 is removed, and its id is never reused.
[Fact]
public void ADestroyedUnitLeavesTheState()
diff --git a/sim/Statecraft.Sim/Combat.cs b/sim/Statecraft.Sim/Combat.cs
index 9fea9cd74..abb5354e7 100644
--- a/sim/Statecraft.Sim/Combat.cs
+++ b/sim/Statecraft.Sim/Combat.cs
@@ -431,10 +431,11 @@ namespace Statecraft.Sim
/// <summary>R-COMBAT-003: the first neighbour of the unit's hex, in the fixed order (R-MOVE-002), that is land, holds no
/// unit of the other team, has room under mvp.stack_limit for the unit's side (R-MOVE-003) and, for the player's unit,
- /// is not an enemy-held locality (R-MOVE-005); null when there is none.</summary>
+ /// is not an enemy-held locality (R-MOVE-005), and for an enemy unit is not a player's locality (R-ENEMY-001,
+ /// #2932); null when there is none.</summary>
static (int, int)? Retreat(Content c, GameState s, MvpRules mvp, Unit u)
{
- var noEntry = Player(u) ? Movement.NoEntry(c, s) : new HashSet<(int Q, int R)>();
+ var noEntry = Movement.NoEntry(c, s, enemy: !Player(u));
foreach (var (dq, dr) in Movement.Neighbours)
{
int q = u.Q + dq, r = u.R + dr;