A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: an event may not span an era boundary (refs #65) (#342)
agamrafaeli-instinctff8c0e2513fe
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 20d6cbce1..6a7b794f5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,9 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB## [Unreleased]### Added+- The loader refuses an event whose window runs past the end of its era (chapters spec 9: an event may not span a boundary;+ split it). A `to` on the boundary is fine (it is exclusive); an open window (no `to`) is allowed only in the last era.+ No current event is affected (refs #65).- The loader refuses a `from`/`to` window on the indicators the code reads by name (`morale`, `food_supply`, `housing`,`security`, `intl_standing`), a follow-up from the review of #313 (refs #57).- Turn lengths per security rung are data: `turn_lengths` in `rules.yaml` or an era override, read in the era the turndiff --git a/sim/Statecraft.Sim.Tests/EraTests.cs b/sim/Statecraft.Sim.Tests/EraTests.csindex 5311ac8c2..402fcf704 100644--- a/sim/Statecraft.Sim.Tests/EraTests.cs+++ b/sim/Statecraft.Sim.Tests/EraTests.cs@@ -264,3 +264,28 @@ public class EraTestsAssert.True(weeklyTurns > 0 && before > 0);}}++public class EventSpanTests+{+ const string Event = "id: probe\ntitle: Probe\ntext: A probe.\nfrom: {1}\n{0}options:\n - id: a\n text: Do a\n effects:\n - {{ target: morale, delta: 0.01 }}\nsources:\n - {{ url: \"https://example.com\", checked: 2026-10-13 }}\nstatus: fact-checked\n";++ static Content Load(string? to, string from = "1948-06-01") => ContentLoader.Load(Fixture.Write(new Dictionary<string, string>+ {+ ["eras.yaml"] = "eras:\n - { id: founding, name: The Founding, from: 1948-05-15, to: 1948-12-01 }\n - { id: next, name: Next, from: 1948-12-01, to: 1949-06-01 }\n",+ }, new Dictionary<string, string> { ["probe.yaml"] = string.Format(Event, to == null ? "" : "to: " + to + "\n", from) }));++ [Fact] public void AnEventInsideOneEraLoads() => Assert.NotNull(Load("1948-12-01")); // to is exclusive: it may end on the boundary++ [Fact]+ public void AnEventThatRunsPastTheEndOfItsEraIsRefused()+ {+ var e = Assert.Throws<ContentException>(() => Load("1948-12-02"));+ Assert.Contains("events[probe].to", e.Message);+ Assert.Contains("may not span a boundary", e.Message);+ }++ // EventSystem keeps an event with no `to` eligible to the end of the game, so an open window spans every later era.+ [Fact] public void AnOpenWindowBeforeTheLastEraIsRefused() => Assert.Contains("may not span a boundary", Assert.Throws<ContentException>(() => Load(null)).Message);++ [Fact] public void AnOpenWindowInTheLastEraLoads() => Assert.NotNull(Load(null, "1949-01-01"));+}diff --git a/sim/Statecraft.Sim/EventRules.cs b/sim/Statecraft.Sim/EventRules.csindex 657cd4f06..d8be79589 100644--- a/sim/Statecraft.Sim/EventRules.cs+++ b/sim/Statecraft.Sim/EventRules.cs@@ -22,6 +22,11 @@ namespace Statecraft.Simif (e.Anchor != "hard" && e.Anchor != "soft") throw new ContentException(e.File, F("anchor"), $"unknown anchor '{e.Anchor}' (must be hard or soft)");ContentLoader.Status(e.File, F("status"), e.Status);ContentLoader.Period(e.File, $"events[{e.Id}]", e.From, e.To);+ // Chapters design 9: an event may not span a boundary; it is split. An open window (no `to`) is allowed only in+ // the last era, since EventSystem keeps an open event eligible to the end of the game.+ var era = c.Eras.FirstOrDefault(x => x.From <= e.From && e.From < x.To);+ if (era != null && (e.To.HasValue ? e.To.Value > era.To : era.To < c.Eras.Max(x => x.To)))+ throw new ContentException(e.File, F("to"), FormattableString.Invariant($"the window runs past the end of era '{era.Id}' ({era.To:yyyy-MM-dd}); an event may not span a boundary, split it"));if (e.Office != "" && !offices.Contains(e.Office)) throw new ContentException(e.File, F("office"), $"unknown office '{e.Office}'");if (c.Offices.Any(o => o.Id == e.Office && o.HistoricalOnly))throw new ContentException(e.File, F("office"), "historical-only titles cannot be delegated events");