A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim, content: reject cyclic requires; document the event keys; Jerusalem cease-fire text
eyalgolan5d64f0f41afb
diff --git a/content/events/jerusalem_ceasefire.yaml b/content/events/jerusalem_ceasefire.yamlindex 945c9606e..eb2dddbd6 100644--- a/content/events/jerusalem_ceasefire.yaml+++ b/content/events/jerusalem_ceasefire.yaml@@ -1,14 +1,15 @@id: jerusalem_ceasefiretitle: Cease-fire in Jerusalem-text: 'In talks that began on 28 November, Dayan and Abdullah el-Tell have agreed a full cease-fire for the Jerusalem area, to be signed at Government House with UN observers present. {prime_minister} must decide whether Israel signs.'+text: 'Talks began on 28 November between Dayan and Abdullah el-Tell on a full cease-fire for the Jerusalem area, with UN observers present. {prime_minister} must decide whether Israel signs it at Government House.'anchor: hardtags: [security]office: prime_minister# Signed on 30 November 1948 at Government House, UN observers present (FRUS 1948 v.V pt 2, editorial note d800 [V]);# talks began on 28 November (UN press release [S]). On 23 December el-Tell apparently received new orders and avoided# further talks (FRUS d844 [S]). Partial releases of prisoners followed [S]. Research notes facts-1948.md section 13b.-# Only a player who put Jerusalem under military government sees this card (with a demilitarised city there would be no-# IDF commander to sign).+# Only a player who put Jerusalem under military government sees this card. The gating is a design inference, not in the+# notes: with a demilitarised city there would be no IDF commander to sign. The card comes on 28 November, when the talks+# began; it states the talks, not their outcome (re-review N1).from: 1948-11-28to: 1948-12-01requires: { event: jerusalem_military_government, option: military_government }diff --git a/sim/Statecraft.Sim.Tests/EventRequiresTests.cs b/sim/Statecraft.Sim.Tests/EventRequiresTests.csindex a0c93608a..37dcaf877 100644--- a/sim/Statecraft.Sim.Tests/EventRequiresTests.cs+++ b/sim/Statecraft.Sim.Tests/EventRequiresTests.cs@@ -113,4 +113,38 @@ options:c.ChosenOptions["first"] = "stay";Assert.NotEqual(b.Hash(), c.Hash());}++ static string Requiring(string id, string other) => $@"+id: {id}+title: {id}+text: 'Waits.'+from: 1948-06-01+requires: {{ event: {other}, option: ok }}+options:+ - id: ok+ text: Fine+";++ /// <summary>Re-review N4: a cycle of requirements could never fire; the loader names every file in it.</summary>+ [Fact]+ public void ACycleOfRequirementsIsALoadErrorNamingItsFiles()+ {+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string>+ {+ ["first.yaml"] = First, ["a.yaml"] = Requiring("a", "b"), ["b.yaml"] = Requiring("b", "c"), ["c.yaml"] = Requiring("c", "a"),+ })));+ Assert.Equal("events/a.yaml", ex.File);+ Assert.Equal("events[a].requires", ex.Field);+ Assert.Contains("requirements form a cycle: events/a.yaml -> events/b.yaml -> events/c.yaml -> events/a.yaml", ex.Message);+ }++ [Fact]+ public void AChainWithoutACycleLoads()+ {+ var c = ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string>+ {+ ["first.yaml"] = First, ["follow.yaml"] = Follow, ["a.yaml"] = Requiring("a", "follow"), ["b.yaml"] = Requiring("b", "a"),+ }));+ Assert.Equal(4, c.Events.Count);+ }}diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex 3632b3169..cb4078bfd 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -162,6 +162,19 @@ namespace Statecraft.Simc.Hexes = Read<MapFile>(readFile, HexesFile).Hexes;c.SettlementHexes = Read<SettlementHexesFile>(readFile, SettlementHexesFileName).Settlements;var settlementIds = ReadSettlementIds(readFile);+ // Event files (content/events/*.yaml), one GameEvent each. Keys, for content authors:+ // id, title, text text may name office holders only through {office_id} placeholders, which+ // must have a holder on every day of the window+ // anchor: hard | soft hard needs a historical option; in Historical mode it resolves to it+ // tags: [...] holocaust, terror, massacre, war-casualties are sensitive (no money reward)+ // office the minister the event is delegated to+ // from, to the window [from, to); it fires on the first turn that overlaps it+ // conditions: [{ indicator, min, max }] indicator bounds that must hold when it fires+ // requires: { event, option } fires only once that other event was resolved (chosen or delegated)+ // with that option; both ids must exist, an event cannot require itself and+ // requirements cannot form a cycle (EventRules)+ // options: [{ id, text, historical, recommended, effects: [{ target, delta }], set_rung, set_policy }]+ // sources: [{ url, checked }], statusforeach (var rel in eventFiles.OrderBy(p => p, StringComparer.Ordinal)){var e = Read<GameEvent>(readFile, rel);diff --git a/sim/Statecraft.Sim/EventRules.cs b/sim/Statecraft.Sim/EventRules.csindex b9da60f11..6be967a8c 100644--- a/sim/Statecraft.Sim/EventRules.cs+++ b/sim/Statecraft.Sim/EventRules.cs@@ -67,6 +67,29 @@ namespace Statecraft.Sim}}}+ CheckRequirementCycles(c);+ }++ /// <summary>Re-review N4: a cycle of `requires` (A needs B, B needs A, ...) could never fire. Called after every+ /// requirement's ids are known to exist; the error names the files around the cycle, starting from the first event+ /// (in load order) that lies on it.</summary>+ static void CheckRequirementCycles(Content c)+ {+ var byId = c.Events.ToDictionary(e => e.Id);+ foreach (var start in c.Events)+ {+ var path = new List<GameEvent> { start };+ var seen = new HashSet<string> { start.Id };+ for (var e = start; e.Requires != null; )+ {+ e = byId[e.Requires.Event];+ path.Add(e);+ if (e.Id == start.Id)+ throw new ContentException(start.File, $"events[{start.Id}].requires",+ "requirements form a cycle: " + string.Join(" -> ", path.Select(x => x.File)));+ if (!seen.Add(e.Id)) break; // a cycle that does not pass through start; reported from its own member+ }+ }}static void CheckPlaceholders(Content c, GameEvent e, string field, string text, HashSet<string> offices)diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.csindex 739b9d617..aca80f06c 100644--- a/sim/Statecraft.Sim/EventSystem.cs+++ b/sim/Statecraft.Sim/EventSystem.cs@@ -23,7 +23,7 @@ namespace Statecraft.Simvar start = turnStart ?? s.Date;var eligible = c.Events.Where(e => !s.FiredEvents.Contains(e.Id) && e.From <= s.Date && (e.To == null || start < e.To.Value))- .Where(e => e.Requires == null || (s.ChosenOptions.TryGetValue(e.Requires.Event, out var chosen) && chosen == e.Requires.Option))+ .Where(e => e.Requires == null || (s.ChosenOptions.TryGetValue(e.Requires.Event, out var picked) && picked == e.Requires.Option)).Where(e => e.Conditions.All(k => (!k.Min.HasValue || s.Indicators[k.Indicator] >= k.Min.Value)&& (!k.Max.HasValue || s.Indicators[k.Indicator] <= k.Max.Value))).OrderBy(e => e.From).ThenBy(e => e.Id, StringComparer.Ordinal)