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.

feat(sim): Appoint command with coalition costs; appointees drive effects, delegation and event text

eyalgolanfc6ce7d1be8a
diff --git a/content/rules.yaml b/content/rules.yaml
index e5cb037fe..80fc6c8ea 100644
--- a/content/rules.yaml
+++ b/content/rules.yaml
@@ -2,7 +2,11 @@
start: 1948-05-15 # first day covered by the CBS 1948 immigration series (aliyah.yaml)
start_rung: 5 # the war is under way when the slice opens
attention_per_turn: 4
-attention_cost: { set_policy: 1, allocate_budget: 2, choose_event_option: 1, set_mobilization: 1, security_order: 1 }
+attention_cost: { set_policy: 1, allocate_budget: 2, choose_event_option: 1, set_mobilization: 1, security_order: 1, appoint: 2 }
+# 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.06
+appoint_stability_cost_same_party: 0.02
rung_attention_step: 0.25
rung_min_mobilization: [0.02, 0.05, 0.15, 0.4, 0.8]
ceasefire_weeks: 52 # long enough that the historical armistice events end the war first
diff --git a/docs/determinism.md b/docs/determinism.md
index ae9cfdd9b..106d8a14a 100644
--- a/docs/determinism.md
+++ b/docs/determinism.md
@@ -20,8 +20,8 @@ with `GoldenRun.Seed = 1948` on the real `content/`, then steps with `Historical
| Run | Ends | Hash |
|---|---|---|
-| to 1950-01-01 (`Hash1950`) | 1950-02-26, turn 45 | `43cc7773f890d8b79a7fc6a733d90b1314f452a91d766b0e7cf56aa8b9d43210` |
-| to 1952-01-01 (`Hash1952`) | 1952-02-26, turn 53 | `0359fa91b04d300084897a0d25b13dc92715d332363cfa2c285e6db740b83001` |
+| to 1950-01-01 (`Hash1950`) | 1950-02-26, turn 45 | `549b49cb2337e5cc9c3e626fbddd4bade1ff68f0e8c6b8cea83dc2a85386b19b` |
+| to 1952-01-01 (`Hash1952`) | 1952-02-26, turn 53 | `860928f23dd1658ef31c1d981e31595ce297853a51d6d7373b8a19b2037fd9e5` |
Each constant is written in three places that must agree:
- `sim/Statecraft.Sim/GoldenRun.cs`, which Unity code and players compare against;
@@ -49,3 +49,5 @@ rules or content, treat it as a determinism bug.
| M3 Task 5 | 1952 | `1753fb88` | new run covering the M3 content range. Task 4 fix round 1 changed 1951 event windows/effects (hula, forex, bonds, clothing rationing, education, reparations), so capital_inflow_per_year was re-fitted from 192 to 193.8 (first fx crisis in H2 1951) |
| M3 Task 5 fix 1 | 1950 | `43cc7773` | capital_inflow_per_year re-fitted 193.8 -> 200 (it acts from 1948) after the missing $45m credit maturity was added |
| M3 Task 5 fix 1 | 1952 | `0359fa91` | forex_crisis_1951 now applies the documented -45 fx (FRUS d513) in both options, and capital_inflow_per_year is 200 |
+| M3 Task 6 | 1950 | `549b49cb` | hash format adds the player's appointments (empty in the run); no state change |
+| M3 Task 6 | 1952 | `860928f2` | same |
diff --git a/sim/Statecraft.Sim.Tests/CabinetTests.cs b/sim/Statecraft.Sim.Tests/CabinetTests.cs
new file mode 100644
index 000000000..7f3dc9105
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/CabinetTests.cs
@@ -0,0 +1,188 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Statecraft.Sim;
+
+/// <summary>The Appoint command: who may be appointed, what it costs, and how long it lasts.</summary>
+public class CabinetTests
+{
+ const string ExtraPeople = @"
+ - id: outsider
+ name: Out Sider
+ living: false
+ party: beta
+ competence: 9
+ loyalty: 3
+ offices: []
+ - id: loyalist
+ name: Loy Alist
+ living: false
+ party: alpha
+ competence: 2
+ loyalty: 9
+ offices: []
+ - id: loyal_two
+ name: Loyal Two
+ living: false
+ party: alpha
+ competence: 6
+ loyalty: 9
+ offices: []
+ - id: late
+ name: Late Comer
+ living: false
+ died: 1948-07-01
+ party: alpha
+ competence: 5
+ loyalty: 5
+ offices: []
+ - id: gone
+ name: Gone Early
+ living: false
+ died: 1948-05-01
+ competence: 5
+ loyalty: 5
+ offices: []
+";
+
+ static Content Load(Dictionary<string, string>? events = null) =>
+ ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["people.yaml"] = Fixture.Files["people.yaml"] + ExtraPeople }, events));
+
+ static readonly Content C = Load();
+ static readonly IReadOnlyList<Command> None = new Command[0];
+
+ [Fact]
+ public void AppointingReplacesTheMinisterAndCostsCoalitionStability()
+ {
+ var s = Simulation.NewGame(C, 42, Mode.Historical);
+ var why = new List<Cause>();
+ Assert.Null(Cabinet.Appoint(C, s, "finance_minister", "loyalist", why));
+ Assert.Equal("loyalist", Cabinet.Holder(C, s, "finance_minister")!.Id);
+ Assert.Equal("def_two", Offices.Holder(C, "finance_minister", s.Date)!.Id); // history itself is unchanged
+ Assert.Equal(0.9, s.CoalitionStability, 9); // Def Two had no party: a seat lost
+ Assert.Contains(why, w => w.System == "cabinet" && w.Message == "Loy Alist appointed Minister of Finance, replacing Def Two");
+ Assert.Contains(why, w => w.Target == "coalition_stability" && w.Message == "coalition stability -0.10 (Def Two lost the Minister of Finance)");
+ }
+
+ [Fact]
+ public void AReshuffleWithinAPartyCostsLess()
+ {
+ var s = Simulation.NewGame(C, 42, Mode.Historical);
+ Cabinet.Appoint(C, s, "finance_minister", "loyalist", new List<Cause>());
+ var why = new List<Cause>();
+ Assert.Null(Cabinet.Appoint(C, s, "finance_minister", "loyal_two", why));
+ Assert.Equal(0.9 - 0.03, s.CoalitionStability, 9);
+ Assert.Contains(why, w => w.Message == "coalition stability -0.03 (Alpha resents the reshuffle)");
+ }
+
+ [Theory]
+ [InlineData("prime_minister", "loyalist", "You are the Prime Minister: that office is not yours to fill")]
+ [InlineData("finance_minister", "outsider", "Out Sider's party (Beta) is not in the coalition")]
+ [InlineData("finance_minister", "gone", "Gone Early died on 1948-05-01")]
+ [InlineData("finance_minister", "def_two", "Def Two already holds the office of Minister of Finance")]
+ [InlineData("finance_minister", "nobody", "Unknown person 'nobody'")]
+ [InlineData("treasurer", "loyalist", "Unknown office 'treasurer'")]
+ public void IllegalAppointmentsAreRejectedWithAReason(string office, string person, string reason)
+ {
+ var s = Simulation.NewGame(C, 42, Mode.Historical);
+ var before = s.Hash();
+ Assert.Equal(reason, Cabinet.Appoint(C, s, office, person, new List<Cause>()));
+ Assert.Equal(before, s.Hash());
+ }
+
+ [Fact]
+ public void ARejectedAppointCommandIsRefundedAndReported()
+ {
+ var s0 = Simulation.NewGame(C, 42, Mode.Historical);
+ var r = Simulation.Step(C, s0, new Command[] { new Appoint("finance_minister", "outsider") });
+ Assert.Equal("Out Sider's party (Beta) is not in the coalition", r.Rejected.Single().Reason);
+ Assert.Equal("def_two", Cabinet.Holder(C, r.State, "finance_minister")!.Id);
+ }
+
+ [Fact]
+ public void ThePartyRuleFollowsTheCoalitionOfTheDay()
+ {
+ var s = Simulation.NewGame(C, 42, Mode.Historical);
+ s.Date = new DateTime(1949, 3, 10); // Government Two: Alpha and Beta
+ Assert.Null(Cabinet.Check(C, s, "finance_minister", "outsider"));
+ }
+
+ [Fact]
+ public void AppointmentsEndWhenANewGovernmentTakesOffice()
+ {
+ var s = Simulation.NewGame(C, 42, Mode.Historical);
+ s = Simulation.Step(C, s, new Command[] { new Appoint("finance_minister", "loyalist") }).State;
+ Assert.Equal("loyalist", Cabinet.Holder(C, s, "finance_minister")!.Id);
+ StepResult r;
+ do { r = Simulation.Step(C, s, None); s = r.State; } while (Offices.Government(C, s.Date)!.Id == "gov1");
+ Assert.Equal("def_two", Cabinet.Holder(C, s, "finance_minister")!.Id);
+ Assert.Empty(s.Appointments);
+ Assert.Contains(r.Why, w => w.Message == "A new government took office with its own ministers; your appointments ended");
+ }
+
+ [Fact]
+ public void AnAppointeeWhoDiesLeavesOfficeOnTheDateOfDeath()
+ {
+ var s = Simulation.NewGame(C, 42, Mode.Historical);
+ Assert.Null(Cabinet.Appoint(C, s, "finance_minister", "late", new List<Cause>()));
+ Assert.Equal("late", Cabinet.Holder(C, s, "finance_minister", new DateTime(1948, 6, 30))!.Id);
+ Assert.Equal("def_two", Cabinet.Holder(C, s, "finance_minister", new DateTime(1948, 7, 1))!.Id);
+ }
+
+ [Fact]
+ public void TheAppointeesCompetenceDrivesTheMinistrysEffects()
+ {
+ var s = Simulation.NewGame(C, 42, Mode.Historical);
+ Assert.Equal(0.7, EffectsSystem.Multiplier(C, s, "finance_minister"), 9); // Def Two, competence 4
+ Cabinet.Appoint(C, s, "finance_minister", "loyalist", new List<Cause>());
+ Assert.Equal(0.6, EffectsSystem.Multiplier(C, s, "finance_minister"), 9); // Loy Alist, competence 2
+ }
+
+ [Fact]
+ public void EventTextNamesTheAppointee()
+ {
+ var c = Load(new Dictionary<string, string> { ["drought.yaml"] = ValidationTests.Event });
+ var s = Simulation.NewGame(c, 42, Mode.Historical);
+ Cabinet.Appoint(c, s, "finance_minister", "loyalist", new List<Cause>());
+ var drought = c.Events.Single(e => e.Id == "drought");
+ Assert.Equal("Loy Alist reports a drought.", EventSystem.Render(c, s, drought));
+ }
+
+ [Fact]
+ public void TheLineupListsEveryExistingOfficeAndMarksAppointees()
+ {
+ var s = Simulation.NewGame(C, 42, Mode.Historical);
+ Cabinet.Appoint(C, s, "finance_minister", "loyalist", new List<Cause>());
+ var lineup = Cabinet.Lineup(C, s);
+ Assert.Equal(new[] { "prime_minister", "defense_minister", "finance_minister" }, lineup.Select(x => x.Office.Id));
+ Assert.True(lineup.Single(x => x.Office.Id == "finance_minister").Appointed);
+ Assert.False(lineup.Single(x => x.Office.Id == "defense_minister").Appointed);
+ }
+
+ [Fact]
+ public void AppointmentsAreInTheHashAndStepNeverMutatesItsInput()
+ {
+ var s0 = Simulation.NewGame(C, 42, Mode.Historical);
+ var plain = Simulation.Step(C, s0, None).State;
+ var appointed = Simulation.Step(C, s0, new Command[] { new Appoint("finance_minister", "loyalist") }).State;
+ Assert.Empty(s0.Appointments);
+ Assert.NotEqual(plain.Hash(), appointed.Hash());
+ }
+
+ [Fact]
+ public void RealContentRules()
+ {
+ var c = ContentLoader.Load(RealContentTests.ContentRoot());
+ var s = new GameState { Date = new DateTime(1951, 1, 1) };
+ Assert.Equal("Golda Meir is not an IDF career officer", Cabinet.Check(c, s, "chief_of_staff", "golda_meir"));
+ Assert.Equal("The office of Minister of War Victims was abolished on 1951-10-08",
+ Cabinet.Check(c, new GameState { Date = new DateTime(1951, 11, 1) }, "war_victims_minister", "maimon"));
+ Assert.Equal("Aharon Zisling's party (Mapam) is not in the coalition", Cabinet.Check(c, s, "agriculture_minister", "zisling"));
+ Assert.Equal("The President is elected by the Knesset, not appointed", Cabinet.Check(c, s, "president", "sharett"));
+ Assert.Null(Cabinet.Check(c, s, "agriculture_minister", "eshkol"));
+ Assert.Equal("Chaim Weizmann is the President", Cabinet.Check(c, s, "finance_minister", "weizmann"));
+ Assert.Equal("Yigael Yadin is the serving Chief of Staff", Cabinet.Check(c, s, "finance_minister", "yadin"));
+ s.Date = new DateTime(1951, 6, 1);
+ Assert.Equal("David Remez died on 1951-05-19", Cabinet.Check(c, s, "transportation_minister", "remez"));
+ }
+}
diff --git a/sim/Statecraft.Sim.Tests/DeterminismTests.cs b/sim/Statecraft.Sim.Tests/DeterminismTests.cs
index d1377041e..02eb2da8a 100644
--- a/sim/Statecraft.Sim.Tests/DeterminismTests.cs
+++ b/sim/Statecraft.Sim.Tests/DeterminismTests.cs
@@ -19,7 +19,7 @@ public class DeterminismTests
/// <summary>Any change to this value is a deliberate rules or content change: update it here, in
/// GoldenRun.Hash1950 and in docs/determinism.md in the same commit.</summary>
- public const string GoldenHash = "43cc7773f890d8b79a7fc6a733d90b1314f452a91d766b0e7cf56aa8b9d43210";
+ public const string GoldenHash = "549b49cb2337e5cc9c3e626fbddd4bade1ff68f0e8c6b8cea83dc2a85386b19b";
/// <summary>Real content, seed 1948, Historical mode, HistoricalAI until the date reaches 1950-01-01.</summary>
public static GameState GoldenPlaythrough(Content c) => GoldenRun.Play(c, GoldenRun.Until1950);
@@ -34,7 +34,7 @@ public class DeterminismTests
}
/// <summary>Same rule for the second golden run, which covers the M3 content range (to 1952-01-01).</summary>
- public const string GoldenHash1952 = "0359fa91b04d300084897a0d25b13dc92715d332363cfa2c285e6db740b83001";
+ public const string GoldenHash1952 = "860928f23dd1658ef31c1d981e31595ce297853a51d6d7373b8a19b2037fd9e5";
[Fact]
public void GoldenPlaythroughTo1952HashIsFixed()
diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.cs
index 8b6b32bcc..5f950b081 100644
--- a/sim/Statecraft.Sim.Tests/Fixture.cs
+++ b/sim/Statecraft.Sim.Tests/Fixture.cs
@@ -114,7 +114,9 @@ actors:
start: 1948-05-15
start_rung: 5
attention_per_turn: 3
-attention_cost: { set_policy: 1, allocate_budget: 1, choose_event_option: 1, set_mobilization: 1, security_order: 1 }
+attention_cost: { set_policy: 1, allocate_budget: 1, choose_event_option: 1, set_mobilization: 1, security_order: 1, appoint: 1 }
+appoint_stability_cost_other_party: 0.1
+appoint_stability_cost_same_party: 0.03
rung_attention_step: 0.25
ceasefire_weeks: 4
rung_min_mobilization: [0.02, 0.05, 0.15, 0.4, 0.8]
diff --git a/sim/Statecraft.Sim/AttentionSystem.cs b/sim/Statecraft.Sim/AttentionSystem.cs
index e9b23039d..bc1366868 100644
--- a/sim/Statecraft.Sim/AttentionSystem.cs
+++ b/sim/Statecraft.Sim/AttentionSystem.cs
@@ -7,7 +7,7 @@ namespace Statecraft.Sim
public static class AttentionSystem
{
static readonly HashSet<string> Kinds = new HashSet<string>
- { "set_policy", "allocate_budget", "choose_event_option", "set_mobilization", "security_order" };
+ { "set_policy", "allocate_budget", "choose_event_option", "set_mobilization", "security_order", "appoint" };
public static IReadOnlyCollection<string> CommandKinds => Kinds;
diff --git a/sim/Statecraft.Sim/Cabinet.cs b/sim/Statecraft.Sim/Cabinet.cs
new file mode 100644
index 000000000..f5fd24ac8
--- /dev/null
+++ b/sim/Statecraft.Sim/Cabinet.cs
@@ -0,0 +1,138 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Statecraft.Sim
+{
+ /// <summary>A player appointment: <see cref="Person"/> holds the office from <see cref="From"/> while the government
+ /// that was in office then still is. Immutable, so GameState.Clone can copy the dictionary shallowly.</summary>
+ public sealed class Appointment
+ {
+ public string Person { get; }
+ public DateTime From { get; }
+ public Appointment(string person, DateTime from) { Person = person; From = from; }
+ }
+
+ /// <summary>One office and who holds it now.</summary>
+ public sealed class Seat
+ {
+ public Office Office { get; }
+ public Person? Holder { get; }
+ /// <summary>True when the holder is the player's appointee, not the historical minister.</summary>
+ public bool Appointed { get; }
+ public Seat(Office office, Person? holder, bool appointed) { Office = office; Holder = holder; Appointed = appointed; }
+ }
+
+ /// <summary>The cabinet as the game sees it: the historical holders from people.yaml, overridden by the player's
+ /// appointments until the government changes (a new government takes office with its own, historical, ministers).</summary>
+ public static class Cabinet
+ {
+ public const string Kind = "appoint";
+
+ /// <summary>The player's appointee for the office on the date: appointed by then, same government, and alive (an
+ /// appointee who dies leaves office on the date of death, and the historical holder applies again).</summary>
+ static Appointment? Active(Content c, GameState s, string office, DateTime date)
+ {
+ if (!s.Appointments.TryGetValue(office, out var a) || date < a.From) return null;
+ var died = c.People.First(p => p.Id == a.Person).Died;
+ if (died.HasValue && date >= died.Value) return null;
+ return Offices.Government(c, date)?.Id == s.AppointedUnder ? a : null;
+ }
+
+ /// <summary>Who holds <paramref name="office"/> on <paramref name="date"/> (default: the state's date).</summary>
+ public static Person? Holder(Content c, GameState s, string office, DateTime? date = null)
+ {
+ var d = date ?? s.Date;
+ var a = Active(c, s, office, d);
+ return a != null ? c.People.First(p => p.Id == a.Person) : Offices.Holder(c, office, d);
+ }
+
+ /// <summary>Offices.Fill with the player's appointments: {office_id} becomes the name of whoever holds it.</summary>
+ public static string Fill(Content c, GameState s, string text, DateTime date) =>
+ Offices.Placeholder.Replace(text, m =>
+ Holder(c, s, m.Groups[1].Value, date)?.Name
+ ?? throw new InvalidOperationException(FormattableString.Invariant($"no holder of '{m.Groups[1].Value}' on {date:yyyy-MM-dd}")));
+
+ /// <summary>Every office that exists on the state's date, in offices.yaml order, with its holder (null = vacant).</summary>
+ public static IReadOnlyList<Seat> Lineup(Content c, GameState s) =>
+ c.Offices.Where(o => !o.Until.HasValue || s.Date < o.Until.Value)
+ .Select(o => new Seat(o, Holder(c, s, o.Id), Active(c, s, o.Id, s.Date) != null))
+ .ToList();
+
+ /// <summary>Null when <paramref name="personId"/> may be appointed to <paramref name="officeId"/> now, else the
+ /// reason shown to the player. Checks, in order: the office exists and has not been abolished; it is not the
+ /// Prime Minister's (the player) or the President's (elected by the Knesset); the person exists, is alive, is not
+ /// the sitting President, is not the serving Chief of Staff (for any other office) and does not already hold it; a
+ /// government is in office; a Chief of Staff must be a career officer (has held the post in people.yaml); a
+ /// minister's party, if any, must be in the coalition.</summary>
+ public static string? Check(Content c, GameState s, string officeId, string personId)
+ {
+ var office = c.Offices.FirstOrDefault(o => o.Id == officeId);
+ if (office == null) return $"Unknown office '{officeId}'";
+ if (office.Until.HasValue && s.Date >= office.Until.Value)
+ return FormattableString.Invariant($"The office of {office.Title} was abolished on {office.Until:yyyy-MM-dd}");
+ if (officeId == "prime_minister") return "You are the Prime Minister: that office is not yours to fill";
+ if (officeId == "president") return "The President is elected by the Knesset, not appointed";
+ var person = c.People.FirstOrDefault(p => p.Id == personId);
+ if (person == null) return $"Unknown person '{personId}'";
+ if (person.Died.HasValue && s.Date >= person.Died.Value)
+ return FormattableString.Invariant($"{person.Name} died on {person.Died:yyyy-MM-dd}");
+ if (Holder(c, s, "president")?.Id == personId) return $"{person.Name} is the President";
+ if (officeId != "chief_of_staff" && Holder(c, s, "chief_of_staff")?.Id == personId) return $"{person.Name} is the serving Chief of Staff";
+ if (Holder(c, s, officeId)?.Id == personId) return $"{person.Name} already holds the office of {office.Title}";
+ var gov = Offices.Government(c, s.Date);
+ if (gov == null) return "No government is in office";
+ if (officeId == "chief_of_staff")
+ return person.Offices.Any(t => t.Office == "chief_of_staff") ? null : $"{person.Name} is not an IDF career officer";
+ var party = Offices.PartyOf(c, person, s.Date);
+ if (party != "" && !gov.Coalition.Contains(party))
+ return $"{person.Name}'s party ({c.Parties.First(p => p.Id == party).Name}) is not in the coalition";
+ return null;
+ }
+
+ /// <summary>Every person with the reason they cannot be appointed (null = they can), in people.yaml order.</summary>
+ public static IReadOnlyList<(Person person, string? reason)> Candidates(Content c, GameState s, string officeId) =>
+ c.People.Select(p => (p, Check(c, s, officeId, p.Id))).ToList();
+
+ /// <summary>Returns null and appoints, or the reason (state untouched). Replacing a minister costs coalition
+ /// stability: rules appoint_stability_cost_other_party when the seat leaves the displaced minister's party (a
+ /// non-party appointee counts as another party), appoint_stability_cost_same_party otherwise. A vacant seat costs
+ /// nothing.</summary>
+ public static string? Appoint(Content c, GameState s, string officeId, string personId, List<Cause> why)
+ {
+ var reason = Check(c, s, officeId, personId);
+ if (reason != null) return reason;
+ var gov = Offices.Government(c, s.Date)!;
+ var office = c.Offices.First(o => o.Id == officeId);
+ var person = c.People.First(p => p.Id == personId);
+ var displaced = Holder(c, s, officeId);
+ if (s.AppointedUnder != gov.Id) { s.Appointments.Clear(); s.AppointedUnder = gov.Id; }
+ s.Appointments[officeId] = new Appointment(personId, s.Date);
+ why.Add(new Cause("cabinet", officeId, 0, displaced == null
+ ? $"{person.Name} appointed {office.Title}"
+ : $"{person.Name} appointed {office.Title}, replacing {displaced.Name}"));
+ if (displaced == null) return null;
+ var oldParty = Offices.PartyOf(c, displaced, s.Date);
+ var newParty = Offices.PartyOf(c, person, s.Date);
+ bool sameParty = oldParty != "" && oldParty == newParty;
+ var cost = sameParty ? c.Rules.AppointStabilityCostSameParty : c.Rules.AppointStabilityCostOtherParty;
+ if (cost <= 0) return null;
+ var before = s.CoalitionStability;
+ s.CoalitionStability = Math.Max(0, before - cost);
+ var who = oldParty == "" ? displaced.Name : c.Parties.First(p => p.Id == oldParty).Name;
+ why.Add(new Cause("politics", "coalition_stability", s.CoalitionStability - before, FormattableString.Invariant(
+ $"coalition stability {s.CoalitionStability - before:+0.00;-0.00;+0.00} ({who} {(sameParty ? "resents the reshuffle" : "lost the " + office.Title)})")));
+ return null;
+ }
+
+ /// <summary>Called after the date advances: when a new government takes office, the player's appointments end.</summary>
+ public static void ExpireOnGovernmentChange(Content c, GameState s, List<Cause> why)
+ {
+ if (s.AppointedUnder == "" || Offices.Government(c, s.Date)?.Id == s.AppointedUnder) return;
+ if (s.Appointments.Count > 0)
+ why.Add(new Cause("cabinet", "appointments", -s.Appointments.Count, "A new government took office with its own ministers; your appointments ended"));
+ s.Appointments.Clear();
+ s.AppointedUnder = "";
+ }
+ }
+}
diff --git a/sim/Statecraft.Sim/Commands.cs b/sim/Statecraft.Sim/Commands.cs
index 6caacd7ac..a7b53014b 100644
--- a/sim/Statecraft.Sim/Commands.cs
+++ b/sim/Statecraft.Sim/Commands.cs
@@ -41,6 +41,14 @@ namespace Statecraft.Sim
public SecurityOrder(int delta) { Delta = delta; }
}
+ /// <summary>Puts <see cref="Person"/> in <see cref="Office"/> (Cabinet.Appoint has the rules).</summary>
+ public sealed class Appoint : Command
+ {
+ public override string Kind => Cabinet.Kind;
+ public string Office { get; } public string Person { get; }
+ public Appoint(string office, string person) { Office = office; Person = person; }
+ }
+
public sealed class Rejection
{
public Command Command { get; } public string Reason { get; }
diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.cs
index d1415a2e4..8f640e0a1 100644
--- a/sim/Statecraft.Sim/Content.cs
+++ b/sim/Statecraft.Sim/Content.cs
@@ -129,6 +129,10 @@ namespace Statecraft.Sim
/// <summary>Change to food_supply per year while the foreign currency crisis lasts (imports of food are cut); &lt;= 0.</summary>
public double FxCrisisFoodPerYear { get; set; }
public double MobilizationCostPerYear { get; set; }
+ /// <summary>Coalition stability lost when an appointment takes a seat from the displaced minister's party.</summary>
+ public double AppointStabilityCostOtherParty { get; set; }
+ /// <summary>Coalition stability lost when an appointment replaces a minister with one of the same party.</summary>
+ public double AppointStabilityCostSameParty { get; set; }
public double NaturalIncreasePerYear { get; set; }
public Dictionary<string, double> InitialPopulation { get; set; } = new Dictionary<string, double>();
public Dictionary<string, double> BudgetStart { get; set; } = new Dictionary<string, double>();
diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.cs
index af4995efc..ad4453b22 100644
--- a/sim/Statecraft.Sim/ContentLoader.cs
+++ b/sim/Statecraft.Sim/ContentLoader.cs
@@ -334,6 +334,8 @@ namespace Statecraft.Sim
("mobilization_cost_per_year", r.MobilizationCostPerYear), ("natural_increase_per_year", r.NaturalIncreasePerYear),
("capital_inflow_per_year", r.CapitalInflowPerYear), ("fx_crisis_food_per_year", r.FxCrisisFoodPerYear) })
Finite("rules.yaml", key, v);
+ Unit("rules.yaml", "appoint_stability_cost_other_party", r.AppointStabilityCostOtherParty);
+ Unit("rules.yaml", "appoint_stability_cost_same_party", r.AppointStabilityCostSameParty);
if (r.FxCrisisFoodPerYear > 0) throw new ContentException("rules.yaml", "fx_crisis_food_per_year", "must be <= 0 (a crisis cuts food imports)");
if (r.FxCrisisFoodPerYear < 0 && !indicators.Contains("food_supply")) throw new ContentException("rules.yaml", "fx_crisis_food_per_year", "needs a food_supply indicator in model.yaml");
foreach (var kv in r.InitialPopulation) Count("rules.yaml", $"initial_population.{kv.Key}", kv.Value);
diff --git a/sim/Statecraft.Sim/EffectsSystem.cs b/sim/Statecraft.Sim/EffectsSystem.cs
index 0da5e91b6..b178f79de 100644
--- a/sim/Statecraft.Sim/EffectsSystem.cs
+++ b/sim/Statecraft.Sim/EffectsSystem.cs
@@ -13,11 +13,12 @@ namespace Statecraft.Sim
foreach (var e in c.Effects) s.EffectContributions[e.Id] = 0;
}
- /// <summary>Competence (0.5 + competence/20) times budget factor. No office: 1.0.</summary>
+ /// <summary>Competence (0.5 + competence/20) of the office holder (player appointments included) times budget
+ /// factor. No office: 1.0.</summary>
public static double Multiplier(Content c, GameState s, string office)
{
if (office == "") return 1.0;
- var holder = Offices.Holder(c, office, s.Date);
+ var holder = Cabinet.Holder(c, s, office);
var competence = holder == null ? 0.5 : 0.5 + holder.Competence / 20.0;
return competence * BudgetFactor(s, office);
}
diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.cs
index cc81876f0..ac379b232 100644
--- a/sim/Statecraft.Sim/EventSystem.cs
+++ b/sim/Statecraft.Sim/EventSystem.cs
@@ -34,7 +34,7 @@ namespace Statecraft.Sim
{
s.FiredEvents.Add(e.Id);
s.PendingEvents.Add(e.Id);
- why.Add(new Cause("events", e.Id, 0, $"New: {Offices.Fill(c, e.Title, FillDate(e, s.Date))}"));
+ why.Add(new Cause("events", e.Id, 0, $"New: {Cabinet.Fill(c, s, e.Title, FillDate(e, s.Date))}"));
}
}
@@ -56,7 +56,7 @@ namespace Statecraft.Sim
{
s.PendingEvents.Remove(eventId);
var fillDate = FillDate(Get(c, eventId), s.Date);
- why.Add(new Cause("events", eventId, 0, $"{how}: {Offices.Fill(c, o.Text, fillDate)}"));
+ why.Add(new Cause("events", eventId, 0, $"{how}: {Cabinet.Fill(c, s, o.Text, fillDate)}"));
foreach (var fx in o.Effects)
{
var change = fx.Delta;
@@ -82,7 +82,7 @@ namespace Statecraft.Sim
foreach (var id in s.PendingEvents.ToList())
{
var e = Get(c, id);
- var minister = e.Office == "" ? null : Offices.Holder(c, e.Office, s.Date);
+ var minister = e.Office == "" ? null : Cabinet.Holder(c, s, e.Office);
var competence = (minister?.Competence ?? 5) / 10.0;
var anchored = s.Mode == Mode.Historical && e.Anchor == "hard" ? e.Options.FirstOrDefault(o => o.Historical) : null;
var option = anchored ?? (rng.NextDouble() < competence
@@ -94,5 +94,8 @@ namespace Statecraft.Sim
}
public static string Render(Content c, GameEvent e, DateTime date) => Offices.Fill(c, e.Text, FillDate(e, date));
+
+ /// <summary>Event text as the player sees it now: names follow the player's appointments.</summary>
+ public static string Render(Content c, GameState s, GameEvent e) => Cabinet.Fill(c, s, e.Text, FillDate(e, s.Date));
}
}
diff --git a/sim/Statecraft.Sim/GameState.cs b/sim/Statecraft.Sim/GameState.cs
index 32f62f16e..d776c0944 100644
--- a/sim/Statecraft.Sim/GameState.cs
+++ b/sim/Statecraft.Sim/GameState.cs
@@ -34,6 +34,9 @@ namespace Statecraft.Sim
public double Attention;
public SortedSet<string> FiredEvents = new SortedSet<string>(StringComparer.Ordinal);
public List<string> PendingEvents = new List<string>();
+ /// <summary>Player appointments by office id; valid while the government in AppointedUnder is in office (Cabinet).</summary>
+ public Dictionary<string, Appointment> Appointments = new Dictionary<string, Appointment>();
+ public string AppointedUnder = "";
public string? GameOver;
public double TotalPopulation => Population.Values.Sum();
@@ -50,6 +53,7 @@ namespace Statecraft.Sim
c.Population = new Dictionary<string, double>(Population);
c.FiredEvents = new SortedSet<string>(FiredEvents, StringComparer.Ordinal);
c.PendingEvents = new List<string>(PendingEvents);
+ c.Appointments = new Dictionary<string, Appointment>(Appointments);
return c;
}
@@ -75,6 +79,10 @@ namespace Statecraft.Sim
Num("mob", Mobilization); Num("stab", CoalitionStability); Num("att", Attention);
sb.Append("fired[").Append(string.Join(",", FiredEvents)).Append(']');
sb.Append("pending[").Append(string.Join(",", PendingEvents)).Append(']');
+ sb.Append("appt{");
+ foreach (var kv in Appointments.OrderBy(k => k.Key, StringComparer.Ordinal))
+ sb.Append(kv.Key).Append('=').Append(kv.Value.Person).Append('@').Append(kv.Value.From.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).Append(';');
+ sb.Append("}under=").Append(AppointedUnder).Append(';');
sb.Append("over=").Append(GameOver ?? "");
using var sha = SHA256.Create();
var bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(sb.ToString()));
diff --git a/sim/Statecraft.Sim/GoldenRun.cs b/sim/Statecraft.Sim/GoldenRun.cs
index 23d070055..f7b00e5e5 100644
--- a/sim/Statecraft.Sim/GoldenRun.cs
+++ b/sim/Statecraft.Sim/GoldenRun.cs
@@ -11,12 +11,12 @@ namespace Statecraft.Sim
/// <summary>Final hash of Play(content, Until1950). Changing it is a deliberate rules or content change:
/// update it, DeterminismTests and docs/determinism.md in the same commit and say why in the message.</summary>
- public const string Hash1950 = "43cc7773f890d8b79a7fc6a733d90b1314f452a91d766b0e7cf56aa8b9d43210";
+ public const string Hash1950 = "549b49cb2337e5cc9c3e626fbddd4bade1ff68f0e8c6b8cea83dc2a85386b19b";
public static readonly DateTime Until1950 = new DateTime(1950, 1, 1);
/// <summary>Final hash of Play(content, Until1952): the M3 content range (to 31 December 1951).</summary>
- public const string Hash1952 = "0359fa91b04d300084897a0d25b13dc92715d332363cfa2c285e6db740b83001";
+ public const string Hash1952 = "860928f23dd1658ef31c1d981e31595ce297853a51d6d7373b8a19b2037fd9e5";
public static readonly DateTime Until1952 = new DateTime(1952, 1, 1);
diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.cs
index 1f6d75cfd..f7a63ab98 100644
--- a/sim/Statecraft.Sim/Simulation.cs
+++ b/sim/Statecraft.Sim/Simulation.cs
@@ -63,6 +63,7 @@ namespace Statecraft.Sim
var turnStart = s.Date;
s.Date = next;
s.Turn++;
+ Cabinet.ExpireOnGovernmentChange(c, s, why);
AttentionSystem.Refill(c, s);
if (s.GameOver == null) EventSystem.Trigger(c, s, why, turnStart); // a game that just ended raises no new events
return new StepResult(s, why, rejected);
@@ -105,6 +106,8 @@ namespace Statecraft.Sim
return EventSystem.Choose(c, s, e.EventId, e.OptionId, why);
case SetMobilization m:
return SecuritySystem.SetMobilization(c, s, m.Level, why);
+ case Appoint a:
+ return Cabinet.Appoint(c, s, a.Office, a.Person, why);
case SecurityOrder o:
// long arithmetic: an extreme delta clamps to the ladder's end instead of wrapping around.
SecuritySystem.SetRung(c, s, (int)Math.Max(1L, Math.Min(5L, (long)s.Rung + o.Delta)), why);