A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
feat(sim): craftsman orders refuse with a reason on a Historical ledger game (Refs #1725, Refs #2476) (#2986)
Eyal Golan3fe9a1b5644d
diff --git a/changelog.d/1725-craftsmen-refuse.md b/changelog.d/1725-craftsmen-refuse.mdnew file mode 100644index 000000000..952864fe7--- /dev/null+++ b/changelog.d/1725-craftsmen-refuse.md@@ -0,0 +1,3 @@+- GDD 0.3 starting population (Refs #1725): on the inactive dark start's Historical ledger, the ReturnCraftsmen and+ ReassignCraftsmen orders are refused with a plain reason until #2476 makes craftsmen exist there, instead of+ stopping with an error. No new-game wiring, so there is no change in the game.diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex 001b15dcc..72882f024 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -218,11 +218,11 @@ Owner ruling "Two-way, keep training" and its three answers (23 October 2026, #1R-QUAL-001: Each city keeps its qualified civilians (`City.Qualified`): qualified craftsmen, qualified halutz groups (each with the turns of service it had, ascending) and qualified veteran pioneers. They are part of the city's civilians, not in addition to them, so a qualified civilian is an ordinary civilian for jobs (R-CITY-001, R-CITY-009), housing (R-HOUSE-003), income (R-CITY-002, the ordinary rate, not R-CRAFT-002's) and training (R-TRAIN-001), and keeps the qualification for reassignment (owner ruling 2). The sum of the three never exceeds the city's civilians.-R-QUAL-002: `ReturnCraftsmen(city, n)` turns `n` of the city's craftsmen into civilians and qualified craftsmen, at once and with no Money. Employed is unchanged. It is refused, with the state unchanged and the Attention refunded, when the city is unknown, `n` is below 1 or `n` is above the city's craftsmen.+R-QUAL-002: `ReturnCraftsmen(city, n)` turns `n` of the city's craftsmen into civilians and qualified craftsmen, at once and with no Money. Employed is unchanged. It is refused, with the state unchanged and the Attention refunded, when the city is unknown, `n` is below 1 or `n` is above the city's craftsmen. On a game with an initialized Historical ledger (the dark start, R-POP-002; #1725) the order is refused, after the unknown city and the count below 1, with "Craftsmen are not on the population ledger yet (#2476)", the state unchanged and nothing thrown, until #2476 makes craftsmen exist there: the Historical start has none, and the craftsman course is refused until then (R-TRAIN-001) (owner, 9 November 2026: "Refuse for now (Recommended)"). A synthetic or Open ledger is still refused (R-POP-002). This internal English text gets its Hebrew with the UI wiring PR.R-QUAL-003: `UnitOrder(unit, return_civilian)` (the unit card's "Return", an order with no hex) takes an idle halutz or veteran pioneer unit off the map, at once and with no Money. It joins the nearest city (hex distance to the settlement hex, ties by ordinal city id, R-UNIT-005's rule) as one civilian and one qualified halutz group with the unit's service, or one qualified veteran pioneer. A halutz's partial service toward veteran is kept (owner ruling 3). It is refused, state unchanged, for an unknown unit, a unit that is not a halutz or veteran ("Only a pioneer unit takes that order") and a unit at work on a site or corridor segment ("That unit is at work; stop the work first").-R-QUAL-004: `ReassignCraftsmen(city, n)` turns `n` of the city's qualified craftsmen, who have no job, into craftsmen again, at once, with no Money and no training. It is refused, state unchanged, when the city is unknown, `n` is below 1, `n` is above its qualified craftsmen or `n` is above its civilians without work (R-TRAIN-001's Idle; owner, 24 October 2026: "Accept all as built", https://github.com/eyalgolan/statecraft-israel/issues/1511#issuecomment-6375597377: the check counts all the city's idle civilians). Queued, it counts in full against the city's civilians without work as a queued `Train` does (R-TRAIN-001), so the orders are accepted in any order, and it counts against `Cities.MaxWorkers` (R-CITY-001) for the turn it is queued: its craftsmen stay in the city, but if the job order runs first they are already in work.+R-QUAL-004: `ReassignCraftsmen(city, n)` turns `n` of the city's qualified craftsmen, who have no job, into craftsmen again, at once, with no Money and no training. It is refused, state unchanged, when the city is unknown, `n` is below 1, `n` is above its qualified craftsmen or `n` is above its civilians without work (R-TRAIN-001's Idle; owner, 24 October 2026: "Accept all as built", https://github.com/eyalgolan/statecraft-israel/issues/1511#issuecomment-6375597377: the check counts all the city's idle civilians). Queued, it counts in full against the city's civilians without work as a queued `Train` does (R-TRAIN-001), so the orders are accepted in any order, and it counts against `Cities.MaxWorkers` (R-CITY-001) for the turn it is queued: its craftsmen stay in the city, but if the job order runs first they are already in work. On a game with an initialized Historical ledger it is refused as R-QUAL-002 sets, with the same reason (owner, 9 November 2026: "Refuse for now (Recommended)").R-QUAL-005: `ReassignPioneers(city, track, n)` (`track` is `halutz` or `veteran_halutz`) turns `n` of the city's qualified halutz groups or veteran pioneers, who have no job, into `n` units at the city's settlement hex, as R-TRAIN-003 places them, taking the next ids in turn: a halutz keeps its service and a veteran comes back a veteran with `veteran_halutz_service`, and the halutz groups with the most service come back first (owner, 24 October 2026: "Accept all as built", https://github.com/eyalgolan/statecraft-israel/issues/1511#issuecomment-6375597377). Refusals as R-QUAL-004's, and "There is no such qualification" for another track. Queued, it counts against the city's civilians without work as a queued `Train` does (R-TRAIN-001) and against `Cities.MaxWorkers` (R-CITY-001), since its groups leave the city as units.diff --git a/sim/Statecraft.Sim.Tests/LedgerCraftsmenOrdersTests.cs b/sim/Statecraft.Sim.Tests/LedgerCraftsmenOrdersTests.csnew file mode 100644index 000000000..ada4c3148--- /dev/null+++ b/sim/Statecraft.Sim.Tests/LedgerCraftsmenOrdersTests.cs@@ -0,0 +1,68 @@+using Statecraft.Sim;++/// <summary>#1725: ReturnCraftsmen (R-QUAL-002) and ReassignCraftsmen (R-QUAL-004) on a game with an initialized Historical+/// ledger, the dark start (R-POP-002). The Historical start has no craftsmen and the craftsman course is refused until #2476,+/// so both orders are refused with a plain reason, with no state change and nothing thrown (owner, 9 November 2026: "Refuse+/// for now (Recommended)"). A synthetic or Open ledger is still refused as before.</summary>+public class LedgerCraftsmenOrdersTests+{+ const string TelAviv = "tel_aviv";+ const string Refusal = "Craftsmen are not on the population ledger yet (#2476)";++ static Content Gdd03() => HistoricalPopulationTests.Real(true);++ static GameState Dark(Content c) => Simulation.NewGame(c, 1, Mode.Historical, darkStart: true);++ static string? Order(Content c, GameState s, bool reassign, string city, int count, List<Cause> why) => reassign+ ? Qualification.ReassignCraftsmen(c, s, city, count, why)+ : Qualification.ReturnCraftsmen(c, s, city, count, why);++ // Owner, 9 November 2026, "Refuse for now (Recommended)": each order is refused with a plain reason on the dark start,+ // the state hash, the ledger and the description unchanged, and no Why line.+ [Theory]+ [InlineData(false)] [InlineData(true)]+ public void EachCraftsmanOrderIsRefusedOnTheDarkStart(bool reassign)+ {+ var c = Gdd03();+ var s = Dark(c);+ Assert.True(s.PopulationLedger.IsInitialized);+ var hash = s.Hash(); var ledger = s.PopulationLedger.Canonical().ToList(); var before = s.Describe();+ var why = new List<Cause>();+ Assert.Equal(Refusal, Order(c, s, reassign, TelAviv, 1, why));+ Assert.Empty(why);+ Assert.Equal(hash, s.Hash());+ Assert.Equal(ledger, s.PopulationLedger.Canonical().ToList());+ Assert.Equal(before, s.Describe());+ s.PopulationLedger.Reconcile();+ }++ // The orders' own refusals for an unknown city and a count below 1 come first, as Train's do before its craftsman+ // refusal (R-TRAIN-001), with the state unchanged.+ [Theory]+ [InlineData(false)] [InlineData(true)]+ public void TheOrdersOwnRefusalsComeFirst(bool reassign)+ {+ var c = Gdd03();+ var s = Dark(c);+ var hash = s.Hash(); var why = new List<Cause>();+ Assert.Equal("There is no such city", Order(c, s, reassign, "nowhere", 1, why));+ Assert.Equal(reassign ? Qualification.RefusedReassignCount : Qualification.RefusedReturnCount, Order(c, s, reassign, TelAviv, 0, why));+ Assert.Empty(why);+ Assert.Equal(hash, s.Hash());+ }++ // R-POP-002: an initialized Open ledger, like a synthetic one (no mode), is still refused by throwing, state unchanged.+ [Theory]+ [InlineData(true, false)] [InlineData(false, false)] [InlineData(true, true)] [InlineData(false, true)]+ public void AnOpenOrSyntheticLedgerIsStillRefused(bool open, bool reassign)+ {+ var c = PopulationLedgerTests.Content();+ var s = PopulationLedger.CreateFixture(c, PopulationLedgerTests.Bindings(),+ new[] { new PopulationInventoryRow("fixture", 0, PopulationLedgerTests.Person()) }, mode: open ? Mode.Open : null);+ Assert.Equal((true, false), (s.PopulationLedger.IsInitialized, s.PopulationLedger.IsHistorical));+ var hash = s.Hash(); var why = new List<Cause>();+ Assert.Contains("integration is held", Assert.Throws<NotSupportedException>(() => Order(c, s, reassign, TelAviv, 1, why)).Message);+ Assert.Empty(why);+ Assert.Equal(hash, s.Hash());+ }+}diff --git a/sim/Statecraft.Sim/Qualification.cs b/sim/Statecraft.Sim/Qualification.csindex f69f12b8f..7008febd9 100644--- a/sim/Statecraft.Sim/Qualification.cs+++ b/sim/Statecraft.Sim/Qualification.cs@@ -67,6 +67,13 @@ namespace Statecraft.SimRefusedNotPioneer = "Only a pioneer unit takes that order", RefusedPioneerBusy = "That unit is at work; stop the work first",RefusedNoQualification = "There is no such qualification";+ // #1725: the refusal only a Historical ledger game gives. Internal, not a Refused* constant: no player reaches it yet+ // (Simulation.Step still refuses a ledger game, R-POP-002), and the UI string follows when it does.+ /// <summary>Owner, 9 November 2026, "Refuse for now (Recommended)": ReturnCraftsmen and ReassignCraftsmen are refused+ /// with a plain reason until #2476 makes craftsmen exist on the ledger (the Historical start has none, and the craftsman+ /// course is refused until then, Training.LedgerRefusedCraftsman).</summary>+ internal const string LedgerRefusedCraftsmen = "Craftsmen are not on the population ledger yet (#2476)";+public const string ReturnCraftsmenKind = "return_craftsmen";public const string ReassignCraftsmenKind = "reassign_craftsmen";public const string ReassignPioneersKind = "reassign_pioneers";@@ -79,9 +86,10 @@ namespace Statecraft.Sim/// untouched, for an unknown city, a count below 1 or more than the city's craftsmen.</summary>public static string? ReturnCraftsmen(Content c, GameState s, string city, int count, List<Cause> why){- PopulationLedger.RefuseAggregate(s);+ PopulationLedger.RefuseUnlessHistorical(s); // #1725: on a Historical ledger the order is refused with a reasonif (!s.Cities.TryGetValue(city, out var x)) return "There is no such city";if (count < 1) return RefusedReturnCount;+ if (s.PopulationLedger.IsHistorical) return LedgerRefusedCraftsmen; // owner, 9 November 2026: "Refuse for now (Recommended)"var name = PlayerText.Settlement(c, city);if (count > x.Craftsmen) return FormattableString.Invariant($"{name} has {x.Craftsmen} craftsmen");s.Cities[city] = x.WithCraftsmen(x.Craftsmen - count).WithCounts(x.Civilians + count, x.Employed, x.Refugees)@@ -96,9 +104,10 @@ namespace Statecraft.Sim/// not idle, R-ARMS-005, R-CITY-011; #2730).</summary>public static string? ReassignCraftsmen(Content c, GameState s, string city, int count, List<Cause> why){- PopulationLedger.RefuseAggregate(s);+ PopulationLedger.RefuseUnlessHistorical(s); // #1725: on a Historical ledger the order is refused with a reasonif (!s.Cities.TryGetValue(city, out var x)) return "There is no such city";if (count < 1) return RefusedReassignCount;+ if (s.PopulationLedger.IsHistorical) return LedgerRefusedCraftsmen; // owner, 9 November 2026: "Refuse for now (Recommended)"var name = PlayerText.Settlement(c, city);if (count > x.Qualified.Craftsmen) return FormattableString.Invariant($"{name} has {x.Qualified.Craftsmen} qualified craftsmen");var idle = Training.Idle(s, x); // R-ARMS-005, R-CITY-011: as Train and ReassignPioneers count it