A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
fix(content): event condition bounds must be finite, within [0,1], and min <= max
eyalgolan94dcc11fc39b
diff --git a/sim/Statecraft.Sim.Tests/ValidationTests.cs b/sim/Statecraft.Sim.Tests/ValidationTests.csindex cee722977..910506ec7 100644--- a/sim/Statecraft.Sim.Tests/ValidationTests.cs+++ b/sim/Statecraft.Sim.Tests/ValidationTests.cs@@ -168,6 +168,26 @@ status: draftAssert.Equal(field, ex.Field);}+ // Final fix 3 M6: event condition bounds are finite, within [0,1], and min <= max.+ [Theory]+ [InlineData("max: 0.9", "max: .inf", "events[drought].conditions.food_supply.max", "must be a finite number")]+ [InlineData("max: 0.9", "max: 1.5", "events[drought].conditions.food_supply.max", "must be a number from 0 to 1")]+ [InlineData("max: 0.9", "max: -0.1", "events[drought].conditions.food_supply.max", "must be a number from 0 to 1")]+ [InlineData("max: 0.9", "min: -0.5\n max: 0.9", "events[drought].conditions.food_supply.min", "must be a number from 0 to 1")]+ [InlineData("max: 0.9", "min: .nan\n max: 0.9", "events[drought].conditions.food_supply.min", "must be a finite number")]+ [InlineData("max: 0.9", "min: 0.95\n max: 0.9", "events[drought].conditions.food_supply.min", "must not exceed max")]+ public void EventConditionBoundsAreCheckedAtLoad(string from, string to, string field, string message)+ {+ var ex = Bad("events/drought.yaml", from, to);+ Assert.Equal("events/drought.yaml", ex.File);+ Assert.Equal(field, ex.Field);+ Assert.EndsWith(message, ex.Message);+ }++ [Fact]+ public void EqualConditionBoundsAreAllowed() =>+ ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string> { ["drought.yaml"] = Event.Replace("max: 0.9", "min: 0.9\n max: 0.9") }));+[Fact]public void EqualMobilizationFloorsAreAllowed() =>ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["rules.yaml"] = Fixture.Files["rules.yaml"].Replace("[0.02, 0.05, 0.15, 0.4, 0.8]", "[0.05, 0.05, 0.15, 0.4, 0.8]") }));diff --git a/sim/Statecraft.Sim/EventRules.cs b/sim/Statecraft.Sim/EventRules.csindex 95a4a5162..5c2916126 100644--- a/sim/Statecraft.Sim/EventRules.cs+++ b/sim/Statecraft.Sim/EventRules.cs@@ -28,8 +28,10 @@ namespace Statecraft.Simforeach (var cond in e.Conditions){if (!indicators.Contains(cond.Indicator)) throw new ContentException(e.File, F($"conditions.{cond.Indicator}"), "unknown indicator");- if (cond.Min.HasValue) ContentLoader.Finite(e.File, F($"conditions.{cond.Indicator}.min"), cond.Min.Value);- if (cond.Max.HasValue) ContentLoader.Finite(e.File, F($"conditions.{cond.Indicator}.max"), cond.Max.Value);+ // Indicators live in [0,1], so a bound outside it (or min above max) could never be met.+ if (cond.Min.HasValue) { ContentLoader.Finite(e.File, F($"conditions.{cond.Indicator}.min"), cond.Min.Value); ContentLoader.Unit(e.File, F($"conditions.{cond.Indicator}.min"), cond.Min.Value); }+ if (cond.Max.HasValue) { ContentLoader.Finite(e.File, F($"conditions.{cond.Indicator}.max"), cond.Max.Value); ContentLoader.Unit(e.File, F($"conditions.{cond.Indicator}.max"), cond.Max.Value); }+ if (cond.Min > cond.Max) throw new ContentException(e.File, F($"conditions.{cond.Indicator}.min"), "must not exceed max");}if (e.Options.Count == 0) throw new ContentException(e.File, F("options"), "at least one option required");if (e.Options.Count(o => o.Historical) > 1) throw new ContentException(e.File, F("options"), "at most one option can be historical");