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): calibrate the 1950-51 economy; currency crisis cuts food imports; reserves go home; 1952 golden
eyalgolane32ede3f780b
diff --git a/content/rules.yaml b/content/rules.yamlindex d589227b6..efee37a98 100644--- a/content/rules.yaml+++ b/content/rules.yaml@@ -6,12 +6,31 @@ attention_cost: { set_policy: 1, allocate_budget: 2, choose_event_option: 1, setrung_attention_step: 0.25rung_min_mobilization: [0.02, 0.05, 0.15, 0.4, 0.8]ceasefire_weeks: 52 # long enough that the historical armistice events end the war first+# ---- Economy (calibrated in M3; checked by sim/Statecraft.Sim.Tests/EconomyCalibrationTests.cs) ----+# Units: treasury and debt in IL millions; fx_start, exports, donations/loans and imports in US$ millions.+# Formal rate 1950-51: IL 0.36 per US$ (IL 1 = $2.80), Michaely, Foreign Trade Regimes and Economic Development: Israel+# (NBER 1975) Table 5-1, https://www.nber.org/system/files/chapters/c4560/c4560.pdf (checked 2026-10-10).treasury_start: 20fx_start: 40-tax_per_capita_per_year: 0.00012-spending_per_capita_per_year: 0.00016-exports_per_year: 30-imports_per_capita_per_year: 0.00008+# Taxes finance the ordinary budget: FY 1950/51 IL 60 million, approved 29 June 1950+# (https://en.wikipedia.org/wiki/1950_in_Israel, checked 2026-10-10). 60m / ~1.10m Jews (CBS average 1950) = 0.0000545.+tax_per_capita_per_year: 0.0000545+# Spending above taxes is borrowed. The gap is set so 1950-51 borrowing matches the rise in internal debt, IL 65.4m (1950)+# + 33.0m (1951) = 98.4m (Michaely Table 5-2, same chapter). The 1951 fiscal tightening is not modelled, so the model+# matches the two-year total, not each year: (98.4m - 6m reserve call-up) / ~2.40m person-years = 0.0000385 per person.+spending_per_capita_per_year: 0.000093+# Exports cover under a third of imports (spec section 3; EconomyCalibrationTests checks it every turn of 1950-51).+exports_per_year: 40+imports_per_capita_per_year: 0.00025+# Donations, loans and transfers, set so reserves run out in the last quarter of 1951: the October 1951 crisis+# (FRUS 1951 v.V doc 513, https://history.state.gov/historicaldocuments/frus1951v05/d513, checked 2026-10-10).+# Re-fitted from 192 to 193.8 after Task 4 moved the Israel Bonds inflow to its 10 May 1951 launch; consistency anchor: first+# fx crisis in H2 1951 (FRUS d513, 19 Oct 1951). Only about 193.76 to 193.88 satisfies it (reserves non-negative through+# May 1951, first negative at the turn ending 1951-11-26), because the events' lump sums and the quarterly turns make the+# fit knife-edged; 193.8 is the smallest value on a 0.05 grid inside that range.+capital_inflow_per_year: 193.8+# While reserves are exhausted, food imports are cut: food_supply falls by this much per year.+fx_crisis_food_per_year: -0.2mobilization_cost_per_year: 60# Derived from CBS table 2.1 (1949): (end-1949 1,013.9k - end-1948 758.7k - 1949 immigrants 239,954) / average 1949 population 901.0k.natural_increase_per_year: 0.0169diff --git a/docs/determinism.md b/docs/determinism.mdindex 80233e3f6..5609d884b 100644--- a/docs/determinism.md+++ b/docs/determinism.md@@ -20,7 +20,8 @@ with `GoldenRun.Seed = 1948` on the real `content/`, then steps with `Historical| Run | Ends | Hash ||---|---|---|-| to 1950-01-01 (`Hash1950`) | 1950-02-26, turn 45 | `e2fa38969b15171a95d6ab7e3d3236d135a6b7af94e0dc822cf391fb3fb898d0` |+| to 1950-01-01 (`Hash1950`) | 1950-02-26, turn 45 | `bf6baf3ff8880b06b82ebf66a01157b29754eed117a7c2bdca528b05fa7959a4` |+| to 1952-01-01 (`Hash1952`) | 1952-02-26, turn 53 | `1753fb88dfeef95d8260b8ffe6250e52b04b71ba10babe8a96d07914047257d0` |Each constant is written in three places that must agree:- `sim/Statecraft.Sim/GoldenRun.cs`, which Unity code and players compare against;@@ -44,3 +45,5 @@ rules or content, treat it as a determinism bug.| M3 Task 2 | 1950 | `d46ce5ff` | the Immigration budget line moves to the Prime Minister (the Ministry of Immigration ends on 1951-10-08), which renames a key in the hashed budget || M3 Task 3 | 1950 | `3d360deb` | CBS immigration for 1950 adds January-February 1950 arrivals inside the run || M3 Task 4 | 1950 | `e2fa3896` | frumkin_commission (window from 1950-01-01) fires inside the run |+| M3 Task 5 | 1950 | `bf6baf3f` | economy calibrated (rules.yaml) and HistoricalAI sends reserves home after the armistices; capital_inflow_per_year 193.8 acts from 1948, so it moves this hash too |+| M3 Task 5 | 1952 | `1753fb88` | new run covering the M3 content range. Task 4 fix round 1 changed 1951 event windows/effects (hula, forex, bonds, clothing rationing, education, reparations), so capital_inflow_per_year was re-fitted from 192 to 193.8 (first fx crisis in H2 1951) |diff --git a/sim/Statecraft.Sim.Tests/DeterminismTests.cs b/sim/Statecraft.Sim.Tests/DeterminismTests.csindex abf016897..809477d40 100644--- a/sim/Statecraft.Sim.Tests/DeterminismTests.cs+++ b/sim/Statecraft.Sim.Tests/DeterminismTests.cs@@ -19,7 +19,7 @@ public class DeterminismTests/// <summary>Any change to this value is a deliberate rules or content change: update it here, in/// GoldenRun.Hash1950 and in docs/determinism.md in the same commit.</summary>- public const string GoldenHash = "e2fa38969b15171a95d6ab7e3d3236d135a6b7af94e0dc822cf391fb3fb898d0";+ public const string GoldenHash = "bf6baf3ff8880b06b82ebf66a01157b29754eed117a7c2bdca528b05fa7959a4";/// <summary>Real content, seed 1948, Historical mode, HistoricalAI until the date reaches 1950-01-01.</summary>public static GameState GoldenPlaythrough(Content c) => GoldenRun.Play(c, GoldenRun.Until1950);@@ -33,7 +33,23 @@ public class DeterminismTestsAssert.Equal(GoldenHash, s.Hash());}- /// <summary>The library constant Unity players compare against is the value this test pins.</summary>+ /// <summary>Same rule for the second golden run, which covers the M3 content range (to 1952-01-01).</summary>+ public const string GoldenHash1952 = "1753fb88dfeef95d8260b8ffe6250e52b04b71ba10babe8a96d07914047257d0";++ [Fact]+ public void GoldenPlaythroughTo1952HashIsFixed()+ {+ var s = GoldenRun.Play(ContentLoader.Load(RealContentTests.ContentRoot()), GoldenRun.Until1952);+ Assert.Null(s.GameOver);+ Assert.Equal(new DateTime(1952, 2, 26), s.Date);+ Assert.Equal(GoldenHash1952, s.Hash());+ }++ /// <summary>The library constants Unity players compare against are the values these tests pin.</summary>[Fact]- public void LibraryGoldenConstantMatchesThisTest() => Assert.Equal(GoldenHash, GoldenRun.Hash1950);+ public void LibraryGoldenConstantsMatchThisTest()+ {+ Assert.Equal(GoldenHash, GoldenRun.Hash1950);+ Assert.Equal(GoldenHash1952, GoldenRun.Hash1952);+ }}diff --git a/sim/Statecraft.Sim.Tests/EconomyCalibrationTests.cs b/sim/Statecraft.Sim.Tests/EconomyCalibrationTests.csnew file mode 100644index 000000000..6eb776598--- /dev/null+++ b/sim/Statecraft.Sim.Tests/EconomyCalibrationTests.cs@@ -0,0 +1,126 @@+using System;+using System.Collections.Generic;+using System.Globalization;+using System.Linq;+using Statecraft.Sim;++/// <summary>+/// Plays the historical choices to 1952 and compares the economy with sourced anchors (rules.yaml cites each).+///+/// ANCHOR INDEPENDENCE (as in CalibrationTests): rules.yaml derives or tunes a parameter from each of the first four+/// anchors, so they are CONSISTENCY checks that the derivation holds in play:+/// - internal debt rose IL 98.4m over 1950-51 (Michaely 1975, Table 5-2: 65.4 + 33.0): spending_per_capita is derived from it;+/// - the FY 1950/51 ordinary budget was IL 60m (en.wiki "1950 in Israel"): tax_per_capita is derived from it;+/// - exports covered under a third of imports (spec section 3): exports and imports were chosen to satisfy it;+/// - foreign currency ran out in autumn 1951 (FRUS 1951 v.V doc 513): capital_inflow_per_year is tuned to it.+/// M3 has NO fully independent economy anchor. The one loose INDEPENDENT check: external debt rose IL 65.7m over 1950-51+/// (Michaely Table 5-2: 22.6 + 43.1), which nothing in rules.yaml was derived from (see its test for the tolerance).+/// M4 adds independent anchors (GNP +25% 1950 to 1951, the FY1951/52 instalments).+/// </summary>+public class EconomyCalibrationTests+{+ const double DebtTolerance = 0.15;+ static readonly Content C = ContentLoader.Load(RealContentTests.ContentRoot());+ static readonly List<GameState> History = Play();++ static List<GameState> Play()+ {+ var s = Simulation.NewGame(C, GoldenRun.Seed, Mode.Historical);+ var h = new List<GameState> { s };+ while (s.Date <= new DateTime(1952, 1, 1) && s.GameOver == null)+ {+ s = Simulation.Step(C, s, HistoricalAI.Commands(C, s)).State;+ h.Add(s);+ }+ return h;+ }++ /// <summary>A state value on a date, linearly interpolated between the two turns around it.</summary>+ static double On(DateTime date, Func<GameState, double> value)+ {+ var after = History.First(s => s.Date >= date);+ var before = History.Last(s => s.Date <= date);+ if (after.Date == before.Date) return value(after);+ var t = (date - before.Date).TotalDays / (after.Date - before.Date).TotalDays;+ return value(before) + t * (value(after) - value(before));+ }++ static string F(double v) => v.ToString("0.0", CultureInfo.InvariantCulture);++ [Fact]+ public void ThePlaythroughSurvivesTo1952()+ {+ var last = History[History.Count - 1];+ Assert.True(last.GameOver == null, "game over: " + last.GameOver);+ Assert.True(last.CoalitionStability > PoliticsSystem.CollapseBelow);+ }++ [Fact]+ public void BorrowingIn1950And1951MatchesTheRiseInInternalDebt()+ {+ const double michaely = 65.4 + 33.0;+ var rise = On(new DateTime(1952, 1, 1), s => s.Debt) - On(new DateTime(1950, 1, 1), s => s.Debt);+ Assert.True(Math.Abs(rise - michaely) / michaely <= DebtTolerance,+ $"[consistency: spending_per_capita_per_year is derived from this anchor] debt rose {F(rise)}m in 1950-51; Michaely: {F(michaely)}m");+ }++ [Fact]+ public void TaxesAtMidFiscalYear1950_51FundTheIl60mBudget()+ {+ var perYear = C.Rules.TaxPerCapitaPerYear * On(new DateTime(1950, 10, 1), s => s.TotalPopulation);+ Assert.True(Math.Abs(perYear - 60) / 60 <= DebtTolerance,+ $"[consistency: tax_per_capita_per_year is derived from this anchor] tax revenue {F(perYear)}m a year; budget IL 60m");+ }++ [Fact]+ public void ExportsCoverUnderAThirdOfImportsIn1950And1951()+ {+ foreach (var s in History.Where(s => s.Date.Year == 1950 || s.Date.Year == 1951))+ {+ var ratio = C.Rules.ExportsPerYear / (C.Rules.ImportsPerCapitaPerYear * s.TotalPopulation);+ Assert.True(ratio < 1.0 / 3, $"[consistency: exports and imports were chosen to satisfy this] {s.Date:yyyy-MM-dd}: exports cover {ratio:P0} of imports");+ }+ }++ [Fact]+ public void ForeignCurrencyRunsOutInTheLastHalfOf1951()+ {+ var first = History.FirstOrDefault(s => s.ActiveSituations.Contains(EconomySystem.FxCrisis));+ Assert.True(first != null, "[consistency: capital_inflow_per_year is tuned to this anchor] reserves never ran out");+ Assert.True(first!.Date > new DateTime(1951, 7, 1) && first.Date <= new DateTime(1952, 1, 1),+ $"[consistency: capital_inflow_per_year is tuned to this anchor] reserves ran out on {first.Date:yyyy-MM-dd}; historically in October 1951");+ Assert.All(History.Where(s => s.Date < first.Date), s => Assert.True(s.FxReserves >= 0, $"{s.Date:yyyy-MM-dd}: fx {F(s.FxReserves)}"));+ }++ /// <summary>[independent, loose] External debt rose IL 22.6m + 43.1m = 65.7m over 1950-51 (Michaely Table 5-2), which+ /// at the formal IL 0.36 per dollar is $182.5m. The model does not split loans from donations: its foreign currency+ /// from abroad (capital_inflow_per_year plus the event grants and bond sales in the run) is loans + donations, and+ /// donations (the UJA, transfers) are not debt. So Michaely's loans must be covered by the model's inflow+ /// (ratio >= 1), and the inflow must stay within three times the loans (ratio <= 3): the research notes give no+ /// donation total, so the band only guards the order of magnitude. Tightening it needs the donation series (M4).</summary>+ [Fact]+ public void ForeignInflowIsOfTheOrderOfTheRiseInExternalDebt()+ {+ const double externalDebtUsd = (22.6 + 43.1) / 0.36;+ double inflow = 0;+ for (int i = 1; i < History.Count; i++)+ {+ var (a, b) = (History[i - 1], History[i]);+ if (a.Date < new DateTime(1950, 1, 1) || a.Date >= new DateTime(1952, 1, 1)) continue;+ var yf = SimTime.YearFraction(SecuritySystem.TurnLengthFor(a.Rung));+ var trade = C.Rules.ExportsPerYear * yf - C.Rules.ImportsPerCapitaPerYear * a.TotalPopulation * yf;+ inflow += (b.FxReserves - a.FxReserves) - trade; // everything that reached the reserves except trade+ }+ var ratio = inflow / externalDebtUsd;+ Assert.True(ratio >= 1 && ratio <= 3,+ $"[independent, loose] foreign inflow {F(inflow)} $m in 1950-51 is {ratio:0.00}x the rise in external debt ({F(externalDebtUsd)} $m); expected 1-3x");+ }++ [Fact]+ public void ReservesGoHomeAfterTheArmistices()+ {+ var s = History.First(x => x.Date >= new DateTime(1950, 1, 1));+ Assert.Equal(2, s.Rung);+ Assert.Equal(C.Rules.RungMinMobilization[1], s.Mobilization);+ }+}diff --git a/sim/Statecraft.Sim.Tests/EconomyM3Tests.cs b/sim/Statecraft.Sim.Tests/EconomyM3Tests.csnew file mode 100644index 000000000..154081df6--- /dev/null+++ b/sim/Statecraft.Sim.Tests/EconomyM3Tests.cs@@ -0,0 +1,84 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>M3 economy rules on the fixture: donations and loans, the food cut during a currency crisis, and the+/// historical AI sending reserves home.</summary>+public class EconomyM3Tests+{+ static Content Load(string rulesExtra) =>+ ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["rules.yaml"] = Fixture.Files["rules.yaml"] + rulesExtra }));++ static GameState Fresh(Content c)+ {+ var s = new GameState { Date = new DateTime(1948, 6, 1) };+ EffectsSystem.Init(c, s);+ EconomySystem.Init(c, s);+ s.Population["veterans"] = 1000;+ return s;+ }++ [Fact]+ public void DonationsAndLoansAddForeignCurrency()+ {+ var c = Load("capital_inflow_per_year: 8\n");+ var s = Fresh(c);+ var why = new List<Cause>();+ EconomySystem.Apply(c, s, 0.25, why);+ Assert.Equal(50 + 5 + 2 - 0.025, s.FxReserves, 9); // exports 20/4, inflow 8/4, imports 0.0001*1000/4+ Assert.Contains(why, w => w.Target == "fx_reserves" && w.Message.Contains("donations and loans 2.00"));+ }++ [Fact]+ public void ACurrencyCrisisCutsFoodImports()+ {+ var c = Load("fx_crisis_food_per_year: -0.4\n");+ var s = Fresh(c);+ s.FxReserves = -20; // still negative after a quarter of exports (+5)+ var why = new List<Cause>();+ EconomySystem.Apply(c, s, 0.25, why);+ Assert.Contains(EconomySystem.FxCrisis, s.ActiveSituations);+ Assert.Equal(0.4 - 0.1, s.Indicators["food_supply"], 9);+ Assert.Equal(-0.1, s.IndicatorShifts["food_supply"], 9);+ Assert.Contains(why, w => w.Target == "food_supply" && w.Message == "food_supply -0.100 (foreign currency crisis: food imports cut)");+ }++ [Fact]+ public void NoCrisisNoFoodCut()+ {+ var c = Load("fx_crisis_food_per_year: -0.4\n");+ var s = Fresh(c);+ EconomySystem.Apply(c, s, 0.25, new List<Cause>());+ Assert.Equal(0.4, s.Indicators["food_supply"], 9);+ }++ [Fact]+ public void APositiveFoodCutIsALoadError()+ {+ var ex = Assert.Throws<ContentException>(() => Load("fx_crisis_food_per_year: 0.1\n"));+ Assert.Equal("fx_crisis_food_per_year", ex.Field);+ }++ [Fact]+ public void TheBudgetFactorRuleWorksOnAnyShares()+ {+ var draft = new Dictionary<string, double> { ["a"] = 0.5, ["b"] = 0.3, ["c"] = 0.2 };+ Assert.Equal(1.25, EffectsSystem.BudgetFactor(draft, "a"), 9); // 0.5 + 0.5 * 3 / 2+ Assert.Equal(0.8, EffectsSystem.BudgetFactor(draft, "c"), 9);+ Assert.Equal(1.0, EffectsSystem.BudgetFactor(draft, "z"), 9); // no line: neutral+ var s = new GameState { Budget = draft };+ Assert.Equal(EffectsSystem.BudgetFactor(draft, "b"), EffectsSystem.BudgetFactor(s, "b"));+ }++ [Fact]+ public void HistoricalAiSendsReservesHomeToTheRungMinimum()+ {+ var c = ContentLoader.Load(Fixture.Write());+ var s = Simulation.NewGame(c, 42, Mode.Historical);+ Assert.Empty(HistoricalAI.Commands(c, s)); // at war: the call-up is already the rung-5 minimum+ s.Rung = 2;+ var order = Assert.IsType<SetMobilization>(HistoricalAI.Commands(c, s).Single());+ Assert.Equal(0.05, order.Level);+ }+}diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex a855eb672..d1415a2e4 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -124,6 +124,10 @@ namespace Statecraft.Simpublic double SpendingPerCapitaPerYear { get; set; }public double ExportsPerYear { get; set; }public double ImportsPerCapitaPerYear { get; set; }+ /// <summary>Foreign currency arriving each year without exports (donations, loans, transfers), in the units of fx_start.</summary>+ public double CapitalInflowPerYear { get; set; }+ /// <summary>Change to food_supply per year while the foreign currency crisis lasts (imports of food are cut); <= 0.</summary>+ public double FxCrisisFoodPerYear { get; set; }public double MobilizationCostPerYear { get; set; }public double NaturalIncreasePerYear { get; set; }public Dictionary<string, double> InitialPopulation { get; set; } = new Dictionary<string, double>();diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex 29954fec9..af4995efc 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -331,8 +331,11 @@ namespace Statecraft.Simvar r = c.Rules;foreach (var (key, v) in new[] { ("treasury_start", r.TreasuryStart), ("fx_start", r.FxStart), ("tax_per_capita_per_year", r.TaxPerCapitaPerYear),("spending_per_capita_per_year", r.SpendingPerCapitaPerYear), ("exports_per_year", r.ExportsPerYear), ("imports_per_capita_per_year", r.ImportsPerCapitaPerYear),- ("mobilization_cost_per_year", r.MobilizationCostPerYear), ("natural_increase_per_year", r.NaturalIncreasePerYear) })+ ("mobilization_cost_per_year", r.MobilizationCostPerYear), ("natural_increase_per_year", r.NaturalIncreasePerYear),+ ("capital_inflow_per_year", r.CapitalInflowPerYear), ("fx_crisis_food_per_year", r.FxCrisisFoodPerYear) })Finite("rules.yaml", key, v);+ if (r.FxCrisisFoodPerYear > 0) throw new ContentException("rules.yaml", "fx_crisis_food_per_year", "must be <= 0 (a crisis cuts food imports)");+ if (r.FxCrisisFoodPerYear < 0 && !indicators.Contains("food_supply")) throw new ContentException("rules.yaml", "fx_crisis_food_per_year", "needs a food_supply indicator in model.yaml");foreach (var kv in r.InitialPopulation) Count("rules.yaml", $"initial_population.{kv.Key}", kv.Value);foreach (var kv in r.BudgetStart){diff --git a/sim/Statecraft.Sim/EconomySystem.cs b/sim/Statecraft.Sim/EconomySystem.csindex e0c15559f..c11f0e46c 100644--- a/sim/Statecraft.Sim/EconomySystem.cs+++ b/sim/Statecraft.Sim/EconomySystem.cs@@ -32,13 +32,23 @@ namespace Statecraft.Sim}var exports = r.ExportsPerYear * yearFraction;+ var inflow = r.CapitalInflowPerYear * yearFraction;var imports = r.ImportsPerCapitaPerYear * pop * yearFraction;- s.FxReserves += exports - imports;- why.Add(new Cause("economy", "fx_reserves", exports - imports, FormattableString.Invariant($"foreign currency {exports - imports:+0.00;-0.00;+0.00} (exports {exports:0.00}, imports {imports:0.00})")));+ var net = exports + inflow - imports;+ s.FxReserves += net;+ why.Add(new Cause("economy", "fx_reserves", net, FormattableString.Invariant($"foreign currency {net:+0.00;-0.00;+0.00} (exports {exports:0.00}, donations and loans {inflow:0.00}, imports {imports:0.00})")));bool on = s.ActiveSituations.Contains(FxCrisis);if (!on && s.FxReserves < 0) { s.ActiveSituations.Add(FxCrisis); why.Add(new Cause("economy", FxCrisis, 1, "Foreign currency reserves are exhausted")); }else if (on && s.FxReserves > 0.25 * r.FxStart) { s.ActiveSituations.Remove(FxCrisis); why.Add(new Cause("economy", FxCrisis, -1, "Foreign currency crisis eased")); }++ // The consequence: with no currency to pay for them, food imports are cut while the crisis lasts.+ if (s.ActiveSituations.Contains(FxCrisis) && r.FxCrisisFoodPerYear < 0)+ {+ var change = EffectsSystem.Shift(c, s, "food_supply", r.FxCrisisFoodPerYear * yearFraction);+ if (change != 0)+ why.Add(new Cause("economy", "food_supply", change, FormattableString.Invariant($"food_supply {change:+0.000;-0.000;+0.000} (foreign currency crisis: food imports cut)")));+ }}/// <summary>Returns null on success, or the reason the allocation was rejected.</summary>diff --git a/sim/Statecraft.Sim/EffectsSystem.cs b/sim/Statecraft.Sim/EffectsSystem.csindex f58ebd6b1..0da5e91b6 100644--- a/sim/Statecraft.Sim/EffectsSystem.cs+++ b/sim/Statecraft.Sim/EffectsSystem.cs@@ -25,10 +25,13 @@ namespace Statecraft.Sim/// <summary>An equal split of the budget is neutral (1.0); a ministry's factor runs from 0.5 (no money) to 1.5./// An office with no budget line (not in budget_start, so the player can never fund it) is neutral too:/// treating it as unfunded would halve its effects permanently with no way to fix it.</summary>- public static double BudgetFactor(GameState s, string office)+ public static double BudgetFactor(GameState s, string office) => BudgetFactor(s.Budget, office);++ /// <summary>The same rule for any set of shares (the Budget screen shows the factor of a draft budget).</summary>+ public static double BudgetFactor(IReadOnlyDictionary<string, double> budget, string office){- if (!s.Budget.TryGetValue(office, out var share)) return 1.0;- return Math.Min(1.5, 0.5 + share * s.Budget.Count / 2.0);+ if (!budget.TryGetValue(office, out var share)) return 1.0;+ return Math.Min(1.5, 0.5 + share * budget.Count / 2.0);}public static void Apply(Content c, GameState s, List<Cause> why)@@ -66,6 +69,19 @@ namespace Statecraft.Siminternal static double Level(Content c, GameState s, Indicator i) =>Math.Max(0, Math.Min(1, Inner(c, s, i) + s.IndicatorShifts[i.Id]));+ /// <summary>Moves an indicator's level by <paramref name="delta"/> through its permanent shift (the layer event+ /// choices and crises use), clamped to [0, 1]. The shift is set so the level lands exactly on the visible result.+ /// Returns the change actually applied (0 when the indicator was already at the clamp).</summary>+ public static double Shift(Content c, GameState s, string indicator, double delta)+ {+ var ind = c.Indicators.First(i => i.Id == indicator);+ var level = Level(c, s, ind);+ var newLevel = Math.Max(0, Math.Min(1, level + delta));+ s.IndicatorShifts[ind.Id] = newLevel - Inner(c, s, ind);+ s.Indicators[ind.Id] = newLevel;+ return newLevel - level;+ }+public static void UpdateSituations(Content c, GameState s, List<Cause> why){foreach (var sit in c.Situations)diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.csindex d220fc81c..cc81876f0 100644--- a/sim/Statecraft.Sim/EventSystem.cs+++ b/sim/Statecraft.Sim/EventSystem.cs@@ -62,16 +62,7 @@ namespace Statecraft.Simvar change = fx.Delta;if (fx.Target == "treasury") s.Treasury += fx.Delta;else if (fx.Target == "fx_reserves") s.FxReserves += fx.Delta;- else- {- // The shift is set so the level lands exactly on the visible result; it never exceeds the clamp.- var ind = c.Indicators.First(i => i.Id == fx.Target);- var level = EffectsSystem.Level(c, s, ind);- var newLevel = Math.Max(0, Math.Min(1, level + fx.Delta));- s.IndicatorShifts[ind.Id] = newLevel - EffectsSystem.Inner(c, s, ind);- s.Indicators[ind.Id] = newLevel;- change = newLevel - level;- }+ else change = EffectsSystem.Shift(c, s, fx.Target, fx.Delta);why.Add(new Cause("events", fx.Target, change, FormattableString.Invariant($"{fx.Target} {change:+0.00;-0.00;+0.00} ({eventId}/{o.Id})")));}foreach (var kv in o.SetPolicy.OrderBy(k => k.Key, StringComparer.Ordinal))diff --git a/sim/Statecraft.Sim/GoldenRun.cs b/sim/Statecraft.Sim/GoldenRun.csindex 18f717e2e..da8234f7e 100644--- a/sim/Statecraft.Sim/GoldenRun.cs+++ b/sim/Statecraft.Sim/GoldenRun.cs@@ -11,10 +11,15 @@ namespace Statecraft.Sim/// <summary>Final hash of Play(content, Until1950). Changing it is a deliberate rules or content change:/// update it, DeterminismTests and docs/determinism.md in the same commit and say why in the message.</summary>- public const string Hash1950 = "e2fa38969b15171a95d6ab7e3d3236d135a6b7af94e0dc822cf391fb3fb898d0";+ public const string Hash1950 = "bf6baf3ff8880b06b82ebf66a01157b29754eed117a7c2bdca528b05fa7959a4";public static readonly DateTime Until1950 = new DateTime(1950, 1, 1);+ /// <summary>Final hash of Play(content, Until1952): the M3 content range (to 31 December 1951).</summary>+ public const string Hash1952 = "1753fb88dfeef95d8260b8ffe6250e52b04b71ba10babe8a96d07914047257d0";++ public static readonly DateTime Until1952 = new DateTime(1952, 1, 1);+/// <summary>Steps with HistoricalAI until Date >= <paramref name="until"/>, the game ends, or 1000 turns pass.</summary>public static GameState Play(Content c, DateTime until){diff --git a/sim/Statecraft.Sim/HistoricalAI.cs b/sim/Statecraft.Sim/HistoricalAI.csindex 4cd893b8e..80d6a5dca 100644--- a/sim/Statecraft.Sim/HistoricalAI.cs+++ b/sim/Statecraft.Sim/HistoricalAI.cs@@ -1,16 +1,23 @@+using System;using System.Collections.Generic;using System.Linq;namespace Statecraft.Sim{- /// <summary>Plays what really happened: picks each pending event's historical option (else its first).- /// It sends no budget allocation, so the budget stays at rules.yaml budget_start.</summary>+ /// <summary>Plays what really happened: picks each pending event's historical option (else its first), then sends+ /// reserves home down to the current security level's minimum call-up (the army demobilised after the 1949+ /// armistices). It sends no budget allocation, so the budget stays at rules.yaml budget_start.</summary>public static class HistoricalAI{- public static IReadOnlyList<Command> Commands(Content c, GameState s) =>- s.PendingEvents+ public static IReadOnlyList<Command> Commands(Content c, GameState s)+ {+ var list = s.PendingEvents.Select(id => c.Events.First(e => e.Id == id)).Select(e => (Command)new ChooseEventOption(e.Id, (e.Options.FirstOrDefault(o => o.Historical) ?? e.Options[0]).Id)).ToList();+ var floor = c.Rules.RungMinMobilization[Math.Max(1, Math.Min(5, s.Rung)) - 1];+ if (s.Mobilization > floor) list.Add(new SetMobilization(floor));+ return list;+ }}}diff --git a/unity/Assets/Tests/EditMode/SimSmokeTests.cs b/unity/Assets/Tests/EditMode/SimSmokeTests.csindex 70c3e1260..a2025dc5c 100644--- a/unity/Assets/Tests/EditMode/SimSmokeTests.cs+++ b/unity/Assets/Tests/EditMode/SimSmokeTests.cs@@ -27,4 +27,12 @@ public class SimSmokeTestsAssert.IsNull(s.GameOver);Assert.AreEqual(GoldenRun.Hash1950, s.Hash());}++ [Test]+ public void GoldenPlaythroughTo1952MatchesDotNet()+ {+ var s = GoldenRun.Play(ContentLoader.Load(Paths.Content), GoldenRun.Until1952);+ Assert.IsNull(s.GameOver);+ Assert.AreEqual(GoldenRun.Hash1952, s.Hash());+ }}