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.

sim: later death dates on open terms; a holder's death ends an open term (#1) (#167)

agamrafaeli-instincta307444d4980
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ee67790ac..132dbe234 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,6 +34,7 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
authored model can replace a code-built one per unit type (docs/units.md).
### Changed
+- Later death dates can be recorded for people with open-ended terms in the latest authored government; explicit term ends still cannot pass the holder's death.
- Source Dov Yosef's food-supply and rationing responsibility in the Third Government from 8 October 1951,
replacing the unsupported vacancy (#2).
- The interface is restyled to the promo art (`promo/final/03`, `04`, `05`, `08`):
diff --git a/sim/Statecraft.Sim.Tests/EventTests.cs b/sim/Statecraft.Sim.Tests/EventTests.cs
index d22b6bf14..06a21e019 100644
--- a/sim/Statecraft.Sim.Tests/EventTests.cs
+++ b/sim/Statecraft.Sim.Tests/EventTests.cs
@@ -298,6 +298,18 @@ options:
Assert.Contains("1949-01-01", ex.Message);
}
+ [Fact]
+ public void PlaceholderOfficeLeftByAHoldersDeathFailsToLoad()
+ {
+ // def_two's finance term is open-ended; a death inside the latest government (from 1949-03-10) loads, but
+ // the office is then vacant from the date of death on, inside the open event window.
+ var people = Fixture.Files["people.yaml"].Replace(" name: Def Two\n", " name: Def Two\n died: 1949-06-01\n");
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["people.yaml"] = people },
+ new Dictionary<string, string> { ["shortage.yaml"] = Shortage })));
+ Assert.Equal("events[shortage].text", ex.Field);
+ Assert.Contains("office 'finance_minister' has no holder on 1949-06-01", ex.Message);
+ }
+
[Fact]
public void PlaceholderUncoveredAtWindowStartNamesThatDate()
{
diff --git a/sim/Statecraft.Sim.Tests/PeriodValidationTests.cs b/sim/Statecraft.Sim.Tests/PeriodValidationTests.cs
index addb6182a..2b4e536de 100644
--- a/sim/Statecraft.Sim.Tests/PeriodValidationTests.cs
+++ b/sim/Statecraft.Sim.Tests/PeriodValidationTests.cs
@@ -82,10 +82,62 @@ public class PeriodValidationTests
Assert.Contains("is abolished on 1949-01-01: give its budget line to the office that took over", ex.Message);
}
+ [Theory]
+ [InlineData("1949-03-09", false)]
+ [InlineData("1949-03-10", true)]
+ [InlineData("1973-12-01", true)]
+ public void OpenTermDeathIsCheckedAgainstLatestGovernmentStart(string death, bool loads)
+ {
+ var people = Fixture.Files["people.yaml"].Replace(" name: Pm One\n", " name: Pm One\n died: " + death + "\n");
+ var dir = Fixture.Write(new Dictionary<string, string> { ["people.yaml"] = people });
+ if (loads) Assert.Equal(DateTime.Parse(death), ContentLoader.Load(dir).People.Find(p => p.Id == "pm_one")!.Died);
+ else
+ {
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(dir));
+ Assert.Equal("people.yaml", ex.File);
+ Assert.Equal("people[pm_one].offices.prime_minister.to", ex.Field);
+ }
+ }
+
+ [Fact]
+ public void AHolderWhoDiesInTheLatestGovernmentLeavesAnOpenTermOnTheDateOfDeath()
+ {
+ // gov2 (the latest) starts 1949-03-10; Pm One's prime_minister term is open-ended.
+ var people = Fixture.Files["people.yaml"].Replace(" name: Pm One\n", " name: Pm One\n died: 1949-06-01\n");
+ var c = ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["people.yaml"] = people }));
+ Assert.Equal("pm_one", Offices.Holder(c, "prime_minister", new DateTime(1949, 5, 31))!.Id);
+ Assert.Null(Offices.Holder(c, "prime_minister", new DateTime(1949, 6, 1)));
+ Assert.Null(Offices.Holder(c, "prime_minister", new DateTime(1950, 1, 1)));
+ }
+
+ [Fact]
+ public void AnOpenTermStartingOnTheHoldersDeathIsALoadError()
+ {
+ // The later-death rule must not let an open term begin after its holder died.
+ var people = Fixture.Files["people.yaml"].Replace(" name: Def Two\n", " name: Def Two\n died: 1949-06-01\n")
+ .Replace(" from: 1949-01-01\n", " from: 1949-06-01\n");
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["people.yaml"] = people })));
+ Assert.Equal("people.yaml", ex.File);
+ Assert.Equal("people[def_two].offices.defense_minister.from", ex.Field);
+ Assert.Contains("must be before 1949-06-01, the date of death", ex.Message);
+ }
+
+ [Fact]
+ public void WithNoGovernmentsAnOpenTermAfterDeathIsStillALoadError()
+ {
+ var people = Fixture.Files["people.yaml"].Replace(" name: Pm One\n", " name: Pm One\n died: 1973-12-01\n");
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["people.yaml"] = people, ["governments.yaml"] = "governments: []\n" })));
+ Assert.Equal("people.yaml", ex.File);
+ Assert.Equal("people[pm_one].offices.prime_minister.to", ex.Field);
+ }
+
[Fact]
public void ATermRunningPastTheHoldersDeathIsALoadError()
{
- var ex = ValidationTests.Bad("people.yaml", " name: Def Two\n", " name: Def Two\n died: 1949-06-01\n");
+ var people = Fixture.Files["people.yaml"].Replace(" name: Def Two\n", " name: Def Two\n died: 1949-06-01\n")
+ .Replace(" from: 1949-01-01\n", " from: 1949-01-01\n to: 1949-06-02\n");
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["people.yaml"] = people })));
+ Assert.Equal("people.yaml", ex.File);
Assert.Equal("people[def_two].offices.defense_minister.to", ex.Field);
Assert.Contains("must be on or before 1949-06-01, the date of death", ex.Message);
}
diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.cs
index 92b5ffc02..6a67e1cbf 100644
--- a/sim/Statecraft.Sim/ContentLoader.cs
+++ b/sim/Statecraft.Sim/ContentLoader.cs
@@ -372,10 +372,17 @@ namespace Statecraft.Sim
foreach (var t in p.Offices.Where(t => t.Office == o.Id))
if (!t.To.HasValue || t.To.Value > o.Until!.Value)
throw new ContentException("people.yaml", $"people[{p.Id}].offices.{o.Id}.to", FormattableString.Invariant($"must be on or before {o.Until:yyyy-MM-dd}, when the office was abolished"));
+ // An open-ended term runs past the authored governments, so it only conflicts with a death before the latest
+ // government began (#167). With no governments, every open-ended term conflicts, as before.
+ var latestGovernmentStart = c.Governments.Count > 0 ? c.Governments.Max(g => g.From) : DateTime.MaxValue;
foreach (var p in c.People.Where(p => p.Died.HasValue))
foreach (var t in p.Offices)
- if (!t.To.HasValue || t.To.Value > p.Died!.Value)
+ {
+ if (t.From >= p.Died!.Value)
+ throw new ContentException("people.yaml", $"people[{p.Id}].offices.{t.Office}.from", FormattableString.Invariant($"must be before {p.Died:yyyy-MM-dd}, the date of death"));
+ if (t.To.HasValue ? t.To.Value > p.Died!.Value : p.Died!.Value < latestGovernmentStart)
throw new ContentException("people.yaml", $"people[{p.Id}].offices.{t.Office}.to", FormattableString.Invariant($"must be on or before {p.Died:yyyy-MM-dd}, the date of death"));
+ }
foreach (var p in c.People)
for (int i = 0; i < p.Offices.Count; i++)
for (int j = i + 1; j < p.Offices.Count; j++)
diff --git a/sim/Statecraft.Sim/EventRules.cs b/sim/Statecraft.Sim/EventRules.cs
index b4eb138a2..59ed9d8dd 100644
--- a/sim/Statecraft.Sim/EventRules.cs
+++ b/sim/Statecraft.Sim/EventRules.cs
@@ -109,7 +109,7 @@ namespace Statecraft.Sim
}
/// <summary>First date in [from, to) with nobody holding office, or null. Holders only change at term
- /// starts and ends, so checking those dates (plus from) covers the whole window.</summary>
+ /// starts and ends and at a holder's death, so checking those dates (plus from) covers the whole window.</summary>
static DateTime? FirstUncovered(Content c, string office, DateTime from, DateTime? to)
{
bool Inside(DateTime d) => d >= from && (to == null || d < to.Value);
@@ -120,6 +120,8 @@ namespace Statecraft.Sim
if (Inside(t.From)) points.Add(t.From);
if (t.To.HasValue && Inside(t.To.Value)) points.Add(t.To.Value);
}
+ foreach (var p in c.People.Where(p => p.Died.HasValue && Inside(p.Died.Value) && p.Offices.Any(t => t.Office == office)))
+ points.Add(p.Died!.Value);
// An open-ended window needs no extra check: a last finite term ends inside [from, ∞) and is caught above.
foreach (var d in points)
if (Offices.Holder(c, office, d) == null) return d;
diff --git a/sim/Statecraft.Sim/Offices.cs b/sim/Statecraft.Sim/Offices.cs
index 27a18970e..216027d22 100644
--- a/sim/Statecraft.Sim/Offices.cs
+++ b/sim/Statecraft.Sim/Offices.cs
@@ -9,8 +9,10 @@ namespace Statecraft.Sim
{
static bool In(DateTime d, DateTime from, DateTime? to) => d >= from && (to == null || d < to.Value);
+ /// <summary>The historical holder on date. A holder has left office from their date of death on, even when the
+ /// term is open-ended (the loader lets an open term outlive a death inside the latest government, #167).</summary>
public static Person? Holder(Content c, string office, DateTime date) =>
- c.People.FirstOrDefault(p => p.Offices.Any(t => t.Office == office && In(date, t.From, t.To)));
+ c.People.FirstOrDefault(p => (!p.Died.HasValue || date < p.Died.Value) && p.Offices.Any(t => t.Office == office && In(date, t.From, t.To)));
/// <summary>Party of the person on date: the party of a term held that day, else Person.Party.</summary>
public static string PartyOf(Content c, Person p, DateTime date) =>