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: GDD Phase 3 PR 5, the craftsman and the job default (R-CRAFT-001, R-CRAFT-002, R-CITY-009; refs #736) (#1049)

Eyal Golan0dbffe6915d8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d4a1bab31..1c3c3027e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,11 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
scale (24x real, an 8.5 m house as long as the steam train's locomotive), and stream after the first frame in a new
`collection-special-buildings` bundle with the shikun and the workshop, which stay unplaced until a place and date are
sourced (refs #707).
+- The craftsman and the job default (GDD Phase 3 PR 5; R-CRAFT-001, R-CRAFT-002, R-CITY-009; #736): a civilian trains
+ as a craftsman in a city with a completed industry project (3 turns, IL 0.5m a group), fills an ordinary job slot and
+ earns twice the job income, all labelled design values (Q-CRAFT-1 to Q-CRAFT-3). Each city's free jobs now fill on the
+ housing step at no Attention cost until an `AssignWorkers` order fixes that city's number (Q-JOBS-1). The reference
+ player stops sending `AssignWorkers`; only `scenario-mvp-absorb-first` moves (`,jobs=manual` on Tel Aviv).
- Kiryat Shmona (founded 18 July 1949) and Beit Shemesh (15 December 1950, the National Library's December 1950
under the monthly turn) join the yishuv sites in `content/sites.yaml`, each with a field site in its hex; the
founding days are the owner's (#785), and the rows stay draft. The reference player builds them in id order, so
diff --git a/content/rules.yaml b/content/rules.yaml
index 2fa378f16..e439446c2 100644
--- a/content/rules.yaml
+++ b/content/rules.yaml
@@ -31,6 +31,7 @@ mvp:
end: 1952-01-15
people_per_unit: 1000 # DESIGN VALUE: owner-set balance, not a historical figure (D-A1: people in one population unit)
income_per_job_per_year: 0.06 # DESIGN VALUE: owner-set balance, not a historical figure (D-C6: IL millions per employed unit a year)
+ craftsman_income_multiple: 2 # DESIGN VALUE: owner-set balance, not a historical figure (D-D4, Q-CRAFT-2: an employed craftsman earns this times income_per_job_per_year; R-CRAFT-002)
# R-MONEY-002, option 3 (owner, 18 October 2026, #884): ordinary spending already represents aggregate public expense,
# so no civilian place pays upkeep in the MVP. These are design values, not claims that historical upkeep was zero.
city_upkeep_per_year: 0.0 # DESIGN VALUE: owner-set balance, not a historical figure (D-C6: IL millions per city a year)
diff --git a/content/unit_types.yaml b/content/unit_types.yaml
index e7af5dcbc..88753bce2 100644
--- a/content/unit_types.yaml
+++ b/content/unit_types.yaml
@@ -16,6 +16,11 @@ types:
training_turns: 4 # DESIGN VALUE: owner-set balance, not a historical figure (D-A3)
training_cost: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-A3: IL millions per group)
- { id: veteran_halutz, kind: unit } # a halutz unit after rules.yaml mvp.veteran_halutz_service turns of work (R-VET-001; D-D9); not trained
+ - id: craftsman # civilian to craftsman, through craft training (D-D4, Q-CRAFT-1; R-CRAFT-001)
+ kind: population # a count per city (D-A2)
+ facility: industry # a city with a completed industry project (projects.yaml, R-PROJ-003)
+ training_turns: 3 # DESIGN VALUE: owner-set balance, not a historical figure (D-A3, D-D4: Q-CRAFT-3)
+ training_cost: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-A3, D-D4: Q-CRAFT-3, IL millions per group)
# Phase 5's military types (R-UNIT-001; Q-UNIT-1, owner, 15 October 2026; #741, owner, 18 October 2026: "all defaults").
# A side and a class only: movement points come with movement (Phase 5 PR 5), strength from the unit's sourced row or
# its cohort (Q-UNIT-4) and upkeep with Phase 5 PR 3. The recruit stays a count per city until PR 3; the enemy types come in PR 4.
diff --git a/docs/determinism.md b/docs/determinism.md
index 2bd8c2175..aa7cd4ed3 100644
--- a/docs/determinism.md
+++ b/docs/determinism.md
@@ -20,7 +20,7 @@ The simulation must produce the same state, bit for bit, on .NET, Unity Mono and
with `GoldenRun.Seed = 1948` on the real `content/`, then steps with `GoldenRun.Orders` until `Date >= until`
(or the game ends, or 1000 turns pass). Since the GDD cutover (Phase 2 PR 1) the orders are the reference player's
(`Statecraft.Sim.Reference.ReferencePlayer`, decision D-A7): a stated test policy, not game AI and not history. It sends
-`HistoricalAI`'s orders, then fills each city's jobs, then trains one halutz group when there is none and none in training,
+`HistoricalAI`'s orders and leaves the jobs to each city's default (R-CITY-009), then trains one halutz group when there is none and none in training,
while the turn's Attention and the Treasury last. No game mode or UI reaches it (`ReferencePlayerTests`); every copy of the
golden loop (the writer preview, the invariants, the era goldens) takes its orders from `GoldenRun.Orders`. The real game
plays the GDD loop on monthly turns from 15 May 1948 and ends on 15 January 1952 after 44 turns (R-LOOP-004). Each run's
@@ -294,3 +294,4 @@ The hash reads the state keys, so it never sees a record outside its window. An
| GDD Phase 3 PR 4 | 1952 | `548a6acc` | same; five Tel Aviv projects built (1949-08-15 to 1951-08-15; capacity 273, was 248) and a sixth, in Haifa, being built. Every city is back at condition 0 by the end, so `housing` is unchanged and `morale` moves only in the 10th decimal; debt IL 223.9m (was 187.9m, 6 x IL 6m), inside invariants.yaml's 100 to 300 band; stability 0.4432 (unchanged to 4 places) (was `b34faec6`) |
| GDD Phase 3 PR 4 | mvp-end | `548a6acc` | same; the same run as hash1952 (was `b34faec6`) |
| GDD Phase 7 PR 5 | scenario-mvp-defeat | `d1e0dcf6` | new: full mobilisation and the non-historical option of the four foreign currency cards; the debt passes the IL 250m ceiling on 15 April 1951, foreign currency runs out on 15 August, food imports stop, the stock is empty from 15 November, and the third turn end with Money and Food both exhausted ends the game with `defeat_economy` on 15 January 1952 (`exhausted=3`). No other golden moves: the reference and the no-order runs never have Food at 0, so the counter stays at 0 and out of the hash. Rebased on the Hula swamp (#968): `hula_drainage` no longer fires in this run (no works at the Hula) and, as in the 1952 run on main, `iraqi_exodus` resolves to `airlift` (was `pace`), so the end state differs; the defeat dates above are unchanged (was `cbebedfa` before the rebase) |
+| GDD Phase 3 PR 5 | scenario-mvp-absorb-first | `be13c409` | the job default and the craftsman (R-CITY-009, R-CRAFT-001, R-CRAFT-002; Q-JOBS-1, Q-CRAFT-1 to Q-CRAFT-3, owner, 15 October 2026, #375; #736): the scenario's one order, `AssignWorkers` for 90 of Tel Aviv's 106 jobs on 15 May 1948, now turns Tel Aviv's job default off, so its `city{}` record gains `,jobs=manual`. No number moves: Tel Aviv keeps its 90 as before, and the other cities' jobs stay full. `hash1950`, `hash1952`, `mvp-end`, `smoke5`, `scenario-cautious`, `scenario-reckless` and `scenario-mvp-defeat` do not move: the reference player no longer sends `AssignWorkers`, and on those runs the default fills the same jobs it did; nobody trains a craftsman (was `a77a8f20`) |
diff --git a/docs/gdd/craftsman.md b/docs/gdd/craftsman.md
new file mode 100644
index 000000000..8015a903a
--- /dev/null
+++ b/docs/gdd/craftsman.md
@@ -0,0 +1,41 @@
+# Craftsman, and the default that fills jobs
+
+## Player story
+
+As a player of the MVP, I want to train craftsmen in a city that has industry, so that its jobs earn more Money (GDD "Population and units": a craftsman "Generates more money than an ordinary civilian" [S1]); and I want each city's free jobs filled without an order, so that I am not assigning jobs by hand in twelve cities every month (the impact plan's Phase 3 risk [S2]).
+
+## Rules
+
+- A craftsman is a count per city, not a movable unit, and not one of the city's civilians (D-A2 [S2]) (R-CRAFT-001).
+- `Train(city, craftsman, n)` follows the training rules (`training.md`) in a city with a completed industry project; a project still being built does not count (`Q-CRAFT-1`, decided 15 October 2026 [S3]) (R-CRAFT-001).
+- The course takes 3 turns, the order's turn counted, and costs IL 0.5m a group: labelled design values (`Q-CRAFT-3`, decided 15 October 2026 [S3]).
+- A craftsman fills an ordinary job slot. Of a city's employed, the craftsmen are counted first, and each employed craftsman earns twice `income_per_job_per_year` (IL 0.06m a year), so IL 0.12m a year; the multiple is a labelled design value (`Q-CRAFT-2`, decided 15 October 2026 [S3]) (R-CRAFT-002).
+- On each housing step, after the refugees are housed, every city whose job default is on sets its employed to the smaller of its job slots and its civilians plus craftsmen, in ascending city id, at a cost of 0 Attention (`Q-JOBS-1`, decided 15 October 2026 [S3]) (R-CITY-009).
+- An accepted `AssignWorkers(city, job, n)` fixes that city's number and turns its default off for the rest of the game (R-CITY-001, R-CITY-009). `job` stays the only role (unitless).
+- Craftsmen take housing (R-HOUSE-003), count in Social cohesion's employed share (R-CITY-005) and in the cities' part of the national head count (R-CITY-008).
+
+## Data touched
+
+- `content/unit_types.yaml` `craftsman` (`facility: industry`, `training_turns`, `training_cost`) and `content/rules.yaml` `mvp.craftsman_income_multiple`, labelled design values listed in `DesignValuesTests`.
+- `GameState`: a city's `Craftsmen` (in its hash record as `craftsmen=` only when not 0) and `JobsDefault` (`jobs=manual` only when off).
+- The reference player sends no `AssignWorkers`; the default fills its jobs.
+- `sim/Statecraft.Sim.Tests/golden/manifest.txt`: `scenario-mvp-absorb-first` moves (its `AssignWorkers` turns Tel Aviv's default off); the other goldens do not (`docs/determinism.md`).
+
+## Done when
+
+- `dotnet test sim/Statecraft.sln` passes, including `CraftsmanTests`, `CitiesTests.TheJobDefaultFillsFreeSlots`, `ReferencePlayerTests` and `DesignValuesTests`.
+- `uv run scripts/oss/rule_ids.py` finds a citing test for R-CRAFT-001, R-CRAFT-002 and R-CITY-009.
+
+## Out of scope
+
+- Showing craftsmen or the job default in Unity (Phase 3 PR 8), a way to turn a city's default back on, the winery (Phase 3 PR 6), and any balance pass on the values.
+
+## Sources
+
+- [S1] The game design of record, docs/GDD.md
+- [S2] GDD v0.1 impact analysis and phased plan, docs/superpowers/specs/2026-10-12-gdd-v0.1-impact-and-plan.md
+- [S3] GDD Phase 3 implementation plan, PR 0's table and PR 5, docs/superpowers/plans/2026-10-15-gdd-phase-3.md
+
+## Open questions
+
+- None.
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 913b9d180..edab36579 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -38,17 +38,19 @@ R-SAVE-002: A save that names a ruleset this build does not know, or a newer sav
Each GDD turn resolves in the order of the approved plan's section 2.3 (decision D-A6): production, then housing and Social cohesion, then arrivals.
-R-CITY-001: `AssignWorkers(city, role, n)` sets how many of the city's civilians work in `role` (only `job` exists). It is refused, with the state unchanged and the Attention refunded, when the city or role is unknown, `n` is negative, or `n` is above the city's jobs or its civilians. The legacy loop refuses it before charging Attention.
+R-CITY-001: `AssignWorkers(city, role, n)` sets how many of the city's people work in `role` (only `job` exists: a craftsman fills an ordinary job slot, R-CRAFT-002). It is refused, with the state unchanged and the Attention refunded, when the city or role is unknown, `n` is negative, or `n` is above the city's jobs or its civilians and craftsmen. An accepted order turns the city's job default off (R-CITY-009). The legacy loop refuses it before charging Attention.
-R-CITY-002: Each turn every city's employed units add `employed * income_per_job_per_year * the turn's share of a year` to the Treasury.
+R-CITY-002: Each turn every city's employed units add `employed * income_per_job_per_year * the turn's share of a year` to the Treasury (an employed craftsman earns more, R-CRAFT-002).
R-CITY-003: Arrivals from the CBS series (`aliyah.yaml`) become refugees in the cities. Let `P(t)` be the people the series brings from `city_arrivals_from` to the date `t` (0 before it), summed over the origin groups in ordinal order. `city_arrivals_from` is 8 November 1948, the census day the cities' start values count: the census already holds the people who arrived from 15 May, so the cities take none before it (Q-ARRV-3, owner, 15 October 2026). The cities' arrived units by `t` are `U(t) = floor(P(t) / people_per_unit)`, and a turn from date `d` to date `e` adds `U(e) - U(d)` refugees over all cities. `people_per_unit` and `city_arrivals_from` are the same in every era (the loader refuses an era that changes either), so over any run of turns the refugees added are `U(end) - U(start)`: no unit is lost or counted twice. The units are split in proportion to the cities' census `people` (Q-ARRV-1): the first `U` units are handed out one at a time, unit `n` to the city with the largest remainder `n * people / total people - units it holds`, a tie to the lower city id (ordinal), and a turn gives each city its share of `U(e)` minus its share of `U(d)`. Building the split up one unit at a time keeps it cumulative: a fresh largest-remainder split of each total could take a unit back from a city as the total grows (the Alabama paradox; on the twelve cities it first happens at 7 units). The loader refuses a GDD game with no city.
-R-CITY-008: `GameState.Population` is the one record of the nation's people: it takes every arrival from 15 May 1948 and is the count the CBS anchors check. The cities are the part of it placed in towns, so their people (civilians, refugees, recruits and the groups in training, times `people_per_unit`) never exceed it (Q-ARRV-2, owner, 15 October 2026). No person is counted twice.
+R-CITY-008: `GameState.Population` is the one record of the nation's people: it takes every arrival from 15 May 1948 and is the count the CBS anchors check. The cities are the part of it placed in towns, so their people (civilians, craftsmen, refugees, recruits and the groups in training, times `people_per_unit`) never exceed it (Q-ARRV-2, owner, 15 October 2026). No person is counted twice.
-R-CITY-004: Each turn, on the housing step, all of a city's refugees become civilians without a job. There is no hard cap (D-D1, Q-HOUSE-1, owner, 15 October 2026): the people beyond the city's housing stay in the city as its overflow (R-HOUSE-002), and residents are housed automatically (Q-HOUSE-4).
+R-CITY-004: Each turn, on the housing step, all of a city's refugees become civilians without a job (R-CITY-009's default may then give them jobs). There is no hard cap (D-D1, Q-HOUSE-1, owner, 15 October 2026): the people beyond the city's housing stay in the city as its overflow (R-HOUSE-002), and residents are housed automatically (Q-HOUSE-4).
-R-CITY-005: The cities' employed share (employed over civilians, summed over all cities; 1 with no civilians) is an effect-web source of `morale`, Social cohesion (`work_lifts_cohesion`, source id `employed_share`), read after the turn's housing. The legacy loop has no cities, so there it reads 0 and adds nothing. Housing reaches Social cohesion through the existing `housing` link (`homes_lift_morale`) until Phase 3 makes it the cities' aggregate (Q-NAT-2, decided 15 October 2026). Phase 1's separate cohesion value and its two weights are gone (D-C1, Reading 2).
+R-CITY-009: The job default (Q-JOBS-1, owner, 15 October 2026). On each housing step, after the refugees become civilians (R-CITY-004), each city whose default is on sets its employed to `min(job slots, civilians + craftsmen)`, in ascending city id, at no Attention cost. Every city's default is on at the start; an accepted `AssignWorkers` order fixes that city's number and turns its default off for the rest of the game. Each change is a `city` cause on the Why screen ("Town: N groups in work"). A city's record writes `jobs=manual` into the state hash only when its default is off.
+
+R-CITY-005: The cities' employed share (employed over civilians and craftsmen, summed over all cities; 1 with none) is an effect-web source of `morale`, Social cohesion (`work_lifts_cohesion`, source id `employed_share`), read after the turn's housing. The legacy loop has no cities, so there it reads 0 and adds nothing. Housing reaches Social cohesion through the existing `housing` link (`homes_lift_morale`) until Phase 3 makes it the cities' aggregate (Q-NAT-2, decided 15 October 2026). Phase 1's separate cohesion value and its two weights are gone (D-C1, Reading 2).
R-CITY-006: The cities are the `city` and `town` rows of `map/settlements_1948.yaml`, in that file's order, and their start values are `cities.yaml`'s. Each of a city's values (`people`, `employed_share`, `housing_capacity`, `job_slots`) is required and has a status: `sourced` (read from the source named), `derived` (computed from sourced values), `wikipedia-only` (an owner-accepted Wikipedia figure) or `design` (a labelled design value, R-LOOP-005). A `sourced`, `derived` or `wikipedia-only` value has at least one source, each with a url and a checked date, and the day (YYYY-MM-DD) or month (YYYY-MM) it describes; the loader refuses a value without them, naming the file and field (GDD Phase 3 plan, review focus 3).
@@ -58,7 +60,7 @@ R-HOUSE-001: Each city has a housing condition from 0 to 1, an average over the
R-HOUSE-002: A city's overflow is `max(0, housed - housing_capacity)`, one capacity point housing one population unit (D-D1, Q-HOUSE-1, owner, 15 October 2026). On the housing step, after R-CITY-004 and before Social cohesion (D-A6), a city with overflow loses `overflow_condition_loss * overflow / housed` of its condition, never below 0; a city without overflow keeps its condition. `overflow_condition_loss` is 0.15, a design value. The loader requires both values, from 0 to 1. Overflow reaches Social cohesion through R-HOUSE-004 (a lower condition lowers the base of the national `housing` indicator) and the existing `homes_lift_morale` link (k 0.15) from `housing` into `morale`, which is Social cohesion (R-NAT-001); there is no direct overflow term (Q-HOUSE-1, decided by the owner 15 October 2026, plan:165 of `docs/superpowers/plans/2026-10-15-gdd-phase-3.md`: cohesion follows through the existing `housing` to `morale` link, "so it needs no number of its own"; the cohesion half was built after #728, merged as #857, owner 17 October 2026).
-R-HOUSE-003: The people who take a city's housing (`housed`) are its civilians, its recruits and its groups in training, a halutz group included until it becomes a movable unit. Halutz units do not (Q-HOUSE-5, owner, 15 October 2026). Refugees wait for housing and are not in it.
+R-HOUSE-003: The people who take a city's housing (`housed`) are its civilians, its craftsmen, its recruits and its groups in training, a halutz group included until it becomes a movable unit. Halutz units do not (Q-HOUSE-5, owner, 15 October 2026). Refugees wait for housing and are not in it.
R-HOUSE-004: In the GDD loop the base of the national `housing` indicator is the people-weighted mean of the cities' housing condition, each city weighed by its housed people (R-HOUSE-003): `sum(condition * housed) / sum(housed)`. Policy effects, map actions and events still act on top, as on any indicator. Decided (owner, 17 Oct 2026, option (a) of Q-PR3-A, relayed on [#855 at 06:33Z](https://github.com/eyalgolan/statecraft-israel/pull/855#issuecomment-6230731177)): the national housing base is the people-weighted mean of city condition, with policy, map actions and events still applied on top. When no city houses anybody the mean is undefined, and the base is `model.yaml`'s. Capacity reaches the level through overflow and condition (R-HOUSE-002).
@@ -78,11 +80,17 @@ R-PROJ-005: A specialised project is allowed only in a city that has its resourc
Training 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` in a military camp, `halutz` in a Hakhshara) 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.
+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` in a military camp, `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.
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 cohort that does not exist, or has finished, is refused with the state unchanged.
-R-TRAIN-003: Each turn, in ascending id, every cohort has one turn less to go. A cohort that reaches 0 ends: recruits are added to the city's count of recruits (a count until Phase 5), and halutzim become one movable unit per group at the city's settlement hex, taking the next ids in turn. A city's recruits and the cohorts are written into the state hash only when there are some.
+R-TRAIN-003: Each turn, in ascending id, every cohort has one turn less to go. A cohort that reaches 0 ends: recruits are added to the city's count of recruits (a count until Phase 5), craftsmen to its count of craftsmen (R-CRAFT-001), and halutzim become one movable unit per group at the city's settlement hex, taking the next ids in turn. A city's recruits and the cohorts are written into the state hash only when there are some.
+
+## 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-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.
## Sites
diff --git a/docs/superpowers/plans/2026-10-15-gdd-phase-3.md b/docs/superpowers/plans/2026-10-15-gdd-phase-3.md
index 8309f0f8b..3c9c68a69 100644
--- a/docs/superpowers/plans/2026-10-15-gdd-phase-3.md
+++ b/docs/superpowers/plans/2026-10-15-gdd-phase-3.md
@@ -366,12 +366,12 @@ Issue (Task form): "GDD Phase 3: city projects (housing, industry) and the end o
**Files:** `GddState.cs` (`City.Craftsmen`, hashed only when not 0), `Cities.cs` (`Assign` accepts the `craftsman` role, today refused with "There is no such role"; `Produce` pays craftsmen at their rate), `Training.cs` and `unit_types.yaml` if craftsmen are trained (D-D4's recommendation), `content/rules.yaml` (design values), `ReferencePlayer.cs`, tests `CraftsmanTests.cs`, `CitiesTests.cs`, `docs/rules/mvp.md`, `docs/gdd/craftsman.md`.
-**Rule IDs (proposed):** **R-CRAFT-001** how a civilian becomes a craftsman (D-D4); **R-CRAFT-002** a craftsman's income and the job slots it needs; R-CITY-001 reworded if `AssignWorkers` gains the role; **R-CITY-008** the job default (Q-JOBS-1), if the owner wants one.
+**Rule IDs (proposed):** **R-CRAFT-001** how a civilian becomes a craftsman (D-D4); **R-CRAFT-002** a craftsman's income and the job slots it needs; R-CITY-001 reworded if `AssignWorkers` gains the role; **R-CITY-009** the job default (Q-JOBS-1), if the owner wants one.
**Test-first steps:**
- [ ] `CraftsmanTests.ACraftsmanEarnsMoreThanAWorker` (R-CRAFT-002): two cities that differ only by one craftsman; the Treasury difference is the stated rate. Fails to compile today.
- [ ] `CraftsmanTests.ACraftsmanIsMadeAsStated` (R-CRAFT-001): the D-D4 path; every refusal leaves the state unchanged.
-- [ ] `CitiesTests.TheJobDefaultFillsFreeSlots` (R-CITY-008), if Q-JOBS-1 adds one: after housing, free slots fill from civilians without a job, in ascending city id, with no Attention cost unless the owner sets one.
+- [ ] `CitiesTests.TheJobDefaultFillsFreeSlots` (R-CITY-009), if Q-JOBS-1 adds one: after housing, free slots fill from civilians without a job, in ascending city id, with no Attention cost unless the owner sets one.
- [ ] Mutate (pay craftsmen the worker rate), restore. Re-pin the goldens, history row.
**Golden impact:** every golden moves.
diff --git a/sim/Statecraft.Sim.Tests/ArrivalsTests.cs b/sim/Statecraft.Sim.Tests/ArrivalsTests.cs
index c41f701d4..0b7a6c68c 100644
--- a/sim/Statecraft.Sim.Tests/ArrivalsTests.cs
+++ b/sim/Statecraft.Sim.Tests/ArrivalsTests.cs
@@ -25,7 +25,7 @@ public class ArrivalsTests
/// <summary>The cities' people in units: civilians, refugees, recruits and the groups in training (Q-ARRV-2).</summary>
static int CityUnits(GameState s) =>
- s.Cities.Values.Sum(x => x.Civilians + x.Refugees + x.Recruits) + s.Cohorts.Values.Sum(x => x.Count);
+ s.Cities.Values.Sum(x => x.Civilians + x.Craftsmen + x.Refugees + x.Recruits) + s.Cohorts.Values.Sum(x => x.Count);
/// <summary>The cities' arrivals P(t): the series' people from the census day to <paramref name="t"/> (Q-ARRV-3).</summary>
static double CityPeople(Content c, DateTime t)
diff --git a/sim/Statecraft.Sim.Tests/CitiesContentTests.cs b/sim/Statecraft.Sim.Tests/CitiesContentTests.cs
index 9c58a1109..dcbd8d1d6 100644
--- a/sim/Statecraft.Sim.Tests/CitiesContentTests.cs
+++ b/sim/Statecraft.Sim.Tests/CitiesContentTests.cs
@@ -18,7 +18,7 @@ public class CitiesContentTests
var c = Load();
var city = Assert.Single(c.Cities);
Assert.Equal(("town_a", 12, 8, 10, 6), (city.Id, city.HousingCapacity, city.JobSlots, city.Civilians, city.Employed));
- Assert.Equal(new[] { "civilian", "refugee", "recruit", "halutz" }, c.UnitTypes.Select(t => t.Id));
+ Assert.Equal(new[] { "civilian", "refugee", "recruit", "halutz", "craftsman" }, c.UnitTypes.Select(t => t.Id));
var halutz = c.UnitTypes.Single(t => t.Id == "halutz");
Assert.Equal(("unit", "hakhshara", 3, 0.25), (halutz.Kind, halutz.Facility, halutz.TrainingTurns, halutz.TrainingCost));
Assert.Equal("", c.UnitTypes.Single(t => t.Id == "civilian").Facility);
@@ -46,7 +46,7 @@ public class CitiesContentTests
Assert.True(c.Rules.AttentionCost.ContainsKey("assign_workers"));
Assert.Equal(new[] { "tel_aviv" }, c.Cities.Where(x => x.Facilities.Count > 0).Select(x => x.Id));
Assert.Equal(new[] { "military_camp", "hakhshara" }, c.Cities.Single(x => x.Id == "tel_aviv").Facilities); // D-D5: one of each at the start
- Assert.Equal(new[] { ("recruit", "military_camp"), ("halutz", "hakhshara") },
+ Assert.Equal(new[] { ("recruit", "military_camp"), ("halutz", "hakhshara"), ("craftsman", "industry") },
c.UnitTypes.Where(t => t.Facility != "").Select(t => (t.Id, t.Facility)));
Assert.True(c.Rules.AttentionCost.ContainsKey("train") && c.Rules.AttentionCost.ContainsKey("cancel_training"));
}
@@ -194,6 +194,8 @@ public class CitiesContentTests
new object[] { "unit_types.yaml", "types:\n - { id: civilian, kind: crowd }\n", "types[civilian].kind", "must be population or unit" },
new object[] { "rules.yaml", Rules(Fixture.GddRules.Replace("people_per_unit: 10", "people_per_unit: 0")), "mvp.people_per_unit", "must be >= 1" },
new object[] { "rules.yaml", Rules(Fixture.GddRules.Replace("income_per_job_per_year: 1.2", "income_per_job_per_year: -1")), "mvp.income_per_job_per_year", "must be a finite number >= 0" },
+ new object[] { "rules.yaml", Rules(Fixture.GddRules.Replace("craftsman_income_multiple: 2", "craftsman_income_multiple: 1")), "mvp.craftsman_income_multiple", "must be a finite number > 1" },
+ new object[] { "rules.yaml", Rules(Fixture.GddRules.Replace(" craftsman_income_multiple: 2\n", "")), "mvp.craftsman_income_multiple", "must be a finite number > 1" },
new object[] { "rules.yaml", Rules(Fixture.GddRules.Replace(" city_arrivals_from: 1948-05-15\n", "")), "mvp.city_arrivals_from", "required when eras.yaml systems.loop is gdd" },
new object[] { "rules.yaml", Rules(""), "mvp", "required when eras.yaml systems.loop is gdd" },
new object[] { "rules.yaml", Fixture.Files["rules.yaml"] + Fixture.GddRules, "attention_cost.assign_workers", "missing cost" },
@@ -204,7 +206,8 @@ public class CitiesContentTests
new object[] { "unit_types.yaml", Types(" - { id: halutz, kind: unit, facility: hakhshara, training_turns: 3, training_cost: -1 }\n"), "types[halutz].training_cost", "must be a finite number >= 0" },
new object[] { "unit_types.yaml", Types(" - { id: halutz, kind: unit, training_turns: 3 }\n"), "types[halutz].training_turns", "only a type with a facility trains" },
new object[] { "unit_types.yaml", Types(" - { id: halutz, kind: unit, training_cost: 0.5 }\n"), "types[halutz].training_cost", "only a type with a facility trains" },
- new object[] { "unit_types.yaml", Types(" - { id: craftsman, kind: population, facility: hakhshara, training_turns: 3, training_cost: 0.5 }\n"), "types[craftsman].kind", "only recruit is a trained count" },
+ new object[] { "unit_types.yaml", Types(" - { id: craftsman, kind: population, facility: hakhshara, training_turns: 3, training_cost: 0.5 }\n"), "types[craftsman].facility", "a craftsman trains at industry" },
+ new object[] { "unit_types.yaml", Types(" - { id: settler, kind: population, facility: hakhshara, training_turns: 3, training_cost: 0.5 }\n"), "types[settler].kind", "only recruit and craftsman are trained counts" },
};
[Theory]
diff --git a/sim/Statecraft.Sim.Tests/CitiesTests.cs b/sim/Statecraft.Sim.Tests/CitiesTests.cs
index 66504251e..05bae0b70 100644
--- a/sim/Statecraft.Sim.Tests/CitiesTests.cs
+++ b/sim/Statecraft.Sim.Tests/CitiesTests.cs
@@ -37,15 +37,16 @@ public class CitiesTests
Assert.Empty(r.Rejected);
Assert.Equal(90, r.State.Cities["tel_aviv"].Employed);
Assert.Contains(r.Why, x => x.System == "city" && x.Message == "Tel Aviv: 90 groups in work");
+ Assert.False(r.State.Cities["tel_aviv"].JobsDefault); // R-CITY-009: the order fixes the number
}
// R-CITY-001
[Theory]
[InlineData("town_a", "job", -1, "The number of workers cannot be negative")]
[InlineData("town_a", "job", 21, "Town A has 20 jobs")]
- [InlineData("town_a", "job", 11, "Town A has 10 civilians")]
+ [InlineData("town_a", "job", 11, "Town A has 10 civilians and craftsmen")]
[InlineData("nowhere", "job", 1, "There is no such city")]
- [InlineData("town_a", "craftsman", 1, "There is no such role")]
+ [InlineData("town_a", "craftsman", 1, "There is no such role")] // a craftsman fills an ordinary job slot (R-CRAFT-002)
public void TheLimitsAreRefusedAndChangeNothing(string city, string role, int count, string reason)
{
var c = Town();
@@ -130,6 +131,44 @@ public class CitiesTests
Assert.Equal(6 * 1.2 * SimTime.YearFraction(TurnLength.Week), paid, 9); // the fixture's first turn is a week
}
+ /// <summary>Two cities with free job slots: town_b (listed first in cities.yaml) has more civilians than jobs, town_a more
+ /// jobs than civilians, so each limit of min(job slots, civilians + craftsmen) is met once.</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",
+ ["cities.yaml"] = "cities:\n" + Fixture.City("town_b", 40, 8, 10, 0) + Fixture.City("town_a", 40, 20, 10, 6),
+ })));
+
+ // R-CITY-009 (Q-JOBS-1): after housing, free slots fill from the people without a job, in ascending city id, with no
+ // Attention cost; an AssignWorkers order fixes that city's number and turns its default off.
+ [Fact]
+ public void TheJobDefaultFillsFreeSlots()
+ {
+ var c = TwoTowns();
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ s.Cities["town_a"] = s.Cities["town_a"].WithCraftsmen(2); // 10 civilians and 2 craftsmen for 20 jobs
+ var r = Step(c, s);
+ Assert.Equal((12, 8), (r.State.Cities["town_a"].Employed, r.State.Cities["town_b"].Employed));
+ Assert.True(r.State.Cities["town_a"].JobsDefault && r.State.Cities["town_b"].JobsDefault);
+ Assert.Equal(new[] { ("town_a", 6.0, "Town A: 12 groups in work"), ("town_b", 8.0, "Town B: 8 groups in work") },
+ r.Why.Where(x => x.System == "city" && x.Message.EndsWith(" groups in work")).Select(x => (x.Target, x.Delta, x.Message)));
+
+ // No Attention cost: a turn begun with no Attention left fills the same jobs.
+ var tired = s.Clone();
+ tired.Attention = 0;
+ Assert.Equal(r.State.Hash(), Step(c, tired).State.Hash());
+
+ // AssignWorkers fixes town_a's number from then on; town_b keeps its default.
+ var manual = Step(c, s, new AssignWorkers("town_a", "job", 3));
+ Assert.Empty(manual.Rejected);
+ Assert.Equal((3, 8), (manual.State.Cities["town_a"].Employed, manual.State.Cities["town_b"].Employed));
+ Assert.False(manual.State.Cities["town_a"].JobsDefault);
+ var later = Step(c, manual.State).State;
+ Assert.Equal((3, 8), (later.Cities["town_a"].Employed, later.Cities["town_b"].Employed));
+ }
+
// R-CITY-004 (Q-HOUSE-1: no hard cap; the 3 beyond the housing for 12 are the city's overflow, HousingTests)
[Fact]
public void EveryRefugeeIsHousedWithNoHardCap()
@@ -137,7 +176,7 @@ public class CitiesTests
var c = Town();
var s = With(Simulation.NewGame(c, 1, Mode.Historical), "town_a", 10, 6, 5);
var city = Step(c, s).State.Cities["town_a"]; // the first week brings under one unit of arrivals
- Assert.Equal((15, 6, 0), (city.Civilians, city.Employed, city.Refugees));
+ Assert.Equal((15, 15, 0), (city.Civilians, city.Employed, city.Refugees)); // then the job default fills 15 of the 20 jobs (R-CITY-009)
}
// R-CITY-003, R-CITY-004 (D-A6: arrivals come after housing, so they are housed on the next turn)
@@ -170,10 +209,10 @@ public class CitiesTests
["model.yaml"] = Fixture.Files["model.yaml"].Replace("effects:\n", "effects:\n - { id: work, source: employed_share, target: morale, k: 1, inertia: 1, name: Work }\n"),
})));
var s = With(Simulation.NewGame(c, 1, Mode.Historical), "town_a", 10, 6, 10);
- var after = Step(c, s).State; // all 10 housed (no hard cap): 6 of 20 employed
+ var after = Step(c, s).State; // all 10 housed, then the job default fills 20 of 20 jobs (R-CITY-009)
Assert.Equal((20, 0), (after.Cities["town_a"].Civilians, after.Cities["town_a"].Refugees));
- Assert.Equal(6.0 / 20, Cities.EmployedShare(after), 12);
- Assert.Equal(6.0 / 20, after.EffectContributions["work"], 12);
+ Assert.Equal(1.0, Cities.EmployedShare(after), 12);
+ Assert.Equal(1.0, after.EffectContributions["work"], 12);
}
[Fact]
diff --git a/sim/Statecraft.Sim.Tests/CraftsmanTests.cs b/sim/Statecraft.Sim.Tests/CraftsmanTests.cs
new file mode 100644
index 000000000..c9356a6c3
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/CraftsmanTests.cs
@@ -0,0 +1,102 @@
+using System.Linq;
+using Statecraft.Sim;
+
+/// <summary>GDD Phase 3 PR 5, the craftsman (D-D4): a civilian trains as one in a city with a completed industry project
+/// (Q-CRAFT-1), and an employed craftsman fills an ordinary job slot and earns a multiple of the job income (Q-CRAFT-2). The
+/// fixture's values are its own: an income multiple of 2, and 3 turns and IL 0.75m a group for the course.</summary>
+public class CraftsmanTests
+{
+ /// <summary>The GDD fixture's one city, town_a: housing for 12, 8 jobs, 10 civilians, 6 of them employed.</summary>
+ static Content Town() => ContentLoader.Load(Fixture.Write(Fixture.Gdd()));
+
+ static StepResult Step(Content c, GameState s, params Command[] commands) => Simulation.Step(c, s, commands);
+
+ /// <summary>A copy of <paramref name="s"/> with an industry project in town_a, built when <paramref name="built"/>.</summary>
+ static GameState WithIndustry(GameState s, bool built)
+ {
+ var x = s.Clone();
+ var id = x.NextId++;
+ x.CityProjects.Add(id, new CityProject(id, Training.Industry, "town_a", 1, 1, built ? 0 : 3, built ? x.Date : (System.DateTime?)null));
+ return x;
+ }
+
+ // R-CRAFT-002
+ [Fact]
+ public void ACraftsmanEarnsMoreThanAWorker()
+ {
+ var c = Town();
+ var worker = Simulation.NewGame(c, 1, Mode.Historical);
+ worker.Cities["town_a"] = new City("town_a", 12, 8, 10, 1, 0); // 1 civilian in work
+ var craftsman = worker.Clone();
+ craftsman.Cities["town_a"] = new City("town_a", 12, 8, 9, 1, 0, craftsmen: 1); // the same, but a craftsman in the job
+
+ var difference = Step(c, craftsman).State.Treasury - Step(c, worker).State.Treasury;
+ var rate = c.Rules.Mvp!.IncomePerJobPerYear * SimTime.YearFraction(TurnLength.Week); // the fixture's first turn is a week
+ Assert.Equal(2.0, c.Rules.Mvp.CraftsmanIncomeMultiple);
+ Assert.Equal(rate * (2.0 - 1), difference, 9);
+
+ // Without a job a craftsman earns nothing, like a civilian (R-CITY-002 pays the employed only).
+ worker.Cities["town_a"] = new City("town_a", 12, 8, 10, 0, 0);
+ craftsman.Cities["town_a"] = new City("town_a", 12, 8, 9, 0, 0, craftsmen: 1);
+ Assert.Equal(Step(c, worker).State.Treasury, Step(c, craftsman).State.Treasury, 12);
+ }
+
+ // R-CRAFT-001
+ [Fact]
+ public void ACraftsmanIsMadeAsStated()
+ {
+ var c = Town();
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ var order = new Train("town_a", Training.Craftsman, 1);
+
+ // No industry project, or one still being built: refused, as if the order had not been given.
+ foreach (var none in new[] { s, WithIndustry(s, built: false) })
+ {
+ var refused = Step(c, none, order);
+ Assert.Equal("Town A has no completed industry project", Assert.Single(refused.Rejected).Reason);
+ Assert.Equal(Step(c, none).State.Hash(), refused.State.Hash());
+ }
+
+ var built = WithIndustry(s, built: true);
+ var one = Step(c, built, order);
+ Assert.Empty(one.Rejected);
+ Assert.Equal(0.75, Step(c, built).State.Treasury - one.State.Treasury, 9); // training_cost, paid at once
+ var cohort = Assert.Single(one.State.Cohorts.Values);
+ Assert.Equal((Training.Craftsman, "town_a", 1, 2), (cohort.Type, cohort.City, cohort.Count, cohort.TurnsLeft)); // 3 turns, this one counted
+ Assert.Equal(9, one.State.Cities["town_a"].Civilians); // the trainee left the civilians at once
+ Assert.Equal(0, one.State.Cities["town_a"].Craftsmen);
+
+ var two = Step(c, one.State).State;
+ Assert.Equal(0, two.Cities["town_a"].Craftsmen);
+ var done = Step(c, two);
+ var city = done.State.Cities["town_a"];
+ Assert.Empty(done.State.Cohorts);
+ var never = Step(c, Step(c, Step(c, built).State).State).State.Cities["town_a"]; // the same three turns, no order
+ Assert.Equal((never.Civilians - 1, 1), (city.Civilians, city.Craftsmen));
+ Assert.Contains(done.Why, x => x.System == "city" && x.Message == "Town A: 1 group finished craft training and are craftsmen");
+ Assert.Contains(",craftsmen=1", city.Canonical());
+ }
+
+ // R-CRAFT-001 (R-TRAIN-001's refusals): every refusal leaves the state as if the order had not been given.
+ [Theory]
+ [InlineData("unknown", 1, "There is no such training")]
+ [InlineData(Training.Craftsman, 0, "Train at least one group")]
+ [InlineData(Training.Craftsman, 5, "Town A has 4 civilians without work")]
+ public void ARefusedCraftsmanTrainingLeavesTheStateUnchanged(string track, int count, string reason)
+ {
+ var c = Town();
+ var s = WithIndustry(Simulation.NewGame(c, 1, Mode.Historical), built: true);
+ var r = Step(c, s, new Train("town_a", track, count));
+ Assert.Equal(reason, Assert.Single(r.Rejected).Reason);
+ Assert.Equal(Step(c, s).State.Hash(), r.State.Hash());
+ }
+
+ // R-CRAFT-002, R-TRAIN-001: craftsmen take the jobs first, so only the employed beyond them are civilians in work.
+ [Fact]
+ public void CraftsmenTakeTheJobsFirst()
+ {
+ var x = new City("town_a", 12, 8, 6, 5, 0, craftsmen: 2); // 5 in work: the 2 craftsmen and 3 civilians
+ Assert.Equal(3, Training.Idle(x));
+ Assert.Equal(8, Cities.MaxWorkers(x)); // min(8 jobs, 6 civilians + 2 craftsmen)
+ }
+}
diff --git a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs
index b04b22869..0c7c99241 100644
--- a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs
+++ b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs
@@ -24,6 +24,7 @@ public class DesignValuesTests
("rules.yaml", "attention_cost.stop_work"),
("rules.yaml", "mvp.people_per_unit"),
("rules.yaml", "mvp.income_per_job_per_year"),
+ ("rules.yaml", "mvp.craftsman_income_multiple"),
("rules.yaml", "mvp.city_upkeep_per_year"),
("rules.yaml", "mvp.housing_upkeep_per_year"),
("rules.yaml", "mvp.industry_upkeep_per_year"),
@@ -92,6 +93,8 @@ public class DesignValuesTests
("unit_types.yaml", "types[recruit].training_cost"),
("unit_types.yaml", "types[halutz].training_turns"),
("unit_types.yaml", "types[halutz].training_cost"),
+ ("unit_types.yaml", "types[craftsman].training_turns"),
+ ("unit_types.yaml", "types[craftsman].training_cost"),
// Social cohesion's two new inputs and the national parameters' thresholds (Phase 2 PR 4; Q-NAT-2, Q-NAT-3; Reading 1).
("model.yaml", "effects[work_lifts_cohesion].k"),
("model.yaml", "effects[work_lifts_cohesion].inertia"),
@@ -198,6 +201,7 @@ public class DesignValuesTests
var c = ContentLoader.Load(RealContentTests.ContentRoot());
var m = c.Rules.Mvp!;
Assert.Equal((1000, 0.06), (m.PeoplePerUnit, m.IncomePerJobPerYear));
+ Assert.Equal(2.0, m.CraftsmanIncomeMultiple); // Q-CRAFT-2
Assert.Equal((0.0000545, 0.0001036), (c.Rules.TaxPerCapitaPerYear, c.Rules.SpendingPerCapitaPerYear));
Assert.Equal((0.0, 0.0, 0.0, 0.0, 0.0, 0.0), (m.CityUpkeepPerYear!.Value, m.HousingUpkeepPerYear!.Value,
m.IndustryUpkeepPerYear!.Value, m.TransitCampUpkeepPerYear!.Value, m.MilitaryCampUpkeepPerYear!.Value, m.HakhsharaUpkeepPerYear!.Value));
@@ -210,7 +214,7 @@ public class DesignValuesTests
Assert.Equal(12, c.Cities.Count);
foreach (var x in c.Cities) // the listed housing and job values are the ones Cities.Init starts from
Assert.Equal(((int)x.Housing!.Value, (int)x.Jobs!.Value), (x.HousingCapacity, x.JobSlots));
- Assert.Equal(new[] { ("recruit", 3, 0.5), ("halutz", 4, 0.5) },
+ Assert.Equal(new[] { ("recruit", 3, 0.5), ("halutz", 4, 0.5), ("craftsman", 3, 0.5) }, // the craftsman: Q-CRAFT-3
c.UnitTypes.Where(t => t.Facility != "").Select(t => (t.Id, t.TrainingTurns, t.TrainingCost)));
}
diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.cs
index 54cb9a4dd..88900636b 100644
--- a/sim/Statecraft.Sim.Tests/Fixture.cs
+++ b/sim/Statecraft.Sim.Tests/Fixture.cs
@@ -224,6 +224,7 @@ series:
mvp:
people_per_unit: 10
income_per_job_per_year: 1.2
+ craftsman_income_multiple: 2
city_upkeep_per_year: 0
housing_upkeep_per_year: 0
industry_upkeep_per_year: 0
@@ -268,6 +269,7 @@ types:
- { id: refugee, kind: population }
- { id: recruit, kind: population, facility: military_camp, training_turns: 2, training_cost: 0.5 }
- { id: halutz, kind: unit, facility: hakhshara, training_turns: 3, training_cost: 0.25 }
+ - { id: craftsman, kind: population, facility: industry, training_turns: 3, training_cost: 0.75 }
";
/// <summary>The three city project kinds (R-PROJ-001). Fixture values, not the game's.</summary>
diff --git a/sim/Statecraft.Sim.Tests/GddStateTests.cs b/sim/Statecraft.Sim.Tests/GddStateTests.cs
index 19cc144da..90b82bc51 100644
--- a/sim/Statecraft.Sim.Tests/GddStateTests.cs
+++ b/sim/Statecraft.Sim.Tests/GddStateTests.cs
@@ -119,6 +119,18 @@ public class GddStateTests
Assert.Equal(4, none.WithRecruits(4).WithCounts(5, 1, 0).Recruits); // a change of counts keeps the recruits
}
+ // R-LOOP-002, R-CRAFT-001, R-CITY-009: defaults preserve the old text; only non-zero craftsmen and a manual job
+ // standing order add fields.
+ [Fact]
+ public void CraftsmenAndTheJobDefaultReachTheHashOnlyWhenSet()
+ {
+ var none = new City("a", 1, 2, 3, 1, 0);
+ Assert.Equal("a=1,2,3,1,0", none.Canonical());
+ Assert.Equal("a=1,2,3,1,0,craftsmen=2", none.WithCraftsmen(2).Canonical());
+ Assert.Equal("a=1,2,3,1,0,jobs=manual", none.WithJobsDefault(false).Canonical());
+ Assert.Equal(2, none.WithCraftsmen(2).WithCounts(4, 1, 0).Craftsmen);
+ }
+
[Fact]
public void CloneCopiesEveryNewCollection()
{
diff --git a/sim/Statecraft.Sim.Tests/HousingTests.cs b/sim/Statecraft.Sim.Tests/HousingTests.cs
index f16a69f2d..52fd051e2 100644
--- a/sim/Statecraft.Sim.Tests/HousingTests.cs
+++ b/sim/Statecraft.Sim.Tests/HousingTests.cs
@@ -28,7 +28,7 @@ public class HousingTests
/// <summary>Everyone the city holds: civilians, refugees, recruits and the groups in training there.</summary>
static int People(GameState s, string city) =>
- s.Cities[city].Civilians + s.Cities[city].Refugees + s.Cities[city].Recruits + s.Cohorts.Values.Where(k => k.City == city).Sum(k => k.Count);
+ s.Cities[city].Civilians + s.Cities[city].Craftsmen + s.Cities[city].Refugees + s.Cities[city].Recruits + s.Cohorts.Values.Where(k => k.City == city).Sum(k => k.Count);
// R-HOUSE-001
[Fact]
@@ -51,7 +51,7 @@ public class HousingTests
var s = With(Simulation.NewGame(c, 1, Mode.Historical), "town_a", 10, 6, 5);
var after = Step(c, s); // the fixture's first week brings no unit of arrivals
var x = after.Cities["town_a"];
- Assert.Equal((15, 6, 0), (x.Civilians, x.Employed, x.Refugees)); // no hard cap: every refugee is housed
+ Assert.Equal((15, 15, 0), (x.Civilians, x.Employed, x.Refugees)); // no hard cap: every refugee is housed (and R-CITY-009 fills 15 of the 20 jobs)
Assert.Equal(People(s, "town_a"), People(after, "town_a"));
Assert.Equal(15, Cities.Housed(after, x));
Assert.Equal(3, Cities.Overflow(after, x)); // 15 people in housing for 12
diff --git a/sim/Statecraft.Sim.Tests/NationalParametersTests.cs b/sim/Statecraft.Sim.Tests/NationalParametersTests.cs
index 2feb05700..5251c89f6 100644
--- a/sim/Statecraft.Sim.Tests/NationalParametersTests.cs
+++ b/sim/Statecraft.Sim.Tests/NationalParametersTests.cs
@@ -54,8 +54,8 @@ public class NationalParametersTests
var s = Played();
double After(GameState x) => Step(Mvp, x).State.Indicators["morale"];
- // Employment: the same city with more of its civilians in work.
- var city = s.Cities["tel_aviv"];
+ // Employment: the same city with more of its civilians in work, each number fixed (R-CITY-009's default off).
+ var city = s.Cities["tel_aviv"].WithJobsDefault(false);
Assert.True(city.Employed > 0 && city.Employed < city.Civilians, "precondition: room to move employment both ways");
var idle = s.Clone(); idle.Cities["tel_aviv"] = city.WithCounts(city.Civilians, 0, city.Refugees);
var busy = s.Clone(); busy.Cities["tel_aviv"] = city.WithCounts(city.Civilians, Math.Min(city.Civilians, city.JobSlots), city.Refugees);
diff --git a/sim/Statecraft.Sim.Tests/ReferencePlayerTests.cs b/sim/Statecraft.Sim.Tests/ReferencePlayerTests.cs
index 37796846d..0e119055e 100644
--- a/sim/Statecraft.Sim.Tests/ReferencePlayerTests.cs
+++ b/sim/Statecraft.Sim.Tests/ReferencePlayerTests.cs
@@ -22,20 +22,24 @@ public class ReferencePlayerTests
return s;
}
+ /// <summary>It sends no AssignWorkers: R-CITY-009's default fills the jobs on the housing step, and an order would turn
+ /// that city's default off (GDD Phase 3 PR 5; before it, the player sent min(jobs, civilians) itself).</summary>
[Fact]
- public void ItSendsHistoricalAIsOrdersThenFillsTheJobsThenTrainsOneHalutzGroup()
+ public void ItSendsHistoricalAIsOrdersThenTrainsOneHalutzGroupAndLeavesTheJobsToTheDefault()
{
var s = Start();
s.Cities["tel_aviv"] = s.Cities["tel_aviv"].WithCounts(248, 96, 0); // the start fills every job (Q-START-1): free 10
var orders = ReferencePlayer.Commands(Mvp, s);
var history = HistoricalAI.Commands(Mvp, s);
Assert.Equal(history.Select(x => x.Kind), orders.Take(history.Count).Select(x => x.Kind));
- Assert.Equal(history.Count + 2, orders.Count);
- var assign = Assert.IsType<AssignWorkers>(orders[history.Count]);
- Assert.Equal(("tel_aviv", "job", 106), (assign.City, assign.Role, assign.Count)); // min(106 jobs, 248 civilians)
+ Assert.Equal(history.Count + 1, orders.Count);
+ Assert.DoesNotContain(orders, x => x is AssignWorkers);
var train = Assert.IsType<Train>(orders.Last());
- Assert.Equal(("tel_aviv", "halutz", 1), (train.City, train.Track, train.Count)); // 142 civilians left without work
- Assert.Empty(Simulation.Step(Mvp, s, orders).Rejected);
+ Assert.Equal(("tel_aviv", "halutz", 1), (train.City, train.Track, train.Count)); // 152 civilians without work
+ var r = Simulation.Step(Mvp, s, orders);
+ Assert.Empty(r.Rejected);
+ var city = r.State.Cities["tel_aviv"];
+ Assert.Equal((247, 106, true), (city.Civilians, city.Employed, city.JobsDefault)); // min(106 jobs, 247 civilians)
}
/// <summary>The real start: the 15 May card (idf_founding) is answered first, at full war's price. The cities start with
@@ -193,13 +197,18 @@ public class ReferencePlayerTests
Assert.Empty(ReferencePlayer.Commands(Mvp, tired));
}
+ /// <summary>With more jobs than civilians, the default (not the player) fills no more jobs than there are civilians.</summary>
[Fact]
public void ItFillsNoMoreJobsThanThereAreCivilians()
{
var s = Simulation.NewGame(Mvp, GoldenRun.Seed, Mode.Historical);
s.Cities["tel_aviv"] = s.Cities["tel_aviv"].WithCounts(50, 40, 0); // 106 jobs, 50 civilians
- var assign = Assert.IsType<AssignWorkers>(ReferencePlayer.Commands(Mvp, s).Last());
- Assert.Equal(50, assign.Count);
+ var orders = ReferencePlayer.Commands(Mvp, s);
+ Assert.DoesNotContain(orders, x => x is AssignWorkers);
+ var r = Simulation.Step(Mvp, s, orders);
+ Assert.Empty(r.Rejected);
+ var city = r.State.Cities["tel_aviv"];
+ Assert.Equal((city.Civilians, true), (city.Employed, city.JobsDefault)); // every civilian left (training takes its group first)
}
[Fact]
diff --git a/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs b/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs
index 70ef3ab4c..532c731d5 100644
--- a/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs
+++ b/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs
@@ -91,7 +91,8 @@ from: 1948-05-15
var y = s.Cities["town_a"];
Assert.Equal(x.HousingCapacity + 3, y.HousingCapacity);
Assert.Equal(x.Employed, y.JobSlots);
- Assert.Equal((x.Civilians, x.Employed, x.Refugees, x.Recruits), (y.Civilians, y.Employed, y.Refugees, y.Recruits));
+ Assert.Equal((x.Civilians, x.Employed, x.Refugees, x.Recruits, x.Craftsmen, x.JobsDefault),
+ (y.Civilians, y.Employed, y.Refugees, y.Recruits, y.Craftsmen, y.JobsDefault));
Assert.Contains(why, w => w.System == "events" && w.Target == "town_a.housing_capacity" && w.Delta == 3);
Assert.Contains(why, w => w.System == "events" && w.Target == "town_a.job_slots" && w.Delta == x.Employed - x.JobSlots);
}
@@ -197,8 +198,8 @@ from: 1948-05-15
var y = s.Cities["town_a"];
var want = Math.Min(1.0, Math.Max(0.0, start + delta));
Assert.Equal(want, y.Condition!.Value, 12);
- Assert.Equal((x.HousingCapacity, x.JobSlots, x.Civilians, x.Employed, x.Refugees, x.Recruits),
- (y.HousingCapacity, y.JobSlots, y.Civilians, y.Employed, y.Refugees, y.Recruits));
+ Assert.Equal((x.HousingCapacity, x.JobSlots, x.Civilians, x.Employed, x.Refugees, x.Recruits, x.Craftsmen, x.JobsDefault),
+ (y.HousingCapacity, y.JobSlots, y.Civilians, y.Employed, y.Refugees, y.Recruits, y.Craftsmen, y.JobsDefault));
Assert.Equal(other, s.Cities["town_b"].Canonical()); // R-HOUSE-001: per city
var cause = Assert.Single(why, w => w.Target == "town_a.condition");
Assert.Equal(want - start, cause.Delta, 12);
diff --git a/sim/Statecraft.Sim.Tests/TrainingTests.cs b/sim/Statecraft.Sim.Tests/TrainingTests.cs
index 34d333829..2fbe3f0a7 100644
--- a/sim/Statecraft.Sim.Tests/TrainingTests.cs
+++ b/sim/Statecraft.Sim.Tests/TrainingTests.cs
@@ -39,7 +39,7 @@ public class TrainingTests
var r = Step(c, s, new Train("town_a", "recruit", 3));
Assert.Empty(r.Rejected);
var city = r.State.Cities["town_a"];
- Assert.Equal((7, 6, 0), (city.Civilians, city.Employed, city.Recruits)); // in training: neither civilians nor recruits
+ Assert.Equal((7, 7, 0), (city.Civilians, city.Employed, city.Recruits)); // in training: neither civilians nor recruits; the job default (R-CITY-009) employs the 7
var k = Assert.Single(r.State.Cohorts.Values);
Assert.Equal((id, "recruit", "town_a", 3, 1), (k.Id, k.Type, k.City, k.Count, k.TurnsLeft)); // 2 turns, one of them this one
Assert.Equal(id + 1, r.State.NextId);
@@ -165,6 +165,7 @@ public class TrainingTests
{
var c = Town();
var s = Simulation.NewGame(c, 1, Mode.Historical);
+ s.Cities["town_a"] = s.Cities["town_a"].WithJobsDefault(false); // R-TRAIN-002 alone: the job default (R-CITY-009) would refill the jobs
var trained = Step(c, s, new Train("town_a", "halutz", 4)).State;
var id = Assert.Single(trained.Cohorts.Keys);
var cancelled = Step(c, trained, new CancelTraining(id));
diff --git a/sim/Statecraft.Sim.Tests/golden/manifest.txt b/sim/Statecraft.Sim.Tests/golden/manifest.txt
index 86ed62b3c..60afee935 100644
--- a/sim/Statecraft.Sim.Tests/golden/manifest.txt
+++ b/sim/Statecraft.Sim.Tests/golden/manifest.txt
@@ -7,6 +7,6 @@ hash1952 548a6acce93c677f566e7d6febdeb50ed6aeba0e4f61a884708ef0fc38774d87
smoke5 3005405d64abc6e7418fa1f0d35c36ce5f64ed3af7c5a4c24a73d5dfdb16121f
scenario-reckless 8041988a2c6b5b72a8351fd79ab07c2afca0672f686586cc8b7f9777c2061038
scenario-cautious 6507ddc31437eaf8b0a8858a84c539860dcd7a6febacb0f1d142cb59489e2a9f
-scenario-mvp-absorb-first a77a8f20063c741a680a964e3824946dfee27b5675b9cead5e23bbf4bd146183
+scenario-mvp-absorb-first be13c409eae4391f3da89cec7573c0dfa817884e47ce45ce50976e21d7f03bfe
mvp-end 548a6acce93c677f566e7d6febdeb50ed6aeba0e4f61a884708ef0fc38774d87
scenario-mvp-defeat d1e0dcf687c6af5431c08d319bba128b3b13a84545162320911d3c2b82eea1d1
diff --git a/sim/Statecraft.Sim.Tests/golden/scenario-mvp-absorb-first.txt b/sim/Statecraft.Sim.Tests/golden/scenario-mvp-absorb-first.txt
index 8298b90ab..2bbb8db5d 100644
--- a/sim/Statecraft.Sim.Tests/golden/scenario-mvp-absorb-first.txt
+++ b/sim/Statecraft.Sim.Tests/golden/scenario-mvp-absorb-first.txt
@@ -105,7 +105,7 @@ city{
rishon_lezion=10,5,12,5,1,c0.2590909090909091 [3FD094F2094F2095]
rosh_pinna=1,0,1,0,0,c0.35 [3FD6666666666666]
safed=2,1,3,1,0,c0.25 [3FD0000000000000]
- tel_aviv=248,106,302,90,10,c0.253441763530126 [3FD03863CD735B73]
+ tel_aviv=248,106,302,90,10,c0.253441763530126 [3FD03863CD735B73],jobs=manual
tiberias=6,2,7,2,0,c0.26428571428571435 [3FD0EA0EA0EA0EA2]
zikhron_yaakov=2,1,3,1,0,c0.3 [3FD3333333333333]
food=2556,852,0
\ No newline at end of file
diff --git a/sim/Statecraft.Sim/Cities.cs b/sim/Statecraft.Sim/Cities.cs
index f43263e9e..d4c8ca554 100644
--- a/sim/Statecraft.Sim/Cities.cs
+++ b/sim/Statecraft.Sim/Cities.cs
@@ -10,9 +10,9 @@ namespace Statecraft.Sim
{
public const string Kind = "assign_workers";
- /// <summary>R-CITY-001: the most of the city's civilians AssignWorkers accepts in jobs: its job slots, and no more than
- /// its civilians.</summary>
- public static int MaxWorkers(City city) => Math.Min(city.JobSlots, city.Civilians);
+ /// <summary>R-CITY-001: the most of the city's people AssignWorkers accepts in jobs: its job slots, and no more than its
+ /// 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
@@ -20,7 +20,7 @@ namespace Statecraft.Sim
public static int MaxWorkers(GameState s, string city, IEnumerable<Command> pending)
{
var x = s.Cities[city];
- return Math.Max(0, Math.Min(x.JobSlots, x.Civilians - Training.Ordered(city, pending)));
+ return Math.Max(0, Math.Min(x.JobSlots, x.Civilians + x.Craftsmen - Training.Ordered(city, pending)));
}
/// <summary>R-CITY-007: a city's start people in units: the nearest unit (a half rounds up), and at least 1 for a city
@@ -41,30 +41,33 @@ namespace Statecraft.Sim
if (housing != null) s.Indicators[housing.Id] = EffectsSystem.Level(c, s, housing); // R-HOUSE-004 from the first day
}
- /// <summary>R-CITY-001: sets the number of the city's civilians in jobs (a standing order). Refused, state untouched,
- /// when the city or role is unknown or the count is negative, above the job slots or above the civilians. Step has
- /// already refused it in the legacy loop.</summary>
+ /// <summary>R-CITY-001: sets the number of the city's people in jobs (a standing order), and turns that city's job
+ /// default off (R-CITY-009). Refused, state untouched, when the city or role is unknown or the count is negative, above
+ /// the job slots or above the civilians and craftsmen. Step has already refused it in the legacy loop.</summary>
public static string? Assign(Content c, GameState s, string city, string role, int count, List<Cause> why)
{
if (!s.Cities.TryGetValue(city, out var x)) return "There is no such city";
- if (role != "job") return "There is no such role"; // craftsman: Phase 3 (D-D4)
+ // Craftsmen fill ordinary job slots (Q-CRAFT-2, R-CRAFT-002), so "job" stays the only role.
+ if (role != "job") return "There is no such role";
if (count < 0) return "The number of workers cannot be negative";
if (count > MaxWorkers(x))
return count > x.JobSlots
? FormattableString.Invariant($"{PlayerText.Settlement(c, city)} has {x.JobSlots} jobs")
- : FormattableString.Invariant($"{PlayerText.Settlement(c, city)} has {x.Civilians} civilians");
- s.Cities[city] = x.WithCounts(x.Civilians, count, x.Refugees);
+ : FormattableString.Invariant($"{PlayerText.Settlement(c, city)} has {x.Civilians + x.Craftsmen} civilians and craftsmen");
+ s.Cities[city] = x.WithCounts(x.Civilians, count, x.Refugees).WithJobsDefault(false);
why.Add(new Cause("city", city, count - x.Employed, FormattableString.Invariant($"{PlayerText.Settlement(c, city)}: {count} groups in work")));
return null;
}
- /// <summary>R-CITY-002: each city's employed units earn income_per_job_per_year for the turn's share of a year.</summary>
+ /// <summary>R-CITY-002, R-CRAFT-002: each city's employed units earn income_per_job_per_year for the turn's share of a
+ /// year. Craftsmen take the jobs first, and each employed craftsman earns craftsman_income_multiple times that.</summary>
public static void Produce(Content c, GameState s, MvpRules r, double yearFraction, List<Cause> why)
{
foreach (var x in s.Cities.Values)
{
if (x.Employed == 0) continue;
- var paid = x.Employed * r.IncomePerJobPerYear * yearFraction;
+ var craftsmen = Math.Min(x.Craftsmen, x.Employed);
+ var paid = ((x.Employed - craftsmen) + craftsmen * r.CraftsmanIncomeMultiple) * r.IncomePerJobPerYear * yearFraction;
s.Treasury += paid;
why.Add(new Cause("city", x.Id, paid, $"{PlayerText.Settlement(c, x.Id)}: jobs paid {PlayerText.MoneyChange(c, "treasury", paid)}"));
}
@@ -96,23 +99,31 @@ namespace Statecraft.Sim
/// <summary>R-CITY-004 (D-A5; D-D1, Q-HOUSE-1): no hard cap. Every refugee becomes a civilian, without a job, on the
/// housing step; the people beyond the city's housing are its overflow (<see cref="Overflow"/>), still counted in it.
- /// Residents are housed automatically (Q-HOUSE-4).</summary>
+ /// Residents are housed automatically (Q-HOUSE-4). Then R-CITY-009 (Q-JOBS-1): in ascending city id, a city whose job
+ /// default is on fills its free job slots from its people without a job, at no Attention cost.</summary>
public static void House(Content c, GameState s, List<Cause> why)
{
foreach (var x in s.Cities.Values.ToList())
{
- if (x.Refugees == 0) continue;
- s.Cities[x.Id] = x.WithCounts(x.Civilians + x.Refugees, x.Employed, 0);
- why.Add(new Cause("city", x.Id, x.Refugees, FormattableString.Invariant($"{PlayerText.Settlement(c, x.Id)}: {x.Refugees} groups of immigrants housed")));
+ var housed = x.Refugees == 0 ? x : x.WithCounts(x.Civilians + x.Refugees, x.Employed, 0);
+ if (x.Refugees != 0)
+ why.Add(new Cause("city", x.Id, x.Refugees, FormattableString.Invariant($"{PlayerText.Settlement(c, x.Id)}: {x.Refugees} groups of immigrants housed")));
+ var work = MaxWorkers(housed);
+ if (housed.JobsDefault && work != housed.Employed)
+ {
+ why.Add(new Cause("city", x.Id, work - housed.Employed, FormattableString.Invariant($"{PlayerText.Settlement(c, x.Id)}: {work} groups in work")));
+ housed = housed.WithCounts(housed.Civilians, work, housed.Refugees);
+ }
+ s.Cities[x.Id] = housed;
}
}
- /// <summary>R-HOUSE-003 (Q-HOUSE-5): the people who take the city's housing: its civilians, its recruits and its groups
+ /// <summary>R-HOUSE-003 (Q-HOUSE-5): the people who take the city's housing: its civilians, craftsmen, recruits and groups
/// in training (a halutz group too, until it becomes a movable unit and leaves). Refugees wait for housing and are not
/// in it. Summed as integers, so the order of the training groups cannot change it.</summary>
public static int Housed(GameState s, City x)
{
- var n = x.Civilians + x.Recruits;
+ var n = x.Civilians + x.Craftsmen + x.Recruits;
foreach (var k in s.Cohorts.Values) if (k.City == x.Id) n += k.Count;
return n;
}
@@ -163,12 +174,12 @@ namespace Statecraft.Sim
/// cohesion, read by the effects web after the turn's housing (D-A6). Phase 1's separate cohesion value is folded into it.</summary>
public const string EmployedShareSource = "employed_share";
- /// <summary>R-CITY-005: employed over civilians, summed over all cities as integers (so city order cannot change it);
- /// 1 with no civilians, as nobody is out of work.</summary>
+ /// <summary>R-CITY-005: employed over civilians and craftsmen, summed over all cities as integers (so city order cannot
+ /// change it); 1 with none, as nobody is out of work.</summary>
public static double EmployedShare(GameState s)
{
long civilians = 0, employed = 0;
- foreach (var x in s.Cities.Values) { civilians += x.Civilians; employed += x.Employed; }
+ foreach (var x in s.Cities.Values) { civilians += x.Civilians + x.Craftsmen; employed += x.Employed; }
return civilians == 0 ? 1.0 : (double)employed / civilians;
}
diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.cs
index cf1280409..e4aea3afb 100644
--- a/sim/Statecraft.Sim/Content.cs
+++ b/sim/Statecraft.Sim/Content.cs
@@ -467,6 +467,8 @@ namespace Statecraft.Sim
public int PeoplePerUnit { get; set; }
/// <summary>Money each employed unit earns a year, in IL millions (R-CITY-002).</summary>
public double IncomePerJobPerYear { get; set; }
+ /// <summary>What an employed craftsman earns, as a multiple of <see cref="IncomePerJobPerYear"/> (R-CRAFT-002, Q-CRAFT-2).</summary>
+ public double CraftsmanIncomeMultiple { get; set; }
/// <summary>Annual civilian-place upkeep in IL millions (R-MONEY-002). Required in the GDD loop; the MVP values are 0.</summary>
public double? CityUpkeepPerYear { get; set; }
public double? HousingUpkeepPerYear { get; set; }
diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.cs
index 471ba11fe..1a7568b81 100644
--- a/sim/Statecraft.Sim/ContentLoader.cs
+++ b/sim/Statecraft.Sim/ContentLoader.cs
@@ -979,6 +979,10 @@ namespace Statecraft.Sim
/// <summary>Facilities a city may have (cities.yaml facilities): the GDD's training places (D-D5).</summary>
static readonly string[] Facilities = { "military_camp", "hakhshara" };
+ /// <summary>Where a unit type may train (unit_types.yaml facility): a start facility, or a city's completed industry
+ /// project (<see cref="Training.Industry"/>; R-CRAFT-001), which no city starts with.</summary>
+ static readonly string[] TrainingFacilities = Facilities.Concat(new[] { Training.Industry }).ToArray();
+
/// <summary>A military type's sides (unit_types.yaml side): units_1948.yaml's side ids (Q-START-4, owner, 15 October 2026).</summary>
static readonly string[] Sides = { "israel", "egypt", "jordan", "syria", "iraq", "lebanon", "ala", "local_arab_forces" };
@@ -1064,11 +1068,16 @@ namespace Statecraft.Sim
if (x.TrainingCost != 0) throw new ContentException(uf, at + ".training_cost", "only a type with a facility trains");
continue;
}
- if (!Facilities.Contains(x.Facility)) throw new ContentException(uf, at + ".facility", $"unknown facility '{x.Facility}' (military_camp or hakhshara)");
+ if (!TrainingFacilities.Contains(x.Facility)) throw new ContentException(uf, at + ".facility", $"unknown facility '{x.Facility}' (military_camp, hakhshara or industry)");
+ // A trained count lands in City.Recruits or City.Craftsmen (R-TRAIN-003, R-CRAFT-001); other trained counts
+ // wait for their decisions.
+ if (x.Kind == "population" && x.Id != "recruit" && x.Id != Training.Craftsman)
+ throw new ContentException(uf, at + ".kind", "only recruit and craftsman are trained counts");
+ // Q-CRAFT-1 (owner, 15 October 2026): a craftsman trains in a city with a completed industry project.
+ if (x.Id == Training.Craftsman && x.Facility != Training.Industry)
+ throw new ContentException(uf, at + ".facility", "a craftsman trains at industry (Q-CRAFT-1)");
if (x.TrainingTurns < 1) throw new ContentException(uf, at + ".training_turns", "must be >= 1");
if (!(x.TrainingCost >= 0 && IsFinite(x.TrainingCost))) throw new ContentException(uf, at + ".training_cost", "must be a finite number >= 0");
- // A trained count lands in City.Recruits (R-TRAIN-003); other trained counts wait for their decisions (D-D4).
- if (x.Kind == "population" && x.Id != "recruit") throw new ContentException(uf, at + ".kind", "only recruit is a trained count until Phase 5");
}
// R-CITY-003: the arrivals are spread over the cities, so there must be one to take them.
if (c.Cities.Count == 0) throw new ContentException(cf, "cities", "the GDD loop needs at least one city to take the arrivals");
@@ -1081,6 +1090,9 @@ namespace Statecraft.Sim
if (m.PeoplePerUnit != c.Rules.Mvp!.PeoplePerUnit)
throw new ContentException(file, "mvp.people_per_unit", "must be the same in every era (arrivals are counted in one unit size)");
if (!(m.IncomePerJobPerYear >= 0 && IsFinite(m.IncomePerJobPerYear))) throw new ContentException(file, "mvp.income_per_job_per_year", "must be a finite number >= 0");
+ // R-CRAFT-002 (GDD "Population and units": a craftsman "Generates more money than an ordinary civilian"): a missing key reads 0 and is refused.
+ if (!(m.CraftsmanIncomeMultiple > 1 && IsFinite(m.CraftsmanIncomeMultiple)))
+ throw new ContentException(file, "mvp.craftsman_income_multiple", "must be a finite number > 1");
// R-MONEY-002: explicit values keep an omitted kind from silently becoming free upkeep.
foreach (var (key, v) in new[] {
("city_upkeep_per_year", m.CityUpkeepPerYear), ("housing_upkeep_per_year", m.HousingUpkeepPerYear),
diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.cs
index 0154752d8..cc5bb1621 100644
--- a/sim/Statecraft.Sim/EventSystem.cs
+++ b/sim/Statecraft.Sim/EventSystem.cs
@@ -123,7 +123,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);
+ s.Cities[x.City] = new City(city.Id, housing, jobs, city.Civilians, city.Employed, city.Refugees, city.Recruits, city.Condition, city.Craftsmen, city.JobsDefault);
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 387e9e098..86e256823 100644
--- a/sim/Statecraft.Sim/GddState.cs
+++ b/sim/Statecraft.Sim/GddState.cs
@@ -5,8 +5,7 @@ namespace Statecraft.Sim
{
/// <summary>A city in the GDD v0.1 loop (docs/GDD.md "Cities and construction"; owner decision D-A2: civilians and
/// refugees are counts per city). Counts are population units, each a group (D-A1). Immutable, so GameState.Clone can copy
- /// the map shallowly; a change replaces the record. Only the attributes approved decisions define are here: craftsmen
- /// arrive with the decision that defines them (D-D4).</summary>
+ /// the map shallowly; a change replaces the record. Only the attributes approved decisions define are here.</summary>
public sealed class City
{
public string Id { get; }
@@ -15,34 +14,49 @@ namespace Statecraft.Sim
/// <summary>The number of jobs (GDD "Employment slots").</summary>
public int JobSlots { get; }
public int Civilians { get; }
- /// <summary>The civilians in jobs: part of <see cref="Civilians"/>, not in addition to them.</summary>
+ /// <summary>The people in jobs: part of <see cref="Civilians"/> and <see cref="Craftsmen"/>, not in addition to them.
+ /// Craftsmen take the jobs first (R-CRAFT-002).</summary>
public int Employed { get; }
public int Refugees { get; }
/// <summary>The recruits who finished basic training here (GDD "Progression"; R-TRAIN-003). A count until Phase 5 makes
/// soldiers units.</summary>
public int Recruits { get; }
+ /// <summary>The craftsmen trained here (D-D4; R-CRAFT-001): a count, not movable units (D-A2), and not part of
+ /// <see cref="Civilians"/>.</summary>
+ public int Craftsmen { get; }
+ /// <summary>Whether the housing step fills the city's free jobs (R-CITY-009, Q-JOBS-1). On at the start; an accepted
+ /// AssignWorkers order turns it off for the city.</summary>
+ public bool JobsDefault { get; }
/// <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; }
- public City(string id, int housingCapacity, int jobSlots, int civilians, int employed, int refugees, int recruits = 0, double? condition = null)
+ 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)
{
Id = id; HousingCapacity = housingCapacity; JobSlots = jobSlots; Civilians = civilians; Employed = employed; Refugees = refugees;
- Recruits = recruits; Condition = condition;
+ Recruits = recruits; Condition = condition; Craftsmen = craftsmen; JobsDefault = jobsDefault;
}
/// <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);
+ public City WithCounts(int civilians, int employed, int refugees) => new City(Id, HousingCapacity, JobSlots, civilians, employed, refugees, Recruits, Condition, Craftsmen, JobsDefault);
/// <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);
+ public City WithRecruits(int recruits) => new City(Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees, recruits, Condition, Craftsmen, JobsDefault);
+
+ /// <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);
+
+ /// <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);
/// <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);
+ public City WithCondition(double condition) => new City(Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees, Recruits, condition, Craftsmen, JobsDefault);
- /// <summary>The record as the state hash writes it. The recruits are written only when there are some, and the condition
- /// only when it is set (",c" and its 64 bits in hex; readable, the value and then the bits), so a city with neither hashes
- /// as it did before they existed (R-LOOP-002's rule).</summary>
+ /// <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
+ /// there are some and the job default only when it is off (",jobs=manual"), so a city with none of them hashes as it
+ /// did before they existed (R-LOOP-002's rule).</summary>
public string Canonical(bool readable = false)
{
var text = string.Format(CultureInfo.InvariantCulture, "{0}={1},{2},{3},{4},{5}", Id, HousingCapacity, JobSlots, Civilians, Employed, Refugees)
@@ -53,6 +67,8 @@ namespace Statecraft.Sim
var bits = BitConverter.DoubleToInt64Bits(c).ToString("X16", CultureInfo.InvariantCulture);
text += readable ? ",c" + c.ToString("R", CultureInfo.InvariantCulture) + " [" + bits + "]" : ",c" + bits;
}
+ if (Craftsmen != 0) text += ",craftsmen=" + Craftsmen.ToString(CultureInfo.InvariantCulture);
+ if (!JobsDefault) text += ",jobs=manual";
return text;
}
}
diff --git a/sim/Statecraft.Sim/Projects.cs b/sim/Statecraft.Sim/Projects.cs
index c8948ec38..6adf14c46 100644
--- a/sim/Statecraft.Sim/Projects.cs
+++ b/sim/Statecraft.Sim/Projects.cs
@@ -247,7 +247,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);
+ 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);
why.Add(new Cause("city", p.City, 1, $"{PlayerText.Settlement(c, p.City)}: {k.Name} was finished"));
}
}
diff --git a/sim/Statecraft.Sim/Reference/ReferencePlayer.cs b/sim/Statecraft.Sim/Reference/ReferencePlayer.cs
index 2dd45efe5..91ac18e07 100644
--- a/sim/Statecraft.Sim/Reference/ReferencePlayer.cs
+++ b/sim/Statecraft.Sim/Reference/ReferencePlayer.cs
@@ -5,8 +5,8 @@ using System.Linq;
namespace Statecraft.Sim.Reference
{
/// <summary>Test policy for the GDD goldens (D-A7): a stated simple policy, not game AI and not historical. It sends
- /// HistoricalAI's orders, then fills each city's jobs with as many civilians as there are jobs, then, when no city
- /// project is being built, starts a housing project in the city with the most overflow that has a hex for it, then sends each idle halutz
+ /// HistoricalAI's orders and no AssignWorkers (R-CITY-009's default fills the jobs, and an order would turn it off), then,
+ /// when no city project is being built, starts a housing project in the city with the most overflow that has a hex for it, then sends each idle halutz
/// unit to the first available yishuv site (then to the first ready field, then to the first available camp site), then,
/// when there is no halutz and none in training, trains one halutz group in
/// the first city with a Hakhshara and a civilian left without work, while the turn's Attention lasts (both orders borrow). It lives in Statecraft.Sim only so Unity can replay the goldens (#394; GoldenRun); no game mode or UI may reach it
@@ -17,15 +17,6 @@ namespace Statecraft.Sim.Reference
{
var list = new List<Command>(HistoricalAI.Commands(c, s));
var left = s.Attention - list.Sum(x => AttentionSystem.Cost(c, s, x.Kind));
- foreach (var city in s.Cities.Values)
- {
- var want = Math.Min(city.JobSlots, city.Civilians);
- if (want == city.Employed) continue;
- var cost = AttentionSystem.Cost(c, s, Cities.Kind);
- if (cost > left + 1e-9) continue; // AttentionSystem.TrySpend's rule
- list.Add(new AssignWorkers(city.Id, "job", want));
- left -= cost;
- }
House(c, s, list, ref left);
var halutz = c.UnitTypes.FirstOrDefault(t => t.Id == "halutz");
if (halutz == null) return list;
@@ -35,8 +26,7 @@ namespace Statecraft.Sim.Reference
if (trainCost > left + 1e-9) return list; // training borrows, so the Treasury does not hold it back
foreach (var city in s.Cities.Values)
{
- var employed = list.OfType<AssignWorkers>().Where(a => a.City == city.Id).Select(a => a.Count).DefaultIfEmpty(city.Employed).Last();
- if (city.Civilians - employed < 1 || !Training.HasFacility(c, s, city.Id, halutz.Facility)) continue;
+ if (Training.Idle(city) < 1 || !Training.HasFacility(c, s, city.Id, halutz.Facility)) continue;
list.Add(new Train(city.Id, halutz.Id, 1));
break;
}
diff --git a/sim/Statecraft.Sim/Training.cs b/sim/Statecraft.Sim/Training.cs
index 7d3986d28..b03a976cf 100644
--- a/sim/Statecraft.Sim/Training.cs
+++ b/sim/Statecraft.Sim/Training.cs
@@ -5,7 +5,8 @@ using System.Linq;
namespace Statecraft.Sim
{
/// <summary>The GDD v0.1 training (docs/GDD.md "Progression"; Phase 1 PR 4): a city's civilians train in a military camp to
- /// become recruits, or in a Hakhshara to become halutzim, over several turns (D-A3). The facilities are read from
+ /// become recruits, in a Hakhshara to become halutzim, or in a city with a completed industry project to become craftsmen
+ /// (D-D4, Q-CRAFT-1), over several turns (D-A3). The facilities are read from
/// cities.yaml: one of each exists at the start (D-D5, a design assumption), and pioneers build more at camp sites
/// (R-CAMP-001). Runs only
/// when eras.yaml systems.loop is gdd. Its causes go to the "city" group of the Why screen: they move a city's people and
@@ -15,22 +16,31 @@ namespace Statecraft.Sim
public const string TrainKind = "train";
public const string CancelKind = "cancel_training";
+ /// <summary>The craftsman's unit type id (D-D4; R-CRAFT-001).</summary>
+ public const string Craftsman = "craftsman";
+
+ /// <summary>The facility a craftsman trains at: a completed city project of this kind (projects.yaml; Q-CRAFT-1).</summary>
+ public const string Industry = "industry";
+
/// <summary>The facility's name in text the player reads.</summary>
- static string Place(string facility) => facility == "military_camp" ? "military camp" : "Hakhshara";
+ static string Place(string facility) => facility == "military_camp" ? "military camp" : facility == Industry ? "completed industry project" : "Hakhshara";
/// <summary>The course the facility gives, in text the player reads.</summary>
- static string Course(string facility) => facility == "military_camp" ? "basic training" : "pioneer training";
+ static string Course(string facility) => facility == "military_camp" ? "basic training" : facility == Industry ? "craft training" : "pioneer training";
static string Groups(int n) => n == 1 ? "1 group" : FormattableString.Invariant($"{n} groups");
- /// <summary>R-TRAIN-001, R-CAMP-001: whether <paramref name="city"/> has <paramref name="facility"/>: one it starts with
- /// (cities.yaml, D-D5), or a camp site of that kind built for it (sites.yaml city). A camp being built does not count.</summary>
+ /// <summary>R-TRAIN-001, R-CAMP-001, R-CRAFT-001: whether <paramref name="city"/> has <paramref name="facility"/>: one it
+ /// starts with (cities.yaml, D-D5), a camp site of that kind built for it (sites.yaml city), or, for industry, a
+ /// completed industry project in it (R-PROJ-003). A camp or a project being built does not count.</summary>
public static bool HasFacility(Content c, GameState s, string city, string facility) =>
c.Cities.First(k => k.Id == city).Facilities.Contains(facility)
+ || (facility == Industry && s.CityProjects.Values.Any(p => p.City == city && p.Kind == Industry && p.BuiltOn != null))
|| c.Sites.Any(x => x.City == city && x.Kinds.Contains(facility) && s.Sites.TryGetValue(x.Id, out var w) && w.BuiltOn != null);
- /// <summary>R-TRAIN-001: the city's civilians without work, the most a Train order there accepts.</summary>
- public static int Idle(City city) => city.Civilians - city.Employed;
+ /// <summary>R-TRAIN-001: the city's civilians without work, the most a Train order there accepts. Craftsmen take the
+ /// 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 orders in <paramref name="pending"/> (this turn's queue) take from
/// <paramref name="city"/>, every track together.</summary>
@@ -45,7 +55,8 @@ namespace Statecraft.Sim
var x = s.Cities[city];
var list = pending as IReadOnlyCollection<Command> ?? pending.ToList();
var employed = Math.Max(x.Employed, list.OfType<AssignWorkers>().Where(w => w.City == city).Select(w => w.Count).DefaultIfEmpty(0).Max());
- return Math.Max(0, x.Civilians - employed - Ordered(city, list));
+ var ordinaryEmployed = Math.Max(0, employed - x.Craftsmen);
+ return Math.Max(0, x.Civilians - ordinaryEmployed - Ordered(city, list));
}
/// <summary>R-TRAIN-001: <paramref name="count"/> of the city's civilians without work start training as
@@ -95,8 +106,8 @@ namespace Statecraft.Sim
}
/// <summary>R-TRAIN-003, step 4 of the turn (spec 2026-10-12 section 2.3, D-A6): in ascending id, each cohort has one turn
- /// less to go. One that reaches 0 leaves the state: recruits join the city's count, and halutzim become one movable unit
- /// per group at the city's settlement hex, taking the next ids in turn.</summary>
+ /// less to go. One that reaches 0 leaves the state: recruits and craftsmen join the city's counts (R-CRAFT-001), and
+ /// halutzim become one movable unit per group at the city's settlement hex, taking the next ids in turn.</summary>
public static void Progress(Content c, GameState s, List<Cause> why)
{
foreach (var k in s.Cohorts.Values.ToList())
@@ -111,6 +122,12 @@ namespace Statecraft.Sim
for (int i = 0; i < k.Count; i++) { var id = s.NextId++; s.Units.Add(id, new Unit(id, type.Id, hex.Q, hex.R)); }
why.Add(new Cause("city", k.City, k.Count, $"{name}: {Groups(k.Count)} finished {Course(type.Facility)} and are halutzim"));
}
+ else if (type.Id == Craftsman)
+ {
+ var x = s.Cities[k.City];
+ s.Cities[k.City] = x.WithCraftsmen(x.Craftsmen + k.Count);
+ why.Add(new Cause("city", k.City, k.Count, $"{name}: {Groups(k.Count)} finished {Course(type.Facility)} and are craftsmen"));
+ }
else
{
var x = s.Cities[k.City];