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): clearer policy rejection with no legislature; government change lists party names (M6)

eyalgolanbcc615ad61dd
diff --git a/sim/Statecraft.Sim.Tests/PoliticsTests.cs b/sim/Statecraft.Sim.Tests/PoliticsTests.cs
index e5eaf2730..8ce0884b4 100644
--- a/sim/Statecraft.Sim.Tests/PoliticsTests.cs
+++ b/sim/Statecraft.Sim.Tests/PoliticsTests.cs
@@ -54,4 +54,25 @@ public class PoliticsTests
Assert.Contains(why, w => w.Target == "house");
Assert.Contains(why, w => w.Target == "gov2");
}
+
+ [Fact]
+ public void PolicyRejectedWithNoLegislatureSaysSo()
+ {
+ var c = ContentLoader.Load(Fixture.Write(new System.Collections.Generic.Dictionary<string, string>
+ {
+ ["legislatures.yaml"] = Fixture.Files["legislatures.yaml"].Replace("from: 1948-05-14", "from: 1948-06-01"),
+ }));
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ Assert.Null(Offices.Legislature(c, s.Date));
+ var r = Simulation.Step(c, s, new Command[] { new SetPolicy("rationing", 1.0) });
+ Assert.Equal("No legislature is sitting", Assert.Single(r.Rejected).Reason);
+ }
+
+ [Fact]
+ public void GovernmentChangeNamesThePartiesByName()
+ {
+ var why = new System.Collections.Generic.List<Cause>();
+ PoliticsSystem.ReportChanges(C, new System.DateTime(1949, 3, 1), new System.DateTime(1949, 3, 15), why);
+ Assert.Contains(why, w => w.Message == "Government Two took office (Alpha, Beta)");
+ }
}
diff --git a/sim/Statecraft.Sim/PoliticsSystem.cs b/sim/Statecraft.Sim/PoliticsSystem.cs
index 33f0c34ba..cf4947401 100644
--- a/sim/Statecraft.Sim/PoliticsSystem.cs
+++ b/sim/Statecraft.Sim/PoliticsSystem.cs
@@ -55,7 +55,7 @@ namespace Statecraft.Sim
}
var g0 = Offices.Government(c, from); var g1 = Offices.Government(c, to);
if (g1 != null && g1 != g0)
- why.Add(new Cause("politics", g1.Id, 0, $"{g1.Name} took office ({string.Join(", ", g1.Coalition)})"));
+ why.Add(new Cause("politics", g1.Id, 0, $"{g1.Name} took office ({string.Join(", ", g1.Coalition.Select(id => c.Parties.First(p => p.Id == id).Name))})"));
}
}
}
diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.cs
index fb9501d8b..1aff36f64 100644
--- a/sim/Statecraft.Sim/Simulation.cs
+++ b/sim/Statecraft.Sim/Simulation.cs
@@ -76,7 +76,9 @@ namespace Statecraft.Sim
case SetPolicy p:
if (c.Policies.All(x => x.Id != p.Policy)) return $"Unknown policy '{p.Policy}'";
if (!(p.Level >= 0 && p.Level <= 1)) return "Policy level must be between 0 and 1";
- if (!PassVote(c, s)) return $"{Offices.Legislature(c, s.Date)?.Body ?? "The legislature"} voted it down";
+ var legislature = Offices.Legislature(c, s.Date);
+ if (legislature == null) return "No legislature is sitting";
+ if (!PassVote(c, s)) return $"{legislature.Body} voted it down";
s.Policies[p.Policy] = p.Level;
why.Add(new Cause("policy", p.Policy, p.Level, FormattableString.Invariant($"{p.Policy} set to {p.Level:0.00}")));
return null;