A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: the alternative record on options, who proposed a road not taken (R-ALT-003; refs #947) (#966)
Eyal Golan77e3833a3e08
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3541cc0a5..78d3c4c7b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,8 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIBadds free units at the military camp or a named city, `city_effects` moves one field by whole units, bothapply after the numeric effects and show in the option's effect list, the loader refuses an unknown target, and asensitive event may carry no grant or gain (R-EFX-003 to R-EFX-006; refs #806). No event uses them yet.+- Events: an option that did not happen can record who put it forward, when and on what source, or that it is a design+ assumption (`alternative`, R-ALT-003; optional until #949; refs #947, #939).- Events: `requires` is a list whose entries must all hold, and an entry can say `diverged: true` (any option butthe historical one); the five events with a requirement move to the list form with the same meaning (R-ALT-001,R-ALT-002; refs #946, #939).diff --git a/content/schema/event.schema.json b/content/schema/event.schema.jsonindex 284b6d653..c09f86020 100644--- a/content/schema/event.schema.json+++ b/content/schema/event.schema.json@@ -8,6 +8,29 @@"definitions": {"date": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$", "description": "A day, YYYY-MM-DD." },"id": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$", "description": "Lowercase letters, digits and underscores, starting with a letter." },+ "alternative": {+ "type": "object",+ "additionalProperties": false,+ "required": ["basis"],+ "description": "Who put forward a non-historical option (R-ALT-003). proposed or debated: by (a body or office in words, never a person), date and sources; design: nobody is recorded proposing it, so no by and no date.",+ "properties": {+ "basis": { "enum": ["proposed", "debated", "design"] },+ "by": { "type": "string" },+ "date": { "$ref": "#/definitions/date" },+ "sources": {+ "type": "array",+ "items": {+ "type": "object",+ "additionalProperties": false,+ "required": ["url", "checked"],+ "properties": {+ "url": { "type": "string", "pattern": "^https://" },+ "checked": { "$ref": "#/definitions/date" }+ }+ }+ }+ }+ },"requirement": {"type": "object","additionalProperties": false,@@ -97,7 +120,8 @@"delta": { "type": "integer", "not": { "const": 0 } }}}- }+ },+ "alternative": { "$ref": "#/definitions/alternative" }}}},diff --git a/docs/WRITING_EVENTS.md b/docs/WRITING_EVENTS.mdindex 9ebbfdd83..53eb9b256 100644--- a/docs/WRITING_EVENTS.md+++ b/docs/WRITING_EVENTS.md@@ -145,10 +145,32 @@ Each option has:| `set_policy` | no | A map of policy id to a level from 0 to 1. || `grant_units` | no | GDD loop only. A list of `{ type, n, at }`: see "grant_units and city_effects". || `city_effects` | no | GDD loop only. A list of `{ city, field, delta }`: see "grant_units and city_effects". |+| `alternative` | no (required later, #949) | On an option that did not happen: who put it forward, on what record. See below. |An event needs at least one option. `historical` is a statement of fact and needs a source; `recommended` is a gamedesign choice and does not.+### alternative++An option that did not happen can say who put it forward, and on what record (R-ALT-003):++```yaml+ - id: road+ text: The road not taken+ alternative:+ basis: debated # proposed, debated or design+ by: the Provisional State Council+ date: 1948-06-20+ sources: [{ url: "https://example.org/minutes", checked: 2026-10-17 }]+```++- `proposed` or `debated`: `by` names the body or office in words, never a person and never a `{placeholder}`;+ `date` is the day it was put forward; `sources` (at least one, `https://`, with `checked`) support both.+- `design`: nobody is recorded proposing it. It is a design assumption (GDD "Events and consequences"), so it has no+ `by` and no `date`. Sources are optional.+- The historical option carries none. For now the record is optional; #949 makes it required on every option that did+ not happen, once the fact-check (#948) has checked each one.+### effects`target` is one of:@@ -265,6 +287,14 @@ Errors are printed as `file: field: message`. These are the messages you are mos| `needs an option or diverged: true` | A `requires` entry names neither an option nor `diverged: true`. || `not both` | A `requires` entry names an option and `diverged: true`. || `has no historical option, so it cannot diverge` | `diverged: true` on an event with no historical option. |+| `the historical option is the record, not an alternative` | An `alternative` on the option marked `historical: true`. |+| `must be proposed, debated or design` | `alternative.basis` is another word. |+| `names who put it forward` | A proposed or debated `alternative` with no `by`. |+| `words only, no placeholder` | `alternative.by` has a `{` or `}`. |+| `needs the date it was put forward` | A proposed or debated `alternative` with no `date`. |+| `a design alternative names nobody and no date` | A `design` alternative with a `by` or a `date`. |+| `needs at least one source` | A proposed or debated `alternative` with no `sources`. |+| `needs an https url and a checked date` | An `alternative` source without `https://` or without `checked`. || `is already required` | Two `requires` entries name the same event (they could never both hold, or one is redundant). |A full message looks like this (an effect target misspelled `securty`):diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex 6f5d7dfb8..280fc98e8 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -183,3 +183,5 @@ The alternate-timeline mechanism ([the plan](../superpowers/plans/2026-10-17-altR-ALT-001: An event's `requires` is a list, and the event is eligible only when every entry holds. An entry `{ event, option }` holds when that event was resolved (chosen or delegated) with that option. A list names each event at most once.R-ALT-002: An entry `{ event, diverged: true }` holds when that event was resolved with any option except its historical one. An event with no historical option cannot diverge, and the loader refuses `diverged` on it.++R-ALT-003: A non-historical option may carry `alternative: { basis, by, date, sources }`. `basis` is `proposed` or `debated` (a body or office, in words, is recorded putting it forward on that date; at least one https source with a checked date) or `design` (nobody is recorded proposing it: a design assumption, which names nobody and no date; sources optional). The historical option carries none.diff --git a/sim/Statecraft.Sim.Tests/AlternateTimelineTests.cs b/sim/Statecraft.Sim.Tests/AlternateTimelineTests.csnew file mode 100644index 000000000..dd9e39bd6--- /dev/null+++ b/sim/Statecraft.Sim.Tests/AlternateTimelineTests.cs@@ -0,0 +1,112 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>The alternate-timeline mechanism (docs/superpowers/plans/2026-10-17-alternate-timelines.md).</summary>+public class AlternateTimelineTests+{+ internal const string Parent = @"+id: parent+title: Parent+text: 'A real decision.'+from: 1948-06-01+to: 1948-06-11+options:+ - id: record+ text: What happened+ historical: true+ - id: road+ text: The road not taken+ alternative:+ basis: proposed+ by: the opposition benches+ date: 1948-06-05+ sources: [{ url: ""https://example.org/minutes"", checked: 2026-10-17 }]+";++ internal static Content Load(params (string file, string yaml)[] events) =>+ ContentLoader.Load(Fixture.Write(events: events.ToDictionary(x => x.file, x => x.yaml)));++ static OptionAlternative Road(Content c) => c.Events.Single().Options.Single(o => o.Id == "road").Alternative!;++ // R-ALT-003+ [Fact]+ public void TheAlternativeRecordIsReadFromYaml()+ {+ var a = Road(Load(("parent.yaml", Parent)));+ Assert.Equal("proposed", a.Basis);+ Assert.Equal("the opposition benches", a.By);+ Assert.Equal(new DateTime(1948, 6, 5), a.Date);+ Assert.Equal("https://example.org/minutes", Assert.Single(a.Sources).Url);+ Assert.Equal(new DateTime(2026, 10, 17), a.Sources[0].Checked);+ Assert.True(a.IsConsidered);+ Assert.Null(Load(("parent.yaml", Parent)).Events.Single().Options.Single(o => o.Id == "record").Alternative);+ }++ // R-ALT-003+ [Theory]+ [InlineData("basis: proposed", "basis: maybe", "alternative.basis", "must be proposed, debated or design")]+ [InlineData("by: the opposition benches", "by: ''", "alternative.by", "a proposed or debated alternative names who put it forward")]+ [InlineData("by: the opposition benches", "by: ' '", "alternative.by", "a proposed or debated alternative names who put it forward")]+ [InlineData("by: the opposition benches", "by: '{prime_minister}'", "alternative.by", "words only, no placeholder")]+ [InlineData(" date: 1948-06-05\n", "", "alternative.date", "needs the date it was put forward")]+ [InlineData("sources: [{ url: \"https://example.org/minutes\", checked: 2026-10-17 }]", "sources: []", "alternative.sources", "needs at least one source")]+ [InlineData("https://example.org/minutes", "http://example.org/minutes", "alternative.sources", "needs an https url and a checked date")]+ [InlineData(", checked: 2026-10-17 }]", " }]", "alternative.sources", "needs an https url and a checked date")]+ public void ABadAlternativeIsALoadError(string from, string to, string field, string message)+ {+ var ex = Assert.Throws<ContentException>(() => Load(("parent.yaml", Parent.Replace(from, to))));+ Assert.Equal("events/parent.yaml", ex.File);+ Assert.Equal("events[parent].options[road]." + field, ex.Field);+ Assert.Contains(message, ex.Message);+ }++ // R-ALT-003+ [Fact]+ public void ADebatedAlternativeLoadsLikeAProposedOne()+ {+ var a = Road(Load(("parent.yaml", Parent.Replace("basis: proposed", "basis: debated"))));+ Assert.Equal("debated", a.Basis);+ Assert.True(a.IsConsidered);+ }++ // R-ALT-003+ [Fact]+ public void ADesignAlternativeNamesNobody()+ {+ var design = Parent.Replace("basis: proposed", "basis: design");+ var ex = Assert.Throws<ContentException>(() => Load(("parent.yaml", design)));+ Assert.Equal("events[parent].options[road].alternative.by", ex.Field);+ Assert.Contains("a design alternative names nobody and no date", ex.Message);+ var dated = design.Replace(" by: the opposition benches\n", "");+ var ex2 = Assert.Throws<ContentException>(() => Load(("parent.yaml", dated)));+ Assert.Equal("events[parent].options[road].alternative.date", ex2.Field);+ Assert.Contains("a design alternative names nobody and no date", ex2.Message);+ var bare = design.Replace(" by: the opposition benches\n date: 1948-06-05\n", "");+ Assert.False(Road(Load(("parent.yaml", bare))).IsConsidered);+ var plain = Parent.Substring(0, Parent.IndexOf(" basis:", StringComparison.Ordinal)) + " basis: design\n";+ Assert.Empty(Road(Load(("parent.yaml", plain))).Sources); // sources are optional for a design alternative+ var badSource = plain + " sources: [{ url: \"http://example.org\", checked: 2026-10-17 }]\n";+ var ex3 = Assert.Throws<ContentException>(() => Load(("parent.yaml", badSource))); // but any it gives must be valid+ Assert.Equal("events[parent].options[road].alternative.sources", ex3.Field);+ }++ // R-ALT-003+ [Fact]+ public void TheHistoricalOptionHasNoAlternativeRecord()+ {+ var bad = Parent.Replace(" historical: true\n", " historical: true\n alternative: { basis: design }\n");+ var ex = Assert.Throws<ContentException>(() => Load(("parent.yaml", bad)));+ Assert.Equal("events[parent].options[record].alternative", ex.Field);+ Assert.Contains("the historical option is the record, not an alternative", ex.Message);+ }++ // R-ALT-003: optional at load until #949 requires it, so the content on main loads unchanged.+ [Fact]+ public void AnOptionWithoutARecordStillLoads()+ {+ var bare = Parent.Substring(0, Parent.IndexOf(" alternative:", StringComparison.Ordinal));+ Assert.Null(Load(("parent.yaml", bare)).Events.Single().Options.Single(o => o.Id == "road").Alternative);+ }+}diff --git a/sim/Statecraft.Sim.Tests/SchemaTests.cs b/sim/Statecraft.Sim.Tests/SchemaTests.csindex 04d02c047..b14e97208 100644--- a/sim/Statecraft.Sim.Tests/SchemaTests.cs+++ b/sim/Statecraft.Sim.Tests/SchemaTests.cs@@ -193,6 +193,7 @@ public class SchemaTestsyield return new object[] { "event.schema.json", "/properties/conditions/items", typeof(EventCondition) };yield return new object[] { "event.schema.json", "/definitions/requirement", typeof(EventRequirement) };yield return new object[] { "event.schema.json", "/properties/options/items", typeof(EventOption) };+ yield return new object[] { "event.schema.json", "/definitions/alternative", typeof(OptionAlternative) };yield return new object[] { "event.schema.json", "/properties/options/items/properties/effects/items", typeof(OptionEffect) };yield return new object[] { "event.schema.json", "/properties/sources/items", typeof(Source) };}diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex d3e46ae77..fd1f39f8e 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -716,6 +716,8 @@ namespace Statecraft.Simpublic List<UnitGrant> GrantUnits { get; set; } = new List<UnitGrant>();/// <summary>R-EFX-004: changes to a city's housing capacity or job slots, in list order (D-H2, Q-HFX-1).</summary>public List<CityEffect> CityEffects { get; set; } = new List<CityEffect>();+ /// <summary>Who put this non-historical option forward, and on what record (R-ALT-003). Null when absent.</summary>+ public OptionAlternative? Alternative { get; set; }}/// <summary>An option's grant of <see cref="N"/> units of a unit_types.yaml type of kind unit (R-EFX-003). They stand at@@ -736,6 +738,20 @@ namespace Statecraft.Simpublic int Delta { get; set; }}+ /// <summary>Who put forward a non-historical option, and on what record (R-ALT-003). `proposed` and `debated` name a+ /// body or office in words (never a person), the date and sources; `design` is the GDD's "design assumption": nobody is+ /// recorded proposing it, so it names nobody and no date.</summary>+ public sealed class OptionAlternative+ {+ public const string Proposed = "proposed", Debated = "debated", Design = "design";+ public string Basis { get; set; } = "";+ public string By { get; set; } = "";+ public DateTime? Date { get; set; }+ public List<Source> Sources { get; set; } = new List<Source>();+ /// <summary>True for an alternative contemporaries are recorded proposing or debating (the Ferguson test).</summary>+ [YamlIgnore] public bool IsConsidered => Basis == Proposed || Basis == Debated;+ }+public sealed class GameEvent{public string Id { get; set; } = "";diff --git a/sim/Statecraft.Sim/EventRules.cs b/sim/Statecraft.Sim/EventRules.csindex bb5a4b6a4..801e86e4a 100644--- a/sim/Statecraft.Sim/EventRules.cs+++ b/sim/Statecraft.Sim/EventRules.cs@@ -73,6 +73,7 @@ namespace Statecraft.Simif (!Offices.OfficeId.IsMatch(o.Id)) throw new ContentException(e.File, F($"options[{o.Id}].id"), ContentLoader.IdRule);if (!optionIds.Add(o.Id)) throw new ContentException(e.File, F($"options[{o.Id}].id"), "duplicate option id");CheckPlaceholders(c, e, F($"options[{o.Id}].text"), o.Text, offices);+ if (o.Alternative != null) CheckAlternative(e, o, F($"options[{o.Id}].alternative"));foreach (var kv in o.SetPolicy){if (c.Policies.All(p => p.Id != kv.Key)) throw new ContentException(e.File, F($"options[{o.Id}].set_policy.{kv.Key}"), "unknown policy");@@ -175,6 +176,30 @@ namespace Statecraft.Sim}}+ /// <summary>R-ALT-003: the shape of an option's `alternative` record.</summary>+ static void CheckAlternative(GameEvent e, EventOption o, string at)+ {+ var a = o.Alternative!;+ if (o.Historical) throw new ContentException(e.File, at, "the historical option is the record, not an alternative");+ if (a.Basis != OptionAlternative.Proposed && a.Basis != OptionAlternative.Debated && a.Basis != OptionAlternative.Design)+ throw new ContentException(e.File, at + ".basis", $"'{a.Basis}' must be proposed, debated or design");+ if (a.Basis == OptionAlternative.Design)+ {+ if (a.By != "" || a.Date.HasValue)+ throw new ContentException(e.File, at + (a.By != "" ? ".by" : ".date"), "a design alternative names nobody and no date");+ }+ else+ {+ if (a.By.Trim() == "") throw new ContentException(e.File, at + ".by", "a proposed or debated alternative names who put it forward");+ if (a.By.IndexOfAny(new[] { '{', '}' }) >= 0) throw new ContentException(e.File, at + ".by", "words only, no placeholder: name the body or office");+ if (!a.Date.HasValue) throw new ContentException(e.File, at + ".date", "needs the date it was put forward");+ if (a.Sources.Count == 0) throw new ContentException(e.File, at + ".sources", "needs at least one source");+ }+ foreach (var src in a.Sources)+ if (!src.Url.StartsWith("https://", StringComparison.Ordinal) || src.Checked == default)+ throw new ContentException(e.File, at + ".sources", "needs an https url and a checked date");+ }+/// <summary>R-ALT-001 and R-ALT-002: a requirement names an existing other event and either one of its options or/// `diverged: true`, which needs that event to have a historical option.</summary>internal static void CheckRequirement(Content c, GameEvent e, string at, EventRequirement r)