A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Sim: queued Reassign orders count in Training.Ordered/Available (Fixes #1548) (#1552)
Beri46eaf2732c8a
diff --git a/changelog.d/1548.md b/changelog.d/1548.mdnew file mode 100644index 000000000..6a0d212e7--- /dev/null+++ b/changelog.d/1548.md@@ -0,0 +1,5 @@+### Fixed++- A reassignment queued this turn now counts against the city's free civilians, as a queued Train does, so the Train+ button no longer looks available for civilians a reassignment will take (#1548). A queued craftsman reassignment+ counts against the job limit for that turn too, so the orders are accepted in any order.diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex 92c1a2487..dba7e0bf5 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -124,7 +124,7 @@ R-PROJ-005: A specialised project is allowed only in a city that has its resourcTraining is step 4 of the turn in the approved order (§2.3, D-A6): it runs before production. One military camp and one Hakhshara exist in Tel Aviv at the start, a labelled design assumption (D-D5); pioneers build more at camp sites (R-CAMP-001).-R-TRAIN-001: `Train(city, track, n)` takes `n` of the city's civilians without a job into a cohort that trains as `track` (a unit type with a `facility`: `recruit`, `artillery` and `armoured_car` in a military camp (R-UNIT-008), `halutz` in a Hakhshara, `craftsman` at industry, R-CRAFT-001) for the type's `training_turns`, counting the turn it was ordered in. The Treasury pays `n * training_cost` at once. When the Treasury holds less, the shortfall is borrowed, as for map actions: it is added to the debt and the Treasury stops at 0 (owner decision "Allow borrowing", 15 October 2026). The trainees leave the civilians at once; the cohort takes the next id, which units share. It is refused, with the state unchanged and the Attention refunded, when the city or track is unknown, `n` is below 1, the city lacks the facility, or it has fewer civilians without a job. A city has a facility when `cities.yaml` gives it one at the start or a camp site of that kind built for it is in the state (R-CAMP-001). The legacy loop refuses it before charging Attention. `Reinforce` (R-TRAIN-004) starts a cohort by the same rules, aimed at a unit.+R-TRAIN-001: `Train(city, track, n)` takes `n` of the city's civilians without a job into a cohort that trains as `track` (a unit type with a `facility`: `recruit`, `artillery` and `armoured_car` in a military camp (R-UNIT-008), `halutz` in a Hakhshara, `craftsman` at industry, R-CRAFT-001) for the type's `training_turns`, counting the turn it was ordered in. The Treasury pays `n * training_cost` at once. When the Treasury holds less, the shortfall is borrowed, as for map actions: it is added to the debt and the Treasury stops at 0 (owner decision "Allow borrowing", 15 October 2026). The trainees leave the civilians at once; the cohort takes the next id, which units share. It is refused, with the state unchanged and the Attention refunded, when the city or track is unknown, `n` is below 1, the city lacks the facility, or it has fewer civilians without a job. A city has a facility when `cities.yaml` gives it one at the start or a camp site of that kind built for it is in the state (R-CAMP-001). The legacy loop refuses it before charging Attention. `Reinforce` (R-TRAIN-004) starts a cohort by the same rules, aimed at a unit. A queued `ReassignCraftsmen` or `ReassignPioneers` (R-QUAL-004, R-QUAL-005) takes its civilians without a job as a queued `Train` does (counted in full, so the orders are accepted in any order), in `Training.Ordered` and `Training.Available` (#1548; owner, 24 October 2026: "Yes, count them", https://github.com/eyalgolan/statecraft-israel/issues/1511#issuecomment-6378360813).R-TRAIN-002: `CancelTraining(cohort)` returns the cohort's people to its city as civilians without a job and refunds none of the Money paid (D-A3); a recruit cohort's Arms go back to the pool (R-ARMS-003). A cohort that does not exist, or has finished, is refused with the state unchanged. Replacements (R-TRAIN-004) cancel the same way.@@ -164,9 +164,9 @@ R-QUAL-002: `ReturnCraftsmen(city, n)` turns `n` of the city's craftsmen into ciR-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).+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-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.+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.R-QUAL-006: A Train order (R-TRAIN-001) takes the city's unqualified civilians first. A qualified civilian it has to take loses its qualification, in the order craftsmen, halutz groups with the least service, veterans (owner, 24 October 2026: "Accept all as built", https://github.com/eyalgolan/statecraft-israel/issues/1511#issuecomment-6375597377).diff --git a/sim/Statecraft.Sim.Tests/QualificationTests.cs b/sim/Statecraft.Sim.Tests/QualificationTests.csindex bf4a99a63..325ce7b37 100644--- a/sim/Statecraft.Sim.Tests/QualificationTests.cs+++ b/sim/Statecraft.Sim.Tests/QualificationTests.cs@@ -322,4 +322,59 @@ public class QualificationTestsAssert.Equal(AttentionSystem.Cost(c, s, "unit_order"), AttentionSystem.Cost(c, s, Qualification.ReassignPioneersKind));Assert.Equal(0, AttentionSystem.Cost(c, s, "unit_order"));}++ // R-TRAIN-001 with R-QUAL-004, R-QUAL-005 (#1548; owner, 24 October 2026: "Yes, count them",+ // https://github.com/eyalgolan/statecraft-israel/issues/1511#issuecomment-6378360813): a queued reassignment takes its+ // city's idle civilians as a queued Train does, for its own city only.+ [Fact]+ public void AQueuedReassignCountsAgainstTheCitysFreeCivilians()+ {+ var c = Town();+ var s = WithCity(c, new City("town_a", 12, 8, 10, 0, 0, craftsmen: 0, qualified: new Qualified(3, 1, new[] { 1, 2 })));+ var queue = new Command[] { new Train("town_a", "recruit", 1), new ReassignCraftsmen("town_a", 2), new ReassignPioneers("town_a", "halutz", 1),+ new ReassignPioneers("town_a", "veteran_halutz", 1), new ReassignCraftsmen("elsewhere", 5) };+ Assert.Equal(5, Training.Ordered("town_a", queue));+ Assert.Equal(5, Training.Available(s, "town_a", queue)); // 10 idle civilians less those 5+ Assert.Equal(10, Training.Available(s, "town_a", new Command[] { new ReassignCraftsmen("elsewhere", 5), new ReassignPioneers("elsewhere", "halutz", 2) }));+ }++ // The count is the one the sim accepts: the orders up to Available all run, in either order, and one group more is refused.+ [Theory]+ [InlineData(false)]+ [InlineData(true)]+ public void AvailableAfterQueuedReassignsKeepsEveryOrderAccepted(bool trainFirst)+ {+ var c = Town();+ var s = WithCity(c, new City("town_a", 12, 8, 4, 0, 0, craftsmen: 0, qualified: new Qualified(2, 0, new[] { 1 })));+ s.Attention = 100;+ var reassigns = new Command[] { new ReassignCraftsmen("town_a", 1), new ReassignPioneers("town_a", "halutz", 1) };+ Assert.Equal(2, Training.Available(s, "town_a", reassigns));+ Command[] Orders(int recruits) => trainFirst+ ? new Command[] { new Train("town_a", "recruit", recruits), reassigns[0], reassigns[1] }+ : new Command[] { reassigns[0], reassigns[1], new Train("town_a", "recruit", recruits) };+ Assert.Empty(Step(c, s, Orders(2)).Rejected);+ Assert.Single(Step(c, s, Orders(3)).Rejected);+ }++ // R-CITY-001 with R-QUAL-004, R-QUAL-005 (#1548): every queued reassignment counts against MaxWorkers in full, so the job+ // order up to it is accepted with the reassignments whether it runs first or last (the bound is safe, not tight).+ [Theory]+ [InlineData(false)]+ [InlineData(true)]+ public void MaxWorkersCountsEveryQueuedReassignInAnyOrder(bool jobsFirst)+ {+ var c = Town();+ var s = WithCity(c, new City("town_a", 12, 8, 6, 0, 0, craftsmen: 0, jobsDefault: false, qualified: new Qualified(2, 0, new[] { 1 })));+ Assert.Equal(6, Cities.MaxWorkers(s, "town_a", new Command[0]));+ Assert.Equal(4, Cities.MaxWorkers(s, "town_a", new Command[] { new ReassignCraftsmen("town_a", 2) }));+ Assert.Equal(5, Cities.MaxWorkers(s, "town_a", new Command[] { new ReassignPioneers("town_a", "halutz", 1) }));+ var queue = new Command[] { new ReassignCraftsmen("town_a", 2), new ReassignPioneers("town_a", "halutz", 1) };+ var max = Cities.MaxWorkers(s, "town_a", queue);+ Assert.Equal(3, max);+ s.Attention = 100;+ Command[] Orders(int jobs) => jobsFirst+ ? new Command[] { new AssignWorkers("town_a", "job", jobs) }.Concat(queue).ToArray()+ : queue.Append(new AssignWorkers("town_a", "job", jobs)).ToArray();+ Assert.Empty(Step(c, s, Orders(max)).Rejected);+ }}diff --git a/sim/Statecraft.Sim/Cities.cs b/sim/Statecraft.Sim/Cities.csindex e422be535..064cbf3cd 100644--- a/sim/Statecraft.Sim/Cities.cs+++ b/sim/Statecraft.Sim/Cities.cs@@ -14,9 +14,10 @@ namespace Statecraft.Sim/// civilians and craftsmen (a craftsman fills an ordinary job slot, R-CRAFT-002). R-CITY-009's default fills to it.</summary>public static int MaxWorkers(City city) => Math.Min(city.JobSlots, city.Civilians + city.Craftsmen);- /// <summary>R-CITY-001 with R-TRAIN-001: <see cref="MaxWorkers(City)"/> once the city's Train orders in- /// <paramref name="pending"/> (this turn's queue) have taken their civilians, so a count up to it keeps every one of- /// them accepted, whatever order they run in. Other orders do not count.</summary>+ /// <summary>R-CITY-001 with R-TRAIN-001: <see cref="MaxWorkers(City)"/> once the city's Train, Reinforce and Reassign+ /// orders in <paramref name="pending"/> (this turn's queue) have taken their civilians, so a count up to it keeps every one+ /// of them accepted, whatever order they run in. Every queued reassignment counts in full, craftsmen too (#1548): if the+ /// job order runs first, the civilians a reassignment needs are already in work.</summary>public static int MaxWorkers(GameState s, string city, IEnumerable<Command> pending){var x = s.Cities[city];diff --git a/sim/Statecraft.Sim/Training.cs b/sim/Statecraft.Sim/Training.csindex 973ae6a60..960a50dc9 100644--- a/sim/Statecraft.Sim/Training.cs+++ b/sim/Statecraft.Sim/Training.cs@@ -52,15 +52,17 @@ namespace Statecraft.Sim/// city's jobs first (R-CRAFT-002), so only the employed beyond its craftsmen are civilians in work.</summary>public static int Idle(City city) => city.Civilians - Math.Max(0, city.Employed - city.Craftsmen);- /// <summary>The groups the Train and Reinforce orders in <paramref name="pending"/> (this turn's queue) take from- /// <paramref name="city"/>, every track together.</summary>+ /// <summary>The groups the Train, Reinforce, ReassignCraftsmen and ReassignPioneers orders in <paramref name="pending"/>+ /// (this turn's queue) take from <paramref name="city"/>'s idle civilians, every track together (#1548; owner, 24 October+ /// 2026: "Yes, count them").</summary>public static int Ordered(string city, IEnumerable<Command> pending) =>- pending.OfType<Train>().Where(t => t.City == city).Sum(t => t.Count) + pending.OfType<Reinforce>().Where(t => t.City == city).Sum(t => t.Count);+ pending.OfType<Train>().Where(t => t.City == city).Sum(t => t.Count) + pending.OfType<Reinforce>().Where(t => t.City == city).Sum(t => t.Count)+ + pending.OfType<ReassignCraftsmen>().Where(t => t.City == city).Sum(t => t.Count) + pending.OfType<ReassignPioneers>().Where(t => t.City == city).Sum(t => t.Count);/// <summary>R-TRAIN-001 with R-CITY-001: the groups still free to train in <paramref name="city"/> once the orders in- /// <paramref name="pending"/> (this turn's queue) have run: <see cref="Idle"/>, less every track's Train order there,- /// and less a pending AssignWorkers' rise in jobs. A count up to it keeps every one of those orders accepted, whatever- /// order they run in. A pending CancelTraining is not counted, since it may run after the Train.</summary>+ /// <paramref name="pending"/> (this turn's queue) have run: <see cref="Idle"/>, less every track's Train order there+ /// and every queued reassignment (R-QUAL-004, R-QUAL-005), and less a pending AssignWorkers' rise in jobs. A count up to+ /// it keeps every one of those orders accepted, whatever order they run in. A pending CancelTraining is not counted, since it may run after the Train.</summary>public static int Available(GameState s, string city, IEnumerable<Command> pending){var x = s.Cities[city];