A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: GDD Phase 5 PR 2, the military unit record and types (R-UNIT-001, R-UNIT-002; refs #741) (#1024)
Beri0f9b6a225cc4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 68a5ea0e5..0c480157f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,10 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB## [Unreleased]### Added+- The military unit record (GDD Phase 5 PR 2): a unit can hold a side, a strength and a standing order with its target,+ each written into the state hash only when set, so a halutz hashes as before and no golden moves. `unit_types.yaml`+ gains Israel's `veteran_soldier` (infantry), `artillery` and `armoured_car` (armour) with a `side` and a `class`; the+ loader refuses a military type without both (R-UNIT-001, R-UNIT-002; refs #741, #385). Nothing uses them yet.- Kiryat Shmona (founded 18 July 1949) and Beit Shemesh (15 December 1950, the National Library's December 1950under the monthly turn) join the yishuv sites in `content/sites.yaml`, each with a field site in its hex; thefounding days are the owner's (#785), and the rows stay draft. The reference player builds them in id order, sodiff --git a/content/unit_types.yaml b/content/unit_types.yamlindex f9a52f5b2..e7af5dcbc 100644--- a/content/unit_types.yaml+++ b/content/unit_types.yaml@@ -16,3 +16,9 @@ types:training_turns: 4 # DESIGN VALUE: owner-set balance, not a historical figure (D-A3)training_cost: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-A3: IL millions per group)- { id: veteran_halutz, kind: unit } # a halutz unit after rules.yaml mvp.veteran_halutz_service turns of work (R-VET-001; D-D9); not trained+# 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 }diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex 59076eab6..ede6fc9bf 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -116,6 +116,14 @@ R-CAMP-001: `PioneerWork(unit, build_camp, site)` builds a training camp at a siR-CAMP-002: A camp site's `city` is the MVP city (`cities.yaml`) nearest to the site by hex distance (Q-CAMP-1). When several are equally near, it is the one of them nearest by straight-line km from the point the site's hex comes from to the city's point in `map/settlements_1948.yaml` (owner, 17 October 2026, #927). Tzrifin's hex is one hex from Tel Aviv, Petah Tikva, Rehovot and Rishon LeZion, so it serves Rishon LeZion, about 3.9 km away.+## Military units++Phase 5 PR 2 (#741) adds the record and the types only; nothing moves, fights or trains into them yet (owner, 18 October 2026, #741: movement points in Phase 5 PR 5, upkeep in PR 3, enemy types in PR 4).++R-UNIT-001: A military unit is a group at formation scale, one token per formation (D-A1; Q-UNIT-1). It has a side, a type, a hex, a strength (an integer, in population units) and a standing order with its target. A military type in `unit_types.yaml` is a `unit` with a `side` (one of `units_1948.yaml`'s sides) and a `class` (infantry, artillery or armour); the loader refuses a type with only one of them, an unknown side or class, or a population type with either, naming the file and field. The MVP's military types are Israel's `veteran_soldier`, `artillery` and `armoured_car`; `recruit` stays a count per city (R-TRAIN-003).++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.+## ObjectivesR-OBJ-001: An objective (`objectives.yaml`) names its condition, `completes_when: { site_built: <site> }`, a designated site of kind yishuv whose `founded` date must equal the objective's `reference_date`. In the last step of each GDD turn (spec §2.3, step 11; D-A6), in id order, an objective whose site is built and that is not yet recorded is recorded once, with the turn's end date (the site's `BuiltOn`). Recording it again, or in the legacy loop, changes nothing; a stopped build completes nothing.diff --git a/sim/Statecraft.Sim.Tests/GddStateTests.cs b/sim/Statecraft.Sim.Tests/GddStateTests.csindex e38085fee..19cc144da 100644--- a/sim/Statecraft.Sim.Tests/GddStateTests.cs+++ b/sim/Statecraft.Sim.Tests/GddStateTests.cs@@ -62,7 +62,8 @@ public class GddStateTestsnew City("a", 1, 1, 2, 1, 1), new City("a", 1, 1, 1, 2, 1), new City("a", 1, 1, 1, 1, 2) };Assert.Equal(cities.Length, new HashSet<string>(Array.ConvertAll(cities, H)).Count);var units = new[] { new Unit(1, "halutz", 0, 0), new Unit(2, "halutz", 0, 0), new Unit(1, "recruit", 0, 0), new Unit(1, "halutz", 1, 0), new Unit(1, "halutz", 0, 1),- new Unit(1, "halutz", 0, 0, 1) };+ new Unit(1, "halutz", 0, 0, 1), new Unit(1, "halutz", 0, 0, side: "israel"), new Unit(1, "halutz", 0, 0, strength: 1),+ new Unit(1, "halutz", 0, 0, order: "hold"), new Unit(1, "halutz", 0, 0, order: "hold", orderTarget: "2") };Assert.Equal(units.Length, new HashSet<string>(Array.ConvertAll(units, U)).Count);string K(Cohort k) { var s = new GameState(); s.Cohorts.Add(k.Id, k); return s.Hash(); }var cohorts = new[] { new Cohort(1, "recruit", "a", 1, 1), new Cohort(2, "recruit", "a", 1, 1), new Cohort(1, "halutz", "a", 1, 1),diff --git a/sim/Statecraft.Sim.Tests/MilitaryUnitTests.cs b/sim/Statecraft.Sim.Tests/MilitaryUnitTests.csnew file mode 100644index 000000000..32a9ab346--- /dev/null+++ b/sim/Statecraft.Sim.Tests/MilitaryUnitTests.cs@@ -0,0 +1,67 @@+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>The military unit record and the military unit types (GDD Phase 5 PR 2, #741). No behaviour: the state can hold+/// a unit of any side, and the content can describe the Israeli military types. Movement points, strength and upkeep per+/// type, and the enemy types, come in later PRs (owner, 18 October 2026, #741: "all defaults").</summary>+public class MilitaryUnitTests+{+ static Content Load(string types) =>+ ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string> { ["unit_types.yaml"] = types })));++ // R-UNIT-002: a halutz unit's hash text is the one main wrote before the military fields existed.+ [Fact]+ public void AHalutzHashesAsBefore()+ {+ Assert.Equal("1:halutz@0,0", new Unit(1, "halutz", 0, 0).Canonical());+ Assert.Equal("1:veteran_halutz@0,0/6", new Unit(1, "veteran_halutz", 0, 0, 6).Canonical());+ var s = new GameState();+ s.Units.Add(1, new Unit(1, "halutz", -3, 19));+ Assert.EndsWith("\nunits[\n 1:halutz@-3,19", s.Describe());+ }++ // R-UNIT-001, R-UNIT-002: a unit with a side, a strength and a standing order writes each of them.+ [Fact]+ public void AMilitaryUnitWritesItsFields()+ {+ Assert.Equal("2:veteran_soldier@3,4|side=israel|strength=5|order=hold|target=7",+ new Unit(2, "veteran_soldier", 3, 4, side: "israel", strength: 5, order: "hold", orderTarget: "7").Canonical());+ Assert.Equal("2:artillery@3,4/1|side=israel", new Unit(2, "artillery", 3, 4, 1, side: "israel").Canonical());+ }++ // R-UNIT-001: the game's military types are Israel's three, with their class (Q-UNIT-1; owner, 18 October 2026, #741).+ [Fact]+ public void TheRealGameHasTheThreeIsraeliMilitaryTypes()+ {+ var c = ContentLoader.Load(RealContentTests.ContentRoot());+ Assert.Equal(new[] { ("veteran_soldier", "unit", "israel", "infantry"), ("artillery", "unit", "israel", "artillery"), ("armoured_car", "unit", "israel", "armour") },+ c.UnitTypes.Where(t => t.Side != "").Select(t => (t.Id, t.Kind, t.Side, t.Class)));+ Assert.Equal("", c.UnitTypes.Single(t => t.Id == "recruit").Side); // a count per city until PR 3 (R-TRAIN-003)+ }++ // R-UNIT-001: a military type needs both a side and a class; a type with neither still loads.+ [Theory]+ [InlineData(" - { id: soldier, kind: unit, side: israel }\n", "types[soldier].class", "required for a military type")]+ [InlineData(" - { id: soldier, kind: unit, class: infantry }\n", "types[soldier].side", "required for a military type")]+ [InlineData(" - { id: soldier, kind: unit, side: atlantis, class: infantry }\n", "types[soldier].side", "unknown side 'atlantis'")]+ [InlineData(" - { id: soldier, kind: unit, side: israel, class: cavalry }\n", "types[soldier].class", "unknown class 'cavalry' (infantry, artillery or armour)")]+ [InlineData(" - { id: soldier, kind: population, side: israel, class: infantry }\n", "types[soldier].kind", "a military type is a unit")]+ public void AMilitaryTypeNeedsASideAndAClass(string row, string field, string message)+ {+ var ex = Assert.Throws<ContentException>(() => Load(Fixture.GddUnitTypes + row));+ Assert.Equal("unit_types.yaml", ex.File);+ Assert.Equal(field, ex.Field);+ Assert.Contains(message, ex.Message);+ }++ // R-UNIT-001+ [Fact]+ public void AMilitaryTypeLoadsAndAPopulationTypeNeedsNeither()+ {+ var c = Load(Fixture.GddUnitTypes + " - { id: soldier, kind: unit, side: egypt, class: armour }\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/Content.cs b/sim/Statecraft.Sim/Content.csindex 12dba04b9..5fb7b99f5 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -631,6 +631,10 @@ namespace Statecraft.Simpublic int TrainingTurns { get; set; }/// <summary>IL millions per population unit trained, paid when training starts (R-TRAIN-001). Only with a facility.</summary>public double TrainingCost { get; set; }+ /// <summary>A military type's side (units_1948.yaml's side ids), or "" for a type that is not military (R-UNIT-001).</summary>+ 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>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.csindex 6a6a37c47..eef43f367 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -979,6 +979,12 @@ namespace Statecraft.Sim/// <summary>Facilities a city may have (cities.yaml facilities): the GDD's training places (D-D5).</summary>static readonly string[] Facilities = { "military_camp", "hakhshara" };+ /// <summary>A military type's sides (unit_types.yaml side): units_1948.yaml's side ids (Q-START-4, owner, 15 October 2026).</summary>+ static readonly string[] Sides = { "israel", "egypt", "jordan", "syria", "iraq", "lebanon", "ala", "local_arab_forces" };++ /// <summary>A military type's classes (unit_types.yaml class; GDD Phase 5 plan, PR 2).</summary>+ static readonly string[] Classes = { "infantry", "artillery", "armour" };+static readonly string[] CityStatuses = { "sourced", "derived", "wikipedia-only", "design" };static readonly System.Text.RegularExpressions.Regex Month = new System.Text.RegularExpressions.Regex(@"^\d{4}-\d{2}\z");@@ -1032,6 +1038,15 @@ namespace Statecraft.Sim{var at = $"types[{x.Id}]";if (x.Kind != "population" && x.Kind != "unit") throw new ContentException(uf, at + ".kind", "must be population or unit");+ // R-UNIT-001: a type with a side or a class is military, and needs both; the sides are units_1948.yaml's.+ if (x.Side != "" || x.Class != "")+ {+ if (x.Kind != "unit") throw new ContentException(uf, at + ".kind", "a military type is a unit");+ if (x.Side == "") throw new ContentException(uf, at + ".side", "required for a military type");+ if (x.Class == "") throw new ContentException(uf, at + ".class", "required for a military type");+ 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)");+ }if (x.Facility == ""){// Training (R-TRAIN-001) needs a place to train; values without one would be read by nothing.diff --git a/sim/Statecraft.Sim/GddState.cs b/sim/Statecraft.Sim/GddState.csindex 6892f2a7b..387e9e098 100644--- a/sim/Statecraft.Sim/GddState.cs+++ b/sim/Statecraft.Sim/GddState.cs@@ -67,13 +67,28 @@ namespace Statecraft.Simpublic int R { get; }/// <summary>Turns of work done as a halutz (R-VET-001). Phase 5 Q-UNIT-2 counts soldiers' service in the same field.</summary>public int Service { get; }+ /// <summary>A military unit's side (a unit_types.yaml `side`), or "" for a halutz (R-UNIT-001).</summary>+ public string Side { get; }+ /// <summary>A military unit's strength in population units (Q-UNIT-1, Q-UNIT-4), or 0 (R-UNIT-001).</summary>+ public int Strength { get; }+ /// <summary>The unit's standing order and what it names, or "" for none (R-UNIT-001). Later Phase 5 PRs set them.</summary>+ public string Order { get; }+ public string OrderTarget { get; }++ public Unit(int id, string type, int q, int r, int service = 0, string side = "", int strength = 0, string order = "", string orderTarget = "")+ {+ Id = id; Type = type; Q = q; R = r; Service = service; Side = side; Strength = strength; Order = order; OrderTarget = orderTarget;+ }- public Unit(int id, string type, int q, int r, int service = 0) { Id = id; Type = type; Q = q; R = r; Service = service; }-- /// <summary>The record as the state hash writes it. The service is written only when there is some, so a unit with none- /// hashes as it did before Phase 4 PR 6 (R-LOOP-002's rule).</summary>+ /// <summary>The record as the state hash writes it. Each field after the hex is written only when it is not at its+ /// default, so a halutz with no service hashes as it did before Phase 4 PR 6, and with service as before Phase 5+ /// (R-LOOP-002's rule; R-UNIT-002).</summary>public string Canonical() => string.Format(CultureInfo.InvariantCulture, "{0}:{1}@{2},{3}", Id, Type, Q, R)- + (Service == 0 ? "" : "/" + Service.ToString(CultureInfo.InvariantCulture));+ + (Service == 0 ? "" : "/" + Service.ToString(CultureInfo.InvariantCulture))+ + (Side == "" ? "" : "|side=" + Side)+ + (Strength == 0 ? "" : "|strength=" + Strength.ToString(CultureInfo.InvariantCulture))+ + (Order == "" ? "" : "|order=" + Order)+ + (OrderTarget == "" ? "" : "|target=" + OrderTarget);}/// <summary>A group of a city's people in training (GDD "Progression"; R-TRAIN-001): <see cref="Count"/> population unitsdiff --git a/sim/Statecraft.Sim/Projects.cs b/sim/Statecraft.Sim/Projects.csindex fdb8b1f4e..bffe26d5d 100644--- a/sim/Statecraft.Sim/Projects.cs+++ b/sim/Statecraft.Sim/Projects.cs@@ -62,7 +62,7 @@ namespace Statecraft.Simif (u.Type == "halutz"){var service = u.Service + 1;- u = new Unit(u.Id, service >= r.VeteranHalutzService!.Value ? VeteranType : u.Type, u.Q, u.R, service);+ u = new Unit(u.Id, service >= r.VeteranHalutzService!.Value ? VeteranType : u.Type, u.Q, u.R, service, u.Side, u.Strength, u.Order, u.OrderTarget);}}}@@ -161,7 +161,7 @@ namespace Statecraft.Simif (u.Type != "halutz") continue;var service = u.Service + 1;var promoted = service >= r.VeteranHalutzService!.Value;- s.Units[u.Id] = new Unit(u.Id, promoted ? VeteranType : u.Type, u.Q, u.R, service);+ s.Units[u.Id] = new Unit(u.Id, promoted ? VeteranType : u.Type, u.Q, u.R, service, u.Side, u.Strength, u.Order, u.OrderTarget);if (promoted) why.Add(new Cause("map", w.Site, 1, "A group of halutzim became veteran pioneers"));}}