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.

fix(sim): no '-+0.00' in signed deltas; hard anchors exempt from the per-turn cap; document late fire (R1, R2, R5)

eyalgolan526c859055dc
diff --git a/sim/Statecraft.Sim.Tests/EventTests.cs b/sim/Statecraft.Sim.Tests/EventTests.cs
index 256548433..9bc163393 100644
--- a/sim/Statecraft.Sim.Tests/EventTests.cs
+++ b/sim/Statecraft.Sim.Tests/EventTests.cs
@@ -501,6 +501,33 @@ options:
Assert.Equal(new[] { "a", "b", "z" }, s.PendingEvents); // hard first for the cap, then the usual order
}
+ [Fact]
+ public void AllHardAnchorsFireEvenBeyondTheCap()
+ {
+ var c = ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string>
+ {
+ ["a.yaml"] = Simple("a", "soft", "1948-05-15"),
+ ["h1.yaml"] = Simple("h1", "hard", "1948-05-15"),
+ ["h2.yaml"] = Simple("h2", "hard", "1948-05-15"),
+ ["h3.yaml"] = Simple("h3", "hard", "1948-05-15"),
+ ["h4.yaml"] = Simple("h4", "hard", "1948-05-15"),
+ }));
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ Assert.Equal(new[] { "h1", "h2", "h3", "h4" }, s.PendingEvents); // the soft one finds no slot left
+ }
+
+ [Fact]
+ public void TinyNegativeEffectNeverRendersAsMinusPlusZero()
+ {
+ var ev = Shortage.Replace("delta: -10", "delta: -0.0001");
+ var c = Load(new Dictionary<string, string> { ["shortage.yaml"] = ev });
+ var s = State(c, new DateTime(1948, 6, 1)); var why = new List<Cause>();
+ EventSystem.Trigger(c, s, why);
+ Assert.Null(EventSystem.Choose(c, s, "shortage", "import", why));
+ Assert.Contains(why, w => w.Message == "fx_reserves +0.00 (shortage/import)");
+ Assert.DoesNotContain(why, w => w.Message.Contains("-+"));
+ }
+
[Fact]
public void EventFiredAfterItsWindowNamesTheInWindowHolder()
{
diff --git a/sim/Statecraft.Sim/EconomySystem.cs b/sim/Statecraft.Sim/EconomySystem.cs
index b5c4bd82b..e0c15559f 100644
--- a/sim/Statecraft.Sim/EconomySystem.cs
+++ b/sim/Statecraft.Sim/EconomySystem.cs
@@ -23,7 +23,7 @@ namespace Statecraft.Sim
var mobilization = r.MobilizationCostPerYear * s.Mobilization * yearFraction;
s.Treasury += revenue - spending - mobilization;
why.Add(new Cause("economy", "treasury", revenue - spending - mobilization,
- FormattableString.Invariant($"treasury {revenue - spending - mobilization:+0.00;-0.00} (tax {revenue:0.00}, spending {spending:0.00}, reserve call-up {mobilization:0.00})")));
+ FormattableString.Invariant($"treasury {revenue - spending - mobilization:+0.00;-0.00;+0.00} (tax {revenue:0.00}, spending {spending:0.00}, reserve call-up {mobilization:0.00})")));
if (s.Treasury < 0)
{
s.Debt += -s.Treasury;
@@ -34,7 +34,7 @@ namespace Statecraft.Sim
var exports = r.ExportsPerYear * yearFraction;
var imports = r.ImportsPerCapitaPerYear * pop * yearFraction;
s.FxReserves += exports - imports;
- why.Add(new Cause("economy", "fx_reserves", exports - imports, FormattableString.Invariant($"foreign currency {exports - imports:+0.00;-0.00} (exports {exports:0.00}, imports {imports:0.00})")));
+ why.Add(new Cause("economy", "fx_reserves", exports - imports, FormattableString.Invariant($"foreign currency {exports - imports:+0.00;-0.00;+0.00} (exports {exports:0.00}, imports {imports:0.00})")));
bool on = s.ActiveSituations.Contains(FxCrisis);
if (!on && s.FxReserves < 0) { s.ActiveSituations.Add(FxCrisis); why.Add(new Cause("economy", FxCrisis, 1, "Foreign currency reserves are exhausted")); }
diff --git a/sim/Statecraft.Sim/EffectsSystem.cs b/sim/Statecraft.Sim/EffectsSystem.cs
index c95ac7062..f58ebd6b1 100644
--- a/sim/Statecraft.Sim/EffectsSystem.cs
+++ b/sim/Statecraft.Sim/EffectsSystem.cs
@@ -53,7 +53,7 @@ namespace Statecraft.Sim
if (Math.Abs(delta) <= 1e-9) continue;
var ids = c.Effects.Where(e => e.Target == i.Id && moved.Contains(e.Id)).Select(e => e.Id).ToList();
var from = ids.Count > 0 ? $" ({string.Join(", ", ids)})" : "";
- why.Add(new Cause("effects", i.Id, delta, FormattableString.Invariant($"{i.Id} {delta:+0.000;-0.000}{from}")));
+ why.Add(new Cause("effects", i.Id, delta, FormattableString.Invariant($"{i.Id} {delta:+0.000;-0.000;+0.000}{from}")));
}
UpdateSituations(c, s, why);
}
diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.cs
index 84afb37c9..e2d8538dd 100644
--- a/sim/Statecraft.Sim/EventSystem.cs
+++ b/sim/Statecraft.Sim/EventSystem.cs
@@ -12,8 +12,12 @@ namespace Statecraft.Sim
/// <summary>Fires every unfired event whose window [From, To) overlaps the turn just played,
/// [<paramref name="turnStart"/>, s.Date), or contains s.Date; <paramref name="turnStart"/> defaults to s.Date
- /// (game start). At most MaxNewPerTurn fire: hard anchors claim the slots first, then the usual order
- /// (From, then id). The fired events keep the usual order.</summary>
+ /// (game start). Every eligible hard anchor fires; the MaxNewPerTurn cap applies only to the other events,
+ /// which fill the slots that remain (max(0, cap - hard count)) in the usual order (From, then id). The fired
+ /// events keep the usual order.
+ /// Late fire: an event whose window overlapped the turn just played can fire after its window has ended; its
+ /// conditions are evaluated at the end of the turn, and its text is filled at the last in-window day
+ /// (<see cref="FillDate"/>).</summary>
public static void Trigger(Content c, GameState s, List<Cause> why, DateTime? turnStart = null)
{
var start = turnStart ?? s.Date;
@@ -23,7 +27,9 @@ namespace Statecraft.Sim
&& (!k.Max.HasValue || s.Indicators[k.Indicator] <= k.Max.Value)))
.OrderBy(e => e.From).ThenBy(e => e.Id, StringComparer.Ordinal)
.ToList();
- var chosen = new HashSet<string>(eligible.OrderBy(e => e.Anchor == "hard" ? 0 : 1).Take(MaxNewPerTurn).Select(e => e.Id));
+ var hardCount = eligible.Count(e => e.Anchor == "hard");
+ var chosen = new HashSet<string>(eligible.Where(e => e.Anchor == "hard")
+ .Concat(eligible.Where(e => e.Anchor != "hard").Take(Math.Max(0, MaxNewPerTurn - hardCount))).Select(e => e.Id));
foreach (var e in eligible.Where(e => chosen.Contains(e.Id)))
{
s.FiredEvents.Add(e.Id);
@@ -66,7 +72,7 @@ namespace Statecraft.Sim
s.Indicators[ind.Id] = newLevel;
change = newLevel - level;
}
- why.Add(new Cause("events", fx.Target, change, FormattableString.Invariant($"{fx.Target} {change:+0.00;-0.00} ({eventId}/{o.Id})")));
+ why.Add(new Cause("events", fx.Target, change, FormattableString.Invariant($"{fx.Target} {change:+0.00;-0.00;+0.00} ({eventId}/{o.Id})")));
}
foreach (var kv in o.SetPolicy.OrderBy(k => k.Key, StringComparer.Ordinal))
{
diff --git a/sim/Statecraft.Sim/PoliticsSystem.cs b/sim/Statecraft.Sim/PoliticsSystem.cs
index cf4947401..4a95ab1f5 100644
--- a/sim/Statecraft.Sim/PoliticsSystem.cs
+++ b/sim/Statecraft.Sim/PoliticsSystem.cs
@@ -36,7 +36,7 @@ namespace Statecraft.Sim
var old = s.CoalitionStability;
s.CoalitionStability = old + (EffectsSystem.Approval(c, s) - old) * Math.Min(1.0, yearFraction * 2);
if (Math.Abs(s.CoalitionStability - old) > 1e-9)
- why.Add(new Cause("politics", "coalition_stability", s.CoalitionStability - old, FormattableString.Invariant($"coalition stability {s.CoalitionStability - old:+0.00;-0.00} (public approval)")));
+ why.Add(new Cause("politics", "coalition_stability", s.CoalitionStability - old, FormattableString.Invariant($"coalition stability {s.CoalitionStability - old:+0.00;-0.00;+0.00} (public approval)")));
if (s.CoalitionStability < CollapseBelow && s.GameOver == null)
{
s.GameOver = "coalition_collapse";