Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Sim: return to civilian life and reassign, keeping qualification (Refs #1511) (#1523)

Beri0b17ec4fefe8
diff --git a/changelog.d/1511.md b/changelog.d/1511.md
new file mode 100644
index 000000000..dd99b06c3
--- /dev/null
+++ b/changelog.d/1511.md
@@ -0,0 +1,4 @@
+- Craftsmen, halutzim and veteran pioneers can go back to civilian life and keep their training (refs #1511, sim only). Three new orders
+ (`ReturnCraftsmen`, `ReassignCraftsmen`, `ReassignPioneers`) and a `return_civilian` unit order move people both ways at once, with no Money
+ and no training. A halutz keeps its partial service, a veteran stays one, and qualified civilians work, are housed and are paid as ordinary
+ civilians (R-QUAL-001 to R-QUAL-007). The city panel and the pioneer card do not offer the orders yet; no golden moves.
diff --git a/content/rules.yaml b/content/rules.yaml
index f49cfb120..1c70beffe 100644
--- a/content/rules.yaml
+++ b/content/rules.yaml
@@ -15,6 +15,9 @@ attention_cost:
assign_workers: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6)
train: 1 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6)
cancel_training: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6)
+ return_craftsmen: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6: as assign_workers, the normal Attention of an order, #1511 owner ruling)
+ reassign_craftsmen: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6: as assign_workers, the normal Attention of an order, #1511 owner ruling)
+ reassign_pioneers: 0 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6: unit orders are free, the normal Attention of an order, #1511 owner ruling)
reinforce: 1 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6; owner, 24 October 2026, #1510: "1, like Train")
pioneer_work: 0 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6: unit orders are free)
stop_work: 0 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6: unit orders are free)
diff --git a/docs/GDD.md b/docs/GDD.md
index 04354fb51..138cef7dd 100644
--- a/docs/GDD.md
+++ b/docs/GDD.md
@@ -72,7 +72,7 @@ The player can choose ministers. TBD: minister roles, available candidates, appo
| Arab Legionnaire | Unit representing an Arab Legion soldier. | Equipment, movement, strength and behavior. |
| Palestinian militia | Palestinian militia unit. | Equipment, movement, strength and behavior. |
-**Then decided (owner, 23 Oct 2026, "Two-way, keep training"; [#1511](https://github.com/eyalgolan/statecraft-israel/issues/1511#issuecomment-6372356482)):** craftsmen, halutzim and veteran pioneers can return to civilian life and keep their qualification, and a qualified civilian can be reassigned to the trained role without training again; the rule is built under #1511.
+**Then decided (owner, 23 Oct 2026, "Two-way, keep training"; [#1511](https://github.com/eyalgolan/statecraft-israel/issues/1511#issuecomment-6372356482)):** craftsmen, halutzim and veteran pioneers can return to civilian life and keep their qualification, and a qualified civilian can be reassigned to the trained role without training again; the rule is built under #1511 (R-QUAL-001 to R-QUAL-007).
### Movement and civilian actions
@@ -84,7 +84,8 @@ A civilian can be employed in an available city employment slot. A civilian can
Two transitions are defined:
- civilian to recruit, through basic training;
-- civilian to Halutz, through pioneer training.
+- civilian to Halutz, through pioneer training;
+- craftsman, halutz and veteran pioneer back to civilian life, and a qualified civilian back into the trained role without training again (#1511, R-QUAL-001 to R-QUAL-007).
These transitions are open:
- refugee to civilian;
diff --git a/docs/gdd/training.md b/docs/gdd/training.md
index 98c7c71a5..f143de23c 100644
--- a/docs/gdd/training.md
+++ b/docs/gdd/training.md
@@ -22,7 +22,7 @@ As a player of the MVP, I want to send Tel Aviv's civilians without work to basi
- `unit_types.yaml` (`recruit`, `halutz`: `facility`, `training_turns`, `training_cost`), `cities.yaml` (`facilities`), `rules.yaml` `attention_cost.train`, `cancel_training`, `mvp.build_camp_turns` and `mvp.build_camp_cost`: labelled design values in `content/` since the cutover (Q-CUT-1, R-LOOP-005), the overlay's placeholders before it (ruling 2 [S3]).
- `GameState`: `Cohorts` (hashed as `train[...]` when there are some), a city's `Recruits` (in its hash record when not 0), `Units`, `NextId`, `Treasury`, and a built camp's `Sites` record, which is where `Training.HasFacility` reads a built camp from.
- `content/sites.yaml`: the `camp_80` and `tzrifin` rows, each with a `city`.
-- Save files: the `train CITY TRACK N` and `untrain COHORT` lines. Scenarios: `train` and `cancel_training`.
+- Save files: the `train CITY TRACK N` and `untrain COHORT` lines (and `retcraft`, `regcraft`, `regpioneer`, `order UNIT return_civilian`, R-QUAL-007). Scenarios: `train` and `cancel_training` (and `return_craftsmen`, `reassign_craftsmen`, `reassign_pioneers`).
- `sim/Statecraft.Sim.Tests/golden/manifest.txt`: `mvp-slice` moved (retired at the cutover); `scenario-mvp-absorb-first` did not. Phase 4 PR 3 moves `hash1950`, `hash1952` and `mvp-end`: the reference player builds the two camps once the yishuv sites are taken (docs/determinism.md).
## Done when
diff --git a/docs/oss/DECISIONS.md b/docs/oss/DECISIONS.md
index 86e09a71a..a67115f9e 100644
--- a/docs/oss/DECISIONS.md
+++ b/docs/oss/DECISIONS.md
@@ -90,6 +90,6 @@ The owner's answers to the questions in section 9 of `docs/superpowers/specs/202
## Owner rulings, 23 October 2026
- **Then decided (owner, 23 Oct 2026, "Replacements cost Arms"; [#1510](https://github.com/eyalgolan/statecraft-israel/issues/1510#issuecomment-6372356139)):** trained replacements merge into a damaged formation and consume Arms, as recruit training does (R-ARMS-003). Implementation is #1510.
-- **Then decided (owner, 23 Oct 2026, "Two-way, keep training"; [#1511](https://github.com/eyalgolan/statecraft-israel/issues/1511#issuecomment-6372356482)):** craftsmen, halutzim and veteran pioneers can return to civilian life, keep their qualification, and be reassigned either way without training again. Implementation is #1511.
+- **Then decided (owner, 23 Oct 2026, "Two-way, keep training"; [#1511](https://github.com/eyalgolan/statecraft-israel/issues/1511#issuecomment-6372356482)):** craftsmen, halutzim and veteran pioneers can return to civilian life, keep their qualification, and be reassigned either way without training again. Built under #1511: the qualification is kept as a count of qualified civilians inside each city's civilians (R-QUAL-001), so jobs, housing and income treat them as ordinary civilians; a halutz keeps its partial service (owner answer 3).
- **Then decided (owner, 23 Oct 2026, "Freeze for MVP (Recommended)"; [#1512](https://github.com/eyalgolan/statecraft-israel/issues/1512#issuecomment-6372356819)):** the eight `hexes.json` biomes are the complete MVP terrain catalogue, with no terrain conversions.
- **Then decided (owner, 23 Oct 2026, "Yes, complete (Recommended)"; [#1513](https://github.com/eyalgolan/statecraft-israel/issues/1513#issuecomment-6372357178)):** R-MIN-001 to R-MIN-003 and `Cabinet.Appoint` are the complete MVP minister mechanic (D-H3 closed).
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 6395d0f78..92c1a2487 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -128,13 +128,13 @@ R-TRAIN-001: `Train(city, track, n)` takes `n` of the city's civilians without a
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.
-R-TRAIN-003: Each turn, in ascending id, every cohort has one turn less to go. A cohort that reaches 0 ends: a recruit cohort becomes one military unit with its count as strength (R-UNIT-003), and so does a gun or armoured car cohort, of its own type (R-UNIT-008), craftsmen join the city's count (R-CRAFT-001), and halutzim become one movable unit per group. Units appear at the city's settlement hex, taking the next ids in turn. New recruit completions never fill `City.Recruits`; its old canonical field is retained, and saves still replay their command log. Cohorts are written into the state hash only when there are some. A cohort aimed at a unit ends as R-TRAIN-004 says instead.
+R-TRAIN-003: Each turn, in ascending id, every cohort has one turn less to go. A cohort that reaches 0 ends: a recruit cohort becomes one military unit with its count as strength (R-UNIT-003), and so does a gun or armoured car cohort, of its own type (R-UNIT-008), craftsmen join the city's count (R-CRAFT-001), and halutzim become one movable unit per group. Units appear at the city's settlement hex, taking the next ids in turn. New recruit completions never fill `City.Recruits`; its old canonical field is retained, and saves still replay their command log. Cohorts are written into the state hash only when there are some. A cohort aimed at a unit ends as R-TRAIN-004 says instead. Reassignment of a qualified civilian is a second way into the role, with no cohort (R-QUAL-004, R-QUAL-005).
R-TRAIN-004: `Reinforce(unit, city, n)` (#1510; owner, 23 October 2026: "Replacements cost Arms", https://github.com/eyalgolan/statecraft-israel/issues/1510#issuecomment-6372356139, and "Default (Recommended)") refills a damaged formation of the player's with trained replacements. The unit must be a military unit of the player's side standing on `city`'s settlement hex. Its course is the trained type of the unit's side and class (a type with a `facility`): the recruit's basic training for a recruit or a veteran soldier, the guns' and the armoured cars' own for artillery and armoured cars (R-UNIT-008); a type no course trains (any enemy type) takes none. The cohort then follows R-TRAIN-001: the city's facility, `n` of its civilians without a job, `n * training_cost` with borrowing (R-MONEY-003), and the Arms of R-ARMS-003 for that course; it carries the unit's id, written into the state hash (`|unit=<id>`) only when set. The cap is the strength the unit had before its first loss, `Unit.Full`: combat stores it on a player's unit at its first loss (R-COMBAT-003) and clears it when replacements bring the unit back to it, and it is written into the state hash (`|full=<n>`) only when set, so a unit that has lost nobody, and every enemy unit, hashes as before. The order is refused, the state and Attention unchanged, for an unknown unit ("There is no such unit"), a unit with no side or an enemy unit (R-ORDER-001's wording), an unknown city, a unit off the city's hex ("Unit N is not in <city>"), a type no course trains ("Unit N cannot take replacements"), a unit with nothing to refill ("Unit N has no losses to replace") and `n` past the cap less the unit's strength and the replacements already training for it ("Unit N can take K more groups"), then for R-TRAIN-001's and R-ARMS-003's reasons. A queued `Reinforce` takes its city's civilians as a queued `Train` does (R-CITY-001). In step 4, before a turn is counted, replacements whose unit has left the state (destroyed, captured, sent home) or stands off the city's hex are cancelled as R-TRAIN-002 cancels a cohort: people and Arms back, the Money spent, with a Why line. A cohort that finishes adds its count to the unit's strength and makes no unit and takes no id; the unit keeps its type, service, order and home (a veteran stays a veteran, R-UNIT-004). The people join the unit's home city's housing (R-HOUSE-003). `attention_cost.reinforce` is 1, Train's cost, a design value (owner, 24 October 2026: "1, like Train (Recommended)", https://github.com/eyalgolan/statecraft-israel/issues/1510#issuecomment-6375591436). The save line is `reinforce <unit> <city> <n>` and the scenario form `{ kind: reinforce, unit, city, count }`.
## Craftsmen
-R-CRAFT-001: A civilian becomes a craftsman by training (D-D4; Q-CRAFT-1, owner, 15 October 2026): `Train(city, craftsman, n)` follows R-TRAIN-001 to R-TRAIN-003, and the city's facility is a completed `industry` project (R-PROJ-003); one still being built does not count. `unit_types.yaml` gives the course's `training_turns` (3) and `training_cost` (IL 0.5m a group), labelled design values (Q-CRAFT-3). A finished cohort adds to the city's count of craftsmen, which is not part of its civilians and is written into the state hash only when not 0.
+R-CRAFT-001: A civilian becomes a craftsman by training (D-D4; Q-CRAFT-1, owner, 15 October 2026): `Train(city, craftsman, n)` follows R-TRAIN-001 to R-TRAIN-003, and the city's facility is a completed `industry` project (R-PROJ-003); one still being built does not count. `unit_types.yaml` gives the course's `training_turns` (3) and `training_cost` (IL 0.5m a group), labelled design values (Q-CRAFT-3). A finished cohort adds to the city's count of craftsmen, which is not part of its civilians and is written into the state hash only when not 0. A craftsman can return to civilian life and keep the qualification (R-QUAL-002).
R-CRAFT-002: A craftsman fills an ordinary job slot (Q-CRAFT-2, owner, 15 October 2026). Of a city's employed, its craftsmen are counted first, and each employed craftsman earns `craftsman_income_multiple` (2, a labelled design value) times `income_per_job_per_year`; every other employed unit earns the R-CITY-002 rate.
@@ -150,10 +150,28 @@ R-SITE-003: Each turn, in ordinal site id order, every site being built has one
## Veteran pioneers
-R-VET-001: In step 5, after its site's or segment's progress (R-COR-002), a halutz unit whose site or corridor segment is being built gains one turn of service, the turn it is built included; an idle unit gains none. At `veteran_halutz_service` turns of service it becomes a `veteran_halutz` at the end of that turn, keeping its id, hex, service and project, and a cause says so. A veteran gains no more service. A unit's service is written into the state hash only when it is not 0 (D-D9; Q-VET-1, owner, 17 October 2026, #782).
+R-VET-001: In step 5, after its site's or segment's progress (R-COR-002), a halutz unit whose site or corridor segment is being built gains one turn of service, the turn it is built included; an idle unit gains none. At `veteran_halutz_service` turns of service it becomes a `veteran_halutz` at the end of that turn, keeping its id, hex, service and project, and a cause says so. A veteran gains no more service. A unit's service is written into the state hash only when it is not 0 (D-D9; Q-VET-1, owner, 17 October 2026, #782). A halutz or veteran can return to civilian life and keep its service or its status (R-QUAL-003).
R-VET-002: A veteran's site or corridor segment being built has `veteran_progress` turns less to go each turn, against a halutz's 1; one with that many or fewer left is built that turn. A veteran does the same pioneer work as a halutz (R-SITE-001) (D-D9; Q-VET-2, owner, 17 October 2026, #782).
+### Return to civilian life and reassignment (#1511)
+
+Owner ruling "Two-way, keep training" and its three answers (23 October 2026, #1511): https://github.com/eyalgolan/statecraft-israel/issues/1511#issuecomment-6372356482 and https://github.com/eyalgolan/statecraft-israel/issues/1511#issuecomment-6372642736. Craftsmen, halutzim and veteran pioneers can go back to civilian life and be put back into the trained role, in either direction, without repeating R-TRAIN-001.
+
+R-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-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-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-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).
+
+R-QUAL-007: Attention is that of the matching existing order (owner ruling 1): `return_craftsmen` and `reassign_craftsmen` cost what `assign_workers` does (0.5), and `reassign_pioneers` and the `return_civilian` unit order cost what a unit order does (0), all design values in `rules.yaml`. The qualified counts are written into the state hash only when not 0 (`,qcraftsmen=N,qhalutz=S:S,qveterans=N` after the other city fields), so a game without them hashes as before. The saves write `retcraft CITY N`, `regcraft CITY N`, `regpioneer CITY TRACK N` and `order UNIT return_civilian`; scenarios use `return_craftsmen`, `reassign_craftsmen`, `reassign_pioneers` and `unit_order` with `order: return_civilian`.
+
R-SITE-004: Every designated site has one or more kinds from a fixed list: `yishuv`, `field`, `swamp`, `military_camp` and `hakhshara` (Phase 4, Q-FIELD-1, Q-SWAMP-1, Q-CAMP-3). A pioneer action is accepted only at a site of its kind; any other is refused with the state unchanged and the Attention refunded. A yishuv site has a founding date inside the MVP's years and no other kind has one. A camp site (`military_camp` or `hakhshara`) names a city of `cities.yaml`, the city it trains for (Q-CAMP-1), and no other kind names one. The loader refuses any other row, naming the file and field.
R-SITE-005: At most one `yishuv` site sits in a hex, so a hex shows at most one new yishuv. A site of another kind may share a hex with a yishuv site, as a yishuv's field site does (Q-SITE-3).
diff --git a/sim/Statecraft.Sim.Tests/CommandGuardTests.cs b/sim/Statecraft.Sim.Tests/CommandGuardTests.cs
index 90a0443eb..14e161e5d 100644
--- a/sim/Statecraft.Sim.Tests/CommandGuardTests.cs
+++ b/sim/Statecraft.Sim.Tests/CommandGuardTests.cs
@@ -21,6 +21,9 @@ public class CommandGuardTests
[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),
diff --git a/sim/Statecraft.Sim.Tests/DeportTests.cs b/sim/Statecraft.Sim.Tests/DeportTests.cs
index e94303de9..437bb4d4e 100644
--- a/sim/Statecraft.Sim.Tests/DeportTests.cs
+++ b/sim/Statecraft.Sim.Tests/DeportTests.cs
@@ -187,7 +187,7 @@ public class DeportTests
// These name no place or hex: a city, a cohort, a unit's own work, a policy, a budget, an event, an office or a count.
[typeof(SetPolicy)] = null, [typeof(AllocateBudget)] = null, [typeof(ChooseEventOption)] = null, [typeof(SetMobilization)] = null,
[typeof(SecurityOrder)] = null, [typeof(Appoint)] = null, [typeof(AssignWorkers)] = null, [typeof(Train)] = null,
- [typeof(CancelTraining)] = null, [typeof(Reinforce)] = null, [typeof(StopWork)] = null, [typeof(CancelProject)] = null, [typeof(BuyArms)] = null,
+ [typeof(CancelTraining)] = null, [typeof(Reinforce)] = null, [typeof(ReturnCraftsmen)] = null, [typeof(ReassignCraftsmen)] = null, [typeof(ReassignPioneers)] = null, [typeof(StopWork)] = null, [typeof(CancelProject)] = null, [typeof(BuyArms)] = null,
};
var kinds = typeof(Command).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(Command)) && !t.IsAbstract).OrderBy(t => t.Name, StringComparer.Ordinal);
Assert.Equal(kinds.Select(t => t.Name), aimed.Keys.OrderBy(t => t.Name, StringComparer.Ordinal).Select(t => t.Name));
diff --git a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs
index b0bd3124e..02a8670d6 100644
--- a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs
+++ b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs
@@ -21,6 +21,9 @@ public class DesignValuesTests
("rules.yaml", "attention_cost.train"),
("rules.yaml", "attention_cost.reinforce"),
("rules.yaml", "attention_cost.cancel_training"),
+ ("rules.yaml", "attention_cost.return_craftsmen"),
+ ("rules.yaml", "attention_cost.reassign_craftsmen"),
+ ("rules.yaml", "attention_cost.reassign_pioneers"),
("rules.yaml", "attention_cost.pioneer_work"),
("rules.yaml", "attention_cost.stop_work"),
("rules.yaml", "mvp.people_per_unit"),
diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.cs
index ce9f9b88d..c43c7e16d 100644
--- a/sim/Statecraft.Sim.Tests/Fixture.cs
+++ b/sim/Statecraft.Sim.Tests/Fixture.cs
@@ -243,7 +243,7 @@ series:
}
/// <summary>The fixture's attention_cost line with the GDD command kinds added (replaces "map_action: 1 }").</summary>
- public const string GddCosts = "map_action: 1, assign_workers: 1, train: 1, cancel_training: 1, reinforce: 1, pioneer_work: 0, stop_work: 0, start_project: 1, cancel_project: 0.5, buy_arms: 1, move: 0, unit_order: 0, resolve_capture: 0 }";
+ public const string GddCosts = "map_action: 1, assign_workers: 1, train: 1, cancel_training: 1, reinforce: 1, return_craftsmen: 0.5, reassign_craftsmen: 0.5, reassign_pioneers: 0, pioneer_work: 0, stop_work: 0, start_project: 1, cancel_project: 0.5, buy_arms: 1, move: 0, unit_order: 0, resolve_capture: 0 }";
public const string GddRules = @"
mvp:
diff --git a/sim/Statecraft.Sim.Tests/QualificationTests.cs b/sim/Statecraft.Sim.Tests/QualificationTests.cs
new file mode 100644
index 000000000..bf4a99a63
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/QualificationTests.cs
@@ -0,0 +1,325 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Statecraft.Sim;
+
+/// <summary>Return to civilian life and reassignment (R-QUAL-001 to R-QUAL-007; #1511, owner ruling "Two-way, keep training"
+/// and its three answers, 23 October 2026): instant and Money-free, qualified civilians are ordinary civilians for jobs, housing
+/// and training, and a halutz's partial service is kept. The fixture's town_a has housing for 12, 8 jobs and 10 civilians, 6
+/// in work; a halutz becomes a veteran after 4 turns of service.</summary>
+public class QualificationTests
+{
+ static Content Town() => ContentLoader.Load(Fixture.Write(Fixture.Gdd()));
+
+ /// <summary>town_a (1, 0) and town_b (2, 1), as DemobilizationTests lays them out.</summary>
+ static Content TwoTowns() => ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>
+ {
+ ["map/settlement_hexes.yaml"] = "settlements:\n - { id: town_a, q: 1, r: 0 }\n - { id: town_b, q: 2, r: 1 }\n",
+ ["map/settlements_1948.yaml"] = Fixture.Files["map/settlements_1948.yaml"]
+ + " - { id: town_b, name: Town B, lon: 34.42, lat: 33.28, type: town, founded: 1900, pre_modern: false }\n",
+ ["map/locations_1948.yaml"] = Fixture.Files["map/locations_1948.yaml"]
+ + " - id: town_b\n name: Town B\n name_he: עיר ב\n name_he_sources: [{ url: 'https://example.org/town-b-he', checked: 2026-10-18 }]\n kind: city\n lon: 34.42\n lat: 33.28\n q: 2\n r: 1\n priority: must_have\n marker: true\n managed_city: true\n designated_site: false\n settlement_control_target: false\n sources: [{ url: 'https://example.org/town-b', checked: 2026-10-18 }]\n status: draft\n",
+ ["cities.yaml"] = "cities:\n" + Fixture.City("town_a", 40, 8, 10, 0) + Fixture.City("town_b", 40, 8, 10, 0),
+ })));
+
+ static StepResult Step(Content c, GameState s, params Command[] commands) => Simulation.Step(c, s, commands);
+
+ static GameState WithCity(Content c, City city, params Unit[] units)
+ {
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ s.Cities[city.Id] = city;
+ foreach (var u in units) { s.Units.Add(u.Id, u); s.NextId = Math.Max(s.NextId, u.Id + 1); }
+ return s;
+ }
+
+ static int People(GameState s) => s.Cities.Values.Sum(x => x.Civilians + x.Craftsmen) + s.Units.Values.Count(u => Projects.IsPioneer(u.Type));
+
+ // R-QUAL-002: instant, no Money; the craftsmen become qualified civilians, the jobs stay as they were.
+ [Fact]
+ public void CraftsmenReturnToCivilianLifeAndKeepTheirTraining()
+ {
+ var c = Town();
+ var s = WithCity(c, new City("town_a", 12, 8, 4, 4, 0, craftsmen: 3, jobsDefault: false));
+ var r = Step(c, s, new ReturnCraftsmen("town_a", 2));
+ Assert.Empty(r.Rejected);
+ var x = r.State.Cities["town_a"];
+ Assert.Equal((6, 1, 2, 4), (x.Civilians, x.Craftsmen, x.Qualified.Craftsmen, x.Employed));
+ Assert.Equal(People(s), People(r.State));
+ // no Money is paid, and the 2 who returned earn the ordinary rate (R-QUAL-002): as the same city built by hand does
+ var ordinary = WithCity(c, new City("town_a", 12, 8, 6, 4, 0, craftsmen: 1, jobsDefault: false));
+ Assert.Equal(Step(c, ordinary).State.Treasury, r.State.Treasury, 9);
+ Assert.Equal(Cities.Housed(s, s.Cities["town_a"]), Cities.Housed(r.State, x));
+ }
+
+ [Fact]
+ public void ReturningCraftsmenIsRefusedForAnUnknownCityTooFewCraftsmenOrNoCount()
+ {
+ var c = Town();
+ var s = WithCity(c, new City("town_a", 12, 8, 4, 0, 0, craftsmen: 1));
+ foreach (var (cmd, why) in new (Command, string)[] {
+ (new ReturnCraftsmen("nowhere", 1), "There is no such city"), (new ReturnCraftsmen("town_a", 0), "Return at least one group"),
+ (new ReturnCraftsmen("town_a", 2), "Town A has 1 craftsmen") })
+ {
+ var r = Step(c, s, cmd);
+ Assert.Equal(why, Assert.Single(r.Rejected).Reason);
+ Assert.Equal(Step(c, s).State.Hash(), r.State.Hash());
+ }
+ }
+
+ // R-QUAL-004: no training, no Money, no turns; the craftsmen are back at once.
+ [Fact]
+ public void QualifiedCraftsmenReturnWithoutTrainingOrMoney()
+ {
+ var c = Town();
+ var s = WithCity(c, new City("town_a", 12, 8, 6, 0, 0, jobsDefault: false, qualified: new Qualified(2, 0, new int[0])));
+ var r = Step(c, s, new ReassignCraftsmen("town_a", 2));
+ Assert.Empty(r.Rejected);
+ Assert.Empty(r.State.Cohorts);
+ var x = r.State.Cities["town_a"];
+ Assert.Equal((4, 2, 0), (x.Civilians, x.Craftsmen, x.Qualified.Craftsmen));
+ Assert.Equal(People(s), People(r.State));
+ Assert.Equal(Step(c, s).State.Treasury, r.State.Treasury, 9);
+ }
+
+ // R-QUAL-004: a qualified civilian needs no job, nor does it take one that is taken.
+ [Fact]
+ public void ReassigningCraftsmenIsRefusedWithoutQualifiedOrIdleCivilians()
+ {
+ var c = Town();
+ var q = new Qualified(2, 0, new int[0]);
+ var busy = WithCity(c, new City("town_a", 12, 8, 4, 3, 0, jobsDefault: false, qualified: q)); // 3 of the 4 in work: 1 idle
+ var r = Step(c, busy, new ReassignCraftsmen("town_a", 2));
+ Assert.Equal("Town A has 1 civilians without work", Assert.Single(r.Rejected).Reason);
+ Assert.Equal(Step(c, busy).State.Hash(), r.State.Hash());
+ var none = WithCity(c, new City("town_a", 12, 8, 4, 0, 0, jobsDefault: false, qualified: q));
+ Assert.Equal("Town A has 2 qualified craftsmen", Assert.Single(Step(c, none, new ReassignCraftsmen("town_a", 3)).Rejected).Reason);
+ Assert.Equal("Reassign at least one group", Assert.Single(Step(c, none, new ReassignCraftsmen("town_a", 0)).Rejected).Reason);
+ Assert.Equal("There is no such city", Assert.Single(Step(c, none, new ReassignCraftsmen("x", 1)).Rejected).Reason);
+ }
+
+ // Owner ruling 2: a qualified civilian is an ordinary civilian for jobs, income and housing.
+ [Fact]
+ public void QualifiedCiviliansWorkHouseAndEarnAsOrdinaryOnes()
+ {
+ var c = Town();
+ var plain = WithCity(c, new City("town_a", 12, 8, 5, 5, 0));
+ var qualified = WithCity(c, new City("town_a", 12, 8, 5, 5, 0, jobsDefault: false, qualified: new Qualified(2, 1, new[] { 0, 3 })));
+ Assert.Equal(Step(c, plain).State.Treasury, Step(c, qualified).State.Treasury, 9); // ordinary rate, not the craftsman's
+ Assert.Equal(Cities.Housed(plain, plain.Cities["town_a"]), Cities.Housed(qualified, qualified.Cities["town_a"]));
+ Assert.Equal(Cities.MaxWorkers(plain.Cities["town_a"]), Cities.MaxWorkers(qualified.Cities["town_a"]));
+ Assert.Equal(Training.Idle(plain.Cities["town_a"]), Training.Idle(qualified.Cities["town_a"]));
+ }
+
+ // R-QUAL-006: training takes the unqualified first; a qualified civilian taken loses its qualification.
+ [Fact]
+ public void TrainingTakesUnqualifiedCiviliansFirstAndThenQualifiedOnes()
+ {
+ var c = Town();
+ var q = new Qualified(2, 1, new[] { 2, 3 });
+ var s = WithCity(c, new City("town_a", 12, 8, 6, 0, 0, jobsDefault: false, qualified: q)); // 5 qualified of 6 civilians
+ var one = Step(c, s, new Train("town_a", "halutz", 1));
+ Assert.Empty(one.Rejected);
+ Assert.Equal(5, one.State.Cities["town_a"].Qualified.Total); // the unqualified one went
+ var three = Step(c, s, new Train("town_a", "halutz", 3));
+ Assert.Empty(three.Rejected);
+ var left = three.State.Cities["town_a"];
+ Assert.Equal(3, left.Civilians);
+ Assert.Equal((0, 2, 1), (left.Qualified.Craftsmen, left.Qualified.Halutzim.Count, left.Qualified.Veterans)); // the craftsmen went first
+ var four = Step(c, s, new Train("town_a", "halutz", 5)).State.Cities["town_a"];
+ Assert.Equal((1, 0, 0, 1), (four.Civilians, four.Qualified.Craftsmen, four.Qualified.Halutzim.Count, four.Qualified.Veterans)); // then the halutzim, the veterans last
+ Assert.All(new[] { left, four }, x => Assert.True(x.Qualified.Total <= x.Civilians));
+ }
+
+ // R-QUAL-003 and owner ruling 3: a halutz keeps the service it had.
+ [Fact]
+ public void AnIdleHalutzReturnsToTheNearestCityKeepingItsService()
+ {
+ var c = TwoTowns();
+ var s = WithCity(c, new City("town_a", 40, 8, 1, 0, 0), new Unit(7, "halutz", 2, 1, 3)); // on town_b's hex
+ s.Cities["town_b"] = new City("town_b", 40, 8, 1, 0, 0);
+ var r = Step(c, s, new UnitOrder(7, Qualification.ReturnOrder));
+ Assert.Empty(r.Rejected);
+ Assert.DoesNotContain(7, r.State.Units.Keys);
+ var b = r.State.Cities["town_b"];
+ Assert.Equal(2, b.Civilians);
+ Assert.Equal(new[] { 3 }, b.Qualified.Halutzim);
+ Assert.Equal(1, r.State.Cities["town_a"].Civilians);
+ Assert.Equal(People(s), People(r.State));
+ }
+
+ // R-QUAL-003: the nearest city, ties by city id (R-UNIT-005's rule).
+ [Fact]
+ public void TheReturningUnitTiesGoToTheLowestCityId()
+ {
+ var c = TwoTowns();
+ var s = WithCity(c, new City("town_a", 40, 8, 1, 0, 0), new Unit(7, "veteran_halutz", 2, 0, 4)); // 1 from town_a (1,0) and 1 from town_b (2,1)
+ s.Cities["town_b"] = new City("town_b", 40, 8, 1, 0, 0);
+ var r = Step(c, s, new UnitOrder(7, Qualification.ReturnOrder));
+ Assert.Empty(r.Rejected);
+ Assert.Equal((2, 1), (r.State.Cities["town_a"].Civilians, r.State.Cities["town_a"].Qualified.Veterans));
+ Assert.Equal(0, r.State.Cities["town_b"].Qualified.Total);
+ }
+
+ [Fact]
+ public void AUnitAtWorkAndAUnitThatIsNotAPioneerAreRefused()
+ {
+ var c = Town();
+ var s = WithCity(c, new City("town_a", 12, 8, 4, 0, 0), new Unit(7, "halutz", 1, 0), new Unit(8, "recruit", 1, 0, side: "israel", strength: 2));
+ var working = Step(c, s, new PioneerWork(7, Projects.BuildYishuv, "site_a")).State;
+ Assert.True(Projects.IsBusy(working, 7));
+ var busy = Step(c, working, new UnitOrder(7, Qualification.ReturnOrder));
+ Assert.Equal("That unit is at work; stop the work first", Assert.Single(busy.Rejected).Reason);
+ Assert.Contains(7, busy.State.Units.Keys);
+ Assert.Equal("Only a pioneer unit takes that order", Assert.Single(Step(c, s, new UnitOrder(8, Qualification.ReturnOrder)).Rejected).Reason);
+ Assert.Equal("There is no such unit", Assert.Single(Step(c, s, new UnitOrder(99, Qualification.ReturnOrder)).Rejected).Reason);
+ Assert.Equal("That order names no hex", Assert.Single(Step(c, s, new UnitOrder(7, Qualification.ReturnOrder, 1, 0)).Rejected).Reason);
+ // stopped, it goes at once
+ var stopped = Step(c, working, new StopWork(7), new UnitOrder(7, Qualification.ReturnOrder));
+ Assert.Empty(stopped.Rejected);
+ Assert.DoesNotContain(7, stopped.State.Units.Keys);
+ }
+
+ // R-QUAL-005: units appear at the settlement hex, the halutz with the most service first, a veteran as a veteran.
+ [Fact]
+ public void QualifiedPioneersReappearAsUnitsAtTheSettlementHex()
+ {
+ var c = Town();
+ var q = new Qualified(0, 2, new[] { 0, 2, 3 });
+ var s = WithCity(c, new City("town_a", 12, 8, 6, 0, 0, jobsDefault: false, qualified: q));
+ var halutz = Step(c, s, new ReassignPioneers("town_a", "halutz", 2));
+ Assert.Empty(halutz.Rejected);
+ var units = halutz.State.Units.Values.OrderBy(u => u.Id).ToList();
+ Assert.Equal(new[] { 3, 2 }, units.Select(u => u.Service));
+ Assert.All(units, u => Assert.Equal(("halutz", 1, 0, ""), (u.Type, u.Q, u.R, u.Side)));
+ Assert.Equal(new[] { 0 }, halutz.State.Cities["town_a"].Qualified.Halutzim);
+ Assert.Equal(4, halutz.State.Cities["town_a"].Civilians);
+ Assert.Equal(People(s), People(halutz.State));
+ Assert.Equal(Step(c, s).State.Treasury, halutz.State.Treasury, 9);
+
+ var vet = Step(c, s, new ReassignPioneers("town_a", "veteran_halutz", 1));
+ Assert.Empty(vet.Rejected);
+ var u1 = Assert.Single(vet.State.Units.Values);
+ Assert.Equal(("veteran_halutz", 4, 1, 0), (u1.Type, u1.Service, u1.Q, u1.R));
+ Assert.Equal(1, vet.State.Cities["town_a"].Qualified.Veterans);
+ Assert.Equal(3, vet.State.Cities["town_a"].Qualified.Halutzim.Count); // the halutzim are untouched
+ }
+
+ [Fact]
+ public void ReassigningPioneersIsRefusedAsStated()
+ {
+ var c = Town();
+ var s = WithCity(c, new City("town_a", 12, 8, 3, 2, 0, jobsDefault: false, qualified: new Qualified(0, 1, new[] { 1, 1 }))); // 1 idle
+ foreach (var (cmd, why) in new (Command, string)[] {
+ (new ReassignPioneers("nowhere", "halutz", 1), "There is no such city"),
+ (new ReassignPioneers("town_a", "soldier", 1), "There is no such qualification"),
+ (new ReassignPioneers("town_a", "halutz", 0), "Reassign at least one group"),
+ (new ReassignPioneers("town_a", "veteran_halutz", 2), "Town A has 1 qualified veteran pioneers"),
+ (new ReassignPioneers("town_a", "halutz", 3), "Town A has 2 qualified halutzim"),
+ (new ReassignPioneers("town_a", "halutz", 2), "Town A has 1 civilians without work") })
+ {
+ var r = Step(c, s, cmd);
+ Assert.Equal(why, Assert.Single(r.Rejected).Reason);
+ Assert.Equal(Step(c, s).State.Hash(), r.State.Hash());
+ }
+ }
+
+ // Done-when: nobody is duplicated or lost over a full round trip, a veteran stays one, service is kept.
+ [Fact]
+ public void ARoundTripKeepsEveryPersonAndTheirStatus()
+ {
+ var c = Town();
+ var s = WithCity(c, new City("town_a", 12, 8, 4, 0, 0, craftsmen: 1, jobsDefault: false), new Unit(5, "halutz", 1, 0, 2), new Unit(6, "veteran_halutz", 1, 0, 4));
+ var before = People(s);
+ s = Step(c, s, new UnitOrder(5, Qualification.ReturnOrder), new UnitOrder(6, Qualification.ReturnOrder), new ReturnCraftsmen("town_a", 1)).State;
+ Assert.Equal(before, People(s));
+ Assert.Empty(s.Units);
+ Assert.Equal((7, 0, 3), (s.Cities["town_a"].Civilians, s.Cities["town_a"].Craftsmen, s.Cities["town_a"].Qualified.Total));
+ s = Step(c, s, new ReassignPioneers("town_a", "halutz", 1), new ReassignPioneers("town_a", "veteran_halutz", 1), new ReassignCraftsmen("town_a", 1)).State;
+ Assert.Equal(before, People(s));
+ var x = s.Cities["town_a"];
+ Assert.Equal((4, 1, 0), (x.Civilians, x.Craftsmen, x.Qualified.Total));
+ Assert.Equal(new[] { ("halutz", 2), ("veteran_halutz", 4) }, s.Units.Values.OrderBy(u => u.Id).Select(u => (u.Type, u.Service)));
+ }
+
+ // R-QUAL-007: nothing is written for a city without qualified civilians; the order they returned in does not matter.
+ [Fact]
+ public void QualifiedCiviliansReachTheHashOnlyWhenThereAreSomeInASortedOrder()
+ {
+ string H(City x) { var g = new GameState(); g.Cities[x.Id] = x; return g.Hash(); }
+ var none = new City("a", 1, 1, 3, 1, 0);
+ Assert.Equal(H(none), H(new City("a", 1, 1, 3, 1, 0, qualified: Qualified.None)));
+ Assert.Equal("a=1,1,3,1,0", none.Canonical());
+ var hashes = new[] { new Qualified(1, 0, new int[0]), new Qualified(0, 1, new int[0]), new Qualified(0, 0, new[] { 2 }), new Qualified(0, 0, new[] { 2, 3 }),
+ }.Select(q => H(new City("a", 1, 1, 3, 1, 0, qualified: q))).Append(H(none)).ToList();
+ Assert.Equal(hashes.Count, new HashSet<string>(hashes).Count);
+ Assert.Equal(new Qualified(0, 0, new int[0]).AddHalutz(3).AddHalutz(2).Canonical(), new Qualified(0, 0, new int[0]).AddHalutz(2).AddHalutz(3).Canonical());
+ Assert.Equal(",qcraftsmen=1,qhalutz=2:3,qveterans=2", new Qualified(1, 2, new[] { 2, 3 }).Canonical());
+ }
+
+ // R-SAVE: the new orders are saved and replayed to the same state, in a scenario and as a unit order.
+ [Fact]
+ public void TheNewOrdersSaveReplayAndRunInAScenario()
+ {
+ var c = Town();
+ var g = GameSession.New(c, 1, Mode.Historical);
+ g.State.Cities["town_a"] = new City("town_a", 12, 8, 4, 0, 0, craftsmen: 1);
+ g.State.Units.Add(g.State.NextId, new Unit(g.State.NextId, "halutz", 1, 0, 2));
+ var unit = g.State.NextId++;
+ g.Step(new Command[] { new ReturnCraftsmen("town_a", 1), new UnitOrder(unit, Qualification.ReturnOrder) });
+ var text = g.Save.Write();
+ Assert.Contains("retcraft town_a 1", text);
+ Assert.Contains("order " + unit + " return_civilian", text);
+ foreach (var cmd in new Command[] { new ReassignCraftsmen("town_a", 1), new ReassignPioneers("town_a", "halutz", 1) })
+ {
+ var other = GameSession.New(c, 1, Mode.Historical);
+ other.Step(new[] { cmd }); // refused here, but written and parsed back as the same order
+ Assert.Equal(cmd.GetType(), SaveGame.Parse(other.Save.Write()).Turns.Single().Single().GetType());
+ }
+ var yaml = "name: q\nuntil: 1948-06-01\nsteps:\n - on: 1948-05-15\n commands:\n - { kind: reassign_pioneers, city: town_a, track: halutz, count: 1 }\n";
+ var built = Scenario.Parse(yaml).Steps.Single().Built.Single();
+ Assert.Equal(("town_a", "halutz", 1), (((ReassignPioneers)built).City, ((ReassignPioneers)built).Track, ((ReassignPioneers)built).Count));
+ }
+
+ // R-QUAL-002 and R-QUAL-004: Employed is untouched by a return and by a reassignment, and Idle stays as it was.
+ [Fact]
+ public void EmployedAndIdleAreUnchangedByReturnAndReassignment()
+ {
+ var c = Town();
+ var s = WithCity(c, new City("town_a", 12, 8, 4, 5, 0, craftsmen: 3, jobsDefault: false)); // 5 in work: 3 craftsmen and 2 civilians
+ var idle = Training.Idle(s.Cities["town_a"]);
+ var back = Step(c, s, new ReturnCraftsmen("town_a", 2)).State.Cities["town_a"];
+ Assert.Equal((5, idle), (back.Employed, Training.Idle(back)));
+ var again = Step(c, WithCity(c, back), new ReassignCraftsmen("town_a", 2));
+ Assert.Empty(again.Rejected);
+ var x = again.State.Cities["town_a"];
+ Assert.Equal((5, idle, 3, 0), (x.Employed, Training.Idle(x), x.Craftsmen, x.Qualified.Total));
+ }
+
+ // R-SAVE: a played session of the new orders replays to the live state, and the other scenario kinds build.
+ [Fact]
+ public void ASessionOfTheNewOrdersReplaysToTheSameHash()
+ {
+ var c = Town();
+ var g = GameSession.New(c, 1, Mode.Historical);
+ g.Step(new Command[] { new Train("town_a", "halutz", 1) });
+ var loaded = GameSession.Load(c, g.Save.Write(), out var warnings);
+ Assert.Empty(warnings);
+ Assert.Equal(g.State.Hash(), loaded.State.Hash());
+ var yaml = "name: q\nuntil: 1948-06-01\nsteps:\n - on: 1948-05-15\n commands:\n - { kind: return_craftsmen, city: town_a, count: 1 }\n - { kind: reassign_craftsmen, city: town_a, count: 2 }\n - { kind: unit_order, unit: 3, order: return_civilian }\n";
+ var built = Scenario.Parse(yaml).Steps.Single().Built;
+ Assert.Equal(new[] { typeof(ReturnCraftsmen), typeof(ReassignCraftsmen), typeof(UnitOrder) }, built.Select(x => x.GetType()));
+ Assert.Equal(Qualification.ReturnOrder, ((UnitOrder)built[2]).Order);
+ }
+
+ // Owner ruling 1: "the normal Attention of an order": a craftsman's is assign_workers' 0.5, a pioneer unit's is free.
+ [Fact]
+ public void TheOrdersCostTheNormalAttentionOfAnOrder()
+ {
+ var c = ContentLoader.Load(RealContentTests.ContentRoot());
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ Assert.Equal(AttentionSystem.Cost(c, s, "assign_workers"), AttentionSystem.Cost(c, s, Qualification.ReturnCraftsmenKind));
+ Assert.Equal(AttentionSystem.Cost(c, s, "assign_workers"), AttentionSystem.Cost(c, s, Qualification.ReassignCraftsmenKind));
+ Assert.Equal(AttentionSystem.Cost(c, s, "unit_order"), AttentionSystem.Cost(c, s, Qualification.ReassignPioneersKind));
+ Assert.Equal(0, AttentionSystem.Cost(c, s, "unit_order"));
+ }
+}
diff --git a/sim/Statecraft.Sim.Tests/SaveGameTests.cs b/sim/Statecraft.Sim.Tests/SaveGameTests.cs
index f28885ea8..e27df184d 100644
--- a/sim/Statecraft.Sim.Tests/SaveGameTests.cs
+++ b/sim/Statecraft.Sim.Tests/SaveGameTests.cs
@@ -28,7 +28,7 @@ public class SaveGameTests
new Command[] { new Appoint("finance_minister", "pm_one"), new MapAction("housing", 2, 0) },
new Command[] { new SetPolicy("odd id with spaces%", 0.5), new MapAction("transit_camp", 4, 0) },
new Command[] { new AssignWorkers("town_a", "job", 1), new UnitOrder(1, "hold") }, // GDD orders: the legacy fixture refuses them
- new Command[] { new Train("town_a", "halutz", 1), new CancelTraining(1), new Reinforce(1, "town_a", 1) }, // GDD orders too
+ new Command[] { new Train("town_a", "halutz", 1), new CancelTraining(1), new ReturnCraftsmen("town_a", 1), new ReassignCraftsmen("town_a", 1), new ReassignPioneers("town_a", "halutz", 1), new Reinforce(1, "town_a", 1) }, // GDD orders too
new Command[] { new PioneerWork(1, "build_yishuv", "site_a"), new StopWork(1), new StartProject("housing", "town_a", 1, 1), new CancelProject(1), new BuyArms(2), new Move(1, -2, 3), new ResolveCapture("town_a", "raid") },
new Command[] { new SecurityOrder(1) }, new Command[0],
};
diff --git a/sim/Statecraft.Sim.Tests/TurnPreviewTests.cs b/sim/Statecraft.Sim.Tests/TurnPreviewTests.cs
index b477f50dd..6c2eed84a 100644
--- a/sim/Statecraft.Sim.Tests/TurnPreviewTests.cs
+++ b/sim/Statecraft.Sim.Tests/TurnPreviewTests.cs
@@ -65,6 +65,11 @@ public class TurnPreviewTests
Assert.True(Simulation.IsInstant(new UnitOrder(1, Orders.Hold)));
Assert.True(Simulation.IsInstant(new UnitOrder(1, Combat.Attack, 2, 2)));
Assert.False(Simulation.IsInstant(new UnitOrder(1, Demobilization.SendHome)));
+ // R-QUAL-003 (#1511): Return commits at once like fortify; the city's qualification orders wait for End turn like assign_workers.
+ Assert.True(Simulation.IsInstant(new UnitOrder(1, Qualification.ReturnOrder)));
+ Assert.False(Simulation.IsInstant(new ReassignCraftsmen("town_a", 1)));
+ Assert.False(Simulation.IsInstant(new ReassignPioneers("town_a", "halutz", 1)));
+ Assert.False(Simulation.IsInstant(new ReturnCraftsmen("town_a", 1)));
Assert.False(Simulation.IsInstant(new BuyArms(1)));
Assert.False(Simulation.IsInstant(new ResolveCapture("lod", SettlementControl.Raid)));
Assert.False(Simulation.IsInstant(new SetPolicy("rationing", 0.5)));
diff --git a/sim/Statecraft.Sim/AttentionSystem.cs b/sim/Statecraft.Sim/AttentionSystem.cs
index 21193690d..2357f4528 100644
--- a/sim/Statecraft.Sim/AttentionSystem.cs
+++ b/sim/Statecraft.Sim/AttentionSystem.cs
@@ -8,11 +8,11 @@ namespace Statecraft.Sim
public static class AttentionSystem
{
static readonly HashSet<string> Kinds = new HashSet<string>
- { "set_policy", "allocate_budget", "choose_event_option", "set_mobilization", "security_order", "appoint", "map_action", "assign_workers", "train", "cancel_training", "reinforce", "pioneer_work", "stop_work", "start_project", "cancel_project", "buy_arms", "move", "unit_order", "resolve_capture" };
+ { "set_policy", "allocate_budget", "choose_event_option", "set_mobilization", "security_order", "appoint", "map_action", "assign_workers", "train", "cancel_training", "reinforce", "return_craftsmen", "reassign_craftsmen", "reassign_pioneers", "pioneer_work", "stop_work", "start_project", "cancel_project", "buy_arms", "move", "unit_order", "resolve_capture" };
/// <summary>The kinds only the GDD v0.1 loop runs. Rules price them only when systems.loop is gdd, and the legacy loop
/// refuses them before charging Attention.</summary>
- static readonly HashSet<string> GddKinds = new HashSet<string> { "assign_workers", "train", "cancel_training", "reinforce", "pioneer_work", "stop_work", "start_project", "cancel_project", "buy_arms", "move", "unit_order", "resolve_capture" };
+ static readonly HashSet<string> GddKinds = new HashSet<string> { "assign_workers", "train", "cancel_training", "reinforce", "return_craftsmen", "reassign_craftsmen", "reassign_pioneers", "pioneer_work", "stop_work", "start_project", "cancel_project", "buy_arms", "move", "unit_order", "resolve_capture" };
public static IReadOnlyCollection<string> CommandKinds => Kinds;
diff --git a/sim/Statecraft.Sim/Commands.cs b/sim/Statecraft.Sim/Commands.cs
index 432c40826..5194e2c6b 100644
--- a/sim/Statecraft.Sim/Commands.cs
+++ b/sim/Statecraft.Sim/Commands.cs
@@ -85,6 +85,34 @@ namespace Statecraft.Sim
public CancelTraining(int cohort) { Cohort = cohort; }
}
+ /// <summary>Returns <see cref="Count"/> of <see cref="City"/>'s craftsmen to civilian life, keeping their qualification
+ /// (Qualification.ReturnCraftsmen, R-QUAL-002). GDD v0.1 loop only.</summary>
+ public sealed class ReturnCraftsmen : Command
+ {
+ public override string Kind => Qualification.ReturnCraftsmenKind;
+ public string City { get; } public int Count { get; }
+ public ReturnCraftsmen(string city, int count) { City = city; Count = count; }
+ }
+
+ /// <summary>Puts <see cref="Count"/> of <see cref="City"/>'s qualified craftsmen back among its craftsmen, with no
+ /// training (Qualification.ReassignCraftsmen, R-QUAL-004). GDD v0.1 loop only.</summary>
+ public sealed class ReassignCraftsmen : Command
+ {
+ public override string Kind => Qualification.ReassignCraftsmenKind;
+ public string City { get; } public int Count { get; }
+ public ReassignCraftsmen(string city, int count) { City = city; Count = count; }
+ }
+
+ /// <summary>Puts <see cref="Count"/> of <see cref="City"/>'s qualified halutzim (<see cref="Track"/> `halutz`) or veteran
+ /// pioneers (`veteran_halutz`) back on the map as units, with no training (Qualification.ReassignPioneers, R-QUAL-005).
+ /// GDD v0.1 loop only.</summary>
+ public sealed class ReassignPioneers : Command
+ {
+ public override string Kind => Qualification.ReassignPioneersKind;
+ public string City { get; } public string Track { get; } public int Count { get; }
+ public ReassignPioneers(string city, string track, int count) { City = city; Track = track; Count = count; }
+ }
+
/// <summary>Starts <see cref="Count"/> groups of <see cref="City"/>'s civilians without work training as replacements for
/// damaged formation <see cref="Unit"/>, which stands on the city's settlement hex (Training.Reinforce, R-TRAIN-004; #1510).
/// GDD v0.1 loop only.</summary>
@@ -215,6 +243,9 @@ namespace Statecraft.Sim
case AssignWorkers w: Text(w.City, "City"); Text(w.Role, "Role"); break;
case Train t: Text(t.City, "City"); Text(t.Track, "Track"); break;
case CancelTraining _: break;
+ case ReturnCraftsmen r: Text(r.City, "City"); break;
+ case ReassignCraftsmen r: Text(r.City, "City"); break;
+ case ReassignPioneers r: Text(r.City, "City"); Text(r.Track, "Track"); break;
case Reinforce r: Text(r.City, "City"); break;
case PioneerWork p: Text(p.Action, "Action"); Text(p.Site, "Site"); break;
case StopWork _: break;
diff --git a/sim/Statecraft.Sim/Demobilization.cs b/sim/Statecraft.Sim/Demobilization.cs
index 0d985c5ba..5e2660c5c 100644
--- a/sim/Statecraft.Sim/Demobilization.cs
+++ b/sim/Statecraft.Sim/Demobilization.cs
@@ -77,7 +77,7 @@ namespace Statecraft.Sim
/// <summary>The nearest of the cities by hex distance to its settlement hex; a tie takes the city's id in ordinal
/// order (agent default - the ruling sets no tie break).</summary>
- static string Nearest(Content c, int q, int r) => c.Cities
+ internal static string Nearest(Content c, int q, int r) => c.Cities
.OrderBy(x => { var h = c.SettlementHexes.First(h => h.Id == x.Id); return MapActions.Distance(q, r, h.Q, h.R); })
.ThenBy(x => x.Id, StringComparer.Ordinal)
.First().Id;
diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.cs
index c50b493eb..54e6f2665 100644
--- a/sim/Statecraft.Sim/EventSystem.cs
+++ b/sim/Statecraft.Sim/EventSystem.cs
@@ -136,7 +136,7 @@ namespace Statecraft.Sim
var delta = (int)x.Delta;
var housing = x.Field == HousingField ? Math.Max(0, city.HousingCapacity + delta) : city.HousingCapacity;
var jobs = x.Field == JobsField ? Math.Max(city.Employed, city.JobSlots + delta) : city.JobSlots;
- s.Cities[x.City] = new City(city.Id, housing, jobs, city.Civilians, city.Employed, city.Refugees, city.Recruits, city.Condition, city.Craftsmen, city.JobsDefault);
+ s.Cities[x.City] = new City(city.Id, housing, jobs, city.Civilians, city.Employed, city.Refugees, city.Recruits, city.Condition, city.Craftsmen, city.JobsDefault, city.Qualified);
var applied = housing - city.HousingCapacity + jobs - city.JobSlots;
why.Add(new Cause("events", x.City + "." + x.Field, applied, $"{CityChange(c, x.City, x.Field, applied)} ({title})"));
}
diff --git a/sim/Statecraft.Sim/GddState.cs b/sim/Statecraft.Sim/GddState.cs
index b44158716..72334ac97 100644
--- a/sim/Statecraft.Sim/GddState.cs
+++ b/sim/Statecraft.Sim/GddState.cs
@@ -66,28 +66,34 @@ namespace Statecraft.Sim
/// <summary>The city's housing condition, 0 to 1, an average over the city (GDD "Housing condition"; D-D2, Q-HOUSE-2;
/// R-HOUSE-001). Null only on a record made without one (a test's hand-built city); every GDD game's cities have one.</summary>
public double? Condition { get; }
+ /// <summary>The civilians who keep a pioneer's or craftsman's qualification (R-QUAL-001): part of <see cref="Civilians"/>,
+ /// not in addition to them. <see cref="Qualified.None"/> in every city until someone returns to civilian life.</summary>
+ public Qualified Qualified { get; }
public City(string id, int housingCapacity, int jobSlots, int civilians, int employed, int refugees, int recruits = 0,
- double? condition = null, int craftsmen = 0, bool jobsDefault = true)
+ double? condition = null, int craftsmen = 0, bool jobsDefault = true, Qualified? qualified = null)
{
Id = id; HousingCapacity = housingCapacity; JobSlots = jobSlots; Civilians = civilians; Employed = employed; Refugees = refugees;
- Recruits = recruits; Condition = condition; Craftsmen = craftsmen; JobsDefault = jobsDefault;
+ Recruits = recruits; Condition = condition; Craftsmen = craftsmen; JobsDefault = jobsDefault; Qualified = qualified ?? Qualified.None;
}
/// <summary>The same city with new population counts.</summary>
- public City WithCounts(int civilians, int employed, int refugees) => new City(Id, HousingCapacity, JobSlots, civilians, employed, refugees, Recruits, Condition, Craftsmen, JobsDefault);
+ public City WithCounts(int civilians, int employed, int refugees) => new City(Id, HousingCapacity, JobSlots, civilians, employed, refugees, Recruits, Condition, Craftsmen, JobsDefault, Qualified);
/// <summary>The same city with a new number of recruits.</summary>
- public City WithRecruits(int recruits) => new City(Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees, recruits, Condition, Craftsmen, JobsDefault);
+ public City WithRecruits(int recruits) => new City(Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees, recruits, Condition, Craftsmen, JobsDefault, Qualified);
/// <summary>The same city with a new number of craftsmen.</summary>
- public City WithCraftsmen(int craftsmen) => new City(Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees, Recruits, Condition, craftsmen, JobsDefault);
+ public City WithCraftsmen(int craftsmen) => new City(Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees, Recruits, Condition, craftsmen, JobsDefault, Qualified);
/// <summary>The same city with its job default on or off.</summary>
- public City WithJobsDefault(bool enabled) => new City(Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees, Recruits, Condition, Craftsmen, enabled);
+ public City WithJobsDefault(bool enabled) => new City(Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees, Recruits, Condition, Craftsmen, enabled, Qualified);
/// <summary>The same city with a new housing condition.</summary>
- public City WithCondition(double condition) => new City(Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees, Recruits, condition, Craftsmen, JobsDefault);
+ public City WithCondition(double condition) => new City(Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees, Recruits, condition, Craftsmen, JobsDefault, Qualified);
+
+ /// <summary>The same city with new qualified civilians (R-QUAL-001).</summary>
+ public City WithQualified(Qualified qualified) => new City(Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees, Recruits, Condition, Craftsmen, JobsDefault, qualified);
/// <summary>The record as the state hash writes it. The recruits are written only when there are some, the condition
/// only when it is set (",c" and its 64 bits in hex; readable, the value and then the bits), the craftsmen only when
@@ -105,7 +111,7 @@ namespace Statecraft.Sim
}
if (Craftsmen != 0) text += ",craftsmen=" + Craftsmen.ToString(CultureInfo.InvariantCulture);
if (!JobsDefault) text += ",jobs=manual";
- return text;
+ return text + Qualified.Canonical();
}
}
diff --git a/sim/Statecraft.Sim/Projects.cs b/sim/Statecraft.Sim/Projects.cs
index c4fb6909a..519ee5868 100644
--- a/sim/Statecraft.Sim/Projects.cs
+++ b/sim/Statecraft.Sim/Projects.cs
@@ -357,7 +357,7 @@ namespace Statecraft.Sim
var k = c.ProjectKinds.First(x => x.Id == p.Kind);
var x = s.Cities[p.City];
var condition = x.Condition is double now ? Math.Min(1.0, Math.Max(0.0, now + k.Condition)) : (double?)null;
- s.Cities[p.City] = new City(x.Id, x.HousingCapacity + k.Capacity, x.JobSlots + k.JobSlots, x.Civilians, x.Employed, x.Refugees, x.Recruits, condition, x.Craftsmen, x.JobsDefault);
+ s.Cities[p.City] = new City(x.Id, x.HousingCapacity + k.Capacity, x.JobSlots + k.JobSlots, x.Civilians, x.Employed, x.Refugees, x.Recruits, condition, x.Craftsmen, x.JobsDefault, x.Qualified);
why.Add(new Cause("city", p.City, 1, $"{PlayerText.Settlement(c, p.City)}: {k.Name} was finished"));
}
}
diff --git a/sim/Statecraft.Sim/Qualification.cs b/sim/Statecraft.Sim/Qualification.cs
new file mode 100644
index 000000000..a48f1e987
--- /dev/null
+++ b/sim/Statecraft.Sim/Qualification.cs
@@ -0,0 +1,159 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+
+namespace Statecraft.Sim
+{
+ /// <summary>The civilians of one city who keep a qualification (R-QUAL-001; #1511, owner ruling "Two-way, keep training",
+ /// 23 October 2026): craftsmen, halutzim and veteran pioneers who went back to civilian life. Immutable; a change replaces
+ /// the record. They are part of <see cref="City.Civilians"/>, so jobs, housing and training treat them as ordinary civilians
+ /// (owner ruling 2). A halutz keeps the turns of service it had (owner ruling 3), one entry per group.</summary>
+ public sealed class Qualified
+ {
+ public static readonly Qualified None = new Qualified(0, 0, Array.Empty<int>());
+
+ public int Craftsmen { get; }
+ public int Veterans { get; }
+ /// <summary>The service of each qualified halutz group, ascending (so the record is the same whatever order they returned in).</summary>
+ public IReadOnlyList<int> Halutzim { get; }
+
+ public Qualified(int craftsmen, int veterans, IReadOnlyList<int> halutzim)
+ {
+ Craftsmen = craftsmen; Veterans = veterans; Halutzim = halutzim.OrderBy(x => x).ToArray();
+ }
+
+ public int Total => Craftsmen + Veterans + Halutzim.Count;
+
+ public Qualified WithCraftsmen(int n) => new Qualified(n, Veterans, Halutzim);
+ public Qualified WithVeterans(int n) => new Qualified(Craftsmen, n, Halutzim);
+
+ /// <summary>One more halutz group with <paramref name="service"/> turns of service.</summary>
+ public Qualified AddHalutz(int service) => new Qualified(Craftsmen, Veterans, Halutzim.Append(service).OrderBy(x => x).ToArray());
+
+ /// <summary>Without the <paramref name="n"/> halutz groups with the most service (R-QUAL-005's pick).</summary>
+ public Qualified TakeHalutzim(int n) => new Qualified(Craftsmen, Veterans, Halutzim.Take(Halutzim.Count - n).ToArray());
+
+ /// <summary>Without <paramref name="n"/> qualified people, taken in the order R-QUAL-006 sets: craftsmen, then halutz
+ /// groups with the least service, then veterans.</summary>
+ public Qualified Lose(int n)
+ {
+ var c = Math.Min(n, Craftsmen); n -= c;
+ var h = Math.Min(n, Halutzim.Count); n -= h;
+ return new Qualified(Craftsmen - c, Veterans - n, Halutzim.Skip(h).ToArray());
+ }
+
+ /// <summary>The state hash's text: nothing at all when nobody is qualified, so a city without them hashes as before
+ /// (R-LOOP-002's rule).</summary>
+ public string Canonical()
+ {
+ var text = "";
+ if (Craftsmen != 0) text += ",qcraftsmen=" + Craftsmen.ToString(CultureInfo.InvariantCulture);
+ if (Halutzim.Count != 0) text += ",qhalutz=" + string.Join(":", Halutzim.Select(x => x.ToString(CultureInfo.InvariantCulture)));
+ if (Veterans != 0) text += ",qveterans=" + Veterans.ToString(CultureInfo.InvariantCulture);
+ return text;
+ }
+ }
+
+ /// <summary>Return to civilian life and reassignment (docs/rules/mvp.md R-QUAL-001 to R-QUAL-007; #1511). Instant, no Money:
+ /// a craftsman's or a halutz's qualification is kept in the city, and a qualified civilian without a job goes back into
+ /// the trained role without R-TRAIN-001's training.</summary>
+ public static class Qualification
+ {
+ public const string ReturnCraftsmenKind = "return_craftsmen";
+ public const string ReassignCraftsmenKind = "reassign_craftsmen";
+ public const string ReassignPioneersKind = "reassign_pioneers";
+ /// <summary>The unit order of the pioneer's return (R-QUAL-003).</summary>
+ public const string ReturnOrder = "return_civilian";
+
+ static string Groups(int n) => n == 1 ? "1 group" : FormattableString.Invariant($"{n} groups");
+
+ /// <summary>R-QUAL-002: <paramref name="count"/> of the city's craftsmen become qualified civilians. Refused, state
+ /// 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)
+ {
+ if (!s.Cities.TryGetValue(city, out var x)) return "There is no such city";
+ if (count < 1) return "Return at least one group";
+ 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)
+ .WithQualified(x.Qualified.WithCraftsmen(x.Qualified.Craftsmen + count));
+ why.Add(new Cause("city", city, count, $"{name}: {Groups(count)} of craftsmen returned to civilian life and keep their training"));
+ return null;
+ }
+
+ /// <summary>R-QUAL-004: <paramref name="count"/> of the city's qualified craftsmen, without a job, become craftsmen
+ /// again. Refused, state untouched, for an unknown city, a count below 1, more than the qualified craftsmen, or more than
+ /// the civilians without work (<see cref="Training.Idle"/>).</summary>
+ public static string? ReassignCraftsmen(Content c, GameState s, string city, int count, List<Cause> why)
+ {
+ if (!s.Cities.TryGetValue(city, out var x)) return "There is no such city";
+ if (count < 1) return "Reassign at least one group";
+ 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(x);
+ if (count > idle) return FormattableString.Invariant($"{name} has {idle} civilians without work");
+ s.Cities[city] = x.WithCounts(x.Civilians - count, x.Employed, x.Refugees).WithCraftsmen(x.Craftsmen + count)
+ .WithQualified(x.Qualified.WithCraftsmen(x.Qualified.Craftsmen - count));
+ why.Add(new Cause("city", city, -count, $"{name}: {Groups(count)} of qualified craftsmen are craftsmen again"));
+ return null;
+ }
+
+ /// <summary>R-QUAL-003: an idle halutz or veteran pioneer unit leaves the map and joins the nearest city's civilians,
+ /// qualified (its service kept). Null when it takes the order, else the reason; changes nothing, so the unit card can
+ /// ask before it offers the order.</summary>
+ public static string? CheckReturn(GameState s, int unitId)
+ {
+ if (!s.Units.TryGetValue(unitId, out var u)) return "There is no such unit";
+ if (!Projects.IsPioneer(u.Type)) return "Only a pioneer unit takes that order";
+ if (Projects.IsBusy(s, unitId)) return "That unit is at work; stop the work first";
+ return null;
+ }
+
+ internal static string? Return(Content c, GameState s, int unitId, List<Cause> why)
+ {
+ var refused = CheckReturn(s, unitId);
+ if (refused != null) return refused;
+ var u = s.Units[unitId];
+ var city = Demobilization.Nearest(c, u.Q, u.R);
+ s.Units.Remove(unitId);
+ var x = s.Cities[city];
+ var q = u.Type == Projects.VeteranType ? x.Qualified.WithVeterans(x.Qualified.Veterans + 1) : x.Qualified.AddHalutz(u.Service);
+ s.Cities[city] = x.WithCounts(x.Civilians + 1, x.Employed, x.Refugees).WithQualified(q);
+ why.Add(new Cause("map", unitId.ToString(CultureInfo.InvariantCulture), 1,
+ $"Unit {unitId} returned to civilian life in {PlayerText.Settlement(c, city)} and keeps its training"));
+ return null;
+ }
+
+ /// <summary>R-QUAL-005: <paramref name="count"/> of the city's qualified halutz groups (<paramref name="track"/>
+ /// `halutz`) or veteran pioneers (`veteran_halutz`), without a job, reappear as units at its settlement hex. Refused,
+ /// state untouched, for an unknown city, another track, a count below 1, more than the city's qualified ones, or more
+ /// than its civilians without work.</summary>
+ public static string? ReassignPioneers(Content c, GameState s, string city, string track, int count, List<Cause> why)
+ {
+ if (!s.Cities.TryGetValue(city, out var x)) return "There is no such city";
+ var veteran = track == Projects.VeteranType;
+ if (!veteran && track != "halutz") return "There is no such qualification";
+ if (count < 1) return "Reassign at least one group";
+ var name = PlayerText.Settlement(c, city);
+ var have = veteran ? x.Qualified.Veterans : x.Qualified.Halutzim.Count;
+ if (count > have) return FormattableString.Invariant($"{name} has {have} qualified {(veteran ? "veteran pioneers" : "halutzim")}");
+ var idle = Training.Idle(x);
+ if (count > idle) return FormattableString.Invariant($"{name} has {idle} civilians without work");
+ var hex = c.SettlementHexes.First(h => h.Id == city); // every settlement has one (ValidateMap)
+ var q = x.Qualified;
+ // R-QUAL-005: the most service first (owner, 24 October 2026: "Accept all as built", https://github.com/eyalgolan/statecraft-israel/issues/1511#issuecomment-6375597377). A veteran comes back with the service
+ // that made it one (R-VET-001).
+ var served = veteran ? new int[count] : q.Halutzim.Skip(q.Halutzim.Count - count).Reverse().ToArray();
+ for (int i = 0; i < count; i++)
+ {
+ var id = s.NextId++;
+ s.Units.Add(id, new Unit(id, track, hex.Q, hex.R, veteran ? c.RulesAt(s.Date).Mvp!.VeteranHalutzService!.Value : served[i]));
+ }
+ s.Cities[city] = x.WithCounts(x.Civilians - count, x.Employed, x.Refugees)
+ .WithQualified(veteran ? q.WithVeterans(q.Veterans - count) : q.TakeHalutzim(count));
+ why.Add(new Cause("city", city, -count, $"{name}: {Groups(count)} of qualified {(veteran ? "veteran pioneers" : "halutzim")} are units again"));
+ return null;
+ }
+ }
+}
diff --git a/sim/Statecraft.Sim/SaveGame.cs b/sim/Statecraft.Sim/SaveGame.cs
index 56e49e6c7..eff0d0cb9 100644
--- a/sim/Statecraft.Sim/SaveGame.cs
+++ b/sim/Statecraft.Sim/SaveGame.cs
@@ -143,6 +143,9 @@ namespace Statecraft.Sim
AssignWorkers w => $"work {Esc(w.City)} {Esc(w.Role)} {Int(w.Count)}",
Train t => $"train {Esc(t.City)} {Esc(t.Track)} {Int(t.Count)}",
CancelTraining t => $"untrain {Int(t.Cohort)}",
+ ReturnCraftsmen r => $"retcraft {Esc(r.City)} {Int(r.Count)}",
+ ReassignCraftsmen r => $"regcraft {Esc(r.City)} {Int(r.Count)}",
+ ReassignPioneers r => $"regpioneer {Esc(r.City)} {Esc(r.Track)} {Int(r.Count)}",
Reinforce r => $"reinforce {Int(r.Unit)} {Esc(r.City)} {Int(r.Count)}",
PioneerWork p => $"pioneer {Int(p.Unit)} {Esc(p.Action)} {Esc(p.Site)}",
StopWork w => $"stop {Int(w.Unit)}",
@@ -258,6 +261,9 @@ namespace Statecraft.Sim
case "work": Arity(4); return new AssignWorkers(Str(f[1]), Str(f[2]), I(f[3]));
case "train": Arity(4); return new Train(Str(f[1]), Str(f[2]), I(f[3]));
case "untrain": Arity(2); return new CancelTraining(I(f[1]));
+ case "retcraft": Arity(3); return new ReturnCraftsmen(Str(f[1]), I(f[2]));
+ case "regcraft": Arity(3); return new ReassignCraftsmen(Str(f[1]), I(f[2]));
+ case "regpioneer": Arity(4); return new ReassignPioneers(Str(f[1]), Str(f[2]), I(f[3]));
case "reinforce": Arity(4); return new Reinforce(I(f[1]), Str(f[2]), I(f[3]));
case "pioneer": Arity(4); return new PioneerWork(I(f[1]), Str(f[2]), Str(f[3]));
case "stop": Arity(2); return new StopWork(I(f[1]));
diff --git a/sim/Statecraft.Sim/Scenario.cs b/sim/Statecraft.Sim/Scenario.cs
index 2a4d93a3b..076329b52 100644
--- a/sim/Statecraft.Sim/Scenario.cs
+++ b/sim/Statecraft.Sim/Scenario.cs
@@ -21,7 +21,7 @@ namespace Statecraft.Sim
/// </code>
/// Kinds: set_policy (policy, level), allocate_budget (shares: {office: share}), choose_event_option (event, option),
/// set_mobilization (level), security_order (delta), appoint (office, person), map_action (action, q, r), assign_workers
- /// (city, role, count), train (city, track, count), cancel_training (cohort), pioneer_work (unit, action, site), stop_work
+ /// (city, role, count), train (city, track, count), cancel_training (cohort), return_craftsmen (city, count), reassign_craftsmen (city, count), reassign_pioneers (city, track, count), pioneer_work (unit, action, site), stop_work
/// (unit), move (unit, q, r; GDD content only), unit_order (unit, order, and q, r for an attack; GDD content only). A turn with no
/// scripted command passes; events nobody answered are delegated, as in the game. A command the sim rejects fails the run.</summary>
public sealed class Scenario
@@ -64,6 +64,7 @@ namespace Statecraft.Sim
["security_order"] = new[] { "delta" }, ["appoint"] = new[] { "office", "person" },
["map_action"] = new[] { "action", "q", "r" }, ["assign_workers"] = new[] { "city", "role", "count" },
["train"] = new[] { "city", "track", "count" }, ["cancel_training"] = new[] { "cohort" },
+ ["return_craftsmen"] = new[] { "city", "count" }, ["reassign_craftsmen"] = new[] { "city", "count" }, ["reassign_pioneers"] = new[] { "city", "track", "count" },
["reinforce"] = new[] { "unit", "city", "count" },
["pioneer_work"] = new[] { "unit", "action", "site" }, ["stop_work"] = new[] { "unit" },
["unit_order"] = new[] { "unit", "order", "q", "r" }, // q and r: an attack's hex only (R-COMBAT-001)
@@ -97,6 +98,9 @@ namespace Statecraft.Sim
case "assign_workers": return new AssignWorkers(Str(c, "city"), Str(c, "role"), Whole(c, "count"));
case "train": return new Train(Str(c, "city"), Str(c, "track"), Whole(c, "count"));
case "cancel_training": return new CancelTraining(Whole(c, "cohort"));
+ case "return_craftsmen": return new ReturnCraftsmen(Str(c, "city"), Whole(c, "count"));
+ case "reassign_craftsmen": return new ReassignCraftsmen(Str(c, "city"), Whole(c, "count"));
+ case "reassign_pioneers": return new ReassignPioneers(Str(c, "city"), Str(c, "track"), Whole(c, "count"));
case "reinforce": return new Reinforce(Whole(c, "unit"), Str(c, "city"), Whole(c, "count"));
case "pioneer_work": return new PioneerWork(Whole(c, "unit"), Str(c, "action"), Str(c, "site"));
case "stop_work": return new StopWork(Whole(c, "unit"));
@@ -144,6 +148,7 @@ namespace Statecraft.Sim
SetPolicy p => $"{p.Policy} {p.Level}", ChooseEventOption e => $"{e.EventId}/{e.OptionId}", SetMobilization m => m.Level.ToString(CultureInfo.InvariantCulture),
SecurityOrder o => o.Delta.ToString(CultureInfo.InvariantCulture), Appoint a => $"{a.Office} {a.Person}", MapAction m => $"{m.Action} {m.Q},{m.R}",
AssignWorkers w => $"{w.City} {w.Role} {w.Count}", Train t => $"{t.City} {t.Track} {t.Count}", CancelTraining t => t.Cohort.ToString(CultureInfo.InvariantCulture),
+ ReturnCraftsmen r => $"{r.City} {r.Count}", ReassignCraftsmen r => $"{r.City} {r.Count}", ReassignPioneers r => $"{r.City} {r.Track} {r.Count}",
Reinforce r => FormattableString.Invariant($"{r.Unit} {r.City} {r.Count}"),
PioneerWork p => FormattableString.Invariant($"{p.Unit} {p.Action} {p.Site}"), StopWork w => w.Unit.ToString(CultureInfo.InvariantCulture),
UnitOrder o => FormattableString.Invariant($"{o.Unit} {o.Order}") + (o.Q is int q && o.R is int r ? FormattableString.Invariant($" {q},{r}") : ""),
diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.cs
index 2afbd4c77..2c5bc6ee5 100644
--- a/sim/Statecraft.Sim/Simulation.cs
+++ b/sim/Statecraft.Sim/Simulation.cs
@@ -200,6 +200,12 @@ namespace Statecraft.Sim
return Training.Start(c, s, t.City, t.Track, t.Count, why);
case CancelTraining t:
return Training.Cancel(c, s, t.Cohort, why);
+ case ReturnCraftsmen r:
+ return Qualification.ReturnCraftsmen(c, s, r.City, r.Count, why);
+ case ReassignCraftsmen r:
+ return Qualification.ReassignCraftsmen(c, s, r.City, r.Count, why);
+ case ReassignPioneers r:
+ return Qualification.ReassignPioneers(c, s, r.City, r.Track, r.Count, why);
case Reinforce r:
return Training.Reinforce(c, s, r.Unit, r.City, r.Count, why);
case PioneerWork p:
@@ -210,6 +216,7 @@ namespace Statecraft.Sim
if (o.Order == Movement.GoTo) return Movement.GiveGoTo(c, s, o.Unit, o.Q, o.R, spent, why);
if (o.Order == Combat.Attack) return Combat.Strike(c, s, o.Unit, o.Q, o.R, spent, attacked, why);
if (o.Q != null || o.R != null) return "That order names no hex";
+ if (o.Order == Qualification.ReturnOrder) return Qualification.Return(c, s, o.Unit, why);
return o.Order == Demobilization.SendHome
? Demobilization.Give(c, s, o.Unit, attacked, why)
: Orders.Give(c, s, o.Unit, o.Order, why);
diff --git a/sim/Statecraft.Sim/Training.cs b/sim/Statecraft.Sim/Training.cs
index e1b47ed3e..973ae6a60 100644
--- a/sim/Statecraft.Sim/Training.cs
+++ b/sim/Statecraft.Sim/Training.cs
@@ -127,7 +127,10 @@ namespace Statecraft.Sim
EconomySystem.PayOrBorrow(c, s, cost, "for training", why);
// R-HOUSE-003: trainees remain housed as a cohort, and recruits keep their home city's housing as formations.
// A pioneer unit leaves city housing; a craftsman remains. The employed share also reads the new counts.
- s.Cities[city] = x.WithCounts(x.Civilians - count, x.Employed, x.Refugees);
+ // R-QUAL-006: the trainees are taken from the unqualified civilians first; a qualified one taken loses its
+ // qualification, which is part of the civilians that remain.
+ var lost = Math.Max(0, x.Qualified.Total - (x.Civilians - count));
+ s.Cities[city] = x.WithCounts(x.Civilians - count, x.Employed, x.Refugees).WithQualified(lost == 0 ? x.Qualified : x.Qualified.Lose(lost));
var id = s.NextId++;
// The plan's reading of D-A6, not part of the owner's ruling: the turn of the order is the first training turn, so
// with training_turns 3 an order on turn T is done at the end of T+2 (TrainingTests.ACohortOrderedOnTurnTWithThreeTurnsFinishesAtTheEndOfTurnTPlusTwo). For "done at the end of
diff --git a/unity/Assets/Scripts/UI/SimBridge.cs b/unity/Assets/Scripts/UI/SimBridge.cs
index 61e569f85..26d76886d 100644
--- a/unity/Assets/Scripts/UI/SimBridge.cs
+++ b/unity/Assets/Scripts/UI/SimBridge.cs
@@ -57,6 +57,9 @@ namespace Statecraft.Game.UI
AssignWorkers w => "work:" + w.City,
Train t => "train:" + t.City + ":" + t.Track,
CancelTraining x => FormattableString.Invariant($"untrain:{x.Cohort}"),
+ ReturnCraftsmen r => "retcraft:" + r.City,
+ ReassignCraftsmen r => "regcraft:" + r.City,
+ ReassignPioneers r => "regpioneer:" + r.City + ":" + r.Track,
Reinforce x => FormattableString.Invariant($"reinforce:{x.Unit}"),
PioneerWork w => FormattableString.Invariant($"unit:{w.Unit}"),
StopWork w => FormattableString.Invariant($"unit:{w.Unit}"),
@@ -128,6 +131,10 @@ namespace Statecraft.Game.UI
case Train t:
return Unknown("city", t.City, Content.Cities.Select(x => x.Id))
?? Unknown("training", t.Track, Content.UnitTypes.Where(x => !string.IsNullOrEmpty(x.Facility)).Select(x => x.Id));
+ // Return and reassignment (#1511): the city id only; the sim refuses a count, a track or a busy civilian with its own reason.
+ case ReturnCraftsmen r: return Unknown("city", r.City, Content.Cities.Select(x => x.Id));
+ case ReassignCraftsmen r: return Unknown("city", r.City, Content.Cities.Select(x => x.Id));
+ case ReassignPioneers r: return Unknown("city", r.City, Content.Cities.Select(x => x.Id));
case CancelTraining x:
return Unknown("cohort", x.Cohort.ToString(System.Globalization.CultureInfo.InvariantCulture), State.Cohorts.Keys.Select(k => k.ToString(System.Globalization.CultureInfo.InvariantCulture)));
// Replacements (#1510): ids only; the sim refuses a full, enemy or misplaced unit and the training checks itself.
diff --git a/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs b/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs
index fb58bd391..1ad18f74f 100644
--- a/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs
+++ b/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs
@@ -29,6 +29,9 @@ public class SimBridgeGuardTests
[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("tel_aviv", 1),
+ [typeof(ReassignCraftsmen)] = new ReassignCraftsmen("tel_aviv", 1),
+ [typeof(ReassignPioneers)] = new ReassignPioneers("tel_aviv", "halutz", 1),
[typeof(Reinforce)] = new Reinforce(1, "tel_aviv", 1),
[typeof(PioneerWork)] = new PioneerWork(1, "build_yishuv", "mefalsim"),
[typeof(StopWork)] = new StopWork(1),