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.

24.7 KB
Raw Blame
using System;
using System.Collections.Generic;
using System.Linq;
using Statecraft.Sim;

/// <summary>The event rules of the GDD loop (D-H1; GDD Phase 7 PR 1, #805). The owner took the plan's recommendations
/// for Q-EVT-1 to Q-EVT-4 on 17 October 2026 (#784): keep windows, hard anchors, the cap of 3 soft events a turn and
/// delegation, add no delayed effects, and show every effect of every option. These tests pin those rules on the real
/// monthly content (the mvp-end run) and on small fixtures. The armistice's place ahead of other soft events
/// (TheCapNeverDelaysAnArmistice) needs `front_quiet` and lands with Phase 5 PR 13 (#752).</summary>
public class EventRulesGddTests
{
    static readonly Content C = ContentLoader.Load(RealContentTests.ContentRoot());

    /// <summary>Every state of the mvp-end run (GoldenRun.Orders, seed 1948, Historical mode), the new game first.</summary>
    static readonly List<GameState> Run = Play();

    static List<GameState> Play()
    {
        var s = Simulation.NewGame(C, GoldenRun.Seed, Mode.Historical);
        var run = new List<GameState> { s };
        while (s.GameOver == null && run.Count < 1000) { s = Simulation.Step(C, s, GoldenRun.Orders(C, s)).State; run.Add(s); }
        return run;
    }

    static GameEvent Event(string id) => C.Events.First(e => e.Id == id);

    /// <summary>The events that fired on the turn that ended in Run[i] (for i = 0, those raised by the new game).</summary>
    static List<GameEvent> FiredOn(int i) =>
        Run[i].FiredEvents.Where(id => i == 0 || !Run[i - 1].FiredEvents.Contains(id)).Select(Event).ToList();

    // R-EVT-001: every hard anchor fires on the first turn its window overlaps, when nothing else (requires, conditions,
    // an objective) holds it back.
    [Fact]
    public void HardAnchorsAlwaysFire()
    {
        Assert.Equal(GameOverCodes.MvpEnded, Run[Run.Count - 1].GameOver);
        var plain = C.Events.Where(e => e.Anchor == "hard" && e.Requires.Count == 0 && e.Conditions.Count == 0 && e.Objective == "").ToList();
        Assert.NotEmpty(plain);
        foreach (var e in plain)
        {
            // The first state whose turn overlaps the window: [previous date, date) meets [From, To), or the new game is in it.
            var first = Enumerable.Range(0, Run.Count).First(i => e.From <= Run[i].Date && (e.To == null || (i == 0 ? Run[0].Date : Run[i - 1].Date) < e.To.Value));
            Assert.True(FiredOn(first).Contains(e), $"{e.Id} did not fire on {Run[first].Date:yyyy-MM-dd}, the first turn its window overlaps");
        }
    }

    // R-EVT-001: at most MaxSoftEventsPerTurn (3) soft events fire on any turn of the mvp-end run.
    [Fact]
    public void AtMostThreeSoftEventsATurn()
    {
        Assert.Equal(3, EventSystem.MaxSoftEventsPerTurn);
        for (int i = 0; i < Run.Count; i++)
        {
            // R-OBJ-003, R-EVT-007: objective and Deport cards take no slot. R-WAR-008: an armistice before its date is soft.
            bool Slotless(GameEvent e) => e.Objective != "" || e.Deported != "";
            bool Hard(GameEvent e) => e.Anchor == "hard" && !(e.FrontQuiet != "" && Run[i].Date < e.From);
            var soft = FiredOn(i).Where(e => !Slotless(e) && !Hard(e)).Select(e => e.Id).ToList();
            var hard = FiredOn(i).Count(e => !Slotless(e) && Hard(e));
            // the soft events take only the slots the hard anchors leave
            Assert.True(soft.Count <= Math.Max(0, EventSystem.MaxSoftEventsPerTurn - hard), $"{Run[i].Date:yyyy-MM-dd}: {hard} hard, soft {string.Join(", ", soft)}");
        }
    }

    static string Soft(string id, string from, string? to = null) =>
        $"id: {id}\ntitle: '{id}'\ntext: Something happens.\nfrom: {from}\n" +
        (to == null ? "" : $"to: {to}\n") +
        "options:\n  - id: ok\n    text: Accept\n    historical: true\nsources: [{ url: \"https://example.org/event\", checked: 2026-10-18 }]\n";

    // R-EVT-001 (#2605): red before the fix because d's finite window has closed by the second Trigger, so it is lost.
    // Trigger is the shared path: the same wait and once-only result holds for legacy, gdd-0.1 and gdd-0.3 identities.
    [Theory]
    [InlineData(SaveGame.LegacyRuleset)]
    [InlineData(SaveGame.GddRuleset)]
    [InlineData(SaveGame.Gdd03Ruleset)]
    public void CappedFiniteWindowEventWaitsAcrossEveryRuleset(string ruleset)
    {
        var c = ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string>
        {
            ["a.yaml"] = Soft("a", "1948-05-15", "1948-05-22"),
            ["b.yaml"] = Soft("b", "1948-05-15", "1948-05-22"),
            ["c.yaml"] = Soft("c", "1948-05-15", "1948-05-22"),
            ["d.yaml"] = Soft("d", "1948-05-15", "1948-05-22"),
        }));
        c.Eras[0].Systems.Loop = ruleset == SaveGame.LegacyRuleset ? EraSystems.Legacy : EraSystems.Gdd;
        c.Eras[0].Systems.Ruleset = ruleset;
        var s = new GameState(c) { Date = new DateTime(1948, 5, 22) };

        EventSystem.Trigger(c, s, new List<Cause>(), new DateTime(1948, 5, 15));
        Assert.Equal(new[] { "a", "b", "c" }, s.PendingEvents);
        Assert.Equal(new[] { "d" }, s.CappedEvents);

        s.PendingEvents.Clear();
        s.Date = new DateTime(1948, 5, 29);
        EventSystem.Trigger(c, s, new List<Cause>(), new DateTime(1948, 5, 22));
        Assert.Equal(new[] { "d" }, s.PendingEvents);
        Assert.Empty(s.CappedEvents);

        s.PendingEvents.Clear();
        s.Date = new DateTime(1948, 6, 5);
        EventSystem.Trigger(c, s, new List<Cause>(), new DateTime(1948, 5, 29));
        Assert.Empty(s.PendingEvents);
        Assert.Equal(4, s.FiredEvents.Count);   // the late event fired once
    }

    // R-EVT-001 (#2605): red before the fix because no capped-out state exists to survive replaying a save.
    [Fact]
    public void SaveRoundTripKeepsTheCappedEventSet()
    {
        var c = ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string>
        {
            ["a.yaml"] = Soft("a", "1948-05-15", "1948-05-16"),
            ["b.yaml"] = Soft("b", "1948-05-15", "1948-05-16"),
            ["c.yaml"] = Soft("c", "1948-05-15", "1948-05-16"),
            ["d.yaml"] = Soft("d", "1948-05-15", "1948-05-16"),
        }));
        var played = GameSession.New(c, 1, Mode.Historical);
        Assert.Equal(new[] { "d" }, played.State.CappedEvents);

        var loaded = GameSession.Load(c, played.Save.Write(), out var warnings);
        Assert.Empty(warnings);
        Assert.Equal(played.State.CappedEvents, loaded.State.CappedEvents);
        Assert.Equal(played.State.Hash(), loaded.State.Hash());
    }

    // R-EVT-001 (#2605): a waiting event is past only the date gate; its conditions still have to hold when it fires.
    [Fact]
    public void CappedEventRechecksItsConditions()
    {
        var conditioned = Soft("d", "1948-05-15", "1948-05-22").Replace("options:", "conditions: [{ indicator: food_supply, max: 0.5 }]\noptions:");
        var c = ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string>
        {
            ["a.yaml"] = Soft("a", "1948-05-15", "1948-05-22"),
            ["b.yaml"] = Soft("b", "1948-05-15", "1948-05-22"),
            ["c.yaml"] = Soft("c", "1948-05-15", "1948-05-22"),
            ["d.yaml"] = conditioned,
        }));
        var s = new GameState { Date = new DateTime(1948, 5, 22) };
        EffectsSystem.Init(c, s);
        EventSystem.Trigger(c, s, new List<Cause>(), new DateTime(1948, 5, 15));
        Assert.Equal(new[] { "d" }, s.CappedEvents);

        s.PendingEvents.Clear(); s.Date = new DateTime(1948, 5, 29); s.Indicators["food_supply"] = 0.9;
        EventSystem.Trigger(c, s, new List<Cause>(), new DateTime(1948, 5, 22));
        Assert.Empty(s.PendingEvents); Assert.Equal(new[] { "d" }, s.CappedEvents);

        s.Date = new DateTime(1948, 6, 5); s.Indicators["food_supply"] = 0.4;
        EventSystem.Trigger(c, s, new List<Cause>(), new DateTime(1948, 5, 29));
        Assert.Equal(new[] { "d" }, s.PendingEvents); Assert.Empty(s.CappedEvents);
    }

    // R-OBJ-003 (#2605): red before the fix because only the three ordinary soft events take the three slots and all
    // four same-turn objective cards are held back. Objective cards are ordered after the ordinary events as before.
    // R-OBJ-003: a hard-anchored objective card takes no soft slot and leaves the three slots to the ordinary soft events.
    [Fact]
    public void AHardObjectiveCardLeavesAllThreeSoftSlots()
    {
        var c = ContentLoader.Load(Fixture.Write());
        var s = Simulation.NewGame(c, 1, Mode.Historical);
        c.Objectives.Add(new Objective { Id = "objective_h", Card = "card_h" });
        c.Events.Add(new GameEvent { Id = "card_h", Title = "objective_h", Text = "Done.", From = s.Date, Objective = "objective_h", Anchor = "hard",
            Options = new List<EventOption> { new EventOption { Id = "ok", Text = "Continue", Historical = true } } });
        s.Objectives["objective_h"] = s.Date;
        for (int i = 0; i < 3; i++)
            c.Events.Add(new GameEvent { Id = "soft_" + i, Title = "soft", Text = "Soft.", From = s.Date,
                Options = new List<EventOption> { new EventOption { Id = "ok", Text = "Continue", Historical = true } } });

        EventSystem.Trigger(c, s, new List<Cause>());

        Assert.Equal(new[] { "soft_0", "soft_1", "soft_2", "card_h" }, s.PendingEvents.OrderBy(x => x == "card_h" ? 1 : 0).ToArray());
        Assert.Empty(s.CappedEvents);
    }
    [Fact]
    public void FourObjectiveCardsDoNotTakeTheThreeSoftSlots()
    {
        var c = ContentLoader.Load(Fixture.Write());
        var s = Simulation.NewGame(c, 1, Mode.Historical);
        for (int i = 0; i < 4; i++)
        {
            var id = "objective_" + i;
            c.Objectives.Add(new Objective { Id = id, Card = "card_" + i });
            c.Events.Add(new GameEvent { Id = "card_" + i, Title = id, Text = "Done.", From = s.Date, Objective = id,
                Options = new List<EventOption> { new EventOption { Id = "ok", Text = "Continue", Historical = true } } });
            s.Objectives[id] = s.Date;   // all four completed on this turn
        }
        for (int i = 0; i < 3; i++)
            c.Events.Add(new GameEvent { Id = "soft_" + i, Title = "soft", Text = "Soft.", From = s.Date,
                Options = new List<EventOption> { new EventOption { Id = "ok", Text = "Continue", Historical = true } } });

        EventSystem.Trigger(c, s, new List<Cause>());

        Assert.Equal(new[] { "soft_0", "soft_1", "soft_2", "card_0", "card_1", "card_2", "card_3" }, s.PendingEvents);
        Assert.Empty(s.CappedEvents);
    }

    // R-EVT-001: the soft events take only the slots the hard anchors leave. With 1 hard anchor and 3 soft events
    // eligible on one turn, exactly 2 soft events fire (the mvp-end run has no such turn, so a fixture pins it).
    [Fact]
    public void HardAnchorsUseUpSoftSlots()
    {
        var c = ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string>
        {
            ["a.yaml"] = Soft("a", "1948-05-15"),
            ["b.yaml"] = Soft("b", "1948-05-15"),
            ["c.yaml"] = Soft("c", "1948-05-15"),
            ["h.yaml"] = Soft("h", "1948-05-15").Replace("from:", "anchor: hard\nfrom:"),
        }));
        var s = Simulation.NewGame(c, 1, Mode.Historical);
        Assert.Equal(new[] { "a", "b", "h" }, s.PendingEvents);   // h takes one of the 3 slots; c waits
    }

    // R-EVT-002: the soft events take the free slots in order of From, then id; the one left over waits for the next turn.
    [Fact]
    public void SoftEventsTakeTheSlotsInOrderOfFromThenId()
    {
        var c = ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string>
        {
            ["a.yaml"] = Soft("a", "1948-05-15"),
            ["b.yaml"] = Soft("b", "1948-05-15"),
            ["c.yaml"] = Soft("c", "1948-05-15"),
            ["d.yaml"] = Soft("d", "1948-05-01"),
        }));
        var s = Simulation.NewGame(c, 1, Mode.Historical);
        Assert.Equal(new[] { "d", "a", "b" }, s.PendingEvents);   // d opened first; then a and b by id; c finds no slot
        var next = Simulation.Step(c, s, new List<Command>()).State;
        Assert.Equal(new[] { "c" }, next.PendingEvents);
    }

    // R-EVT-006: among the cards of the same `from` (and, for objective cards, the same objective place), an event's
    // `order` (default 0) comes before the id, so a later `order` waits behind the others for the slots and the queue.
    [Fact]
    public void OrderComesBeforeTheIdAmongTheSameFrom()
    {
        var c = ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string>
        {
            ["a.yaml"] = Soft("a", "1948-05-15") + "order: 1\n",
            ["b.yaml"] = Soft("b", "1948-05-15"),
            ["c.yaml"] = Soft("c", "1948-05-15"),
            ["d.yaml"] = Soft("d", "1948-05-01") + "order: 5\n",
        }));
        Assert.Equal(1, c.Events.Single(e => e.Id == "a").Order);
        Assert.Equal(0, c.Events.Single(e => e.Id == "b").Order);   // the default
        var s = Simulation.NewGame(c, 1, Mode.Historical);
        Assert.Equal(new[] { "d", "b", "c" }, s.PendingEvents);   // from still comes first; a waits behind b and c
        Assert.Equal(new[] { "a" }, Simulation.Step(c, s, new List<Command>()).State.PendingEvents);
    }

    // R-EVT-006 on the real start (owner, 24 October 2026, #1568: "One Army first"): One Army opens the game, and the
    // defence of Degania, the same turn's other card, comes second.
    [Fact]
    public void OneArmyOpensTheGameAndDeganiaComesSecond()
    {
        Assert.Equal(new[] { "idf_founding", "degania_defence" }, Run[0].PendingEvents);
        Assert.Equal(1, Event("degania_defence").Order);
        Assert.Equal(new[] { "armistice_jordan", "degania_defence" }, C.Events.Where(e => e.Order != 0).Select(e => e.Id).OrderBy(id => id, StringComparer.Ordinal));
    }

    // R-EVT-006 on the real armistices (#2551): Lebanon's and Jordan's cards both open on 15 March 1949, and Lebanon signed
    // first (23 March 1949; Jordan on 3 April), so Jordan's card has order 1 and comes second, not first by its id.
    [Fact]
    public void LebanonsArmisticeComesBeforeJordansOnTheirTurn()
    {
        var turn = Run.First(s => s.PendingEvents.Contains("armistice_jordan"));
        Assert.Equal(new DateTime(1949, 3, 15), turn.Date);
        Assert.Equal(new[] { "armistice_lebanon", "armistice_jordan" }, turn.PendingEvents.Where(id => id.StartsWith("armistice_", StringComparison.Ordinal)));
        Assert.Equal(1, Event("armistice_jordan").Order);
    }

    const string Choice = @"
id: choice
title: A choice
text: '{finance_minister} asks for a decision.'
office: finance_minister
anchor: {ANCHOR}
from: 1948-05-15
options:
  - id: first
    text: The first way
    alternative: { basis: design }
    recommended: true
    effects:
      - target: fx_reserves
        delta: -10
  - id: history
    text: The way it went
    historical: true
    effects:
      - target: food_supply
        delta: 0.1
    set_policy:
      rationing: 0.4
    set_rung: 3
sources: [{ url: https://example.org/event, checked: 2026-10-18 }]
";

    static Content ChoiceContent(string anchor) =>
        ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string> { ["choice.yaml"] = Choice.Replace("{ANCHOR}", anchor) }));

    // R-EVT-003: an event the player leaves unanswered at End Turn is delegated to its office's holder; in Historical
    // mode a hard anchor takes its historical option with no RNG draw.
    [Fact]
    public void AnUnansweredEventIsDelegated()
    {
        var c = ChoiceContent("soft");
        var s = Simulation.NewGame(c, 1, Mode.Historical);
        Assert.Equal(new[] { "choice" }, s.PendingEvents);
        var r = Simulation.Step(c, s, new List<Command>());
        Assert.Empty(r.State.PendingEvents);
        Assert.True(r.State.ChosenOptions.ContainsKey("choice"));
        Assert.Contains(r.Why, w => w.System == "events" && w.Target == "choice" && w.Message.StartsWith("Delegated to "));

        var hard = ChoiceContent("hard");
        var h = Simulation.NewGame(hard, 1, Mode.Historical);
        var rng = h.RngState;
        EventSystem.Delegate(hard, h, new List<Cause>());
        Assert.Equal("history", h.ChosenOptions["choice"]);   // not the recommended one: the historical option, always
        Assert.Equal(rng, h.RngState);                       // and no draw
    }

    // R-EVT-003 (#107; owner, 18 October 2026): a holder whose loyalty is below delegation_loyalty_floor carries a delegated
    // decision out half-heartedly: disloyal_effect_share of each numeric effect lands. Which option is drawn does not change.
    [Theory]
    [InlineData(5, -10.0)]   // at the fixture's floor (5): the whole effect
    [InlineData(4, -5.0)]    // below it: the fixture's share, 0.5
    public void ADisloyalMinisterDeliversPartOfTheEffect(int loyalty, double want)
    {
        var files = Fixture.Gdd();
        // def_two holds finance_minister on the first day; competence 10 always draws the recommended option
        files["people.yaml"] = Fixture.Files["people.yaml"].Replace("competence: 4", "competence: 10").Replace("loyalty: 5", $"loyalty: {loyalty}");
        var c = ContentLoader.Load(Fixture.Write(files, new Dictionary<string, string> { ["choice.yaml"] = Choice.Replace("{ANCHOR}", "soft") }));
        var s = Simulation.NewGame(c, 1, Mode.Historical);
        var why = new List<Cause>();
        EventSystem.Delegate(c, s, why);
        Assert.Equal("first", s.ChosenOptions["choice"]);
        Assert.Equal(want, Assert.Single(why, w => w.Target == "fx_reserves").Delta);
        Assert.Equal(loyalty < 5, Assert.Single(why, w => w.Target == "choice").Message.Contains("carried out half-heartedly"));   // the Why says why the numbers are cut
    }

    // R-EVT-003 (#107): the share reaches the Treasury and Food paths too; a hard anchor's historical option, and the
    // option's structured effects (here its policy and security level), stay whole.
    [Fact]
    public void TheShareReachesEveryNumericEffectAndNothingElse()
    {
        var files = Fixture.Gdd();
        files["people.yaml"] = Fixture.Files["people.yaml"].Replace("competence: 4", "competence: 10").Replace("loyalty: 5", "loyalty: 4");
        var money = Choice.Replace("{ANCHOR}", "soft").Replace("        delta: -10\n",
            "        delta: -10\n      - target: treasury\n        delta: 4\n      - target: food\n        delta: 7\n");
        var c = ContentLoader.Load(Fixture.Write(files, new Dictionary<string, string> { ["choice.yaml"] = money }));
        var s = Simulation.NewGame(c, 1, Mode.Historical);
        var (treasury, food) = (s.Treasury, s.Food);
        var why = new List<Cause>();
        EventSystem.Delegate(c, s, why);
        Assert.Equal(treasury + 2, s.Treasury, 12);
        Assert.Equal(food + 4, s.Food);   // 3.5 rounds half away from zero

        var hard = ContentLoader.Load(Fixture.Write(files, new Dictionary<string, string> { ["choice.yaml"] = Choice.Replace("{ANCHOR}", "hard") }));
        var h = Simulation.NewGame(hard, 1, Mode.Historical);
        var whyHard = new List<Cause>();
        EventSystem.Delegate(hard, h, whyHard);
        Assert.Equal("history", h.ChosenOptions["choice"]);
        Assert.Equal(0.1, Assert.Single(whyHard, w => w.Target == "food_supply").Delta, 12);   // whole, not 0.05
        Assert.Equal(0.4, h.Policies["rationing"]);
        Assert.Equal(3, h.Rung);
    }

    // R-EVT-003 (#107): both values are required in the GDD loop, so a missing key is never read as 0.
    [Theory]
    [InlineData("  delegation_loyalty_floor: 5\n", "", "mvp.delegation_loyalty_floor", "required")]
    [InlineData("  delegation_loyalty_floor: 5\n", "  delegation_loyalty_floor: 11\n", "mvp.delegation_loyalty_floor", "0-10")]
    [InlineData("  disloyal_effect_share: 0.5\n", "", "mvp.disloyal_effect_share", "required")]
    [InlineData("  disloyal_effect_share: 0.5\n", "  disloyal_effect_share: 1.5\n", "mvp.disloyal_effect_share", "from 0 to 1")]
    public void TheLoyaltyValuesAreRequiredAndInRange(string line, string replacement, string field, string reason)
    {
        var files = Fixture.Gdd();
        Assert.Contains(line, files["rules.yaml"]);
        files["rules.yaml"] = files["rules.yaml"].Replace(line, replacement);
        var e = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(files)));
        Assert.Contains(field, e.Message);
        Assert.Contains(reason, e.Message);
    }

    // R-EVT-004: an option's effects apply on the turn it is chosen, never later; no option can carry a delay.
    [Fact]
    public void NoEffectArrivesLater()
    {
        var c = ChoiceContent("soft");
        var s = Simulation.NewGame(c, 1, Mode.Historical);
        var first = Simulation.Step(c, s, new List<Command> { new ChooseEventOption("choice", "first") });
        Assert.Contains(first.Why, w => w.System == "events" && w.Target == "fx_reserves" && w.Delta == -10);
        var later = first.State;
        for (int turn = 0; turn < 3; turn++)
        {
            var r = Simulation.Step(c, later, new List<Command>());
            // Nothing of the event comes back on a later turn. An effect is applied only in Resolve, which writes an
            // "events" cause for each change, so the causes are the record to check.
            Assert.DoesNotContain(r.Why, w => w.System == "events");
            later = r.State;
        }
        var delayed = Choice.Replace("{ANCHOR}", "soft").Replace("        delta: -10\n", "        delta: -10\n    delay: 2\n");
        Assert.Contains("delay", delayed);
        var refused = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string> { ["choice.yaml"] = delayed })));
        Assert.Contains("delay", refused.Message);
    }

    // R-EVT-005: one sim helper lists every effect of an option, in the order they apply: the numeric effects, the
    // policies it sets, then the security level.
    [Fact]
    public void ThePreviewListsEveryEffectOfAnOption()
    {
        var c = ChoiceContent("soft");
        var s = Simulation.NewGame(c, 1, Mode.Historical);
        var e = c.Events.First(x => x.Id == "choice");
        var lines = EventSystem.OptionEffects(c, s, e.Options[1]);
        Assert.Equal(new[] { "food_supply", "rationing", "rung" }, lines.Select(l => l.Target));
        Assert.Equal(new[] { 0.1, 0.4, 3.0 }, lines.Select(l => l.Delta));
        Assert.Equal(PlayerText.Capitalised(PlayerText.Change(c, "food_supply", 0.1)), lines[0].Message);
        Assert.All(lines, l => Assert.Equal("events", l.System));
        var money = EventSystem.OptionEffects(c, s, e.Options[0]).Single();
        Assert.Equal(("fx_reserves", -10.0), (money.Target, money.Delta));

        // What the helper lists is what choosing the option applies.
        var why = new List<Cause>();
        Assert.Null(EventSystem.Choose(c, s, "choice", "history", why));
        Assert.Equal(new[] { "food_supply", "rationing" }, why.Where(w => w.System == "events" && w.Target != "choice").Select(w => w.Target));
        Assert.Equal(3, s.Rung);
    }

    // R-EVT-005: on the real content, for every option of every event on the turn its card reaches the player, the
    // helper lists exactly the option's effects, policies and security level.
    [Fact]
    public void ThePreviewListsEveryEffectOnTheRealContent()
    {
        var checkedOptions = 0;
        // A consequence card never fires in the historical run (R-ALT-012); its state comes from a run on its road.
        foreach (var e in C.Events)
        {
            // Every historical event fires in the run (EventRetimingTests) but hula_drainage, which waits for works the
            // reference player never starts (R-SWAMP-002), absorb_immigrants, which waits for its objective (R-OBJ-004, #1039),
            // and Deport's cards, which wait for a Deport the reference player never orders (R-EVT-007, R-CTRL-009);
            // their options are read on the first turn of their window.
            var s = e.Kind != EventKinds.Consequence
                ? Run.FirstOrDefault(x => x.FiredEvents.Contains(e.Id)) ?? Run.First(x => (e.Site != "" || e.Objective != "" || e.Deported != "") && x.Date >= e.From)
                : AltRun.Play(C, AltRun.RoadTo(C, e)).First(x => x.FiredEvents.Contains(e.Id));
            foreach (var o in e.Options)
            {
                var expected = o.Effects.Select(fx => (fx.Target, fx.Delta))
                    .Concat(o.SetPolicy.OrderBy(k => k.Key, StringComparer.Ordinal).Select(k => (k.Key, k.Value)))
                    .Concat(o.SetRung.HasValue ? new[] { ("rung", (double)o.SetRung.Value) } : new (string, double)[0])
                    .Concat(o.Rejoin != "" ? new[] { ("rejoin", 0.0) } : new (string, double)[0]);
                Assert.Equal(expected, EventSystem.OptionEffects(C, s, o).Select(l => (l.Target, l.Delta)));
                checkedOptions++;
            }
        }
        Assert.True(checkedOptions > 60, $"only {checkedOptions} options");
    }
}