A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Add an inactive combat catalogue and contract guards (Refs #1706) (#1837)
Eyal Golan0c21705bab3f
diff --git a/changelog.d/1706-c303.md b/changelog.d/1706-c303.mdnew file mode 100644index 000000000..30b65047f--- /dev/null+++ b/changelog.d/1706-c303.md@@ -0,0 +1 @@+- Add inactive synthetic combat catalogue validation and contract fixtures for #1706 (slices 0/1 only). No strength calculation or combat activation; runtime rules and shipped content remain unchanged.diff --git a/docs/gdd03-catalogue.md b/docs/gdd03-catalogue.mdindex 50dba4b65..8726e3a6c 100644--- a/docs/gdd03-catalogue.md+++ b/docs/gdd03-catalogue.md@@ -26,3 +26,9 @@ The coordinator's catalogue citation is **owner ruling, 25 Oct 2026, on #1668**.| Attention removed | None | No Attention key invented. Rule implementation tracked separately in #1688. |Numeric parameters the owner did not set are not made Agreed by these rulings. The catalogue contains no new debt, economic-defeat or timing numbers. Other GDD 0.3 systems and the eventual switch-over have their own issues.++## #1706 slices 0/1: inactive combat catalogue foundation++Coordinator decision, 26 Oct 2026 (Q5): synthetic catalogue validation only; the foundation remains inactive in the actual game. The catalogue defines one draw (Agreed), four ratio ranges, complete, non-overlapping inclusive 0..99 outcome bands, role factors and artillery support range (Default). Required missing, malformed or Deferred entries are refused without an old-table fallback.++Sources: `content/gdd03-balance.yaml:447-475,484-495`; pinned GDD `605277df`, `docs/gdd/balance.md:172,175-177,180-185`. See [the combat rules](rules/mvp.md#combat) for current runtime behavior.diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex cf0f73f82..4061180e0 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -506,3 +506,5 @@ R-POP-001: Only exact `gdd-0.3` enables the population-ledger capability, indepeR-POP-002: A ledger record has exactly one typed status and assignment, validated location, home and captor references, whole reception-turn ticks capped by the catalogue requirement, civilian profession-specific tier and actual-work XP, separate military qualification/combat XP, and distinct issued civilian/military equipment and paid facts. Unknown references, unresolved teacher ids, incompatible statuses/assignments, inconsistent region/hex/facility bindings, invalid progress/tiers and duplicate issued-item ownership are refused before mutation. Moves and atomic status/location/assignment transitions retain identity/history. Capture retains home context without inventing a prison hex or refunding equipment. Ledger changes never touch resources, causes, RNG or Attention. Initialization is internal and fixture-only; initialized ledger fixtures refuse aggregate Simulation commands and turns. Old identities refuse ledger mutation. Prices, progression awards, return destinations, tool lock-in and captive-equipment outcomes remain with their owning issues.R-POP-003: Clone copies all ledger containers; immutable records and frozen bindings may be shared. The canonical writer emits a gdd-0.3-only section ordered by numeric population id, with fixed field order, stable machine tokens, invariant integer formatting and length-prefixed reference strings. It covers every record/assignment/equipment/reference field, binding, creation/loss provenance and allocator even after the last combat loss. Legacy/gdd-0.1 emit no ledger section or allocator marker. R-SAVE-001/002 still govern identity mismatch refusal and replay: no ledger snapshot or new command syntax is added in this foundation, and fixture injection is not replay evidence. Existing unpublished schema-4 draft hashes change; no migration promise is made.++#1706 slices 0/1 (coordinator decision, 26 Oct 2026, Q5): the synthetic combat catalogue foundation is inactive in the actual game. R-COMBAT-001 through R-COMBAT-008 retain their current runtime meanings. See [the catalogue foundation](../gdd03-catalogue.md#1706-slices-01-inactive-combat-catalogue-foundation) for its data contract and sources.diff --git a/sim/Statecraft.Sim.Tests/Gdd03CombatCatalogueTests.cs b/sim/Statecraft.Sim.Tests/Gdd03CombatCatalogueTests.csnew file mode 100644index 000000000..c3487bc5f--- /dev/null+++ b/sim/Statecraft.Sim.Tests/Gdd03CombatCatalogueTests.cs@@ -0,0 +1,175 @@+using System.Globalization;+using Statecraft.Sim;+using YamlDotNet.Serialization;+using YamlDotNet.Serialization.NamingConventions;++// R-COMBAT-002, R-COMBAT-007, R-COMBAT-008: #1706 slices 0/1, synthetic catalogue only.+public class Gdd03CombatCatalogueTests+{+ internal static Content Synthetic(string identity = SaveGame.Gdd03Ruleset)+ {+ // Copy design data, never shipped scenario state. The content file is not changed by this draft.+ var data = new DeserializerBuilder().WithNamingConvention(UnderscoredNamingConvention.Instance)+ .WithDuplicateKeyChecking().Build().Deserialize<Gdd03BalanceCatalogue>(+ File.ReadAllText(Path.Combine(RealContentTests.ContentRoot(), Gdd03BalanceCatalogue.FileName)));+ var c = PopulationLedgerTests.Content(identity);+ c.Gdd03Balance = data;+ return c;+ }++ static Gdd03DesignValue At(Content c, string path)+ {+ var pieces = path.Split('/');+ var value = c.Gdd03Balance!.Values[pieces[0]];+ return pieces.Length == 1 ? value : value.Parts[pieces[1]];+ }++ [Theory, InlineData("he-IL"), InlineData("en-US")]+ public void PositiveFractionalEndpointRefuses(string culture)+ {+ InCulture(culture, () => {+ var c = Synthetic(); At(c, "combat.draw_count/below_0_5").Values[1] = 59.5m;+ Assert.Throws<ContentException>(() => Gdd03BalanceCatalogue.ReadCombatCatalogue(c));+ });+ }++ [Theory, InlineData("he-IL"), InlineData("en-US")]+ public void NonnegativeReversedPairRefuses(string culture)+ {+ InCulture(culture, () => {+ var c = Synthetic(); var values = At(c, "combat.draw_count/below_0_5").Values;+ // Keep adjacent endpoints contiguous around the reversed 60..59 pair.+ values[3] = 59; values[4] = 60;+ Assert.Throws<ContentException>(() => Gdd03BalanceCatalogue.ReadCombatCatalogue(c));+ });+ }++ public static IEnumerable<object[]> RequiredCases()+ {+ foreach (var culture in new[] { "he-IL", "en-US" })+ foreach (var path in new[] { "combat.draw_count", "combat.draw_count/ratio_thresholds",+ "combat.draw_count/draw_band", "combat.draw_count/below_0_5", "combat.draw_count/from_0_5_below_1",+ "combat.draw_count/from_1_below_2", "combat.draw_count/at_least_2",+ "combat.armoured_factor", "combat.artillery_factor", "combat.artillery_range" })+ foreach (var defect in new[] { "missing", "null", "Deferred", "basis", "relabel", "note", "expression", "values", "parts", "empty", "extra", "fraction" })+ yield return new object[] { culture, path, defect };+ }++ [Theory, MemberData(nameof(RequiredCases))]+ public void EveryRequiredEntryRefusesMissingDeferredOrMalformed(string culture, string path, string defect)+ {+ InCulture(culture, () => {+ var c = Synthetic(); var pieces = path.Split('/'); var v = At(c, path);+ var map = pieces.Length == 1 ? c.Gdd03Balance!.Values : c.Gdd03Balance!.Values[pieces[0]].Parts;+ switch (defect)+ {+ case "missing": map.Remove(pieces[^1]); break;+ case "null": map[pieces[^1]] = null!; break;+ case "Deferred": v.Basis = "Deferred"; v.Values.Clear(); v.Parts.Clear(); v.Expression = "pending"; break;+ case "basis": v.Basis = "default"; break;+ case "relabel": v.Basis = v.Basis == "Agreed" ? "Default" : "Agreed"; break;+ case "note": v.Note = " "; break;+ case "expression": v.Expression = "pending"; break;+ case "values": v.Values = null!; break;+ case "parts": v.Parts = null!; break;+ case "empty": v.Values.Clear(); break;+ case "extra": v.Values.Add(100); break;+ case "fraction": v.Values[0] = -0.25m; break;+ }+ Assert.Throws<ContentException>(() => Gdd03BalanceCatalogue.ReadCombatCatalogue(c));+ });+ }++ [Theory, InlineData("he-IL"), InlineData("en-US")]+ public void ExactThresholdsAndAllHundredDrawsMatchPinnedGdd(string culture)+ {+ InCulture(culture, () => {+ var table = Gdd03BalanceCatalogue.ReadCombatCatalogue(Synthetic());+ // Independent endpoint oracle: GDD balance.md:182-185 at 605277df.+ int[][] ends = { new[] { 59, 89, 99, 99 }, new[] { 29, 69, 94, 99 },+ new[] { 9, 39, 84, 99 }, new[] { -1, 9, 69, 99 } };+ var probes = new[] { (0m, 0), (0.4999999999999999999999999999m, 0), (0.5m, 1),+ (0.9999999999999999999999999999m, 1), (1m, 2),+ (1.9999999999999999999999999999m, 2), (2m, 3), (decimal.MaxValue, 3) };+ foreach (var (ratio, row) in probes)+ {+ Assert.Equal(row, table.Row(ratio));+ for (var draw = 0; draw < 100; draw++)+ {+ var outcome = draw <= ends[row][0] ? Gdd03CombatOutcome.AttackerLoss+ : draw <= ends[row][1] ? Gdd03CombatOutcome.BothHold+ : draw <= ends[row][2] ? Gdd03CombatOutcome.DefenderRetreats : Gdd03CombatOutcome.DefenderLoss;+ Assert.Equal(outcome, table.Outcome(ratio, draw));+ Assert.Single(table.Bands(row), b => draw >= b.First && draw <= b.Last);+ }+ }+ Assert.Equal(1, table.DrawCount);+ Assert.Equal(1.50m, table.ArmouredFactor); Assert.Equal(1m, table.ArtilleryFactor);+ Assert.Equal(2, table.ArtilleryRange);+ Assert.Equal("Agreed", table.Sources["combat.draw_count"].Basis);+ foreach (var source in table.Sources.Where(p => p.Key != "combat.draw_count"))+ Assert.Equal("Default", source.Value.Basis);+ foreach (var source in table.Sources.Values) Assert.Contains("605277df", source.Note);+ Assert.Throws<ArgumentOutOfRangeException>(() => table.Outcome(1m, -1));+ Assert.Throws<ArgumentOutOfRangeException>(() => table.Outcome(1m, 100));+ Assert.Throws<ArgumentOutOfRangeException>(() => table.Row(-1m));+ // Validated snapshot must not follow later edits to mutable input.+ var c = Synthetic(); var snapshot = Gdd03BalanceCatalogue.ReadCombatCatalogue(c);+ At(c, "combat.draw_count/below_0_5").Values[1] = 0;+ Assert.Equal(Gdd03CombatOutcome.AttackerLoss, snapshot.Outcome(0m, 59));+ });+ }++ [Theory]+ [InlineData("below_0_5", 2, 59)] // overlap+ [InlineData("below_0_5", 2, 61)] // gap+ [InlineData("from_0_5_below_1", 7, 98)] // incomplete+ [InlineData("from_1_below_2", 1, -1)] // reversed+ [InlineData("at_least_2", 5, 100)] // outside band+ [InlineData("ratio_thresholds", 0, 1)] // duplicate+ [InlineData("draw_band", 1, 98)]+ public void InvalidBandsAndThresholdsRefuse(string part, int index, int value)+ {+ var c = Synthetic(); At(c, "combat.draw_count/" + part).Values[index] = value;+ Assert.Throws<ContentException>(() => Gdd03BalanceCatalogue.ReadCombatCatalogue(c));+ }++ [Fact]+ public void AdditionalDrawsAreRejectedAtTheCatalogueBoundary()+ {+ var c = Synthetic(); At(c, "combat.draw_count").Values[0] = 2;+ Assert.Throws<ContentException>(() => Gdd03BalanceCatalogue.ReadCombatCatalogue(c));+ }++ [Theory, InlineData("combat.armoured_factor"), InlineData("combat.artillery_factor"), InlineData("combat.artillery_range")]+ public void ZeroRoleQuantitiesRefuse(string key)+ {+ var c = Synthetic(); At(c, key).Values[0] = 0;+ Assert.Throws<ContentException>(() => Gdd03BalanceCatalogue.ReadCombatCatalogue(c));+ }++ [Fact]+ public void MissingCatalogueAndWrongCatalogueIdentityNeverFallBack()+ {+ var c = Synthetic(); c.Gdd03Balance = null;+ Assert.Throws<ContentException>(() => Gdd03BalanceCatalogue.ReadCombatCatalogue(c));+ c = Synthetic(); c.Gdd03Balance!.Ruleset = SaveGame.GddRuleset;+ Assert.Throws<ContentException>(() => Gdd03BalanceCatalogue.ReadCombatCatalogue(c));+ c = Synthetic(); c.Gdd03Balance!.Values = null!;+ Assert.Throws<ContentException>(() => Gdd03BalanceCatalogue.ReadCombatCatalogue(c));+ }++ [Theory, InlineData("combat.draw_count"), InlineData("combat.artillery_range")]+ public void FractionalCountsRefuse(string key)+ {+ var c = Synthetic(); At(c, key).Values[0] = 1.5m;+ Assert.Throws<ContentException>(() => Gdd03BalanceCatalogue.ReadCombatCatalogue(c));+ }++ internal static void InCulture(string name, Action action)+ {+ var prior = CultureInfo.CurrentCulture; var ui = CultureInfo.CurrentUICulture;+ try { CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(name); CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture; action(); }+ finally { CultureInfo.CurrentCulture = prior; CultureInfo.CurrentUICulture = ui; }+ }+}diff --git a/sim/Statecraft.Sim.Tests/Gdd03CombatContractTests.cs b/sim/Statecraft.Sim.Tests/Gdd03CombatContractTests.csnew file mode 100644index 000000000..24454fe04--- /dev/null+++ b/sim/Statecraft.Sim.Tests/Gdd03CombatContractTests.cs@@ -0,0 +1,68 @@+using Statecraft.Sim;++// R-POP-001, R-POP-002, R-COMBAT-001..008: groundwork does not release aggregate guards.+public class Gdd03CombatContractTests+{+ [Theory, InlineData("he-IL"), InlineData("en-US")]+ public void InitializedLedgerHasItsOwnAuthorityAndAggregateCombatRefusesAtomically(string culture)+ {+ Gdd03CombatCatalogueTests.InCulture(culture, () => {+ var c = Gdd03CombatCatalogueTests.Synthetic();+ var s = PopulationLedger.CreateFixture(c, PopulationLedgerTests.Bindings(), new[] {+ new PopulationInventoryRow("synthetic-combat-contract", 0, PopulationLedgerTests.Person()) });+ s.Population["fixture"] = 2000; s.Arms = 5; s.Food = 7; s.Treasury = 23; s.Debt = 2; s.RngState = 99;+ Assert.True(s.PopulationLedger.IsInitialized);+ Assert.Equal(10000d, s.TotalPopulation); // ledger authority, not the poisoned aggregate 2000+ s.PopulationLedger.Reconcile();+ var before = s.Describe(); var hash = s.Hash(); var rng = s.RngState;+ var cause = new Cause("fixture", "keep", 1, "keep"); var why = new List<Cause> { cause };+ foreach (var operation in new Action[] {+ () => Combat.Resolve(c, s, why), () => { Combat.Outcomes(c, s, 0); } })+ {+ Assert.Throws<NotSupportedException>(operation);+ Assert.Equal(before, s.Describe()); Assert.Equal(hash, s.Hash());+ Assert.Equal(rng, s.RngState); Assert.Equal(5, s.Arms); Assert.Equal(7, s.Food);+ Assert.Equal(23, s.Treasury); Assert.Equal(2, s.Debt); Assert.Same(cause, Assert.Single(why));+ }+ // Reading design data has no state argument, mutator or RNG source.+ Assert.Equal(1, Gdd03BalanceCatalogue.ReadCombatCatalogue(c).DrawCount);+ Assert.Equal(before, s.Describe()); Assert.Equal(hash, s.Hash());+ });+ }++ [Theory, InlineData(SaveGame.GddRuleset), InlineData(SaveGame.Gdd03Ruleset)]+ public void UninitializedSyntheticStateKeepsTheExistingAggregateOutcomePath(string identity)+ {+ var files = Fixture.Gdd();+ files["eras.yaml"] = files["eras.yaml"].Replace("loop: gdd", "loop: gdd, ruleset: " + identity);+ files[Gdd03BalanceCatalogue.FileName] = File.ReadAllText(Path.Combine(RealContentTests.ContentRoot(), Gdd03BalanceCatalogue.FileName));+ var c = ContentLoader.Load(Fixture.Write(files));+ var s = CombatTests.With(c);+ Assert.False(s.PopulationLedger.IsInitialized);+ var before = s.Describe(); var rng = s.RngState;+ var mvp = c.RulesAt(s.Date).Mvp!; var authored = mvp.CombatTable[0];+ var expected = Enumerable.Range(0, authored.AttackerLoss.Count)+ .Select(i => (AttackersLose: authored.AttackerLoss[i] * mvp.PeoplePerUnit,+ DefendersLose: authored.DefenderLoss[i] * mvp.PeoplePerUnit, Retreat: authored.DefenderRetreats[i] == 1))+ .GroupBy(face => face)+ .Select(group => (Faces: group.Count(), Of: authored.AttackerLoss.Count,+ group.Key.AttackersLose, group.Key.DefendersLose, group.Key.Retreat)).ToArray();+ Assert.Equal(expected, Combat.Outcomes(c, s, 0).ToArray());+ Assert.Equal(before, s.Describe()); Assert.Equal(rng, s.RngState);+ }++ [Fact]+ public void ShippedErasCannotEnterTheNewCatalogueBoundary()+ {+ var shipped = ContentLoader.Load(RealContentTests.ContentRoot());+ Assert.NotEmpty(shipped.Eras);+ foreach (var era in shipped.Eras)+ {+ Assert.NotEqual(SaveGame.Gdd03Ruleset, era.Systems.Ruleset);+ var c = new Content { Eras = new List<Era> { era }, Gdd03Balance = shipped.Gdd03Balance };+ Assert.Throws<NotSupportedException>(() => Gdd03BalanceCatalogue.ReadCombatCatalogue(c));+ }+ foreach (var identity in new[] { SaveGame.LegacyRuleset, SaveGame.GddRuleset, "gdd-0.30" })+ Assert.Throws<NotSupportedException>(() => Gdd03BalanceCatalogue.ReadCombatCatalogue(Gdd03CombatCatalogueTests.Synthetic(identity)));+ }+}diff --git a/sim/Statecraft.Sim/Gdd03BalanceCatalogue.cs b/sim/Statecraft.Sim/Gdd03BalanceCatalogue.csindex 4ae3900c7..66f2901e4 100644--- a/sim/Statecraft.Sim/Gdd03BalanceCatalogue.cs+++ b/sim/Statecraft.Sim/Gdd03BalanceCatalogue.cs@@ -1,5 +1,6 @@using System;using System.Collections.Generic;+using System.Collections.ObjectModel;using System.Linq;namespace Statecraft.Sim@@ -12,6 +13,10 @@ namespace Statecraft.Simpublic string Ruleset { get; set; } = "";public Dictionary<string, Gdd03DesignValue> Values { get; set; } = new Dictionary<string, Gdd03DesignValue>();+ /// <summary>#1706 slices 0/1: explicit design-data read for synthetic gdd-0.3 fixtures.+ /// No loader, combat, preview, AI or shipping caller selects this table.</summary>+ internal static Gdd03CombatCatalogue ReadCombatCatalogue(Content content) => Gdd03Military.ReadCombatCatalogue(content);+internal void Validate(){if (Ruleset != SaveGame.Gdd03Ruleset) throw new ContentException(FileName, "ruleset", "must be gdd-0.3 (catalogue only; not a live-loop switch)");@@ -58,4 +63,68 @@ namespace Statecraft.Sim}}}++ internal enum Gdd03CombatOutcome { AttackerLoss, BothHold, DefenderRetreats, DefenderLoss }++ /// <summary>Inclusive draw interval; no state transition is implemented here.</summary>+ internal sealed class Gdd03CombatBand+ {+ public int First { get; }+ public int Last { get; }+ public Gdd03CombatOutcome Outcome { get; }+ internal Gdd03CombatBand(int first, int last, Gdd03CombatOutcome outcome)+ { First = first; Last = last; Outcome = outcome; }+ }++ /// <summary>Frozen source metadata: Default is never promoted to Agreed by validation.</summary>+ internal sealed class Gdd03CombatSource+ {+ public string Basis { get; }+ public string Note { get; }+ public IReadOnlyList<decimal> Values { get; }+ internal Gdd03CombatSource(Gdd03DesignValue value)+ { Basis = value.Basis; Note = value.Note; Values = Array.AsReadOnly(value.Values.ToArray()); }+ }++ /// <summary>Validated catalogue snapshot only. Accepts an already supplied exact decimal ratio;+ /// it calculates no strength, consumes no RNG and applies no combat outcome.</summary>+ internal sealed class Gdd03CombatCatalogue+ {+ readonly decimal[] thresholds;+ readonly IReadOnlyList<Gdd03CombatBand>[] rows;+ public int DrawCount { get; }+ public decimal ArmouredFactor { get; }+ public decimal ArtilleryFactor { get; }+ public int ArtilleryRange { get; }+ public IReadOnlyDictionary<string, Gdd03CombatSource> Sources { get; }++ internal Gdd03CombatCatalogue(decimal[] thresholds, IReadOnlyList<Gdd03CombatBand>[] rows,+ int draws, decimal armour, decimal artillery, int range, Dictionary<string, Gdd03CombatSource> sources)+ {+ this.thresholds = thresholds; this.rows = rows; DrawCount = draws;+ ArmouredFactor = armour; ArtilleryFactor = artillery; ArtilleryRange = range;+ Sources = new ReadOnlyDictionary<string, Gdd03CombatSource>(sources);+ }++ // Exact comparison of a caller-supplied ratio, with no display-percent rounding.+ public int Row(decimal ratio)+ {+ if (ratio < 0) throw new ArgumentOutOfRangeException(nameof(ratio));+ for (var i = 0; i < thresholds.Length; i++) if (ratio < thresholds[i]) return i;+ return thresholds.Length;+ }++ public IReadOnlyList<Gdd03CombatBand> Bands(int row)+ {+ if (row < 0 || row >= rows.Length) throw new ArgumentOutOfRangeException(nameof(row));+ return rows[row];+ }++ public Gdd03CombatOutcome Outcome(decimal ratio, int draw)+ {+ if (draw < 0 || draw > 99) throw new ArgumentOutOfRangeException(nameof(draw));+ return rows[Row(ratio)].Single(b => draw >= b.First && draw <= b.Last).Outcome;+ }+ }+}diff --git a/sim/Statecraft.Sim/Gdd03Military.cs b/sim/Statecraft.Sim/Gdd03Military.csindex 8fe10ed89..cba9b535a 100644--- a/sim/Statecraft.Sim/Gdd03Military.cs+++ b/sim/Statecraft.Sim/Gdd03Military.cs@@ -1,9 +1,10 @@using System;using System.Linq;+using System.Collections.Generic;namespace Statecraft.Sim{- /// <summary>Only #1708's approved 0.3 consumers. Reads exact catalogue data; never falls back to old balance values.</summary>+ /// <summary>#1708's approved 0.3 consumers and #1706's unhooked catalogue foundation. Reads exact catalogue data; never falls back to old balance values.</summary>internal static class Gdd03Military{internal static bool Applies(Content c) => c.Ruleset == SaveGame.Gdd03Ruleset;@@ -51,6 +52,83 @@ namespace Statecraft.Siminternal static int Defence(Content c, string biome) =>Number(Part(c, biome, "defence_percent"), biome + ".parts.defence_percent", 1, 0, false);+ /// <summary>#1706 catalogue foundation only: intentionally not called from Validate or Combat.</summary>+ internal static Gdd03CombatCatalogue ReadCombatCatalogue(Content c)+ {+ if (!Applies(c)) throw new NotSupportedException("Combat catalogue groundwork requires synthetic gdd-0.3 content.");+ if (c.Gdd03Balance == null || c.Gdd03Balance.Ruleset != SaveGame.Gdd03Ruleset || c.Gdd03Balance.Values == null)+ throw Invalid("combat.draw_count", "requires the separate gdd-0.3 catalogue");+ var sources = new Dictionary<string, Gdd03CombatSource>(StringComparer.Ordinal);+ // content/gdd03-balance.yaml:447-475; GDD 605277df docs/gdd/balance.md:172,180-185.+ // The parent is Agreed (retained one draw); its thresholds, band and rows remain Default.+ Gdd03DesignValue Required(string key, string basis, string? part = null)+ {+ var at = part == null ? key : key + ".parts." + part;+ var root = Entry(c, key);+ var value = root;+ if (part != null && (root.Parts == null || !root.Parts.TryGetValue(part, out value) || value == null))+ throw Invalid(at, "required combat catalogue part");+ value.Validate("values." + at);+ if (value.Basis != basis) throw Invalid(at, "requires its catalogue basis " + basis);+ sources.Add(part == null ? key : key + "/" + part, new Gdd03CombatSource(value));+ return value;+ }+ decimal[] List(Gdd03DesignValue v, string at, int count, bool parent = false)+ {+ if (v.Values.Count != count || !string.IsNullOrEmpty(v.Expression) || (!parent && v.Parts.Count != 0))+ throw Invalid(at, FormattableString.Invariant($"requires exactly {count} numeric values and no expression or nested parts"));+ return v.Values.ToArray();+ }+ decimal[] PartList(string part, int count) => List(Required("combat.draw_count", "Default", part),+ "combat.draw_count.parts." + part, count);+ int Integer(decimal n, string at, bool positive = false)+ {+ if (n != decimal.Truncate(n) || n < (positive ? 1 : 0) || n > int.MaxValue)+ throw Invalid(at, "requires an exact bounded integer");+ return (int)n;+ }+ var parent = Required("combat.draw_count", "Agreed");+ var draws = Integer(List(parent, "combat.draw_count", 1, true)[0], "combat.draw_count", true);+ if (draws != 1) throw Invalid("combat.draw_count", "only the catalogued single draw is supported");+ var expectedParts = new[] { "ratio_thresholds", "draw_band", "below_0_5", "from_0_5_below_1", "from_1_below_2", "at_least_2" };+ if (parent.Parts.Count != expectedParts.Length || parent.Parts.Keys.Except(expectedParts, StringComparer.Ordinal).Any())+ throw Invalid("combat.draw_count.parts", "requires exactly the six catalogued parts");+ var thresholds = PartList("ratio_thresholds", 3);+ if (!thresholds.SequenceEqual(new[] { 0.5m, 1m, 2m }))+ throw Invalid("combat.draw_count.parts.ratio_thresholds", "requires the four catalogued ratio ranges");+ var band = PartList("draw_band", 2);+ if (band[0] != 0 || band[1] != 99) throw Invalid("combat.draw_count.parts.draw_band", "requires inclusive 0..99");+ var rows = new IReadOnlyList<Gdd03CombatBand>[4];+ for (var row = 0; row < rows.Length; row++)+ {+ var name = expectedParts[row + 2];+ var values = PartList(name, row == 0 || row == 3 ? 6 : 8);+ var result = new List<Gdd03CombatBand>();+ var next = 0;+ for (var pair = 0; pair < values.Length / 2; pair++)+ {+ var at = "combat.draw_count.parts." + name;+ var first = Integer(values[pair * 2], at); var last = Integer(values[pair * 2 + 1], at);+ if (first != next || last < first || last > 99)+ throw Invalid(at, "requires ordered, complete, non-overlapping inclusive 0..99 bands");+ result.Add(new Gdd03CombatBand(first, last, (Gdd03CombatOutcome)(pair + (row == 3 ? 1 : 0))));+ next = last + 1;+ }+ if (next != 100) throw Invalid("combat.draw_count.parts." + name, "bands must cover every draw through 99");+ rows[row] = result.AsReadOnly();+ }+ // content/gdd03-balance.yaml:484-495; GDD docs/gdd/balance.md:175-177 at 605277df.+ decimal Role(string key)+ {+ var n = List(Required(key, "Default"), key, 1)[0];+ if (n <= 0) throw Invalid(key, "requires a positive exact role factor");+ return n;+ }+ var armour = Role("combat.armoured_factor"); var artillery = Role("combat.artillery_factor");+ var range = Integer(List(Required("combat.artillery_range", "Default"), "combat.artillery_range", 1)[0], "combat.artillery_range", true);+ return new Gdd03CombatCatalogue(thresholds, rows, draws, armour, artillery, range, sources);+ }+internal static void Validate(Content c){if (!Applies(c)) return;