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.

feat(sim): BuyArms runs on a Historical ledger game (#1725 PR 7, producer 06) (#2947)

Eyal Golane3311b06b28c
diff --git a/changelog.d/1725-pr7-buy-arms.md b/changelog.d/1725-pr7-buy-arms.md
new file mode 100644
index 000000000..de7244d4a
--- /dev/null
+++ b/changelog.d/1725-pr7-buy-arms.md
@@ -0,0 +1,3 @@
+- GDD 0.3 starting population (Refs #1725, Refs #1689): buying Arms (R-ARMS-002) now runs on the inactive dark start's
+ Historical ledger as in the aggregate start, at today's price of IL 1m an Arms. Bought Arms join the national stock,
+ not any record's issued items, so no ledger record changes. No new-game wiring, so there is no change in the game.
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 707380a3c..bb479d94c 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -462,7 +462,7 @@ The national Arms pool (D-G6, decided 15 October 2026: "From events (sourced arm
R-ARMS-001: Arms is a national stock of whole units (`GameState.Arms`, hashed as `arms=` only when not 0); one Arms is the equipment package for one recruit group of `people_per_unit` (1,000) people. A new game starts the stock at `arms_start` (12). It never goes below 0. Under gdd-0.3 an arms workshop's completed cycle adds 1 (R-ARMS-006). `arms_start`, `arms_price` and `arms_per_recruit_group` are required in the GDD loop (`rules.yaml` `mvp:`); a missing or negative value is a load error.
-R-ARMS-002: `BuyArms(count)` adds `count` units to the stock at once, with no delivery delay, and the Treasury pays `count * arms_price` (IL 1m an Arms), borrowing what it lacks (R-MONEY-003). It is refused, state and Attention unchanged, for fewer than one unit, a stock that would pass a whole number's range, or a purchase whose borrowing would take the debt past `debt_ceiling` (#2198; owner, 2 November 2026: "Refuse buys over ceiling (Recommended)", https://github.com/eyalgolan/statecraft-israel/issues/2198#issuecomment-6564721486), with the reason "Buying that many Arms would take the debt past its ceiling"; the legacy loop refuses it before charging Attention. The debt after is R-MONEY-003's: the debt plus what the Treasury lacks (`Debt + max(0, cost - Treasury)`). A debt exactly at the ceiling is allowed, and a purchase the Treasury pays in full borrows nothing and is never refused at it, even with the debt already past it. This overrides Q22 for Arms purchases; an arms workshop's cycle also waits rather than borrow past it (R-ARMS-006), and every other cost still borrows past the ceiling (R-MONEY-003). The Defence screen shows the same reason before End turn when End turn would refuse the amount for the ceiling with the turn's orders as they stand: it runs them from the turn's start on a copy, as End turn runs them, with this purchase in place of a queued one or after them, so the dollar conversions and any other spending queued before the purchase count (#2206). The turn's dollar conversions (R-MONEY-004) run before its Arms purchases, whatever the queue order: a conversion queued after the turn's first `BuyArms` runs just before it, with the other such conversions in their queue order, and every other order keeps its queue place (#2206). Its Attention cost is `attention_cost.buy_arms` (1), whatever the count.
+R-ARMS-002: `BuyArms(count)` adds `count` units to the stock at once, with no delivery delay, and the Treasury pays `count * arms_price` (IL 1m an Arms), borrowing what it lacks (R-MONEY-003). It is refused, state and Attention unchanged, for fewer than one unit, a stock that would pass a whole number's range, or a purchase whose borrowing would take the debt past `debt_ceiling` (#2198; owner, 2 November 2026: "Refuse buys over ceiling (Recommended)", https://github.com/eyalgolan/statecraft-israel/issues/2198#issuecomment-6564721486), with the reason "Buying that many Arms would take the debt past its ceiling"; the legacy loop refuses it before charging Attention. The debt after is R-MONEY-003's: the debt plus what the Treasury lacks (`Debt + max(0, cost - Treasury)`). A debt exactly at the ceiling is allowed, and a purchase the Treasury pays in full borrows nothing and is never refused at it, even with the debt already past it. This overrides Q22 for Arms purchases; an arms workshop's cycle also waits rather than borrow past it (R-ARMS-006), and every other cost still borrows past the ceiling (R-MONEY-003). The Defence screen shows the same reason before End turn when End turn would refuse the amount for the ceiling with the turn's orders as they stand: it runs them from the turn's start on a copy, as End turn runs them, with this purchase in place of a queued one or after them, so the dollar conversions and any other spending queued before the purchase count (#2206). The turn's dollar conversions (R-MONEY-004) run before its Arms purchases, whatever the queue order: a conversion queued after the turn's first `BuyArms` runs just before it, with the other such conversions in their queue order, and every other order keeps its queue place (#2206). Its Attention cost is `attention_cost.buy_arms` (1), whatever the count. It runs on a game with an initialized Historical ledger (the dark start, R-POP-002; #1725 PR 7) as in the aggregate game, at the same `arms_price`: a bought Arms joins the national stock and is not an issued item on any record, so no ledger record changes; a synthetic or Open ledger is still refused (R-POP-002).
R-ARMS-003: Recruit training (R-TRAIN-001) takes `arms_per_recruit_group` (1) Arms for each group when it starts, after its other checks and before it pays. A stock short of that refuses the order with a reason naming the need and the stock, state and Attention unchanged (Q-UNIT-3). A gun or armoured car crew takes its type's `training_arms` a group instead, by the same rule (R-UNIT-008). Pioneer training takes no Arms. The cohort keeps the Arms it took, and the state hash writes them with it; cancelling the cohort (R-TRAIN-002) returns them to the pool, up to the most the stock can hold, although the Money stays paid (owner, 18 October 2026, #1047: "Refund on cancel"). Replacement groups (R-TRAIN-004) take their course's Arms by the same rule (owner, 23 October 2026, #1510: "Replacements cost Arms").
diff --git a/sim/Statecraft.Sim.Tests/LedgerBuyArmsTests.cs b/sim/Statecraft.Sim.Tests/LedgerBuyArmsTests.cs
new file mode 100644
index 000000000..11ccfc18f
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/LedgerBuyArmsTests.cs
@@ -0,0 +1,83 @@
+using Statecraft.Sim;
+
+/// <summary>#1725 PR 7, producer draft 06: BuyArms (R-ARMS-001, R-ARMS-002) runs on a game with an initialized Historical
+/// ledger, the dark start and the ledger fixture. A bought Arms joins the national stock: it is not an issued item on any
+/// record, so no ledger record changes (R-POP-002). The price stays rules.yaml's arms_price, 1.</summary>
+public class LedgerBuyArmsTests
+{
+ static Content Gdd03() => HistoricalPopulationTests.Real(true);
+
+ static GameState Dark(Content c) => Simulation.NewGame(c, 1, Mode.Historical, darkStart: true);
+
+ // R-ARMS-002, R-POP-002: the ledger fixture buys Arms into the stock at arms_price; no record or issued item changes.
+ [Fact]
+ public void TheLedgerFixtureBuysArms()
+ {
+ var c = Gdd03();
+ var s = HistoricalPopulation.LedgerFixture(c);
+ s.Date = c.Rules.Start;
+ s.Treasury = 10; s.Arms = 12;
+ var ledger = s.PopulationLedger.Canonical();
+ var why = new List<Cause>();
+ Assert.Null(Pools.BuyArms(c, s, 3, why));
+ Assert.Equal((15, 7.0, 0.0), (s.Arms, s.Treasury, s.Debt));
+ Assert.Contains(why, x => x.System == "economy" && x.Target == "arms" && x.Delta == 3);
+ s.PopulationLedger.Reconcile();
+ Assert.Equal(ledger, s.PopulationLedger.Canonical());
+ }
+
+ // R-ARMS-002 with R-MONEY-003: the dark start buys as the aggregate start of the same content does, at arms_price 1,
+ // borrowing what a short Treasury lacks; Arms, Treasury, Debt and the causes match, and the ledger is unchanged.
+ [Fact]
+ public void TheDarkStartBuysAndBorrowsAsTheAggregateStart()
+ {
+ var c = Gdd03();
+ Assert.Equal(1, c.RulesAt(c.Rules.Start).Mvp!.ArmsPrice);
+ var dark = Dark(c); var pub = Simulation.NewGame(c, 1, Mode.Historical);
+ Assert.Equal(pub.Arms, dark.Arms);
+ foreach (var s in new[] { dark, pub }) { s.Treasury = 1; s.Debt = 2; }
+ var ledger = dark.PopulationLedger.Canonical(); var arms = dark.Arms;
+ var darkWhy = new List<Cause>(); var pubWhy = new List<Cause>();
+ Assert.Null(Pools.BuyArms(c, dark, 4, darkWhy));
+ Assert.Null(Pools.BuyArms(c, pub, 4, pubWhy));
+ Assert.Equal((arms + 4, 0.0, 5.0), (dark.Arms, dark.Treasury, dark.Debt));
+ Assert.Equal((pub.Arms, pub.Treasury, pub.Debt), (dark.Arms, dark.Treasury, dark.Debt));
+ Assert.Equal(pubWhy.Select(x => (x.System, x.Target, x.Delta, x.Message)), darkWhy.Select(x => (x.System, x.Target, x.Delta, x.Message)));
+ dark.PopulationLedger.Reconcile();
+ Assert.Equal(ledger, dark.PopulationLedger.Canonical());
+ }
+
+ // R-ARMS-002 (#2198; owner, 2 November 2026: "Refuse buys over ceiling (Recommended)"): on the dark start a purchase
+ // that would borrow past debt_ceiling is refused with the state, ledger and causes unchanged.
+ [Fact]
+ public void TheDarkStartRefusesABuyPastTheDebtCeiling()
+ {
+ var c = Gdd03();
+ var s = Dark(c);
+ s.Treasury = 0; s.Debt = c.RulesAt(s.Date).Mvp!.DebtCeiling!.Value;
+ var hash = s.Hash(); var before = s.Describe();
+ var why = new List<Cause>();
+ Assert.Equal(Pools.RefusedDebtCeiling, Pools.BuyArms(c, s, 1, why));
+ Assert.Empty(why);
+ Assert.Equal(hash, s.Hash());
+ Assert.Equal(before, s.Describe());
+ s.PopulationLedger.Reconcile();
+ }
+
+ // R-POP-002 (#1725 PR 7 review S2): only a ledger initialized with mode Historical is let through. An initialized Open
+ // ledger, like a synthetic one (no mode), is still refused before any purchase, with the state unchanged.
+ [Theory]
+ [InlineData(true)] [InlineData(false)]
+ public void AnOpenOrSyntheticLedgerIsStillRefused(bool open)
+ {
+ var c = PopulationLedgerTests.Content();
+ var s = PopulationLedger.CreateFixture(c, PopulationLedgerTests.Bindings(),
+ new[] { new PopulationInventoryRow("fixture", 0, PopulationLedgerTests.Person()) }, mode: open ? Mode.Open : null);
+ Assert.Equal((true, false), (s.PopulationLedger.IsInitialized, s.PopulationLedger.IsHistorical));
+ s.Treasury = 23; s.Arms = 5;
+ var why = new List<Cause>();
+ var before = s.Describe(); var hash = s.Hash();
+ Assert.Contains("integration is held", Assert.Throws<NotSupportedException>(() => Pools.BuyArms(c, s, 1, why)).Message);
+ Assert.Equal(before, s.Describe()); Assert.Equal(hash, s.Hash()); Assert.Empty(why);
+ }
+}
diff --git a/sim/Statecraft.Sim/Pools.cs b/sim/Statecraft.Sim/Pools.cs
index 8890af154..2afaf6090 100644
--- a/sim/Statecraft.Sim/Pools.cs
+++ b/sim/Statecraft.Sim/Pools.cs
@@ -63,10 +63,12 @@ namespace Statecraft.Sim
/// stock that would pass a whole number's range, or borrowing that would take the debt past mvp.debt_ceiling (#2198,
/// owner 2 Nov 2026: "Refuse buys over ceiling (Recommended)"; the debt after is PayOrBorrow's, the debt plus what the
/// Treasury lacks, and exactly at the ceiling is allowed). A purchase the Treasury pays in full borrows nothing and is
- /// never refused at the ceiling. Step has already refused it in the legacy loop.</summary>
+ /// never refused at the ceiling. Step has already refused it in the legacy loop. It reads no population, so it runs
+ /// on an initialized Historical ledger (the dark start, #1725 PR 7): a bought Arms joins the national stock, not a
+ /// record's issued items. A synthetic or Open ledger stays refused (R-POP-002).</summary>
public static string? BuyArms(Content c, GameState s, int count, List<Cause> why)
{
- PopulationLedger.RefuseAggregate(s);
+ PopulationLedger.RefuseUnlessHistorical(s);
if (count < 1) return RefusedCount;
if ((long)s.Arms + count > int.MaxValue) return RefusedStockCapacity;
if (BorrowsPastDebtCeiling(c, s, count)) return RefusedDebtCeiling;