A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: delegation reads minister loyalty (R-EVT-003, refs #107) (#1021)
Beri40ae33f51735
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 708900658..a23225d66 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -62,6 +62,10 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIBkibbutzim and the moshav (a townsman, a smith and a nurse), and an arriving man and woman beside each transit camp fromthe day it is placed. They are scenery, never units; the static figures stream after the first frame and the animatedones only at close zoom (refs #666, #663).+- Delegation reads a minister's loyalty (R-EVT-003): when an unanswered event goes to a minister rated below+ `delegation_loyalty_floor` (5), only `disloyal_effect_share` (0.5) of each numeric effect of the option lands. Both+ are labelled design values in `rules.yaml` `mvp:`. No minister in `people.yaml` is rated below 5 today, so the+ goldens do not move (refs #107).### Changed- The population-tier badge on the twelve city and town pills keeps the values it shipped with, now owner-approved: tiers 1diff --git a/content/rules.yaml b/content/rules.yamlindex 26918d6fd..9107ec80e 100644--- a/content/rules.yaml+++ b/content/rules.yaml@@ -83,6 +83,12 @@ mvp:# is a historical figure; the Phase 7 balance pass (PR 12) sets the final ceiling.defeat_turns: 3 # DESIGN VALUE: owner-set balance, not a historical figure (D-B5, Q-DEF-2: turn ends in a row with Money and Food exhausted)debt_ceiling: 250 # DESIGN VALUE: owner-set balance, not a historical figure (D-B5, Q-DEF-1: IL millions of debt at which Money is exhausted)+ # Delegation and loyalty (R-EVT-003; #107, owner, 18 October 2026: "Yes: minister loyalty changes a delegated event's+ # outcome, with labelled values in the PR"). A minister below the floor still picks as competence says, but carries the+ # decision out half-heartedly: only the share of each numeric effect lands. The floor is 5 because people.yaml rates+ # the deputies 5 as a neutral rating, so neutral is not disloyal. Agent-proposed; the owner may override them.+ delegation_loyalty_floor: 5 # DESIGN VALUE: owner-set balance, not a historical figure (D-H1, #107: loyalty below which a delegated decision is half-done)+ disloyal_effect_share: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-H1, #107: share of each numeric effect a disloyal minister delivers)# Coalition stability lost by replacing a minister (Cabinet.Appoint): a seat taken from the minister's party, or a# reshuffle within it.appoint_stability_cost_other_party: 0.06diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex ede6fc9bf..68fe24d7e 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -194,13 +194,13 @@ R-EFX-006: The structured effects apply after the numeric effects, grants first## Events-D-H1 in the GDD loop (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). As the plan's Decided rows record them (`docs/superpowers/plans/2026-10-15-gdd-phase-7.md`), that keeps windows, hard anchors and the cap of 3 soft events a turn, keeps delegation, adds no delayed effects in the MVP, and shows every effect of every option from the sim's preview. These rules state what the code already does; no behaviour changed.+D-H1 in the GDD loop (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). As the plan's Decided rows record them (`docs/superpowers/plans/2026-10-15-gdd-phase-7.md`), that keeps windows, hard anchors and the cap of 3 soft events a turn, keeps delegation, adds no delayed effects in the MVP, and shows every effect of every option from the sim's preview. These rules state what the code already does; no behaviour changed. On 18 October 2026 the owner added loyalty to delegation (#107: "Yes: minister loyalty changes a delegated event's outcome, with labelled values in the PR"); R-EVT-003 states it, with two design values (`delegation_loyalty_floor`, `disloyal_effect_share`).R-EVT-001: An event fires on the first turn whose span overlaps its window `[from, to)` (or at the new game, when the start date is in it), once its `requires` is met and its conditions hold; an objective's card also waits for its objective (R-OBJ-003). Every eligible hard anchor fires. At most 3 soft events fire a turn (`EventSystem.MaxSoftEventsPerTurn`); they take the slots the hard anchors leave, `max(0, 3 - hard anchors)`, and the rest wait for a later turn (Q-CUT-6).R-EVT-002: The soft events take the free slots in order: consequence cards first (R-ALT-008), then the rest by `from`, then id (ordinal). The decided place of an early armistice ahead of the other soft events (Q-EVT-1, through `front_quiet`, Q-OBJ-1) lands with that key in Phase 5 PR 13 (#752), and this rule is reworded then.-R-EVT-003: An event the player leaves unanswered at End Turn is delegated to its office's holder (Q-EVT-2): with probability competence/10 the holder picks the recommended option (else the first), otherwise a random option. In Historical mode a hard anchor takes its historical option, and an objective's card its one option, with no RNG draw.+R-EVT-003: An event the player leaves unanswered at End Turn is delegated to its office's holder (Q-EVT-2): with probability competence/10 the holder picks the recommended option (else the first), otherwise a random option. In Historical mode a hard anchor takes its historical option, and an objective's card its one option, with no RNG draw. A holder whose loyalty is below `delegation_loyalty_floor` (5) applies only `disloyal_effect_share` (0.5) of each numeric effect of the option drawn; the grants, city effects, policies and security level apply whole, and so do a hard anchor's historical option and an objective's card. Why: competence decides which option a minister picks, loyalty how hard he works to carry out a decision the player left to him (#107, owner, 18 October 2026: "minister loyalty changes a delegated event's outcome"). Both are design values (R-LOOP-005), required by the loader: the floor 0 to 10, the share 0 to 1. Every minister in `people.yaml` is rated 5 or more today (5 is the deputies' neutral rating), so the rule changes no shipped game until a rating goes below the floor.R-EVT-004: An option's effects apply when it is chosen or delegated, on that turn, and never later; an option has no delayed form, and the loader refuses an unknown key such as `delay` (Q-EVT-3).diff --git a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs b/sim/Statecraft.Sim.Tests/DesignValuesTests.csindex d828aa478..0dad2d34d 100644--- a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs+++ b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs@@ -44,6 +44,8 @@ public class DesignValuesTests("rules.yaml", "mvp.overflow_condition_loss"),("rules.yaml", "mvp.defeat_turns"),("rules.yaml", "mvp.debt_ceiling"),+ ("rules.yaml", "mvp.delegation_loyalty_floor"), // R-EVT-003, #107+ ("rules.yaml", "mvp.disloyal_effect_share"),// Q-START-1 (owner, 15 October 2026, #375): no city has a sourced housing stock or job count, so every city's// housing is its start people and its job slots its start employed; seven towns with no CBS working share take// the national one. The census people and the five CBS shares are sourced, not design values (R-CITY-006).@@ -191,6 +193,7 @@ public class DesignValuesTestsAssert.Equal((6, 2.0), (m.BuildYishuvTurns, m.BuildYishuvCost));Assert.Equal((100, 5, 60), (m.ObjectivePoints, m.ObjectiveBonusPerMonth, m.ObjectiveBonusCap)); // D-B6, D-B2Assert.Equal((0.35, 0.15), (m.HousingStartCondition, m.OverflowConditionLoss)); // Q-START-3, Q-HOUSE-1 (D-D1)+ Assert.Equal((5, 0.5), (m.DelegationLoyaltyFloor, m.DisloyalEffectShare)); // R-EVT-003, #107 (D-H1)Assert.Equal(12, c.Cities.Count);foreach (var x in c.Cities) // the listed housing and job values are the ones Cities.Init starts fromAssert.Equal(((int)x.Housing!.Value, (int)x.Jobs!.Value), (x.HousingCapacity, x.JobSlots));diff --git a/sim/Statecraft.Sim.Tests/EventRulesGddTests.cs b/sim/Statecraft.Sim.Tests/EventRulesGddTests.csindex bbb3350d0..2623e4fd0 100644--- a/sim/Statecraft.Sim.Tests/EventRulesGddTests.cs+++ b/sim/Statecraft.Sim.Tests/EventRulesGddTests.cs@@ -144,6 +144,68 @@ options: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()diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.csindex 91a3ee83e..a7c044417 100644--- a/sim/Statecraft.Sim.Tests/Fixture.cs+++ b/sim/Statecraft.Sim.Tests/Fixture.cs@@ -245,6 +245,8 @@ mvp:overflow_condition_loss: 0.2defeat_turns: 3debt_ceiling: 10+ delegation_loyalty_floor: 5+ disloyal_effect_share: 0.5";public static readonly string GddCities = "\ncities:\n" + City("town_a", 12, 8, 10, 6, "[military_camp, hakhshara]");diff --git a/sim/Statecraft.Sim.Tests/RealContentTests.cs b/sim/Statecraft.Sim.Tests/RealContentTests.csindex a4567b267..b5df54448 100644--- a/sim/Statecraft.Sim.Tests/RealContentTests.cs+++ b/sim/Statecraft.Sim.Tests/RealContentTests.cs@@ -3,6 +3,7 @@ using System.Collections.Generic;using System.IO;using System.Linq;using Statecraft.Sim;+using YamlDotNet.RepresentationModel;/// <summary>Checks the real content/ folder at the repository root.</summary>public class RealContentTests@@ -62,6 +63,19 @@ public class RealContentTests}}+ /// <summary>Person.Loyalty is a plain int, so a row without loyalty: would load as 0 and that minister would half-deliver+ /// every delegated decision (R-EVT-003, #107). Every row sets it.</summary>+ [Fact]+ public void EveryPersonSetsLoyalty()+ {+ var yaml = new YamlStream();+ using (var r = new StringReader(File.ReadAllText(Path.Combine(ContentRoot(), "people.yaml")))) yaml.Load(r);+ var rows = (YamlSequenceNode)((YamlMappingNode)yaml.Documents[0].RootNode)[new YamlScalarNode("people")];+ Assert.Equal(C.People.Count, rows.Children.Count);+ foreach (YamlMappingNode m in rows)+ Assert.True(m.Children.ContainsKey(new YamlScalarNode("loyalty")), $"people[{m[new YamlScalarNode("id")]}] has no loyalty");+ }+[Fact]public void EveryHistoricalRecordIsSourcedAndFactChecked(){diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex 5fb7b99f5..5cce0db7f 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -525,6 +525,12 @@ namespace Statecraft.Sim/// <summary>The debt, in IL millions, at or above which Money is exhausted (R-END-001; D-B5, Q-DEF-1). Required in the/// GDD loop, a finite number >= 0.</summary>public double? DebtCeiling { get; set; }+ /// <summary>A minister whose loyalty is below this carries a delegated decision out half-heartedly (R-EVT-003; #107,+ /// owner, 18 October 2026). Required in the GDD loop, 0 to 10 (0: nobody is below it).</summary>+ public int? DelegationLoyaltyFloor { get; set; }+ /// <summary>The share of each numeric effect a delegated option applies when its minister is below the loyalty floor+ /// (R-EVT-003; #107). Required in the GDD loop, 0 to 1.</summary>+ public double? DisloyalEffectShare { get; set; }}/// <summary>A kind of city project (projects.yaml; GDD "Cities and construction"; R-PROJ-001 to R-PROJ-003): permanentdiff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex eef43f367..059f5bab8 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -1112,6 +1112,11 @@ namespace Statecraft.Simif (m.DefeatTurns < 1) throw new ContentException(file, "mvp.defeat_turns", "must be >= 1");if (m.DebtCeiling == null) throw new ContentException(file, "mvp.debt_ceiling", "required when eras.yaml systems.loop is gdd");if (!(m.DebtCeiling >= 0 && IsFinite(m.DebtCeiling.Value))) throw new ContentException(file, "mvp.debt_ceiling", "must be a finite number >= 0");+ // R-EVT-003 (#107): required, so a missing key is never read as 0 (no floor, or a disloyal minister who does nothing).+ if (m.DelegationLoyaltyFloor == null) throw new ContentException(file, "mvp.delegation_loyalty_floor", "required when eras.yaml systems.loop is gdd");+ if (m.DelegationLoyaltyFloor < 0 || m.DelegationLoyaltyFloor > 10) throw new ContentException(file, "mvp.delegation_loyalty_floor", "must be 0-10");+ if (m.DisloyalEffectShare == null) throw new ContentException(file, "mvp.disloyal_effect_share", "required when eras.yaml systems.loop is gdd");+ Unit(file, "mvp.disloyal_effect_share", m.DisloyalEffectShare.Value);if (c.Indicators.All(i => i.Id != Pools.FoodIndicator))throw new ContentException(file, "mvp.k_food", "the Food stock feeds the food_supply indicator, which model.yaml must define");// One game has one last day (R-LOOP-004): an era cannot move it.diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.csindex 851928f35..0154752d8 100644--- a/sim/Statecraft.Sim/EventSystem.cs+++ b/sim/Statecraft.Sim/EventSystem.cs@@ -63,7 +63,8 @@ namespace Statecraft.Simreturn null;}- static void Resolve(Content c, GameState s, string eventId, EventOption o, string how, List<Cause> why)+ /// <param name="share">The share of each numeric effect that applies: 1, except for a disloyal minister's delegation (R-EVT-003).</param>+ static void Resolve(Content c, GameState s, string eventId, EventOption o, string how, List<Cause> why, double share = 1.0){s.PendingEvents.Remove(eventId);s.ChosenOptions[eventId] = o.Id;@@ -72,13 +73,14 @@ namespace Statecraft.Simwhy.Add(new Cause("events", eventId, 0, $"{how}: {Cabinet.Fill(c, s, o.Text, fillDate)}"));foreach (var fx in o.Effects.Where(fx => Reaches(s, fx.Target))){- var change = fx.Delta;+ var delta = fx.Delta * share;+ var change = delta;if (fx.Target == "treasury"){// R-MONEY-003: the cost first, then what was borrowed for it, as every other payment borrows.why.Add(new Cause("events", fx.Target, change, $"{PlayerText.Change(c, fx.Target, change)} ({title})"));- if (fx.Delta < 0) EconomySystem.PayOrBorrow(c, s, -fx.Delta, $"for {title}", why);- else s.Treasury += fx.Delta;+ if (delta < 0) EconomySystem.PayOrBorrow(c, s, -delta, $"for {title}", why);+ else s.Treasury += delta;continue;}if (fx.Target == Pools.FoodTarget)@@ -86,13 +88,13 @@ namespace Statecraft.Sim// R-EFX-001: an event moves the national Food stock by whole units (the delta rounds half away// from zero, and the loader bounds it to the int range). The stock stays in 0..int.MaxValue,// computed in long so nothing wraps, and the cause carries the change that applied.- var want = (long)Math.Round(fx.Delta, MidpointRounding.AwayFromZero);+ var want = (long)Math.Round(delta, MidpointRounding.AwayFromZero);var applied = Math.Max(-(long)s.Food, Math.Min(want, (long)int.MaxValue - s.Food));s.Food = (int)(s.Food + applied);change = applied;}- else if (fx.Target == "fx_reserves") s.FxReserves += fx.Delta;- else change = EffectsSystem.Shift(c, s, fx.Target, fx.Delta);+ else if (fx.Target == "fx_reserves") s.FxReserves += delta;+ else change = EffectsSystem.Shift(c, s, fx.Target, delta);why.Add(new Cause("events", fx.Target, change, $"{PlayerText.Change(c, fx.Target, change)} ({title})"));}// R-EFX-006: the structured effects after the numeric ones, in list order. The loader has checked every target.@@ -176,10 +178,14 @@ namespace Statecraft.Sim/// <summary>Unanswered events go to the responsible minister: with probability competence/10 they pick the/// recommended option (else the first), otherwise a random option. In Historical mode a hard-anchor event/// resolves to its historical option without drawing from the RNG (major anchors happen). An objective's card has one- /// option and resolves to it without a draw (R-OBJ-003: GDD Phase 1 adds no RNG draw).</summary>+ /// option and resolves to it without a draw (R-OBJ-003: GDD Phase 1 adds no RNG draw).+ /// In the GDD loop a drawn option of a minister whose loyalty is below the floor applies only disloyal_effect_share of+ /// each numeric effect (R-EVT-003; #107, owner, 18 October 2026). Why: loyalty decides how hard a minister works for a+ /// decision he was left to make, competence which decision he makes; anchors and objective cards stay whole.</summary>public static void Delegate(Content c, GameState s, List<Cause> why){var rng = new Rng(s.RngState);+ var mvp = c.IsGdd ? c.RulesAt(s.Date).Mvp : null; // the legacy loop has no floor, so its goldens holdforeach (var id in s.PendingEvents.ToList()){var e = Get(c, id);@@ -194,7 +200,10 @@ namespace Statecraft.Simvar option = anchored ?? (rng.NextDouble() < competence? e.Options.FirstOrDefault(o => o.Recommended) ?? e.Options[0]: e.Options[(int)(rng.NextDouble() * e.Options.Count)]);- Resolve(c, s, id, option, $"delegated to {minister?.Name ?? "the cabinet"}", why);+ var share = anchored == null && mvp != null && minister != null && minister.Loyalty < mvp.DelegationLoyaltyFloor+ ? mvp.DisloyalEffectShare!.Value : 1.0;+ var how = $"delegated to {minister?.Name ?? "the cabinet"}" + (share < 1 ? ", carried out half-heartedly" : "");+ Resolve(c, s, id, option, how, why, share);}s.RngState = rng.State;}