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: aliyah regions accept from/to (refs #57) (#332)

agamrafaeli-instinct471f6ea23089
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 26feb5ffc..d1babdca6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,8 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
loader refuses an unknown or self successor, one without `until`, one not in office at the handover, and one that
could not own the budget lines and policies it takes over (several holders, or a historical title). Nothing reads it
yet. Goldens unchanged.
+- Aliyah regions accept `from`/`to` (chapters spec 3.2, refs #57). The loader refuses a window that runs backwards or is
+ empty, and an aliyah period that counts a region outside its window. With no dates nothing changes (goldens unchanged).
- Map: today's name of a 1948 locality by tap and in the info panel. A tap on a locality pill toggles its tooltip, a tap
elsewhere hides it, and a mouse still hovers as before. The info panel lists the selected hex's 1948 localities with
today's name where a living place carries on, by the same rule as the tooltip. Keyboard players reach the panel list
diff --git a/sim/Statecraft.Sim.Tests/RegionWindowTests.cs b/sim/Statecraft.Sim.Tests/RegionWindowTests.cs
new file mode 100644
index 000000000..0ac716f96
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/RegionWindowTests.cs
@@ -0,0 +1,42 @@
+using System.Collections.Generic;
+using Statecraft.Sim;
+
+/// <summary>Aliyah region windows (#57): the loader checks a period against the windows of the regions it counts.</summary>
+public class RegionWindowTests
+{
+ static Content Load(string regions, string series = "")
+ {
+ var a = Fixture.Files["aliyah.yaml"].Replace(" - { id: asia, name: Asia }\n", regions);
+ if (series != "") a = a.Replace("series:\n", "series:\n" + series);
+ return ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["aliyah.yaml"] = a }));
+ }
+
+ static void Refused(string regions, string expected, string series = "") =>
+ Assert.Contains(expected, Assert.Throws<ContentException>(() => Load(regions, series)).Message);
+
+ [Fact]
+ public void ARegionWithNoWindowBehavesAsBefore() => Assert.Equal(2, Load(" - { id: asia, name: Asia }\n").Regions.Count);
+
+ [Fact]
+ public void AWindowThatCoversThePeriodIsAccepted()
+ {
+ var c = Load(" - { id: asia, name: Asia, from: 1948-05-15, to: 1949-01-01 }\n");
+ Assert.Equal(new System.DateTime(1949, 1, 1), c.Regions[1].To);
+ }
+
+ [Theory]
+ [InlineData("1949-01-01")] // backwards
+ [InlineData("1950-01-01")] // empty: to is exclusive
+ public void AWindowThatRunsBackwardsOrIsEmptyIsRefused(string to) =>
+ // A region no period counts, so only the window's own check can refuse it.
+ Refused($" - {{ id: asia, name: Asia }}\n - {{ id: africa, name: Africa, from: 1950-01-01, to: {to} }}\n", "aliyah.yaml: regions[africa].to");
+
+ [Fact] public void ARegionThatEndsInsideThePeriodIsRefused() =>
+ Refused(" - { id: asia, name: Asia, to: 1948-12-31 }\n", "aliyah.yaml: series[0].origins.asia: region 'asia' does not exist for the whole period");
+
+ [Fact] public void ARegionThatBeginsInsideThePeriodIsRefused() =>
+ Refused(" - { id: asia, name: Asia, from: 1948-06-01 }\n", "does not exist for the whole period");
+
+ [Fact] public void ThePeriodsLastDayIsInclusiveSoToMayBeTheDayAfter() =>
+ Assert.NotNull(Load(" - { id: asia, name: Asia, to: 1949-01-01 }\n"));
+}
diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.cs
index b0b51a3ab..17bdef307 100644
--- a/sim/Statecraft.Sim/Content.cs
+++ b/sim/Statecraft.Sim/Content.cs
@@ -333,6 +333,10 @@ namespace Statecraft.Sim
public string Id { get; set; } = "";
/// <summary>Display name shown to the player (Cause text); required.</summary>
public string Name { get; set; } = "";
+ /// <summary>First day the origin group exists (inclusive); null when it exists from the start (chapters spec 3.2).</summary>
+ public DateTime? From { get; set; }
+ /// <summary>First day it no longer exists (exclusive, like every window); null while it still does.</summary>
+ public DateTime? To { get; set; }
}
public sealed class AliyahPeriod
diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.cs
index 11c0130b3..1de345277 100644
--- a/sim/Statecraft.Sim/ContentLoader.cs
+++ b/sim/Statecraft.Sim/ContentLoader.cs
@@ -746,6 +746,8 @@ namespace Statecraft.Sim
ValidateRules(c, c.Rules, "rules.yaml", indicators, offices, historicalOffices);
foreach (var kv in c.EraRules)
ValidateRules(c, kv.Value, "rules/" + kv.Key + ".yaml", indicators, offices, historicalOffices);
+ foreach (var g in c.Regions.Where(g => g.From.HasValue && g.To.HasValue && g.To.Value <= g.From.Value))
+ throw new ContentException("aliyah.yaml", $"regions[{g.Id}].to", FormattableString.Invariant($"must be after from ({g.From:yyyy-MM-dd})"));
for (int i = 0; i < c.Aliyah.Count; i++)
{
var a = c.Aliyah[i]; var path = FormattableString.Invariant($"series[{i}]");
@@ -754,6 +756,10 @@ namespace Statecraft.Sim
foreach (var kv in a.Origins)
{
if (c.Regions.All(g => g.Id != kv.Key)) throw new ContentException("aliyah.yaml", $"{path}.origins.{kv.Key}", $"unknown region '{kv.Key}' (add it to regions with a name)");
+ var region = c.Regions.First(g => g.Id == kv.Key);
+ // A period's dates are inclusive, a region's window is [from, to): the period covers [a.From, a.To + 1 day).
+ if (!Window.Covers(region.From, region.To, a.From, a.To.AddDays(1)))
+ throw new ContentException("aliyah.yaml", $"{path}.origins.{kv.Key}", $"region '{kv.Key}' does not exist for the whole period (its window is {(region.From.HasValue ? region.From.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) : "the start")} to {(region.To.HasValue ? region.To.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) : "open")})");
Count("aliyah.yaml", $"{path}.origins.{kv.Key}", kv.Value);
}
}