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.

Add a synthetic absorption boundary predicate (Refs #1714) (#1959)

Eyal Golan23279aa1c8e8
diff --git a/changelog.d/1714-synthetic-absorption-boundary.md b/changelog.d/1714-synthetic-absorption-boundary.md
new file mode 100644
index 000000000..20b616968
--- /dev/null
+++ b/changelog.d/1714-synthetic-absorption-boundary.md
@@ -0,0 +1 @@
+- Add an inactive synthetic absorption boundary contract using catalogue thresholds and explicit settled facts.
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 751e32e9c..3d4fd4db0 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -360,6 +360,12 @@ R-OBJ-003: An event with `objective:` is that objective's card. It is eligible o
R-OBJ-004: An objective may instead name `completes_when: { absorbed: { population_at_least, overflow_at_most, employed_at_least } }` (D-B4; owner, 18 October 2026, #738, option (a)). It holds at step 11 once the Jewish population (`GameState.TotalPopulation`, the national count as step 11 reads it, before the turn's population step) is at or above `population_at_least`, and then the cities' overflow (R-HOUSE-002), summed, is at most `overflow_at_most` of their housed people (R-HOUSE-003), summed, and their employed civilians, summed, are at least `employed_at_least` of their civilians (as R-CITY-005 counts them). Refugees waiting do not count: each turn's arrivals (step 9) wait at step 11, after housing (step 8). The gate keeps the census start values (41% employed, no overflow) from completing it on the first turn. Sums are integers, compared with the decimal share, so city order cannot change the result. An objective names exactly one kind; all three keys are required (a missing key is never read as 0), the shares are from 0 to 1 and the population above 0 (the loader). Recorded and scored as R-OBJ-001 and R-OBJ-002 say; its card follows R-OBJ-003.
+For R-OBJ-004, the preceding active gdd-0.1 rule remains unchanged. The gdd-0.3 addition is an inactive, synthetic-only boundary: `Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts` accepts supplied represented own units, a canonical refugee-awaiting-legal-bed flag, ordinary-housing overflow/demand and employed/all-free-civilian counts; it neither produces nor classifies them (`sim/Statecraft.Sim/Gdd03SyntheticAbsorptionBoundary.cs:6-25@1e4b8a248`). Source: `docs/gdd/objective-card.md:19@605277dfa511dc512562ececeb273b8393b21d35`, "Empty denominators mean no overflow/full employment." and "Reference remains 20 December 1949"; `docs/gdd/balance.md:195-196` at that source revision gives the exceeded population target and inclusive percentage limits.
+
+The synthetic boundary reads the supplied catalogue's Agreed population scale, target and percentages. With the current scale and thresholds, 100 units fail and 101 pass; overflow exactly 10% and employment exactly 40% pass. A true waiting flag blocks the result; the tests supply false for a legal reception bed and true for a port queue or refugee evacuation transit, without implementing that classification. Each valid 0/0 pair passes its ratio subcondition, but cannot bypass population or waiting. Exact BigInteger cross-products avoid rounded shares. Null/wrong-identity catalogues, missing, Deferred, non-Agreed or malformed quantities and negative/non-subset counts throw before any failing gate can hide them; the population scale retains the positive Int32 bound, the target must be positive and whole, and percentage limits must be whole numbers in 0..100 (`sim/Statecraft.Sim/Gdd03SyntheticAbsorptionBoundary.cs:27-65@1e4b8a248`; `sim/Statecraft.Sim/Content.cs:1270-1278@1e4b8a248`; boundary tests in `sim/Statecraft.Sim.Tests/Gdd03SyntheticAbsorptionBoundaryTests.cs:12-108@1e4b8a248`, scale/threshold/exact-product fixtures at `:114-190` at the same head).
+
+No live completion or completion date is recorded. The #1714 status comment of 27 October 2026 says, "It does not yet compute actual regional totals or award the objective." Represented population (#1689), regional aggregation and approved locations (#1690/#1691), shared employment (#1692/#1702, also to feed #1715), canonical waiting (#1696), housing (#1703), and monthly-versus-end-state sampling (#1716) remain pending integration decisions/evidence, not choices made by this helper (`sim/Statecraft.Sim/Gdd03SyntheticAbsorptionBoundary.cs:6-17@1e4b8a248`; #1714 status comment, "Human check pending: unresolved rules for combining totals and when to count people"). The 20 December 1949 reference is retained; this slice does not select when to award it.
+
R-OBJ-005: An objective part (`part_of`) may name `completes_when: { corridor_complete: <corridor> }` or `completes_when: { sites_built: [<site>, ...] }`. It completes at step 11 of the first GDD turn when every corridor segment (R-COR-003) or every listed yishuv site is built, records once with that turn's end date and earns `min(objective_bonus_cap, objective_bonus_per_month * monthsEarly)` once. Every part has a sourced `reference_date` inside the MVP and its own card under R-OBJ-003. The infrastructure objective's parts are `railway`, `burma_road` and `yishuvim` (Q-OBJ-1 to Q-OBJ-3, owner, 17 October 2026, #782; #791).
R-OBJ-006: Parts with the same `part_of` are one objective for `objective_points`: its base points are added exactly once, when the last part records. Earlier parts add only their R-OBJ-005 timing bonus. Rechecking any recorded part changes neither the records nor the score (Q-OBJ-1, owner, 17 October 2026, #782).
diff --git a/sim/Statecraft.Sim.Tests/Gdd03SyntheticAbsorptionBoundaryTests.cs b/sim/Statecraft.Sim.Tests/Gdd03SyntheticAbsorptionBoundaryTests.cs
new file mode 100644
index 000000000..c88d8748c
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/Gdd03SyntheticAbsorptionBoundaryTests.cs
@@ -0,0 +1,198 @@
+using System.Globalization;
+using Statecraft.Sim;
+
+// R-OBJ-004: inactive boundary contract, not an integrated objective test.
+public class Gdd03SyntheticAbsorptionBoundaryTests
+{
+ static Gdd03BalanceCatalogue Catalogue() =>
+ ContentLoader.Load(RealContentTests.ContentRoot()).Gdd03Balance!;
+
+ // All counts here are test-only synthetic settled facts, not population/region initialization.
+ // 100/101 follows the strict target/scale in gdd03-balance.yaml:46-49,512-515.
+ [Theory]
+ [InlineData(100, false)]
+ [InlineData(101, true)]
+ public void RepresentedOwnPopulationMustExceedTheTarget(long own, bool expected)
+ {
+ Assert.Equal(expected, Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ Catalogue(), own, false, 0, 0, 0, 0));
+ }
+
+ // The caller supplies canonical waiting, not a location/status inferred by this predicate.
+ [Theory]
+ [InlineData(false, true)] // synthetic legal reception bed: no waiting
+ [InlineData(true, false)] // synthetic port queue OR refugee evacuation transit: waiting
+ public void OnlyTheSuppliedCanonicalWaitingFlagBlocksReception(bool waiting, bool expected)
+ {
+ Assert.Equal(expected, Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ Catalogue(), 101, waiting, 0, 0, 0, 0));
+ }
+
+ // Synthetic demand 100 and free civilians 10; source percentages are 10 and 40.
+ [Theory]
+ [InlineData(10, 4, true)]
+ [InlineData(11, 4, false)]
+ [InlineData(10, 3, false)]
+ [InlineData(9, 5, true)]
+ public void HousingAndEmploymentBoundariesAreInclusive(long overflow, long employed, bool expected)
+ {
+ Assert.Equal(expected, Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ Catalogue(), 101, false, overflow, 100, employed, 10));
+ }
+
+ [Theory]
+ [InlineData(0, 0, 4, 10)]
+ [InlineData(10, 100, 0, 0)]
+ [InlineData(0, 0, 0, 0)]
+ public void EmptyDenominatorsPassTheirRespectiveSubconditions(long overflow, long demand, long employed, long free)
+ {
+ Assert.True(Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ Catalogue(), 101, false, overflow, demand, employed, free));
+ Assert.False(Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ Catalogue(), 0, false, overflow, demand, employed, free));
+ }
+
+ // Invalid test-only facts must fail even if the population/waiting gate would already fail.
+ [Theory]
+ [InlineData(-1, 0, 0, 0, 0)]
+ [InlineData(101, -1, 100, 4, 10)]
+ [InlineData(101, 0, -1, 4, 10)]
+ [InlineData(101, 0, 100, -1, 10)]
+ [InlineData(101, 0, 100, 0, -1)]
+ [InlineData(0, 1, 0, 0, 0)]
+ [InlineData(101, 0, 100, 1, 0)]
+ [InlineData(101, 101, 100, 4, 10)]
+ [InlineData(101, 0, 100, 11, 10)]
+ public void InvalidSettledCountsAreRejected(long own, long overflow, long demand, long employed, long free)
+ {
+ Assert.Throws<ArgumentOutOfRangeException>(() =>
+ Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ Catalogue(), own, true, overflow, demand, employed, free));
+ }
+
+ [Theory]
+ [InlineData("population.people_per_unit")]
+ [InlineData("absorption.population_target")]
+ [InlineData("absorption.max_overflow")]
+ [InlineData("absorption.min_employment")]
+ public void MissingDeferredOrMalformedThresholdsHaveNoFallback(string key)
+ {
+ foreach (var fault in new[] { "missing", "Deferred", "Default", "empty", "multiple", "fraction", "negative", "expression", "parts", "range" })
+ {
+ var catalogue = Catalogue();
+ var entry = catalogue.Values[key];
+ switch (fault)
+ {
+ case "missing": catalogue.Values.Remove(key); break;
+ case "Deferred": entry.Basis = "Deferred"; entry.Values.Clear(); entry.Expression = "unresolved"; break;
+ case "Default": entry.Basis = "Default"; break;
+ case "empty": entry.Values.Clear(); break;
+ case "multiple": entry.Values.Add(1); break;
+ case "fraction": entry.Values[0] = 0.5m; break;
+ case "negative": entry.Values[0] = -1; break;
+ case "expression": entry.Expression = "unresolved"; break;
+ case "parts": entry.Parts.Add("synthetic", new Gdd03DesignValue()); break;
+ case "range": entry.Values[0] = key.StartsWith("absorption.m", StringComparison.Ordinal) ? 101 : 0; break;
+ }
+ if (key == "population.people_per_unit")
+ Assert.Throws<ContentException>(() => Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ catalogue, 0, true, 0, 0, 0, 0));
+ else
+ Assert.Throws<ArgumentException>(() => Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ catalogue, 0, true, 0, 0, 0, 0));
+ }
+ Assert.Throws<ArgumentNullException>(() => Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ null!, 101, false, 0, 0, 0, 0));
+ var wrongIdentity = Catalogue(); wrongIdentity.Ruleset = "gdd-0.1";
+ Assert.Throws<ArgumentException>(() => Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ wrongIdentity, 101, false, 0, 0, 0, 0));
+ }
+
+ [Theory]
+ [InlineData("he-IL")]
+ [InlineData("en-US")]
+ public void PopulationScaleSharesMainInt32Limit(string locale)
+ {
+ var previous = CultureInfo.CurrentCulture;
+ var previousUi = CultureInfo.CurrentUICulture;
+ try
+ {
+ CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(locale);
+ CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo(locale);
+ var catalogue = Catalogue();
+ var content = new Content {
+ Eras = new() { new Era { Systems = new EraSystems { Loop = EraSystems.Gdd, Ruleset = SaveGame.Gdd03Ruleset } } },
+ Gdd03Balance = catalogue
+ };
+ // Test-only synthetic scales: Int32 maximum is valid; larger whole decimals must be refused.
+ catalogue.Values["population.people_per_unit"].Values[0] = int.MaxValue;
+ Assert.Equal(int.MaxValue, content.PopulationPeoplePerUnit);
+ Assert.True(Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ catalogue, long.MaxValue, false, 0, 0, 0, 0));
+ foreach (var scale in new[] { int.MaxValue + 1m, decimal.MaxValue })
+ {
+ catalogue.Values["population.people_per_unit"].Values[0] = scale;
+ Assert.Throws<ContentException>(() => { _ = content.PopulationPeoplePerUnit; });
+ Assert.Throws<ContentException>(() => Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ catalogue, long.MaxValue, false, 0, 0, 0, 0));
+ }
+ }
+ finally
+ {
+ CultureInfo.CurrentCulture = previous;
+ CultureInfo.CurrentUICulture = previousUi;
+ }
+ }
+
+ // Catalogue overrides below are labelled test-only synthetic values, never shipped defaults.
+ [Theory]
+ [InlineData("population.people_per_unit", 20000, 51, 0, 4, true)]
+ [InlineData("absorption.population_target", 2000000, 101, 0, 4, false)]
+ [InlineData("absorption.max_overflow", 20, 101, 20, 4, true)]
+ [InlineData("absorption.min_employment", 50, 101, 0, 4, false)]
+ public void EachThresholdIsReadFromTheSuppliedCatalogue(string key, int syntheticValue,
+ long own, long overflow, long employed, bool expected)
+ {
+ var catalogue = Catalogue();
+ catalogue.Values[key].Values[0] = syntheticValue;
+ Assert.Equal(expected, Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ catalogue, own, false, overflow, 100, employed, 10));
+ }
+
+ [Theory]
+ [InlineData("he-IL")]
+ [InlineData("en-US")]
+ public void LargeSyntheticCountsAndBothCulturesKeepExactBoundaries(string locale)
+ {
+ var previous = CultureInfo.CurrentCulture;
+ var previousUi = CultureInfo.CurrentUICulture;
+ try
+ {
+ CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(locale);
+ CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo(locale);
+ var catalogue = Catalogue();
+ // Test-only stress values, chosen near Int64.MaxValue to expose cross-product overflow.
+ const long demand = 9000000000000000000;
+ const long overflow = 900000000000000000;
+ const long employed = 3600000000000000000;
+ Assert.True(Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ catalogue, long.MaxValue, false, overflow, demand, employed, demand));
+ Assert.False(Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ catalogue, long.MaxValue, false, overflow + 1, demand, employed, demand));
+ Assert.False(Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ catalogue, long.MaxValue, false, overflow, demand, employed - 1, demand));
+ // Purity: repeated calls retain the caller's catalogue entries and values.
+ var entry = catalogue.Values["absorption.max_overflow"];
+ var value = entry.Values.Single();
+ Assert.True(Gdd03SyntheticAbsorptionBoundary.HoldsForSyntheticSettledFacts(
+ catalogue, 101, false, 0, 0, 0, 0));
+ Assert.Same(entry, catalogue.Values["absorption.max_overflow"]);
+ Assert.Equal(value, entry.Values.Single());
+ }
+ finally
+ {
+ CultureInfo.CurrentCulture = previous;
+ CultureInfo.CurrentUICulture = previousUi;
+ }
+ }
+}
diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.cs
index e70b65684..33a5c25eb 100644
--- a/sim/Statecraft.Sim/Content.cs
+++ b/sim/Statecraft.Sim/Content.cs
@@ -1264,8 +1264,13 @@ namespace Statecraft.Sim
internal int RequirePopulationInteger(string key)
{
if (!UsesPopulationLedger) throw new InvalidOperationException("Population catalogue access requires gdd-0.3.");
- if (Gdd03Balance == null || Gdd03Balance.Values == null || Gdd03Balance.Ruleset != SaveGame.Gdd03Ruleset
- || !Gdd03Balance.Values.TryGetValue(key, out var row) || row == null || row.Basis != "Agreed"
+ return RequirePopulationInteger(Gdd03Balance, key);
+ }
+ // Shared catalogue reader; synthetic consumers retain the same positive Agreed Int32 contract.
+ internal static int RequirePopulationInteger(Gdd03BalanceCatalogue? catalogue, string key)
+ {
+ if (catalogue == null || catalogue.Values == null || catalogue.Ruleset != SaveGame.Gdd03Ruleset
+ || !catalogue.Values.TryGetValue(key, out var row) || row == null || row.Basis != "Agreed"
|| row.Values == null || row.Values.Count != 1 || row.Parts == null || row.Parts.Count != 0
|| !string.IsNullOrEmpty(row.Expression) || row.Values[0] <= 0 || row.Values[0] > int.MaxValue
|| decimal.Truncate(row.Values[0]) != row.Values[0])
diff --git a/sim/Statecraft.Sim/Gdd03SyntheticAbsorptionBoundary.cs b/sim/Statecraft.Sim/Gdd03SyntheticAbsorptionBoundary.cs
new file mode 100644
index 000000000..61897059f
--- /dev/null
+++ b/sim/Statecraft.Sim/Gdd03SyntheticAbsorptionBoundary.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Numerics;
+
+namespace Statecraft.Sim
+{
+ /// <summary>Inactive R-OBJ-004 boundary contract for explicit synthetic settled facts only.
+ /// No ledger, region, assignment, snapshot, objective award or turn-path integration.
+ /// See #1714 and docs/gdd/objective-card.md:19 at 605277dfa511dc512562ececeb273b8393b21d35.</summary>
+ public static class Gdd03SyntheticAbsorptionBoundary
+ {
+ /// <summary>Checks already-settled counts; this method does not produce or classify them.
+ /// The caller supplies represented own units, canonical refugee waiting, an agreed ordinary-housing
+ /// overflow/demand pair, and the shared employment producer's employed/all-free-civilian pair.
+ /// Regional aggregation and monthly-versus-end-state sampling are deliberately outside this contract.
+ /// Empty valid pairs satisfy their subcondition. Invalid inputs throw rather than defaulting.
+ /// Current catalogue quantities must be single Agreed whole numbers; later fractional design values
+ /// require a reviewed contract extension. Calling this does not record completion or choose its date.</summary>
+ public static bool HoldsForSyntheticSettledFacts(
+ Gdd03BalanceCatalogue catalogue,
+ long representedOwnUnits,
+ bool hasRefugeeAwaitingLegalBed,
+ long ordinaryOverflow,
+ long ordinaryDemand,
+ long employedFreeCivilians,
+ long allFreeCivilians)
+ {
+ if (catalogue == null) throw new ArgumentNullException(nameof(catalogue));
+ if (catalogue.Ruleset != SaveGame.Gdd03Ruleset)
+ throw new ArgumentException("Synthetic absorption requires the gdd-0.3 catalogue.", nameof(catalogue));
+
+ // content/gdd03-balance.yaml:46-49,512-523 at base 3824eb6f.
+ // Read all required entries before evaluating: Deferred/malformed must never act as false or zero.
+ var peoplePerUnit = Content.RequirePopulationInteger(catalogue, "population.people_per_unit");
+ var populationTarget = RequireAgreedWholeNumber(catalogue, "absorption.population_target", false);
+ var maxOverflow = RequireAgreedWholeNumber(catalogue, "absorption.max_overflow", true);
+ var minEmployment = RequireAgreedWholeNumber(catalogue, "absorption.min_employment", true);
+
+ if (representedOwnUnits < 0) throw new ArgumentOutOfRangeException(nameof(representedOwnUnits));
+ RequireSubset(ordinaryOverflow, ordinaryDemand, nameof(ordinaryOverflow), nameof(ordinaryDemand));
+ RequireSubset(employedFreeCivilians, allFreeCivilians, nameof(employedFreeCivilians), nameof(allFreeCivilians));
+
+ // Exact unbounded integer products; 100 is the definition of percent, not a balance default.
+ // No rounded shares, binary floating point, text formatting, RNG or state mutation.
+ return new BigInteger(representedOwnUnits) * peoplePerUnit > populationTarget
+ && !hasRefugeeAwaitingLegalBed
+ && new BigInteger(ordinaryOverflow) * 100 <= new BigInteger(ordinaryDemand) * maxOverflow
+ && new BigInteger(employedFreeCivilians) * 100 >= new BigInteger(allFreeCivilians) * minEmployment;
+ }
+
+ static BigInteger RequireAgreedWholeNumber(Gdd03BalanceCatalogue catalogue, string key, bool percent)
+ {
+ if (catalogue.Values == null || !catalogue.Values.TryGetValue(key, out var entry) || entry == null
+ || entry.Basis != "Agreed" || entry.Values == null || entry.Values.Count != 1
+ || !string.IsNullOrEmpty(entry.Expression) || entry.Parts == null || entry.Parts.Count != 0)
+ throw new ArgumentException("Required single Agreed catalogue quantity: " + key, nameof(catalogue));
+ var value = entry.Values[0];
+ if (decimal.Truncate(value) != value || (percent ? value < 0 || value > 100 : value <= 0))
+ throw new ArgumentException("Invalid whole-number catalogue quantity: " + key, nameof(catalogue));
+ return new BigInteger(value);
+ }
+
+ static void RequireSubset(long numerator, long denominator, string numeratorName, string denominatorName)
+ {
+ if (denominator < 0) throw new ArgumentOutOfRangeException(denominatorName);
+ if (numerator < 0 || numerator > denominator) throw new ArgumentOutOfRangeException(numeratorName);
+ }
+ }
+}