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.

fix(sim,docs): sensitivity gate, id-free refusals, one call-up cost; itch.io deferred, seven sensitive events (M3 final review I3 I4 M2 M3 M4 M5 M6 M8)

eyalgolan43aa77654e3c
diff --git a/docs/determinism.md b/docs/determinism.md
index 0f084f4cf..dcc0b4616 100644
--- a/docs/determinism.md
+++ b/docs/determinism.md
@@ -25,7 +25,25 @@ with `GoldenRun.Seed = 1948` on the real `content/`, then steps with `Historical
| to 1950-01-01 (`Hash1950`) | 1950-02-27, turn 35 | `71e9904d0ee48083db9bbba281f3f046136482ba83ee056e48d57b62e76a5b07` |
| to 1952-01-01 (`Hash1952`) | 1952-02-27, turn 43 | `73590e324f19e9959a455a4da79e93d7089dfcf283c13aac02af6b0a624b9767` |
-Each constant is written in three places that must agree:
+A third value is pinned for the browser smoke run (`?smoke=5`: the golden seed, five turns played through the UI's own
+buttons, answering each event with its first option): `SMOKE OK 5 turns 1948-06-19 d3fdd459ddb876bd8d775c20edd1202cf56ca7134a8ad06f873d4d92034aa5b6`.
+It depends on the UI path as well as the sim (which option is first, the turn grid), so re-record it when either changes.
+Check every build with:
+
+```
+uv run tools/web_check.py unity/Builds/Web-<compression> --query "golden&smoke=5" \
+ --expect "GOLDEN OK 1950 71e9904d0ee48083db9bbba281f3f046136482ba83ee056e48d57b62e76a5b07" \
+ --expect "GOLDEN OK 1952 73590e324f19e9959a455a4da79e93d7089dfcf283c13aac02af6b0a624b9767" \
+ --expect "SMOKE OK 5 turns 1948-06-19 d3fdd459ddb876bd8d775c20edd1202cf56ca7134a8ad06f873d4d92034aa5b6"
+```
+
+**Cause text is derived, not hashed.** The "Why did this happen?" lines (`Cause.Message`, `Cause.Delta`) are output
+computed from the hashed state; replaying a save's commands regenerates them. Wording changes therefore do not move the
+goldens (playtest 2 changed every line's casing with no hash change). They are still deterministic:
+`FinalWaveTests.AReloadedSaveReproducesTheLastTurnsCauses` checks a reloaded save gives the same last-turn Causes, and
+`TheGoldenRunsCausesAreTheSameInEveryCulture` runs the 1952 golden under de-DE and ar-SA against the invariant culture.
+
+Each golden constant is written in three places that must agree:
- `sim/Statecraft.Sim/GoldenRun.cs`, which Unity code and players compare against;
- `sim/Statecraft.Sim.Tests/DeterminismTests.cs`, which pins the value on .NET and asserts the library constant equals it;
- this file.
diff --git a/docs/dev-setup.md b/docs/dev-setup.md
index 9a5ff65cc..0bcac05a7 100644
--- a/docs/dev-setup.md
+++ b/docs/dev-setup.md
@@ -17,12 +17,14 @@
(`-compression` is `disabled`, `gzip` or `brotli`; output in `unity/Builds/Web-<compression>/`, about 2 minutes).
- macOS IL2CPP build: `"$UNITY" -batchmode -quit -projectPath unity -buildTarget OSXUniversal -executeMethod Statecraft.Game.EditorTools.Build.Mac -logFile "$PWD/unity-build-mac.log"`
(output `unity/Builds/Mac/Statecraft.app`).
-- Browser check: `uv run tools/web_check.py unity/Builds/Web-disabled --query "golden&smoke=5" --expect "GOLDEN OK 1952" --expect "SMOKE OK 5 turns"`.
+- Browser check: `uv run tools/web_check.py unity/Builds/Web-disabled --query "golden&smoke=5"` with the three full `--expect`
+ values pinned in `docs/determinism.md` (both goldens and the smoke line).
It uses Chrome for Testing from the Playwright cache (`~/Library/Caches/ms-playwright/chromium-1228` on this Mac;
elsewhere `npx playwright install chromium`).
- Page flags: `?golden` (golden check), `?smoke=N` (play N turns through the UI; bare `?smoke` = 5, `?smoke=0` = off),
- `?profile` (terrain profile), `?camlog` (log the camera distance). Desktop players take `-golden`, `-smoke N`, `-profile`
- and `-camlog`. The console also shows `GAME OK <date> turn <n> hash <h>` at start and `TURN <n> <date> hash <h>` per turn.
+ `?profile` (terrain profile), `?camlog` (log the camera distance), `?bootlog` (each boot phase's timing) and `?navlog`
+ (every UI pointer and submit event, screen toggle and map click, with its frame). Desktop players take `-golden`,
+ `-smoke N`, `-profile`, `-camlog`, `-bootlog` and `-navlog`. The console also shows `GAME OK <date> turn <n> hash <h>` at start and `TURN <n> <date> hash <h>` per turn.
- A player build rewrites some URP asset and player-setting fields as build-time caches; drop them afterwards with
`git checkout -- unity/Assets/Settings unity/ProjectSettings/ProjectSettings.asset`.
- Play a build locally: `python3 -m http.server 8000 --directory unity/Builds/Web-disabled`, then open http://localhost:8000/.
diff --git a/docs/m3-release.md b/docs/m3-release.md
index 27b78a37a..2d2e49640 100644
--- a/docs/m3-release.md
+++ b/docs/m3-release.md
@@ -1,5 +1,8 @@
# M3 release: the browser build
+**Status:** M3 ships as the local browser build. The itch.io upload and the cross-upload save test are deferred to the
+start of M4, as a private Draft (owner ruling, 2026-10-10); their sections below are kept, marked "Deferred to M4".
+
## What ships
- **Folder and zip:** `unity/Builds/Web-brotli/` uses Brotli compression with no decompression fallback. It is zipped as `unity/Builds/statecraft-m3-web.zip`, with `index.html` at the zip root. Both are build output and are not committed.
- **Built by:** `"$UNITY" -batchmode -quit -projectPath unity -buildTarget WebGL -executeMethod Statecraft.Game.EditorTools.Build.Web -compression brotli -logFile "$PWD/unity-build-web-br.log"`, then `(cd unity/Builds/Web-brotli && rm -f ../statecraft-m3-web.zip && zip -qr ../statecraft-m3-web.zip .)`.
@@ -68,8 +71,18 @@ Each step below passed:
Firefox is not installed on the development Mac, so the Firefox check is open.
-## OWNER STEP: sensitivity review before a public upload
-Spec section 5.5 requires a recorded sensitivity review for events with sensitive tags. The six events below are only `fact-checked`. The owner reviews each and records a sign-off (in progress.md, or by moving its `status` to `sensitivity-reviewed`) before the itch.io upload.
+## OWNER STEP: sensitivity review before any shared build
+Spec section 5.5 requires a recorded sensitivity review for events with sensitive tags (holocaust, terror, massacre,
+war-casualties). The seven events below are only `fact-checked`. The owner reviews each and records the sign-off **only**
+by moving the event's `status:` in its YAML file to `sensitivity-reviewed` and committing it (the loader accepts that
+value). Nothing else counts as a sign-off.
+
+- **Gate:** `Build.Web ... -shareable` refuses to build while any sensitive event is not `sensitivity-reviewed`, and names
+ them (`Statecraft.Sim.ReleaseGate.SensitiveUnreviewed`). Use `-shareable` for every build that leaves this machine,
+ including the M4 private Draft once it is shared with anyone. Local builds (no flag) are not gated.
+- **Pinned set:** `FinalWaveTests.TheSensitiveEventsArePinned` lists the seven ids, and
+ `TheOwnerTableListsEverySensitiveEvent` fails if a sensitive event is missing from this table, so a new one cannot
+ skip the review.
| Event | Tags | What to review |
|---|---|---|
@@ -79,9 +92,11 @@ Spec section 5.5 requires a recorded sensitivity review for events with sensitiv
| `operation_hiram` | security, war-casualties | military text only; the contested population figures and the 26 Sep cabinet quote are left out |
| `operation_horev` | security, war-casualties | military text only |
| `bernadotte_assassination` | security, terror | the `terror` tag follows the Israeli government's own Prevention of Terrorism Ordinance |
+| `reparations_claim` | holocaust | the claim's framing (the cost of absorbing survivors: 500,000 at $3,000 each); the "refuse" option |
-## OWNER STEP: upload to itch.io
-This needs the owner's itch.io account and is never automated.
+## Deferred to M4: upload to itch.io (OWNER STEP)
+Deferred to the start of M4, as a private Draft (owner ruling, 2026-10-10). The steps stay correct for then. This needs the
+owner's itch.io account and is never automated, and the build must pass the sensitivity gate above (`-shareable`).
1. Sign in at https://itch.io. Go to Dashboard, then **Create new project**.
2. Set the title to "Statecraft: Israel (M3 preview)", Kind of project to **HTML**, and Classification to Games.
3. Under Uploads, upload `unity/Builds/statecraft-m3-web.zip` and tick **This file will be played in the browser**.
@@ -100,13 +115,13 @@ itch.io serves `.br` files with `Content-Encoding: br`, because it detects the e
Published at: (owner fills in)
-## Saves on itch.io: the fix and its test
+## Saves on itch.io: the fix, and its test (the test is deferred to M4)
- **Problem:** on WebGL, `Application.persistentDataPath` is `/idbfs/<MD5 of the page's directory URL>`. itch.io serves every upload from a new URL, so a new upload would hide the saves made with the previous one.
- **Fix (Task 21):** the autosave lives at the fixed path `/idbfs/statecraft-saves/autosave.txt`.
- The template sets `autoSyncPersistentDataPath: true`, so closing the file persists it to IndexedDB.
- IndexedDB is per origin, so saves survive re-uploads to the same project and stay separate per browser profile.
- The local checks above passed: reload, tab close, browser restart, and a second directory on the same origin.
-- **Test plan (OWNER STEP, after the first two uploads):**
+- **Test plan (OWNER STEP, deferred to M4 with the upload; after the first two uploads):**
1. Upload A as above. Play two turns (press End Turn twice) and note the date and turn in the top bar.
2. Reload the page. Expected: the game continues on that date. The console line `GAME OK <date> turn <n> hash ...` matches the last `TURN` line.
3. Upload build B to the same project, replacing A. Rebuild first if anything changed.
@@ -124,4 +139,6 @@ Result: (owner fills in)
- English only.
- The headless smoke plays five turns; a full-slice smoke is M4.
- The wheel-zoom step (one notch = 10%) was measured in Chrome on macOS only. Firefox reports wheel deltas in lines and
- Windows at 125% scaling reports 125 px per notch, so re-check the step in the owner's itch.io check.
+ Windows at 125% scaling reports 125 px per notch, so re-check the step in the owner's M4 itch.io check.
+- Not uploaded to itch.io: the upload and the cross-upload save test are deferred to the start of M4 (owner ruling,
+ 2026-10-10). The seven sensitive events await the owner's sensitivity review (see above).
diff --git a/docs/superpowers/plans/2026-10-10-statecraft-m3.md b/docs/superpowers/plans/2026-10-10-statecraft-m3.md
index 305262f91..72c5df9b4 100644
--- a/docs/superpowers/plans/2026-10-10-statecraft-m3.md
+++ b/docs/superpowers/plans/2026-10-10-statecraft-m3.md
@@ -10814,7 +10814,7 @@ Every spec item M3 does not finish has a home. The M3 rows of the M0–M2 Deferr
| Hebrew names and birth/death dates for all people | Content work before M4 | Carried; M3 adds `died` only where a term ends in death (Remez) |
| Open fact: how the budget was approved in 1948–56 (`open_questions: [budget_approval]`, now also on the Second Knesset) | Content work before M4 | Carried |
| Legal review of map-data licences; the Unity MCP check (M0 b) | M5 / owner | Carried |
-| itch.io upload and the two-upload save test | OWNER STEP | Documented in `docs/m3-release.md` (Task 24) |
+| itch.io upload and the two-upload save test | M4 (owner ruling, 2026-10-10) | Deferred to the start of M4 as a private Draft; the steps stay in `docs/m3-release.md` ("Deferred to M4") |
## Self-review
diff --git a/sim/Statecraft.Sim.Tests/CabinetTests.cs b/sim/Statecraft.Sim.Tests/CabinetTests.cs
index 5d6e2cb11..8bef2ffd3 100644
--- a/sim/Statecraft.Sim.Tests/CabinetTests.cs
+++ b/sim/Statecraft.Sim.Tests/CabinetTests.cs
@@ -80,8 +80,8 @@ public class CabinetTests
[InlineData("finance_minister", "outsider", "Out Sider's party (Beta) is not in the coalition")]
[InlineData("finance_minister", "gone", "Gone Early died on 1 May 1948")]
[InlineData("finance_minister", "def_two", "Def Two already holds the office of Minister of Finance")]
- [InlineData("finance_minister", "nobody", "Unknown person 'nobody'")]
- [InlineData("treasurer", "loyalist", "Unknown office 'treasurer'")]
+ [InlineData("finance_minister", "nobody", "That person is not in this game")]
+ [InlineData("treasurer", "loyalist", "That office does not exist in this game")]
public void IllegalAppointmentsAreRejectedWithAReason(string office, string person, string reason)
{
var s = Simulation.NewGame(C, 42, Mode.Historical);
diff --git a/sim/Statecraft.Sim.Tests/EconomyTests.cs b/sim/Statecraft.Sim.Tests/EconomyTests.cs
index 997fdc03f..77a4ae02b 100644
--- a/sim/Statecraft.Sim.Tests/EconomyTests.cs
+++ b/sim/Statecraft.Sim.Tests/EconomyTests.cs
@@ -54,7 +54,7 @@ public class EconomyTests
[Theory]
[InlineData("finance_minister", 1.0, null)]
[InlineData("finance_minister", 0.9, "Budget shares must sum to 1")]
- [InlineData("chief_rabbi", 1.0, "Unknown office 'chief_rabbi'")]
+ [InlineData("chief_rabbi", 1.0, "The budget names a ministry that does not exist in this game")]
[InlineData("finance_minister", -1.0, "Budget shares must sum to 1")]
public void AllocateValidates(string office, double share, string? error)
{
@@ -132,7 +132,7 @@ public class EconomyCoverageTests
{
var c = TwoBudgets(); var s = new GameState(); EconomySystem.Init(c, s);
var before = new Dictionary<string, double>(s.Budget);
- Assert.Equal("Budget shares must cover exactly: defense_minister, finance_minister",
+ Assert.Equal("The budget must give a share to every ministry, and only to them",
EconomySystem.Allocate(c, s, new Dictionary<string, double> { ["finance_minister"] = 1.0 }));
Assert.Equal(before, s.Budget);
}
@@ -141,7 +141,7 @@ public class EconomyCoverageTests
public void MapWithAnUnbudgetedOfficeIsRejected()
{
var c = TwoBudgets(); var s = new GameState(); EconomySystem.Init(c, s);
- Assert.Equal("Budget shares must cover exactly: defense_minister, finance_minister",
+ Assert.Equal("The budget must give a share to every ministry, and only to them",
EconomySystem.Allocate(c, s, new Dictionary<string, double> { ["finance_minister"] = 0.4, ["defense_minister"] = 0.4, ["prime_minister"] = 0.2 }));
}
diff --git a/sim/Statecraft.Sim.Tests/EventTests.cs b/sim/Statecraft.Sim.Tests/EventTests.cs
index fc884874e..d22b6bf14 100644
--- a/sim/Statecraft.Sim.Tests/EventTests.cs
+++ b/sim/Statecraft.Sim.Tests/EventTests.cs
@@ -72,7 +72,7 @@ options:
Assert.Null(EventSystem.Choose(c, s, "shortage", "import", why));
Assert.Equal(40, s.FxReserves);
Assert.Empty(s.PendingEvents);
- Assert.Equal("Event 'shortage' is not waiting for a decision", EventSystem.Choose(c, s, "shortage", "ration", why));
+ Assert.Equal("That event is not waiting for a decision", EventSystem.Choose(c, s, "shortage", "ration", why));
}
[Fact]
@@ -218,7 +218,7 @@ options:
var c = Load(new Dictionary<string, string> { ["shortage.yaml"] = Shortage });
var s = State(c, new DateTime(1948, 6, 1)); var why = new List<Cause>();
EventSystem.Trigger(c, s, why);
- Assert.Equal("Event 'shortage' has no option 'nap'", EventSystem.Choose(c, s, "shortage", "nap", why));
+ Assert.Equal("That event has no such option", EventSystem.Choose(c, s, "shortage", "nap", why));
}
[Fact]
diff --git a/sim/Statecraft.Sim.Tests/FinalWaveTests.cs b/sim/Statecraft.Sim.Tests/FinalWaveTests.cs
new file mode 100644
index 000000000..3f9fa3b3e
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/FinalWaveTests.cs
@@ -0,0 +1,133 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Text.RegularExpressions;
+using Statecraft.Sim;
+
+/// <summary>M3 final review: the sensitive-event gate (I4), Cause determinism (M2), id-free refusals (M3, M4) and the one
+/// call-up cost (M5).</summary>
+public class FinalWaveTests
+{
+ static readonly Content Real = ContentLoader.Load(RealContentTests.ContentRoot());
+
+ // ---- I4: sensitive events ----
+
+ /// <summary>The events with a sensitive tag (spec 5.5): pinned, so a new one cannot miss the owner's review table.</summary>
+ static readonly string[] SensitiveEvents =
+ { "altalena", "bernadotte_assassination", "operation_hiram", "operation_horev", "operation_yoav", "reparations_claim", "ten_days" };
+
+ [Fact]
+ public void TheSensitiveEventsArePinned()
+ {
+ var actual = ReleaseGate.SensitiveEvents(Real).OrderBy(x => x, StringComparer.Ordinal).ToArray();
+ Assert.True(SensitiveEvents.SequenceEqual(actual),
+ $"sensitive events changed: {string.Join(", ", actual)}. Add any new one to m3-release.md's sensitivity table and to this list.");
+ }
+
+ [Fact]
+ public void TheOwnerTableListsEverySensitiveEvent()
+ {
+ var doc = File.ReadAllText(Path.Combine(RealContentTests.ContentRoot(), "..", "docs", "m3-release.md"));
+ foreach (var id in ReleaseGate.SensitiveEvents(Real))
+ Assert.True(doc.Contains($"| `{id}` |"), $"{id} is sensitive: add it to m3-release.md's sensitivity table");
+ }
+
+ /// <summary>The release gate: a sensitive event not yet sensitivity-reviewed blocks a shareable build.</summary>
+ [Fact]
+ public void AShareableBuildNeedsEverySensitiveEventReviewed()
+ {
+ Assert.Equal(SensitiveEvents, ReleaseGate.SensitiveUnreviewed(Real).OrderBy(x => x, StringComparer.Ordinal)); // the owner has not signed off yet
+ var reviewed = Fixture.Write(events: new Dictionary<string, string>
+ {
+ ["a.yaml"] = "id: a\ntitle: A\ntext: x\nfrom: 1948-06-01\ntags: [terror]\noptions:\n - id: o\n text: O\nstatus: sensitivity-reviewed\n",
+ ["b.yaml"] = "id: b\ntitle: B\ntext: x\nfrom: 1948-06-01\ntags: [holocaust]\noptions:\n - id: o\n text: O\nstatus: fact-checked\n",
+ });
+ Assert.Equal(new[] { "b" }, ReleaseGate.SensitiveUnreviewed(ContentLoader.Load(reviewed)));
+ }
+
+ // ---- M2: Cause text is derived output, deterministic ----
+
+ [Fact]
+ public void AReloadedSaveReproducesTheLastTurnsCauses()
+ {
+ var g = GameSession.New(Real, GoldenRun.Seed, Mode.Historical);
+ for (int t = 0; t < 40; t++) g.Step(HistoricalAI.Commands(Real, g.State));
+ var loaded = GameSession.Load(Real, g.Save.Write(), out _);
+ Assert.Equal(g.Last!.Why.Select(w => (w.System, w.Target, w.Delta, w.Message)), loaded.Last!.Why.Select(w => (w.System, w.Target, w.Delta, w.Message)));
+ }
+
+ [Theory]
+ [InlineData("de-DE")]
+ [InlineData("ar-SA")]
+ public void TheGoldenRunsCausesAreTheSameInEveryCulture(string culture)
+ {
+ List<string> Run()
+ {
+ var all = new List<string>();
+ var s = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
+ for (int t = 0; t < 1000 && s.Date < GoldenRun.Until1952 && s.GameOver == null; t++)
+ {
+ var r = Simulation.Step(Real, s, HistoricalAI.Commands(Real, s));
+ all.AddRange(r.Why.Select(w => w.Message + " | " + w.Delta.ToString("R", CultureInfo.InvariantCulture)));
+ s = r.State;
+ }
+ return all;
+ }
+ var prev = CultureInfo.CurrentCulture;
+ List<string> invariant, other;
+ try { CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; invariant = Run(); CultureInfo.CurrentCulture = new CultureInfo(culture); other = Run(); }
+ finally { CultureInfo.CurrentCulture = prev; }
+ Assert.Equal(invariant, other);
+ }
+
+ // ---- M3, M4: refusals and Causes name no hex coordinate and quote no id ----
+
+ [Fact]
+ public void MapActionReasonsAndCausesNameNoCoordinates()
+ {
+ var c = Real;
+ var s = GoldenRun.Play(c, new DateTime(1950, 6, 15));
+ var sea = c.Hexes.First(h => !h.Land);
+ Assert.Equal("This hex is not land", MapActions.Check(c, s, MapActions.Housing, sea.Q, sea.R));
+ var far = c.Hexes.First(h => h.Land && c.SettlementHexes.All(x => MapActions.Distance(h.Q, h.R, x.Q, x.R) > c.Rules.MapActionMaxDistance));
+ Assert.Equal($"This hex is more than {c.Rules.MapActionMaxDistance} hex{(c.Rules.MapActionMaxDistance == 1 ? "" : "es")} from a settlement",
+ MapActions.Check(c, s, MapActions.Housing, far.Q, far.R));
+ var ok = c.Hexes.First(h => MapActions.Check(c, s, MapActions.TransitCamp, h.Q, h.R) == null);
+ var why = new List<Cause>();
+ Assert.Null(MapActions.Apply(c, s, MapActions.TransitCamp, ok.Q, ok.R, why));
+ Assert.Equal("This hex already has a transit camp", MapActions.Check(c, s, MapActions.TransitCamp, ok.Q, ok.R));
+ var built = Assert.Single(why, w => w.System == "map");
+ Assert.StartsWith("Built a transit camp: cost IL 1.5m", built.Message);
+ Assert.DoesNotMatch(@"\(-?\d+, -?\d+\)", built.Message);
+ }
+
+ [Fact]
+ public void RefusalsQuoteNoId()
+ {
+ var c = Real;
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ var r = Simulation.Step(c, s, new Command[]
+ {
+ new Appoint("no_such_office", "ben_gurion"), new Appoint("finance_minister", "no_such_person"),
+ new SetPolicy("no_such_policy", 0.5), new ChooseEventOption("no_such_event", "x"), new MapAction("airport", 0, 0),
+ });
+ Assert.Equal(5, r.Rejected.Count);
+ foreach (var x in r.Rejected)
+ Assert.DoesNotMatch(@"'[^']*'", x.Reason);
+ Assert.Contains(r.Rejected, x => x.Reason == "That office does not exist in this game");
+ Assert.Contains(r.Rejected, x => x.Reason == "That person is not in this game");
+ }
+
+ // ---- M5: one call-up cost ----
+
+ [Fact]
+ public void TheCallUpCostComesFromOneRule()
+ {
+ var s = Simulation.NewGame(Real, 1, Mode.Historical);
+ Assert.Equal(Real.Rules.MobilizationCostPerYear * 0.35, EconomySystem.MobilizationCost(Real, 0.35), 12);
+ s.Mobilization = 0.35;
+ Assert.Equal(EconomySystem.MobilizationCost(Real, 0.35, 0.25), EconomySystem.Flows(Real, s, 0.25).Mobilization, 12);
+ }
+}
diff --git a/sim/Statecraft.Sim.Tests/MapActionTests.cs b/sim/Statecraft.Sim.Tests/MapActionTests.cs
index f3fe8c202..8462c58f4 100644
--- a/sim/Statecraft.Sim.Tests/MapActionTests.cs
+++ b/sim/Statecraft.Sim.Tests/MapActionTests.cs
@@ -32,7 +32,7 @@ public class MapActionTests
Assert.Equal(housing + 0.05, s.Indicators["housing"], 9);
Assert.Equal(morale - 0.02, s.Indicators["morale"], 9);
Assert.Equal("transit_camp", MapActions.At(s, 2, 0)!.Action);
- Assert.Contains(why, w => w.System == "map" && w.Message == "A transit camp at (2, 0): cost IL 2.0m, Housing +5.0%, Morale -2.0%");
+ Assert.Contains(why, w => w.System == "map" && w.Message == "Built a transit camp: cost IL 2.0m, Housing +5.0%, Morale -2.0%");
}
[Fact]
@@ -59,9 +59,9 @@ public class MapActionTests
[Theory]
[InlineData("airport", 2, 0, "There is no such map action")]
- [InlineData("transit_camp", 0, 0, "There is no land hex at (0, 0)")]
- [InlineData("transit_camp", 7, 7, "There is no land hex at (7, 7)")]
- [InlineData("transit_camp", 4, 0, "(4, 0) is more than 1 hex from a settlement")]
+ [InlineData("transit_camp", 0, 0, "This hex is not land")]
+ [InlineData("transit_camp", 7, 7, "This hex is not land")]
+ [InlineData("transit_camp", 4, 0, "This hex is more than 1 hex from a settlement")]
public void IllegalPlacementsAreRejectedWithAReason(string action, int q, int r, string reason)
{
var s = Ready();
@@ -113,9 +113,9 @@ public class MapActionTests
var s = Ready();
MapActions.Apply(C, s, "housing", 2, 0, new List<Cause>());
MapActions.Apply(C, s, "housing", 1, 1, new List<Cause>());
- Assert.Equal("There is no land hex at (7, 7)", MapActions.Check(C, s, "housing", 7, 7));
- Assert.Equal("(4, 0) is more than 1 hex from a settlement", MapActions.Check(C, s, "housing", 4, 0));
- Assert.Equal("(2, 0) already has a housing project", MapActions.Check(C, s, "housing", 2, 0));
+ Assert.Equal("This hex is not land", MapActions.Check(C, s, "housing", 7, 7));
+ Assert.Equal("This hex is more than 1 hex from a settlement", MapActions.Check(C, s, "housing", 4, 0));
+ Assert.Equal("This hex already has a housing project", MapActions.Check(C, s, "housing", 2, 0));
Assert.Equal("There is no such map action", MapActions.Check(C, s, "airport", 0, 1));
Assert.Equal("No more than 2 map actions in one turn", MapActions.Check(C, s, "housing", 0, 1));
}
@@ -140,7 +140,7 @@ public class MapActionTests
var c = ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["map/hexes.json"] = hexes }));
var s = Simulation.NewGame(c, 42, Mode.Historical);
s.Date = new DateTime(1948, 6, 1);
- Assert.Equal("There is no land hex at (2, 0)", MapActions.Check(c, s, "housing", 2, 0));
+ Assert.Equal("This hex is not land", MapActions.Check(c, s, "housing", 2, 0));
}
[Fact]
@@ -175,8 +175,8 @@ public class MapActionTests
{
var s = Ready();
MapActions.Apply(C, s, "housing", 2, 0, new List<Cause>());
- Assert.Equal("(2, 0) already has a housing project", MapActions.Check(C, s, "transit_camp", 2, 0));
- Assert.Equal("(2, 0) already has a housing project", MapActions.Check(C, s, "housing", 2, 0));
+ Assert.Equal("This hex already has a housing project", MapActions.Check(C, s, "transit_camp", 2, 0));
+ Assert.Equal("This hex already has a housing project", MapActions.Check(C, s, "housing", 2, 0));
}
[Fact]
@@ -186,7 +186,7 @@ public class MapActionTests
s0.Date = new DateTime(1948, 6, 1);
// At war (rung 5) each command costs 2 of the 3 attention: the refused first order is refunded, so the second fits.
var r = Simulation.Step(C, s0, new Command[] { new MapAction("housing", 4, 0), new MapAction("housing", 2, 0) });
- Assert.Equal("(4, 0) is more than 1 hex from a settlement", r.Rejected.Single().Reason);
+ Assert.Equal("This hex is more than 1 hex from a settlement", r.Rejected.Single().Reason);
Assert.Equal("housing", MapActions.At(r.State, 2, 0)!.Action);
Assert.Empty(s0.Placements); // Step never mutates its input
Assert.NotEqual(Simulation.Step(C, s0, new Command[0]).State.Hash(), r.State.Hash());
diff --git a/sim/Statecraft.Sim.Tests/PlayerTextTests.cs b/sim/Statecraft.Sim.Tests/PlayerTextTests.cs
index fb1a2c348..c1ea5486b 100644
--- a/sim/Statecraft.Sim.Tests/PlayerTextTests.cs
+++ b/sim/Statecraft.Sim.Tests/PlayerTextTests.cs
@@ -246,7 +246,7 @@ public class PlayerTextTests
[Theory]
[InlineData("chosen: Impose rationing")]
- [InlineData("A housing project at (3, 4): cost IL 1.5m, Housing +3.0%, Morale +1.0%")]
+ [InlineData("Built a housing project: cost IL 1.5m, Housing +3.0%, Morale +1.0%")]
[InlineData("Morale -10.9% (Rationing wears on morale, Homes lift morale, Safety lifts morale)")]
[InlineData("reserve call-up raised to 80%, the minimum for security level 5")]
public void TheGuardLeavesPlainEnglishAlone(string message) => Assert.Empty(Leaks(Real, new[] { message }));
@@ -264,7 +264,7 @@ public class PlayerTextTests
// Every number in the line must carry the unit (fix round 2, N3): strip the unit tokens; no digit may remain.
if (money.Contains(w.Target) && Regex.IsMatch(Regex.Replace(w.Message, @"[+-]?(IL |\$)\d+\.\dm", ""), @"\d"))
bad.Add("money without a unit: " + w.Message);
- if (w.System == "map") // "A housing project at (q, r): cost IL 6.0m, Housing +3.0%, ...": coordinates aside, all units
+ if (w.System == "map") // "Built a housing project: cost IL 6.0m, Housing +3.0%, ...": every number with its unit
{
if (Regex.IsMatch(Regex.Replace(Regex.Replace(w.Message, @"\(-?\d+, -?\d+\)", ""), @"[+-]?(IL |\$)\d+\.\dm|[+-]?\d+(\.\d)?%", ""), @"\d"))
bad.Add("map line number without a unit: " + w.Message);
@@ -339,8 +339,8 @@ public class PlayerTextTests
var hex = c.Hexes.First(h => MapActions.Check(c, s, MapActions.TransitCamp, h.Q, h.R) == null);
var why = new List<Cause>();
Assert.Null(MapActions.Apply(c, s, MapActions.TransitCamp, hex.Q, hex.R, why));
- Assert.Contains(why, w => w.System == "map" && w.Message.StartsWith($"A ma'abara at ({hex.Q}, {hex.R})", StringComparison.Ordinal));
- Assert.Equal($"({hex.Q}, {hex.R}) already has a ma'abara", MapActions.Check(c, s, MapActions.TransitCamp, hex.Q, hex.R));
+ Assert.Contains(why, w => w.System == "map" && w.Message.StartsWith("Built a ma'abara: ", StringComparison.Ordinal));
+ Assert.Equal("This hex already has a ma'abara", MapActions.Check(c, s, MapActions.TransitCamp, hex.Q, hex.R));
Assert.Throws<InvalidOperationException>(() => PlayerText.MapAction(c, "factory"));
}
diff --git a/sim/Statecraft.Sim.Tests/SaveGameTests.cs b/sim/Statecraft.Sim.Tests/SaveGameTests.cs
index b49345da9..299973626 100644
--- a/sim/Statecraft.Sim.Tests/SaveGameTests.cs
+++ b/sim/Statecraft.Sim.Tests/SaveGameTests.cs
@@ -406,13 +406,13 @@ public class SaveGameTests
}
[Fact]
- public void TheFirstUnknownOfficeInOrdinalOrderIsNamedInPlayAndInReplay()
+ public void AnUnknownOfficeIsRefusedAlikeInPlayAndInReplay()
{
var c = Fixture1();
var g = GameSession.New(c, 1, Mode.Historical);
g.Step(new Command[] { new AllocateBudget(new Dictionary<string, double> { ["zzz"] = 0.5, ["aaa"] = 0.5 }) });
var live = g.Last!.Rejected.Single().Reason;
- Assert.Equal("Unknown office 'aaa'", live);
+ Assert.Equal("The budget names a ministry that does not exist in this game", live); // no id in player text (final review M4)
Assert.Equal(live, GameSession.Load(c, g.Save.Write(), out _).Last!.Rejected.Single().Reason);
}
}
diff --git a/sim/Statecraft.Sim.Tests/SimTests.cs b/sim/Statecraft.Sim.Tests/SimTests.cs
index 79bdfa538..163fa5479 100644
--- a/sim/Statecraft.Sim.Tests/SimTests.cs
+++ b/sim/Statecraft.Sim.Tests/SimTests.cs
@@ -47,7 +47,7 @@ public class SimTests
{
var s0 = Simulation.NewGame(C, 42, Mode.Historical);
var r = Simulation.Step(C, s0, new Command[] { new SetPolicy("curfew", 1), new SetMobilization(2) });
- Assert.Equal(new[] { "Unknown policy 'curfew'", "Mobilization must be between 0 and 1" }, r.Rejected.Select(x => x.Reason));
+ Assert.Equal(new[] { "That policy does not exist in this game", "Mobilization must be between 0 and 1" }, r.Rejected.Select(x => x.Reason));
}
[Fact]
@@ -172,7 +172,7 @@ options:
{
var s0 = Simulation.NewGame(C, 42, Mode.Historical);
var r = Simulation.Step(C, s0, new Command[] { new AllocateBudget(new Dictionary<string, double> { ["defense_minister"] = 1.0 }) });
- Assert.Equal("Budget shares must cover exactly: finance_minister", r.Rejected.Single().Reason);
+ Assert.Equal("The budget must give a share to every ministry, and only to them", r.Rejected.Single().Reason);
Assert.Equal(1.0, r.State.Budget["finance_minister"]);
}
@@ -231,7 +231,7 @@ options:
var s0 = Simulation.NewGame(C, 42, Mode.Historical);
s0.Rung = 1; s0.Attention = 1;
var r = Simulation.Step(C, s0, new Command[] { new SetPolicy("no_such_policy", 0.5), new SetPolicy("rationing", 0.5) });
- Assert.Equal(new[] { "Unknown policy 'no_such_policy'" }, r.Rejected.Select(x => x.Reason));
+ Assert.Equal(new[] { "That policy does not exist in this game" }, r.Rejected.Select(x => x.Reason));
Assert.Equal(0.5, r.State.Policies["rationing"]);
Assert.Equal(s0.RngState, r.State.RngState);
}
diff --git a/sim/Statecraft.Sim/Cabinet.cs b/sim/Statecraft.Sim/Cabinet.cs
index ff2a5162f..8c2612906 100644
--- a/sim/Statecraft.Sim/Cabinet.cs
+++ b/sim/Statecraft.Sim/Cabinet.cs
@@ -69,13 +69,13 @@ namespace Statecraft.Sim
public static string? Check(Content c, GameState s, string officeId, string personId)
{
var office = c.Offices.FirstOrDefault(o => o.Id == officeId);
- if (office == null) return $"Unknown office '{officeId}'";
+ if (office == null) return "That office does not exist in this game";
if (office.Until.HasValue && s.Date >= office.Until.Value)
return $"The office of {office.Title} was abolished on {PlayerText.Date(office.Until.Value)}";
if (officeId == "prime_minister") return "You are the Prime Minister: that office is not yours to fill";
if (officeId == "president") return "The President is elected by the Knesset, not appointed";
var person = c.People.FirstOrDefault(p => p.Id == personId);
- if (person == null) return $"Unknown person '{personId}'";
+ if (person == null) return "That person is not in this game";
if (person.Died.HasValue && s.Date >= person.Died.Value)
return $"{person.Name} died on {PlayerText.Date(person.Died.Value)}";
if (Holder(c, s, "president")?.Id == personId) return $"{person.Name} is the President";
diff --git a/sim/Statecraft.Sim/EconomySystem.cs b/sim/Statecraft.Sim/EconomySystem.cs
index 56263535f..29edf837f 100644
--- a/sim/Statecraft.Sim/EconomySystem.cs
+++ b/sim/Statecraft.Sim/EconomySystem.cs
@@ -27,9 +27,13 @@ namespace Statecraft.Sim
{
var r = c.Rules; var pop = s.TotalPopulation;
return new TreasuryFlows(r.TaxPerCapitaPerYear * pop * yearFraction, r.SpendingPerCapitaPerYear * pop * yearFraction,
- r.MobilizationCostPerYear * s.Mobilization * yearFraction);
+ MobilizationCost(c, s.Mobilization, yearFraction));
}
+ /// <summary>The reserve call-up's cost (pay and lost work) for <paramref name="level"/> (0..1) over a share of a year:
+ /// the one rule Flows and the Defence screen both use (M3 final review M5).</summary>
+ public static double MobilizationCost(Content c, double level, double yearFraction = 1.0) => c.Rules.MobilizationCostPerYear * level * yearFraction;
+
public static void Apply(Content c, GameState s, double yearFraction, List<Cause> why)
{
var r = c.Rules; var pop = s.TotalPopulation;
@@ -70,10 +74,10 @@ namespace Statecraft.Sim
{
if (shares == null) return "Budget shares are required";
var unknown = shares.Keys.OrderBy(k => k, StringComparer.Ordinal).FirstOrDefault(k => c.Offices.All(o => o.Id != k)); // ordinal: play and replay name the same office
- if (unknown != null) return $"Unknown office '{unknown}'";
+ if (unknown != null) return "The budget names a ministry that does not exist in this game";
if (shares.Values.Any(v => double.IsNaN(v) || double.IsInfinity(v))) return "Budget shares must be finite numbers";
if (!new HashSet<string>(shares.Keys).SetEquals(c.Rules.BudgetStart.Keys))
- return "Budget shares must cover exactly: " + string.Join(", ", c.Rules.BudgetStart.Keys.OrderBy(k => k, StringComparer.Ordinal));
+ return "The budget must give a share to every ministry, and only to them";
// Summed in key order, not dictionary order, so play and replay agree to the bit whatever order the caller built the map in.
if (Math.Abs(shares.OrderBy(kv => kv.Key, StringComparer.Ordinal).Sum(kv => kv.Value) - 1.0) > 1e-6) return "Budget shares must sum to 1";
if (shares.Values.Any(v => v < 0)) return "Budget shares cannot be negative";
diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.cs
index 10d58ad1d..9ab23a428 100644
--- a/sim/Statecraft.Sim/EventSystem.cs
+++ b/sim/Statecraft.Sim/EventSystem.cs
@@ -46,9 +46,9 @@ namespace Statecraft.Sim
/// <summary>Returns null on success, or the reason the choice was rejected.</summary>
public static string? Choose(Content c, GameState s, string eventId, string optionId, List<Cause> why)
{
- if (!s.PendingEvents.Contains(eventId)) return $"Event '{eventId}' is not waiting for a decision";
+ if (!s.PendingEvents.Contains(eventId)) return "That event is not waiting for a decision";
var option = Get(c, eventId).Options.FirstOrDefault(o => o.Id == optionId);
- if (option == null) return $"Event '{eventId}' has no option '{optionId}'";
+ if (option == null) return "That event has no such option";
Resolve(c, s, eventId, option, "chosen", why);
return null;
}
diff --git a/sim/Statecraft.Sim/MapActions.cs b/sim/Statecraft.Sim/MapActions.cs
index 97b3a4fd8..91712acc8 100644
--- a/sim/Statecraft.Sim/MapActions.cs
+++ b/sim/Statecraft.Sim/MapActions.cs
@@ -49,13 +49,13 @@ namespace Statecraft.Sim
if (action == TransitCamp && !(s.Policies.TryGetValue(MaabarotPolicy, out var m) && m >= 0.5))
return "Transit camps need the ma'abarot policy";
var hex = c.HexAt(q, r);
- if (hex == null || !hex.Land) return FormattableString.Invariant($"There is no land hex at ({q}, {r})");
+ if (hex == null || !hex.Land) return "This hex is not land";
var max = c.Rules.MapActionMaxDistance;
if (!c.SettlementHexes.Any(sh => Distance(q, r, sh.Q, sh.R) <= max))
- return FormattableString.Invariant($"({q}, {r}) is more than {max} {(max == 1 ? "hex" : "hexes")} from a settlement");
+ return FormattableString.Invariant($"This hex is more than {max} {(max == 1 ? "hex" : "hexes")} from a settlement");
var here = At(s, q, r);
if (here != null && !(action == Housing && here.Action == TransitCamp))
- return FormattableString.Invariant($"({q}, {r}) already has {PlayerText.MapAction(c, here.Action)}");
+ return $"This hex already has {PlayerText.MapAction(c, here.Action)}";
// The cap comes last so a player who is over it still sees the specific reason an order is illegal. It counts
// accepted actions (not surviving placements): housing on a camp removes the camp but still used an action.
if (ActionsThisTurn(s) >= c.Rules.MapActionsPerTurn)
@@ -83,7 +83,7 @@ namespace Statecraft.Sim
var housing = rule.Housing == 0 ? 0 : EffectsSystem.Shift(c, s, "housing", rule.Housing);
var morale = rule.Morale == 0 ? 0 : EffectsSystem.Shift(c, s, "morale", rule.Morale);
why.Add(new Cause("map", action, 1, FormattableString.Invariant(
- $"{PlayerText.Capitalised(PlayerText.MapAction(c, action))} at ({q}, {r}): cost {PlayerText.Money(c, "treasury", rule.Cost)}, {PlayerText.Change(c, "housing", housing)}, {PlayerText.Change(c, "morale", morale)}")));
+ $"Built {PlayerText.MapAction(c, action)}: cost {PlayerText.Money(c, "treasury", rule.Cost)}, {PlayerText.Change(c, "housing", housing)}, {PlayerText.Change(c, "morale", morale)}")));
return null;
}
}
diff --git a/sim/Statecraft.Sim/ReleaseGate.cs b/sim/Statecraft.Sim/ReleaseGate.cs
new file mode 100644
index 000000000..df8e2f405
--- /dev/null
+++ b/sim/Statecraft.Sim/ReleaseGate.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Statecraft.Sim
+{
+ /// <summary>The release gate for sensitive content (spec 5.5; M3 final review I4). An event with a sensitive tag
+ /// (holocaust, terror, massacre, war-casualties) needs the owner's sensitivity review, recorded by moving its YAML
+ /// <c>status</c> to <c>sensitivity-reviewed</c>, before any build is shared. Build.Web -shareable refuses to build while
+ /// <see cref="SensitiveUnreviewed"/> is not empty. Setting that status is an OWNER step (docs/m3-release.md).</summary>
+ public static class ReleaseGate
+ {
+ public const string ReviewedStatus = "sensitivity-reviewed";
+
+ /// <summary>The ids of every event carrying a sensitive tag, in id order.</summary>
+ public static IReadOnlyList<string> SensitiveEvents(Content c) =>
+ c.Events.Where(e => e.Tags.Any(EventRules.SensitiveTags.Contains)).Select(e => e.Id).OrderBy(x => x, StringComparer.Ordinal).ToList();
+
+ /// <summary>The sensitive events whose status is not yet sensitivity-reviewed, in id order.</summary>
+ public static IReadOnlyList<string> SensitiveUnreviewed(Content c) =>
+ c.Events.Where(e => e.Tags.Any(EventRules.SensitiveTags.Contains) && e.Status != ReviewedStatus)
+ .Select(e => e.Id).OrderBy(x => x, StringComparer.Ordinal).ToList();
+ }
+}
diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.cs
index 07b571158..17c9ced7a 100644
--- a/sim/Statecraft.Sim/Simulation.cs
+++ b/sim/Statecraft.Sim/Simulation.cs
@@ -45,7 +45,7 @@ namespace Statecraft.Sim
var priceRung = s.Rung; // every command this turn is priced at the rung the turn started at
foreach (var cmd in commands)
{
- if (!AttentionSystem.IsCommandKind(cmd.Kind)) { rejected.Add(new Rejection(cmd, $"Unknown command '{cmd.Kind}'")); continue; }
+ if (!AttentionSystem.IsCommandKind(cmd.Kind)) { rejected.Add(new Rejection(cmd, "That order is not known")); continue; }
var before = s.Attention;
var error = AttentionSystem.TrySpend(c, s, cmd.Kind, priceRung) ?? Execute(c, s, cmd, why);
if (error != null) { s.Attention = before; rejected.Add(new Rejection(cmd, error)); }
@@ -78,7 +78,7 @@ namespace Statecraft.Sim
switch (cmd)
{
case SetPolicy p:
- if (c.Policies.All(x => x.Id != p.Policy)) return $"Unknown policy '{p.Policy}'";
+ if (c.Policies.All(x => x.Id != p.Policy)) return "That policy does not exist in this game";
if (!(p.Level >= 0 && p.Level <= 1)) return "Policy level must be between 0 and 1";
var legislature = Offices.Legislature(c, s.Date);
if (legislature == null) return "No legislature is sitting";
@@ -116,7 +116,7 @@ namespace Statecraft.Sim
SecuritySystem.SetRung(c, s, (int)Math.Max(1L, Math.Min(5L, (long)s.Rung + o.Delta)), why);
return null;
default:
- return $"Unknown command '{cmd.Kind}'";
+ return "That order is not known";
}
}