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): a defeated vote is charged and reported as a politics cause, not a rejection
eyalgolancf814eee7005
diff --git a/sim/Statecraft.Sim.Tests/SimTests.cs b/sim/Statecraft.Sim.Tests/SimTests.csindex 44330b49b..c6889126b 100644--- a/sim/Statecraft.Sim.Tests/SimTests.cs+++ b/sim/Statecraft.Sim.Tests/SimTests.cs@@ -192,7 +192,47 @@ options:var s0 = Simulation.NewGame(C, 42, Mode.Historical);s0.Date = new DateTime(1949, 3, 1); // House sits, gov1 (alpha, 4 of 10) has no majorityvar r = Simulation.Step(C, s0, new Command[] { new AllocateBudget(new Dictionary<string, double> { ["finance_minister"] = 1.0 }) });- Assert.Equal("House voted the budget down", r.Rejected.Single().Reason);+ Assert.Empty(r.Rejected); // a vote held and lost is an outcome, not a rejection+ Assert.Contains(r.Why, w => w.System == "politics" && w.Target == "budget" && w.Message == "House voted the budget down");+ }++ // ---- Final fix 3: a defeated vote is an outcome, not a rejection ----++ [Fact]+ public void DefeatedPolicyVoteIsChargedAndReportedAsACause()+ {+ var s0 = Simulation.NewGame(C, 42, Mode.Historical);+ s0.Date = new DateTime(1949, 3, 1); // House sits, gov1 (alpha, 4 of 10) has no majority: every vote fails+ s0.CoalitionStability = 0.3;+ s0.Rung = 1; s0.Attention = 2; // each set_policy costs 1: two afford, the third cannot+ var cmd = new SetPolicy("rationing", 0.9);+ var r = Simulation.Step(C, s0, new Command[] { cmd, cmd, cmd });+ Assert.Equal(new[] { "Not enough attention (need 1.0, have 0.0)" }, r.Rejected.Select(x => x.Reason));+ Assert.Equal(0.0, r.State.Policies["rationing"]);+ Assert.Equal(2, r.Why.Count(w => w.System == "politics" && w.Target == "rationing" && w.Message == "House voted down rationing 0.90"));+ }++ [Theory]+ [InlineData(1UL)] [InlineData(2UL)] [InlineData(3UL)] [InlineData(4UL)] [InlineData(5UL)]+ public void RepeatedPolicyVotesCostAttentionWhetherTheyPassOrFail(ulong seed)+ {+ var s0 = Simulation.NewGame(C, seed, Mode.Historical); // council: alpha holds 3 of 5+ s0.CoalitionStability = 0.3; // below 0.5: each vote passes with probability 0.6+ s0.Rung = 1; s0.Attention = 2;+ var cmd = new SetPolicy("rationing", 0.9);+ var r = Simulation.Step(C, s0, new Command[] { cmd, cmd, cmd });+ Assert.Equal(new[] { "Not enough attention (need 1.0, have 0.0)" }, r.Rejected.Select(x => x.Reason));+ }++ [Fact]+ public void ValidationFailureIsStillRefunded()+ {+ var s0 = Simulation.NewGame(C, 42, Mode.Historical);+ s0.Rung = 1; s0.Attention = 1;+ var r = Simulation.Step(C, s0, new Command[] { new SetPolicy("no_such_policy", 0.5), new SetPolicy("rationing", 0.5) });+ Assert.Equal(new[] { "Unknown policy 'no_such_policy'" }, r.Rejected.Select(x => x.Reason));+ Assert.Equal(0.5, r.State.Policies["rationing"]);+ Assert.Equal(s0.RngState, r.State.RngState);}[Fact]diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.csindex 1aff36f64..1f6d75cfd 100644--- a/sim/Statecraft.Sim/Simulation.cs+++ b/sim/Statecraft.Sim/Simulation.cs@@ -22,8 +22,9 @@ namespace Statecraft.Simreturn s;}- /// <summary>Applies commands in order (each pays attention first; a rejected command is refunded and carries a- /// reason), delegates unanswered events, then advances one turn. Never mutates <paramref name="state"/>.</summary>+ /// <summary>Applies commands in order (each pays attention first; a command that fails validation is refunded+ /// and carries a reason; a vote that is held and lost is charged and reported as a politics cause), delegates+ /// unanswered events, then advances one turn. Never mutates <paramref name="state"/>.</summary>public static StepResult Step(Content c, GameState state, IReadOnlyList<Command> commands){if (c == null) throw new ArgumentNullException(nameof(c));@@ -67,8 +68,9 @@ namespace Statecraft.Simreturn new StepResult(s, why, rejected);}- /// <summary>Returns null on success, or the reason the command was rejected. A rejected command leaves the- /// state as it found it (attention is refunded by the caller).</summary>+ /// <summary>Returns null when the command was carried out (a lost vote counts: it consumes the RNG draw and is+ /// reported as a politics cause), or the reason it failed validation. A command that fails validation leaves+ /// the state as it found it (attention is refunded by the caller).</summary>static string? Execute(Content c, GameState s, Command cmd, List<Cause> why){switch (cmd)@@ -78,7 +80,11 @@ namespace Statecraft.Simif (!(p.Level >= 0 && p.Level <= 1)) return "Policy level must be between 0 and 1";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";+ if (!PassVote(c, s))+ {+ why.Add(new Cause("politics", p.Policy, 0, FormattableString.Invariant($"{legislature.Body} voted down {p.Policy} {p.Level:0.00}")));+ return null;+ }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;@@ -91,7 +97,7 @@ namespace Statecraft.Simif (PoliticsSystem.BudgetNeedsVote(c, s.Date) && !PassVote(c, s)){s.Budget = old;- return $"{Offices.Legislature(c, s.Date)!.Body} voted the budget down";+ why.Add(new Cause("politics", "budget", 0, $"{Offices.Legislature(c, s.Date)!.Body} voted the budget down"));}return null;}