A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
using System;
using System.Collections.Generic;
using System.Linq;
using Statecraft.Sim;
/// <summary>Every command kind has its touch-points (spec 2026-10-12 section 2.3): an Attention kind with a cost in the real
/// rules, CommandText (Step refuses an unknown type outright), the save format, and the scenario runner. The Unity order
/// queue is the fifth, guarded in Unity's own tests. A new Command type fails EveryCommandTypeHasASample until it is added
/// here, and then fails the others until every touch-point knows it.</summary>
public class CommandGuardTests
{
public static readonly Dictionary<Type, Command> Samples = new Dictionary<Type, Command>
{
[typeof(SetPolicy)] = new SetPolicy("rationing", 0.5),
[typeof(AllocateBudget)] = new AllocateBudget(new Dictionary<string, double> { ["finance_minister"] = 1.0 }),
[typeof(ChooseEventOption)] = new ChooseEventOption("drought", "a"),
[typeof(SetMobilization)] = new SetMobilization(0.5),
[typeof(SecurityOrder)] = new SecurityOrder(1),
[typeof(Appoint)] = new Appoint("prime_minister", "pm_one"),
[typeof(MapAction)] = new MapAction("housing", 1, 2),
[typeof(AssignWorkers)] = new AssignWorkers("tel_aviv", "job", 1),
[typeof(Train)] = new Train("tel_aviv", "halutz", 1),
[typeof(CancelTraining)] = new CancelTraining(1),
[typeof(ReturnCraftsmen)] = new ReturnCraftsmen("town_a", 1), // refused (the fixture has no craftsmen), like BuyArms(0)
[typeof(ReassignCraftsmen)] = new ReassignCraftsmen("town_a", 1), // refused (no qualified craftsmen)
[typeof(ReassignPioneers)] = new ReassignPioneers("town_a", "halutz", 1), // refused (no qualified halutzim)
[typeof(Reinforce)] = new Reinforce(1, "tel_aviv", 1),
[typeof(PioneerWork)] = new PioneerWork(1, "build_yishuv", "mefalsim"),
[typeof(StopWork)] = new StopWork(1),
[typeof(UnitOrder)] = new UnitOrder(1, "fortify"),
[typeof(StartProject)] = new StartProject("housing", "tel_aviv", 1, 0),
[typeof(CancelProject)] = new CancelProject(1),
[typeof(Move)] = new Move(1, 2, 0),
[typeof(BuyArms)] = new BuyArms(0), // refused (fewer than one unit), as GovernmentTests.ARefusedGddOrderRefundsItsAttention needs
[typeof(ConvertDollars)] = new ConvertDollars(0), // refused (below $1m), like BuyArms(0); R-MONEY-004
[typeof(ResolveCapture)] = new ResolveCapture("town_a", "raid"), // refused (nothing awaits a decision), like BuyArms(0)
[typeof(EndOccupation)] = new EndOccupation("town_a", "annex"), // refused (nothing awaits the end of an occupation)
};
static IEnumerable<Type> CommandTypes() =>
typeof(Command).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(Command)) && !t.IsAbstract);
[Fact]
public void EveryCommandTypeHasASample()
{
foreach (var t in CommandTypes()) Assert.True(Samples.ContainsKey(t), $"{t.Name} has no sample: add it, then its touch-points");
}
/// <summary>Every kind, the GDD ones included, is priced in the real rules since the cutover (the GDD kinds' costs are
/// design values, R-LOOP-005).</summary>
[Fact]
public void EveryCommandHasAnAttentionKindAndACostInTheRealRules()
{
var c = ContentLoader.Load(RealContentTests.ContentRoot());
foreach (var cmd in Samples.Values)
{
Assert.True(AttentionSystem.IsCommandKind(cmd.Kind), cmd.Kind);
Assert.True(c.Rules.AttentionCost.ContainsKey(cmd.Kind), cmd.Kind);
}
}
[Fact]
public void EveryCommandIsAcceptedByStepAndRoundTripsThroughASave()
{
var c = ContentLoader.Load(Fixture.Write());
foreach (var cmd in Samples.Values)
{
var g = GameSession.New(c, 1, Mode.Historical);
g.Step(new[] { cmd }); // CommandText throws on a type it does not know; the save throws on one it cannot write
var text = g.Save.Write();
var parsed = SaveGame.Parse(text);
Assert.Equal(text, parsed.Write());
Assert.Equal(cmd.GetType(), parsed.Turns.Single().Single().GetType());
}
}
[Fact]
public void TheScenarioRunnerKnowsEveryKind()
{
foreach (var cmd in Samples.Values)
{
Assert.Contains(cmd.Kind, Scenario.Kinds);
var fields = new Dictionary<string, object> { ["kind"] = cmd.Kind };
foreach (var f in Scenario.FieldsOf(cmd.Kind)) fields[f] = f == "shares" ? new Dictionary<object, object> { ["x"] = "1" } : (object)"1";
Assert.Equal(cmd.GetType(), Scenario.Build(fields).GetType());
}
}
[Fact]
public void EveryAttentionKindHasACommand() =>
Assert.Equal(AttentionSystem.CommandKinds.OrderBy(k => k, StringComparer.Ordinal), Samples.Values.Select(x => x.Kind).OrderBy(k => k, StringComparer.Ordinal));
// R-CITY-001 (#2733 item 2): ResolveCapture is a GDD order, so the legacy loop refuses it before charging (the legacy
// rules give it no price): the exact reason and the missing resolve_capture price (a charge would throw
// KeyNotFoundException) pin the guard; the hash compare shows nothing else changed. Attention is refilled at the end of
// every turn, so its compare cannot fail and pins nothing.
[Fact]
public void TheLegacyLoopRefusesResolveCaptureBeforeCharging()
{
var c = ContentLoader.Load(Fixture.Write()); // the legacy loop (a fixture since the cutover)
Assert.False(c.IsGdd);
var s = Simulation.NewGame(c, GoldenRun.Seed, Mode.Historical);
var r = Simulation.Step(c, s, new Command[] { new ResolveCapture("town_a", SettlementControl.Raid) });
Assert.Equal("That order is not available in this game", Assert.Single(r.Rejected).Reason);
var empty = Simulation.Step(c, s, Array.Empty<Command>());
Assert.Equal(empty.State.Attention, r.State.Attention);
Assert.Equal(empty.State.Hash(), r.State.Hash());
}
}