A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
test(sim): SplitMix64 reference vectors and golden playthrough hash (I4, M7)
eyalgolan97260eab6d2e
diff --git a/docs/determinism.md b/docs/determinism.mdnew file mode 100644index 000000000..76870a1eb--- /dev/null+++ b/docs/determinism.md@@ -0,0 +1,32 @@+# Determinism++The simulation must produce the same state, bit for bit, on .NET, Unity Mono and IL2CPP. Saves, replays and the+"Why did this happen?" report depend on this.++## How it is kept++- **One RNG:** SplitMix64 (`Statecraft.Sim.Rng`). Its whole state is one `ulong` in `GameState.RngState`.+- **Reference vectors:** `DeterminismTests.SplitMix64MatchesTheReferenceVectors` checks the first three outputs for+ seeds 0 and 1234567. The expected values come from Sebastiano Vigna's reference `splitmix64.c`+ (https://prng.di.unimi.it/splitmix64.c), compiled and run separately. They were not copied from this implementation.+- **Canonical hash:** `GameState.Hash()` is SHA-256 over a canonical text. Keys are sorted ordinally. Doubles are+ written as IEEE bit patterns, with -0.0 written as 0.0. Culture is invariant.++## Golden playthrough++The playthrough loads the real `content/` and calls `Simulation.NewGame(content, 1948, Mode.Historical)`. It then+steps with `HistoricalAI.Commands` until `Date >= 1950-01-01`; with the current rules this ends on 1950-02-26 at+turn 45. The final `GameState.Hash()` must equal:++```+eb9756528eeebdc7b078ab90f7fe7a349edcfc94be9543e5f20f258da4e500e9+```++The constant is asserted in two places:+- `sim/Statecraft.Sim.Tests/DeterminismTests.cs` (`GoldenHash`), on .NET.+- `unity/Assets/Tests/EditMode/SimSmokeTests.cs` (`GoldenHash`), inside Unity (plan Task 23).++**Any change to this hash is a deliberate rules or content change.** Such a change could be to a rule, a system,+content in `content/`, or the hash format. When it happens, update the constant here, in `DeterminismTests.cs` and in+`SimSmokeTests.cs`, all in the same commit, and say in the commit message why the hash moved. If the hash changes and+you did not mean to change rules or content, treat it as a determinism bug.diff --git a/docs/superpowers/plans/2026-10-09-statecraft-m0-m2.md b/docs/superpowers/plans/2026-10-09-statecraft-m0-m2.mdindex c00cb8487..571e4d45f 100644--- a/docs/superpowers/plans/2026-10-09-statecraft-m0-m2.md+++ b/docs/superpowers/plans/2026-10-09-statecraft-m0-m2.md@@ -5532,7 +5532,8 @@ These tasks consume the M1 sim library (public interface defined in Task 15) and- Modify: `.gitignore`**Interfaces:**-- Consumes: the M1 public interface (defined in Task 15): `ContentLoader.Load(string)`, `Simulation.NewGame(...)`, `Simulation.Step(...)`, `GameState.Hash()`.+- Consumes: the M1 public interface (defined in Task 15): `ContentLoader.Load(string)`, `Simulation.NewGame(...)`, `Simulation.Step(...)`, `HistoricalAI.Commands(...)`, `GameState.Hash()`.+- Consumes: the golden hash constant in `docs/determinism.md` (also in `sim/Statecraft.Sim.Tests/DeterminismTests.cs`).- Produces:- `Paths.RepoRoot`, `Paths.Content` and `Paths.StreamingMap` (string properties).- The `Statecraft.Game` assembly, which Tasks 24–25 add scripts to.@@ -5623,9 +5624,27 @@ public class SimSmokeTestsAssert.AreEqual(ra.State.Hash(), rb.State.Hash());Assert.IsNotEmpty(ra.State.Hash());}++ /// <summary>The same playthrough and constant as sim/Statecraft.Sim.Tests/DeterminismTests.cs (see docs/determinism.md).+ /// It proves Unity's runtime computes, bit for bit, what .NET computes. Update all three places together.</summary>+ public const string GoldenHash = "eb9756528eeebdc7b078ab90f7fe7a349edcfc94be9543e5f20f258da4e500e9";++ [Test]+ public void GoldenPlaythroughMatchesDotNet()+ {+ var c = ContentLoader.Load(Paths.Content);+ var s = Simulation.NewGame(c, 1948UL, Mode.Historical);+ for (int turn = 0; turn < 1000 && s.Date < new System.DateTime(1950, 1, 1) && s.GameOver == null; turn++)+ s = Simulation.Step(c, s, HistoricalAI.Commands(c, s)).State;+ Assert.IsNull(s.GameOver);+ Assert.GreaterOrEqual(s.Date, new System.DateTime(1950, 1, 1));+ Assert.AreEqual(GoldenHash, s.Hash());+ }}```+`GoldenPlaythroughMatchesDotNet` mirrors the xUnit `DeterminismTests.GoldenPlaythroughHashIsFixed` line for line. Edit mode runs on the editor's Mono runtime. IL2CPP is checked when the first player build (M3) runs the same test in a player. If the two hashes differ, the cause is a determinism bug, not a reason to change the constant.+- [ ] **Step 6: Run the edit-mode tests in batch mode**Run:@@ -6247,3 +6266,6 @@ Each item below is in the spec and has a home. None is silently dropped.| Per-era art prefabs that replace the M2 placeholder markers; in-game portrait pipeline | M3–M4 || Steam page and AI-disclosure manifest | M5 || Open fact: how the budget was approved in 1948–56 (`open_questions: [budget_approval]` is pinned by a test) | Content work before M4 |+| Hebrew names (`name_he`) and birth/death dates for people (spec §5.3) | Content work before M4 |+| "Military or economic collapse ends the state" (spec §4) | M4 |+| Validation that legislature periods do not overlap, and that government periods do not overlap | Before M4 adds the 1951 and 1955 Knessets |diff --git a/sim/Statecraft.Sim.Tests/DeterminismTests.cs b/sim/Statecraft.Sim.Tests/DeterminismTests.csnew file mode 100644index 000000000..11b7b067b--- /dev/null+++ b/sim/Statecraft.Sim.Tests/DeterminismTests.cs@@ -0,0 +1,41 @@+using System;+using Statecraft.Sim;++/// <summary>Fixed reference values for the generator and for one full historical playthrough. See docs/determinism.md.</summary>+public class DeterminismTests+{+ /// <summary>The first three outputs of Vigna's reference splitmix64.c (https://prng.di.unimi.it/splitmix64.c)+ /// for each seed, taken from the reference C code, not from this implementation.</summary>+ [Theory]+ [InlineData(0UL, 0xE220A8397B1DCDAFUL, 0x6E789E6AA1B965F4UL, 0x06C45D188009454FUL)]+ [InlineData(1234567UL, 6457827717110365317UL, 3203168211198807973UL, 9817491932198370423UL)]+ public void SplitMix64MatchesTheReferenceVectors(ulong seed, ulong first, ulong second, ulong third)+ {+ var rng = new Rng(seed);+ Assert.Equal(first, rng.NextULong());+ Assert.Equal(second, rng.NextULong());+ Assert.Equal(third, rng.NextULong());+ }++ /// <summary>Any change to this value is a deliberate rules or content change: update it here and in+ /// docs/determinism.md (and the Unity edit-mode SimSmokeTests) in the same commit.</summary>+ public const string GoldenHash = "eb9756528eeebdc7b078ab90f7fe7a349edcfc94be9543e5f20f258da4e500e9";++ /// <summary>Real content, seed 1948, Historical mode, HistoricalAI until the date reaches 1950-01-01.</summary>+ public static GameState GoldenPlaythrough(Content c)+ {+ var s = Simulation.NewGame(c, 1948UL, Mode.Historical);+ for (int turn = 0; turn < 1000 && s.Date < new DateTime(1950, 1, 1) && s.GameOver == null; turn++)+ s = Simulation.Step(c, s, HistoricalAI.Commands(c, s)).State;+ return s;+ }++ [Fact]+ public void GoldenPlaythroughHashIsFixed()+ {+ var s = GoldenPlaythrough(ContentLoader.Load(RealContentTests.ContentRoot()));+ Assert.Null(s.GameOver);+ Assert.True(s.Date >= new DateTime(1950, 1, 1));+ Assert.Equal(GoldenHash, s.Hash());+ }+}