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.

GDD 0.3 craftsman course: a novice craftsman on the ledger, fixture only (Refs #1698) (#2416)

Eyal Golan36b06fd825a2
diff --git a/changelog.d/1698-novice-craftsman.md b/changelog.d/1698-novice-craftsman.md
new file mode 100644
index 000000000..a473cfae8
--- /dev/null
+++ b/changelog.d/1698-novice-craftsman.md
@@ -0,0 +1,9 @@
+- GDD 0.3 craftsman course in the sim test fixture (Refs #1698): a free civilian, or a novice farmer or pioneer, can start
+ the craftsman course as a novice craftsman under the same population id, and becomes an apprentice on the course's
+ third counted turn. Cancelling before then makes them an ordinary civilian again, keeping their tools with no refund.
+ The course creates no mentor. Nothing in the game calls this fixture yet, so nothing changes for players and saves are
+ unaffected.
+- GDD 0.3 craftsman course (Refs #1698): a trained or veteran farmer or pioneer can start the course too and loses
+ that level; tools are kept, and cancelling leaves an ordinary civilian (owner, 4 November 2026).
+- GDD 0.3 craftsman course (Refs #1698): an apprentice or expert craftsman can take the course again and keeps their
+ level on the course, after graduating and after cancelling (owner, 4 November 2026).
diff --git a/docs/gdd/training.md b/docs/gdd/training.md
index 04bb25385..cff830e79 100644
--- a/docs/gdd/training.md
+++ b/docs/gdd/training.md
@@ -65,6 +65,8 @@ Under retained `R-UNIT-005`, Send home is the only way home: no automatic demobi
Cancelled retained courses award no unfinished qualification. A course whose slot is lost, or whose people are reassigned, is cancelled like `CancelTraining`: people return at once as civilians without a job, Money and tools are not refunded, and Arms return to the pool; a novice may then take another profession, and graduates may re-enrol at any time (owner, 1 November 2026, Q44, Q52, 27M-3 to 27M-5) [S11]. The novice craftsman label starts with the craftsman course and ends on cancelling (#1698 follow-up) [S11]. Proposed reception credit and reusable-equipment cancellation rules are non-operative [S6]. [Resources](cutover-resource-layer.md) owns retained affordability rules. (unitless)
+On the `gdd-0.3` craftsman course (`R-CRAFT-003`), an apprentice or expert craftsman who takes it again keeps their level on the course and after it (owner, 4 November 2026: "Keep their level (Recommended)"), and a trained or veteran farmer or pioneer may start it and loses that level, as under `R-QUAL-006`; tools are kept, and cancelling leaves an ordinary civilian (owner, 4 November 2026: "Yes, lose old level (Recommended)") [S12].
+
## Data touched
- `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]).
@@ -106,6 +108,7 @@ Camp growth into permanent towns, soldier training in civilian centres and unsou
- [S9] Retained training and Send home rules, `docs/rules/mvp.md` (`R-TRAIN-001` and `R-UNIT-005`).
- [S10] Owner's 30 October 2026 rulings, [GDD conflict decisions](../GDD.md#30-october-2026-conflict-decisions).
- [S11] Owner's 1 November 2026 answers, [GDD 1 November 2026 answers](../GDD.md#1-november-2026-answers).
+- [S12] Owner's 4 November 2026 answers on the #1698 craftsman course (PR #2416), recorded in the #1698 issue body ("Update, 4 Nov 2026", https://github.com/eyalgolan/statecraft-israel/issues/1698, checked 2026-11-04) and in `docs/rules/mvp.md` (`R-CRAFT-003`).
## Open questions
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 308704237..d96c139d0 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -184,9 +184,11 @@ R-TRAIN-008: The fixture refuses, with a "Deferred:" reason and the state unchan
## 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. A craftsman can return to civilian life and keep the qualification (R-QUAL-002).
+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). Under `gdd-0.3`, the craftsman course on the population ledger is R-CRAFT-003 (fixture only).
-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.
+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. Under `gdd-0.3`, a craftsman is a novice from the course start, then an apprentice or an expert (R-CRAFT-003); the course's Industry slot and income stay with #1692.
+
+R-CRAFT-003: In `gdd-0.3` synthetic fixtures only (#1698, `Gdd03CraftCourseFixture`; nothing in the game calls it), a craftsman course on the #1689 population ledger. A free civilian with no profession, whatever their reception progress (as R-TRAIN-005; `docs/GDD.md:374`: "Refugees cannot train until they become civilians"), or a novice farmer or pioneer, starts the course and becomes a novice craftsman under the same population id, as a trainee on the course (#1698 follow-up and 27M-3, in the 1 November 2026 answers the owner approved, [answers](https://github.com/eyalgolan/statecraft-israel/pull/1668#issuecomment-6553884547): "When the craftsman course starts." and "The course replaces the novice profession, and paid tools are not refunded."). Work XP restarts at 0 because the course replaces the novice profession, a maintainer call; tools and their paid fact are kept. A person with a job may start: the job is released in the same change, and what they held at the month's opening is no bar. This is a maintainer reading of `docs/gdd/cities.md:42` ("Reassignment releases old capacity atomically.") with `docs/GDD.md:372` Q43(b)/(c), not an owner ruling. A person on a course, teaching or in reception, and a refugee are refused. Course turns follow R-TRAIN-006's Q43 timing: the enrolment month is course turn 1, a later month counts only when its opening snapshot holds the course, and each month ordinal counts once. The turn that reaches Agreed `craft.course_turns` (currently 3) makes an apprentice craftsman with the same id and every other field, released in that turn as a civilian without a job; they cannot start a course that month (Q43(b), R-TRAIN-008), and work starts the next month. Cancelling before that makes an ordinary civilian again: profession and tier none, work XP 0, released at once, same id, tools and their paid fact kept and nothing refunded (#1698 follow-up: "On cancelling before qualifying they are an ordinary civilian again."; 27M-4; Q44). No teacher is read or created and the population count does not change (#1698: "The course adds no mentor population unit"); a teaching record at a craftsman course is refused. The ledger accepts a novice craftsman outside a course too, a maintainer reading of Q55 ("workshop work by a novice craftsman"). A trained or veteran farmer or pioneer may start the course and loses that level, as a qualified civilian a Train order takes does (R-QUAL-006; `docs/GDD.md:349`, D3): they become a novice craftsman with work XP 0, keep their tools and the paid fact, graduate as an apprentice, and on cancelling are an ordinary civilian, not the old level (owner, 4 November 2026, on "#1698: may a trained or veteran farmer or pioneer start the craftsman course?": "Yes, lose old level (Recommended)"). An apprentice or expert craftsman may take the course again (27M-5, `docs/gdd/training.md:66`: "graduates may re-enrol at any time") and keeps their tier and work XP on the course, after graduating and after cancelling; the course never lowers a qualification (owner, 4 November 2026, on "#1698: what level does a craftsman hold when they take the craftsman course again?": "Keep their level (Recommended)"). Not built here, refused with a "Deferred:" reason and the state unchanged: a novice craftsman outside a course starting it (the 4 November 2026 answer names an apprentice or expert), and a course turn when the course is not available at the month's freeze (Q52). Out of this rule, with #1692: the Industry slot, its capacity and the course income; and with their owners: the 0.5 Money course cost, apprentice-to-expert work turns, live `Train` orders and saves. Every refusal leaves the state unchanged; legacy and `gdd-0.1` states are refused.
## Sites
@@ -579,7 +581,7 @@ These contracts cover #1689 steps 1–2 and the Historical start inventory (R-PO
R-POP-001: Only exact `gdd-0.3` enables the population-ledger capability, independently of the broad GDD loop and Attention (R-LOOP-002/005). An immutable own-population record has a dedicated nonnegative ordinal id. Synthetic fixture inventory is ordered by source key (ordinal string comparison), then within-source ordinal. Registered arrivals allocate monotonically; only explicit combat losses remove living ids. Sources remain registered after loss, and ids are never reused. Reconciliation checks the exact created-minus-lost id set against the living ledger, not just equal totals. Status/region counts include every matching record once. The gdd-0.3 scale of a synthetic or Open fixture reads one positive Agreed integer from `population.people_per_unit` in its catalogue (currently 10,000, Open mode's scale under D2); a Historical fixture reads `rules.yaml`'s `people_per_unit` for the start day (1,000), as R-UNIT-006 does (owner, 1 November 2026, D2: "Approve all six (Recommended)", "The Historical MVP keeps main's start: census cities at 1,000 people a unit (`R-CITY-007`)"; R-POP-004); rows with a `census/` or `units_1948/` source key are the Historical start's and are refused in any other fixture. Old identities retain the common rules scale. Missing, fractional, nonpositive, overflowing or Deferred values have no fallback, in either source.
-R-POP-002: A ledger record has exactly one typed status and assignment, validated location, home and captor references, whole reception-turn ticks capped by the catalogue requirement, civilian profession-specific tier and actual-work XP, separate military qualification/combat XP, and distinct issued civilian/military equipment and paid facts. Unknown references, unresolved teacher ids, incompatible statuses/assignments, inconsistent region/hex/facility bindings, invalid progress/tiers and duplicate issued-item ownership are refused before mutation. Moves and atomic status/location/assignment transitions retain identity/history. Capture retains home context without inventing a prison hex or refunding equipment. Ledger changes never touch resources, causes, RNG or Attention. Initialization is internal and fixture-only; initialized ledger fixtures refuse aggregate Simulation commands and turns. Old identities refuse ledger mutation. Prices, progression awards, return destinations, tool lock-in and captive-equipment outcomes remain with their owning issues.
+R-POP-002: A ledger record has exactly one typed status and assignment, validated location, home and captor references, whole reception-turn ticks capped by the catalogue requirement, civilian profession-specific tier and actual-work XP, separate military qualification/combat XP, and distinct issued civilian/military equipment and paid facts. Unknown references, unresolved teacher ids, incompatible statuses/assignments, inconsistent region/hex/facility bindings, invalid progress/tiers and duplicate issued-item ownership are refused before mutation. Moves and atomic status/location/assignment transitions retain identity/history. Capture retains home context without inventing a prison hex or refunding equipment. Ledger changes never touch resources, causes, RNG or Attention. Initialization is internal and fixture-only; initialized ledger fixtures refuse aggregate Simulation commands and turns. Old identities refuse ledger mutation. Prices, progression awards, return destinations, tool lock-in and captive-equipment outcomes remain with their owning issues. A craftsman's tier is novice, apprentice or expert (R-CRAFT-003); a farmer's or pioneer's is novice, trained or veteran.
R-POP-003: Clone copies all ledger containers; immutable records and frozen bindings may be shared. The canonical writer emits a gdd-0.3-only section ordered by numeric population id, with fixed field order, stable machine tokens, invariant integer formatting and length-prefixed reference strings. It covers every record/assignment/equipment/reference field, binding, creation/loss provenance and allocator even after the last combat loss. Legacy/gdd-0.1 emit no ledger section or allocator marker. R-SAVE-001/002 still govern identity mismatch refusal and replay: no ledger snapshot or new command syntax is added in this foundation, and fixture injection is not replay evidence. Existing unpublished schema-4 draft hashes change; no migration promise is made.
diff --git a/sim/Statecraft.Sim.Tests/Gdd03CraftCourseFixtureTests.cs b/sim/Statecraft.Sim.Tests/Gdd03CraftCourseFixtureTests.cs
new file mode 100644
index 000000000..3db5e2f45
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/Gdd03CraftCourseFixtureTests.cs
@@ -0,0 +1,493 @@
+using Statecraft.Sim;
+
+// #1698 first slice (R-CRAFT-003): synthetic fixtures only. No real course, Industry slot, city, region or game caller is
+// exercised. The 1 November 2026 answers quoted below are agent-drafted answers the owner approved (#1668,
+// https://github.com/eyalgolan/statecraft-israel/pull/1668#issuecomment-6553884547).
+public class Gdd03CraftCourseFixtureTests
+{
+ static readonly Lazy<Gdd03BalanceCatalogue> Real = new(() => ContentLoader.Load(RealContentTests.ContentRoot()).Gdd03Balance!);
+ const string CraftA = "fixture-craft-a", CraftB = "fixture-craft-b", CraftSouth = "fixture-craft-south";
+ const string Field = "fixture-field", Centre = "fixture-centre";
+ static readonly string[] Facilities = { CraftA, CraftB, CraftSouth, Field, Centre };
+ static readonly string[] Courses = { CraftA, CraftB, CraftSouth };
+
+ static Content Catalogue(string? key = null, Gdd03DesignValue? replacement = null, string ruleset = SaveGame.Gdd03Ruleset)
+ {
+ var c = PopulationLedgerTests.Content(ruleset);
+ var values = new Dictionary<string, Gdd03DesignValue>(Real.Value.Values, StringComparer.Ordinal);
+ if (key != null) { if (replacement == null) values.Remove(key); else values[key] = replacement; }
+ c.Gdd03Balance = new Gdd03BalanceCatalogue { Ruleset = Real.Value.Ruleset, Values = values };
+ return c;
+ }
+ static Gdd03DesignValue Agreed(decimal v) => new() { Basis = "Agreed", Values = new() { v }, Note = "synthetic test value" };
+ static Gdd03DesignValue Deferred() => new() { Basis = "Deferred", Expression = "X", Note = "synthetic deferred value" };
+
+ static PopulationBindings Bindings() => new(
+ new[] { new PopulationLocation("north"), new PopulationLocation("south") },
+ new[] { new PopulationTarget(CraftA, PopulationAssignmentKind.Course, "north", 3),
+ new PopulationTarget(CraftB, PopulationAssignmentKind.Course, "north", 3),
+ new PopulationTarget(CraftSouth, PopulationAssignmentKind.Course, "south", 3),
+ new PopulationTarget(Centre, PopulationAssignmentKind.Course, "north", 3),
+ new PopulationTarget(Field, PopulationAssignmentKind.Work, "north") },
+ Array.Empty<string>(), new[] { "basic" });
+
+ static PopulationUnit Person(CivilianProfession profession, CivilianTier tier, string? tools,
+ PopulationStatus status = PopulationStatus.FreeCivilian, int reception = 6, PopulationAssignment? assignment = null,
+ string region = "north")
+ => new(0, status, reception, new PopulationLocation(region), assignment ?? PopulationAssignment.Unassigned,
+ profession, tier, profession == CivilianProfession.None ? 0 : 4, "basic", 2,
+ new PopulationEquipment(tools, tools != null));
+
+ // Ids follow the row order.
+ const int Free = 0, NoviceFarmer = 1, NovicePioneer = 2, TrainedFarmer = 3, VeteranPioneer = 4, Apprentice = 5,
+ Expert = 6, Worker = 7, RefugeeId = 8, NoviceCraftsman = 10, SouthFree = 11;
+ static GameState State(Content c, params PopulationUnit[] extra)
+ {
+ var people = new List<PopulationUnit> {
+ Person(CivilianProfession.None, CivilianTier.None, null),
+ Person(CivilianProfession.Farmer, CivilianTier.Novice, "tools-1"),
+ Person(CivilianProfession.Pioneer, CivilianTier.Novice, "tools-2"),
+ Person(CivilianProfession.Farmer, CivilianTier.Trained, "tools-3"),
+ Person(CivilianProfession.Pioneer, CivilianTier.Veteran, "tools-4"),
+ Person(CivilianProfession.Craftsman, CivilianTier.Apprentice, null),
+ Person(CivilianProfession.Craftsman, CivilianTier.Expert, null),
+ Person(CivilianProfession.None, CivilianTier.None, null, assignment: new PopulationAssignment(PopulationAssignmentKind.Work, Field)),
+ Person(CivilianProfession.None, CivilianTier.None, null, PopulationStatus.Refugee, 2),
+ Person(CivilianProfession.None, CivilianTier.None, null, reception: 3), // id 9: keeps the later ids in row order
+ Person(CivilianProfession.Craftsman, CivilianTier.Novice, null),
+ Person(CivilianProfession.None, CivilianTier.None, null, region: "south") };
+ people.AddRange(extra);
+ return PopulationLedger.CreateFixture(c, Bindings(), people.Select((p, i) => new PopulationInventoryRow("synthetic", i, p)));
+ }
+ static Gdd03SyntheticMonthContext Month(GameState s, int ordinal, bool coursesAvailable = true)
+ => Gdd03SyntheticMonthContext.CreateSynthetic(SaveGame.Gdd03Ruleset, ordinal, s.PopulationLedger.Units,
+ Facilities.Select(f => new Gdd03SyntheticFacilitySnapshot(f, coursesAvailable || !f.Contains("craft", StringComparison.Ordinal), 1)),
+ Array.Empty<int>(), Array.Empty<Gdd03SyntheticHousingSnapshot>(), Array.Empty<Gdd03SyntheticPendingEntry>());
+
+ const string GraduationMonth = Gdd03TrainingCentreFixture.GraduationMonthReason;
+ const string CourseAtOpening = Gdd03CraftCourseFixture.CourseAtOpeningReason;
+ // A novice craftsman outside a course is not covered by the owner's 4 November 2026 answer, which names an apprentice
+ // or expert; the whole reason is pinned.
+ const string NoviceCraftsmanDeferred = "Deferred: #1698 (not ruled: a novice craftsman outside a course starting the craftsman course; the owner's 4 November 2026 answer, \"Keep their level (Recommended)\", covers an apprentice or expert craftsman).";
+ const string SlotDeferred = "Deferred: #1668 Q52";
+
+ static void Unchanged(GameState s, Action act, Type expected, string? messagePrefix = null)
+ {
+ var before = s.Describe();
+ var ex = Assert.Throws(expected, act);
+ if (messagePrefix != null) Assert.StartsWith(messagePrefix, ex.Message, StringComparison.Ordinal);
+ else Assert.False(ex.Message.StartsWith("Deferred:", StringComparison.Ordinal), ex.Message);
+ Assert.Equal(before, s.Describe());
+ }
+ static void AssertKept(PopulationUnit before, PopulationUnit after)
+ {
+ Assert.Equal(before.Id, after.Id); Assert.Equal(before.ReceptionTicks, after.ReceptionTicks);
+ Assert.Same(before.Location, after.Location); Assert.Same(before.Equipment, after.Equipment);
+ Assert.Equal(before.Qualification, after.Qualification); Assert.Equal(before.CombatXp, after.CombatXp);
+ Assert.Equal(before.Captor, after.Captor); Assert.Equal(before.Home, after.Home);
+ }
+
+ // R-CRAFT-003, #1698 follow-up ("When the craftsman course starts"), 27M-3 ("Can a not-yet-qualified farmer or pioneer
+ // start a craftsman course? | Yes (two-way professions, D3). The course replaces the novice profession, and paid tools
+ // are not refunded."): a free civilian, a novice farmer and a novice pioneer each start the course as a novice
+ // craftsman under the same population id. Work XP is reset to 0 (a maintainer call: the course replaces the novice
+ // profession); tools and their paid fact are kept. No person is created.
+ [Theory]
+ [InlineData(Free)]
+ [InlineData(NoviceFarmer)]
+ [InlineData(NovicePioneer)]
+ public void CourseStartMakesANoviceCraftsmanWithTheSameId(int id)
+ {
+ var c = Catalogue(); var s = State(c); var l = s.PopulationLedger; var f = new Gdd03CraftCourseFixture(c, s, Courses);
+ var before = l.Get(id); int count = l.Units.Count, next = l.NextPopulationId;
+ f.Start(id, CraftA, Month(s, 0));
+ var p = l.Get(id);
+ Assert.Equal(PopulationStatus.Trainee, p.Status);
+ Assert.Equal(PopulationAssignmentKind.Course, p.Assignment.Kind); Assert.Equal(CraftA, p.Assignment.Target);
+ Assert.Equal(0, p.Assignment.ProgressTicks); Assert.Null(p.Assignment.TeacherId);
+ Assert.Equal(CivilianProfession.Craftsman, p.Profession); Assert.Equal(CivilianTier.Novice, p.Tier);
+ Assert.Equal(0, p.WorkXp);
+ AssertKept(before, p);
+ Assert.Equal(before.Equipment.ToolsId != null, p.Equipment.ToolsPaid);
+ Assert.Equal(count, l.Units.Count); Assert.Equal(next, l.NextPopulationId);
+ l.Reconcile();
+ }
+
+ // R-CRAFT-003, a maintainer reading (not an owner ruling) of docs/gdd/cities.md:42, "Reassignment releases old capacity
+ // atomically.", with docs/GDD.md:372 Q43(b)/(c), as #1697's second slice reads them: what a person held at the month's
+ // opening is no bar, and a job held now is released in the same commit as the course start.
+ [Fact] public void AWorkerStartsTheCourseAndLeavesTheJobInTheSameCommit()
+ {
+ var c = Catalogue(); var s = State(c); var l = s.PopulationLedger; var f = new Gdd03CraftCourseFixture(c, s, Courses);
+ var opening = Month(s, 0);
+ Assert.Contains(Worker, opening.WorkEligibleIds);
+ var before = l.Get(Worker);
+ f.Start(Worker, CraftA, opening);
+ var p = l.Get(Worker);
+ Assert.Equal(PopulationAssignmentKind.Course, p.Assignment.Kind); Assert.Equal(CivilianTier.Novice, p.Tier);
+ AssertKept(before, p);
+ var month = Month(s, 0);
+ Assert.DoesNotContain(Worker, month.WorkEligibleIds); Assert.Contains(Worker, month.CourseEligibleIds);
+ // Released from work this turn after working at the opening: also no bar.
+ var s2 = State(c); var f2 = new Gdd03CraftCourseFixture(c, s2, Courses); var opening2 = Month(s2, 0);
+ s2.PopulationLedger.ChangeAssignment(Worker, PopulationAssignment.Unassigned);
+ f2.Start(Worker, CraftB, opening2);
+ Assert.Equal(CraftB, s2.PopulationLedger.Get(Worker).Assignment.Target);
+ s2.PopulationLedger.Reconcile();
+ }
+
+ // R-CRAFT-003, R-QUAL-006, owner, 4 November 2026, on "#1698: may a trained or veteran farmer or pioneer start the
+ // craftsman course?": "Yes, lose old level (Recommended)". A trained or veteran farmer or pioneer starts the course as
+ // a novice craftsman under the same id and loses the farmer or pioneer level (D3, docs/GDD.md:349: "a Train order can
+ // take a qualified civilian, who then loses the qualification (`R-QUAL-006`)"). Work XP restarts at 0, as for a novice
+ // farmer; tools and their paid fact are kept. Cancelling leaves an ordinary civilian, not the old level, tools kept.
+ [Theory]
+ [InlineData(CivilianProfession.Farmer, CivilianTier.Trained)]
+ [InlineData(CivilianProfession.Farmer, CivilianTier.Veteran)]
+ [InlineData(CivilianProfession.Pioneer, CivilianTier.Trained)]
+ [InlineData(CivilianProfession.Pioneer, CivilianTier.Veteran)]
+ public void QualifiedFarmersAndPioneersStartAndLoseTheirLevel(CivilianProfession profession, CivilianTier tier)
+ {
+ var c = Catalogue(); var s = State(c, Person(profession, tier, "tools-q")); var l = s.PopulationLedger;
+ var f = new Gdd03CraftCourseFixture(c, s, Courses);
+ var before = l.Get(12); int count = l.Units.Count, next = l.NextPopulationId;
+ var m0 = Month(s, 0);
+ f.Start(12, CraftA, m0);
+ var p = l.Get(12);
+ Assert.Equal(PopulationStatus.Trainee, p.Status);
+ Assert.Equal(PopulationAssignmentKind.Course, p.Assignment.Kind); Assert.Equal(CraftA, p.Assignment.Target);
+ Assert.Equal(CivilianProfession.Craftsman, p.Profession); Assert.Equal(CivilianTier.Novice, p.Tier);
+ Assert.Equal(0, p.WorkXp);
+ AssertKept(before, p); Assert.Equal("tools-q", p.Equipment.ToolsId); Assert.True(p.Equipment.ToolsPaid);
+ f.Advance(12, m0);
+ f.Cancel(12);
+ var x = l.Get(12);
+ Assert.Equal(PopulationStatus.FreeCivilian, x.Status); Assert.Same(PopulationAssignment.Unassigned, x.Assignment);
+ Assert.Equal(CivilianProfession.None, x.Profession); Assert.Equal(CivilianTier.None, x.Tier); Assert.Equal(0, x.WorkXp);
+ AssertKept(before, x); Assert.Equal("tools-q", x.Equipment.ToolsId); Assert.True(x.Equipment.ToolsPaid);
+ Assert.Equal(count, l.Units.Count); Assert.Equal(next, l.NextPopulationId);
+ l.Reconcile();
+ }
+
+ // R-CRAFT-003, R-QUAL-006, owner, 4 November 2026: "Yes, lose old level (Recommended)". The fixture's own trained
+ // farmer and veteran pioneer graduate as apprentice craftsmen, with tools kept.
+ [Theory]
+ [InlineData(TrainedFarmer)]
+ [InlineData(VeteranPioneer)]
+ public void AQualifiedFarmerOrPioneerGraduatesAsAnApprentice(int id)
+ {
+ var c = Catalogue(); var s = State(c); var l = s.PopulationLedger; var f = new Gdd03CraftCourseFixture(c, s, Courses);
+ var before = l.Get(id);
+ var m0 = Month(s, 0);
+ f.Start(id, CraftA, m0); f.Advance(id, m0); f.Advance(id, Month(s, 1)); f.Advance(id, Month(s, 2));
+ var g = l.Get(id);
+ Assert.Equal(PopulationStatus.FreeCivilian, g.Status); Assert.Same(PopulationAssignment.Unassigned, g.Assignment);
+ Assert.Equal(CivilianProfession.Craftsman, g.Profession); Assert.Equal(CivilianTier.Apprentice, g.Tier); Assert.Equal(0, g.WorkXp);
+ AssertKept(before, g); Assert.True(g.Equipment.ToolsPaid);
+ l.Reconcile();
+ }
+
+ // R-CRAFT-003, 27M-5 (docs/gdd/training.md:66, "graduates may re-enrol at any time") and owner, 4 November 2026, on
+ // "#1698: what level does a craftsman hold when they take the craftsman course again?": "Keep their level
+ // (Recommended)". An apprentice or expert craftsman starts the course again under the same id and keeps the tier and
+ // work XP on the course and after graduating: the course never lowers a qualification.
+ [Theory]
+ [InlineData(Apprentice)]
+ [InlineData(Expert)]
+ public void ReEnrolmentKeepsTheLevelDuringAndAfterTheCourse(int id)
+ {
+ var c = Catalogue(); var s = State(c); var l = s.PopulationLedger; var f = new Gdd03CraftCourseFixture(c, s, Courses);
+ var before = l.Get(id); int count = l.Units.Count, next = l.NextPopulationId;
+ var m0 = Month(s, 0);
+ f.Start(id, CraftA, m0);
+ var p = l.Get(id);
+ Assert.Equal(PopulationStatus.Trainee, p.Status);
+ Assert.Equal(PopulationAssignmentKind.Course, p.Assignment.Kind); Assert.Equal(CraftA, p.Assignment.Target);
+ Assert.Equal(CivilianProfession.Craftsman, p.Profession); Assert.Equal(before.Tier, p.Tier); Assert.Equal(before.WorkXp, p.WorkXp);
+ AssertKept(before, p);
+ f.Advance(id, m0); f.Advance(id, Month(s, 1));
+ Assert.Equal(before.Tier, l.Get(id).Tier); Assert.Equal(PopulationStatus.Trainee, l.Get(id).Status);
+ f.Advance(id, Month(s, 2));
+ var g = l.Get(id);
+ Assert.Equal(PopulationStatus.FreeCivilian, g.Status); Assert.Same(PopulationAssignment.Unassigned, g.Assignment);
+ Assert.Equal(CivilianProfession.Craftsman, g.Profession); Assert.Equal(before.Tier, g.Tier); Assert.Equal(before.WorkXp, g.WorkXp);
+ AssertKept(before, g);
+ Assert.Equal(count, l.Units.Count); Assert.Equal(next, l.NextPopulationId);
+ l.Reconcile();
+ }
+
+ // R-CRAFT-003, owner, 4 November 2026: "Keep their level (Recommended)". Cancelling a re-enrolled apprentice or expert
+ // at any counted turn keeps the craftsman profession, tier and work XP; only a novice's cancel makes an ordinary civilian.
+ [Theory]
+ [InlineData(Apprentice, 0)]
+ [InlineData(Apprentice, 2)]
+ [InlineData(Expert, 0)]
+ [InlineData(Expert, 1)]
+ public void CancellingAReEnrolmentKeepsTheLevel(int id, int counted)
+ {
+ var c = Catalogue(); var s = State(c); var l = s.PopulationLedger; var f = new Gdd03CraftCourseFixture(c, s, Courses);
+ var before = l.Get(id);
+ f.Start(id, CraftA, Month(s, 0));
+ for (int i = 0; i < counted; i++) f.Advance(id, Month(s, i));
+ f.Cancel(id);
+ var p = l.Get(id);
+ Assert.Equal(PopulationStatus.FreeCivilian, p.Status); Assert.Same(PopulationAssignment.Unassigned, p.Assignment);
+ Assert.Equal(CivilianProfession.Craftsman, p.Profession); Assert.Equal(before.Tier, p.Tier); Assert.Equal(before.WorkXp, p.WorkXp);
+ AssertKept(before, p);
+ l.Reconcile();
+ }
+
+ // R-CRAFT-003 with R-TRAIN-005 (docs/GDD.md:374: "Refugees cannot train until they become civilians"): any free
+ // civilian may enrol, whatever their reception progress, as the training-centre fixture admits them
+ // (Gdd03TrainingCentreFixture: "no reception progress is read here"). Reception progress is kept as it was.
+ [Theory]
+ [InlineData(0)]
+ [InlineData(3)]
+ public void AFreeCivilianEnrolsWhateverTheirReceptionProgress(int reception)
+ {
+ var c = Catalogue(); var s = State(c, Person(CivilianProfession.None, CivilianTier.None, null, reception: reception));
+ var l = s.PopulationLedger; var f = new Gdd03CraftCourseFixture(c, s, Courses);
+ f.Start(12, CraftA, Month(s, 0));
+ var p = l.Get(12);
+ Assert.Equal(PopulationStatus.Trainee, p.Status); Assert.Equal(PopulationAssignmentKind.Course, p.Assignment.Kind);
+ Assert.Equal(CivilianProfession.Craftsman, p.Profession); Assert.Equal(CivilianTier.Novice, p.Tier);
+ Assert.Equal(reception, p.ReceptionTicks);
+ l.Reconcile();
+ }
+
+ // R-CRAFT-003: every other start is refused with the state unchanged. Plain refusals: a refugee, an unknown course, a course outside the person's region, a person already on a course. Deferred: a
+ // novice craftsman outside a course, which the owner's 4 November 2026 answer (apprentice or expert) does not cover.
+ [Fact] public void IneligibleStartsAreRefusedWithoutMutation()
+ {
+ var c = Catalogue(); var s = State(c); var f = new Gdd03CraftCourseFixture(c, s, Courses); var m = Month(s, 0);
+ Unchanged(s, () => f.Start(RefugeeId, CraftA, m), typeof(ArgumentException));
+ Unchanged(s, () => f.Start(Free, "fixture-unknown", m), typeof(ArgumentException));
+ Unchanged(s, () => f.Start(Free, Centre, m), typeof(ArgumentException));
+ Unchanged(s, () => f.Start(Free, CraftSouth, m), typeof(ArgumentException));
+ Unchanged(s, () => f.Start(SouthFree, CraftA, m), typeof(ArgumentException));
+ Unchanged(s, () => f.Start(99, CraftA, m), typeof(ArgumentException));
+ Unchanged(s, () => f.Start(Free, CraftA, null!), typeof(ArgumentNullException));
+ Unchanged(s, () => f.Start(NoviceCraftsman, CraftA, m), typeof(NotSupportedException), NoviceCraftsmanDeferred);
+ Assert.Equal(NoviceCraftsmanDeferred, Assert.Throws<NotSupportedException>(() => f.Start(NoviceCraftsman, CraftA, m)).Message);
+ f.Start(Free, CraftA, m);
+ Unchanged(s, () => f.Start(Free, CraftB, m), typeof(ArgumentException));
+ Unchanged(s, () => f.Start(Free, CraftA, Month(s, 1)), typeof(ArgumentException));
+ }
+
+ // R-CRAFT-003, craft.course_turns (3), Q43(a) as in #2391 (docs/GDD.md:372: "A course occupies its people from its first
+ // turn ... they are released in the turn its last course turn counts"): the enrolment month is course turn 1 and the third
+ // counted turn makes an apprentice, released as a civilian without a job, with the same id and every other field.
+ [Fact] public void ThirdCountedTurnMakesAnApprentice()
+ {
+ var c = Catalogue(); var s = State(c); var l = s.PopulationLedger; var f = new Gdd03CraftCourseFixture(c, s, Courses);
+ var before = l.Get(NovicePioneer); int count = l.Units.Count, next = l.NextPopulationId;
+ var m0 = Month(s, 0);
+ f.Start(NovicePioneer, CraftA, m0);
+ f.Advance(NovicePioneer, m0);
+ Assert.Equal(1, l.Get(NovicePioneer).Assignment.ProgressTicks); Assert.Equal(CivilianTier.Novice, l.Get(NovicePioneer).Tier);
+ f.Advance(NovicePioneer, Month(s, 1));
+ Assert.Equal(2, l.Get(NovicePioneer).Assignment.ProgressTicks);
+ Assert.Equal(PopulationStatus.Trainee, l.Get(NovicePioneer).Status); Assert.Equal(CivilianTier.Novice, l.Get(NovicePioneer).Tier);
+ var graduation = Month(s, 2);
+ f.Advance(NovicePioneer, graduation);
+ var g = l.Get(NovicePioneer);
+ Assert.Equal(PopulationStatus.FreeCivilian, g.Status); Assert.Same(PopulationAssignment.Unassigned, g.Assignment);
+ Assert.Equal(CivilianProfession.Craftsman, g.Profession); Assert.Equal(CivilianTier.Apprentice, g.Tier);
+ Assert.Equal(0, g.WorkXp);
+ AssertKept(before, g); Assert.True(g.Equipment.ToolsPaid);
+ // Q43(c): the graduation month's opening still shows the course, so work starts from the next month.
+ Assert.Contains(NovicePioneer, graduation.CourseEligibleIds);
+ Assert.Equal(count, l.Units.Count); Assert.Equal(next, l.NextPopulationId);
+ l.Reconcile();
+ Unchanged(s, () => f.Advance(NovicePioneer, Month(s, 3)), typeof(ArgumentException));
+ Unchanged(s, () => f.Cancel(NovicePioneer), typeof(ArgumentException));
+ }
+
+ // R-CRAFT-003, Q43(b) as in #2391 (Gdd03TrainingCentreFixture.GraduationMonthReason): a person released by a graduation
+ // cannot start a course in the graduation month, with any snapshot of it. From the next month the apprentice may
+ // re-enrol (27M-5) and keeps the apprentice level (owner, 4 November 2026: "Keep their level (Recommended)").
+ [Fact] public void AGraduateCannotStartACourseInTheGraduationMonth()
+ {
+ var c = Catalogue(); var s = State(c); var f = new Gdd03CraftCourseFixture(c, s, Courses);
+ var m0 = Month(s, 0);
+ f.Start(Free, CraftA, m0); f.Advance(Free, m0); f.Advance(Free, Month(s, 1));
+ var graduation = Month(s, 2);
+ f.Advance(Free, graduation);
+ Unchanged(s, () => f.Start(Free, CraftB, graduation), typeof(ArgumentException), GraduationMonth);
+ Unchanged(s, () => f.Start(Free, CraftA, Month(s, 2)), typeof(ArgumentException), GraduationMonth);
+ Unchanged(s, () => f.Start(Free, CraftB, Month(s, 1)), typeof(ArgumentException), GraduationMonth);
+ f.Start(Free, CraftB, Month(s, 3));
+ Assert.Equal(CivilianProfession.Craftsman, s.PopulationLedger.Get(Free).Profession);
+ Assert.Equal(CivilianTier.Apprentice, s.PopulationLedger.Get(Free).Tier);
+ }
+
+ // R-CRAFT-003, #1698 follow-up ("On cancelling before qualifying they are an ordinary civilian again."), 27M-4 ("It is
+ // cancelled like CancelTraining, with no Money refund."), Q44 ("Tools are not refunded."): a cancel at any counted turn
+ // before graduation gives profession none, tier none and work XP 0, keeps the id, tools and their paid fact, and
+ // releases the person at once (Q43(b)), so they may start a full new course that month.
+ [Theory]
+ [InlineData(NoviceFarmer, 0)]
+ [InlineData(NoviceFarmer, 1)]
+ [InlineData(NoviceFarmer, 2)]
+ [InlineData(Free, 1)]
+ [InlineData(Worker, 2)]
+ public void CancelBeforeQualifyingIsAnOrdinaryCivilianAgain(int id, int counted)
+ {
+ var c = Catalogue(); var s = State(c); var l = s.PopulationLedger; var f = new Gdd03CraftCourseFixture(c, s, Courses);
+ var before = l.Get(id); int count = l.Units.Count, next = l.NextPopulationId;
+ f.Start(id, CraftA, Month(s, 0));
+ for (int i = 0; i < counted; i++) f.Advance(id, Month(s, i));
+ Assert.Equal(counted, l.Get(id).Assignment.ProgressTicks);
+ f.Cancel(id);
+ var p = l.Get(id);
+ Assert.Equal(PopulationStatus.FreeCivilian, p.Status); Assert.Same(PopulationAssignment.Unassigned, p.Assignment);
+ Assert.Equal(CivilianProfession.None, p.Profession); Assert.Equal(CivilianTier.None, p.Tier); Assert.Equal(0, p.WorkXp);
+ AssertKept(before, p);
+ Assert.Equal(before.Equipment.ToolsPaid, p.Equipment.ToolsPaid);
+ Assert.Equal(count, l.Units.Count); Assert.Equal(next, l.NextPopulationId);
+ l.Reconcile();
+ Unchanged(s, () => f.Cancel(id), typeof(ArgumentException));
+ Unchanged(s, () => f.Advance(id, Month(s, counted)), typeof(ArgumentException));
+ // A restart is a full new course: its enrolment month counts as turn 1 again.
+ int month = Math.Max(counted - 1, 0);
+ f.Start(id, CraftB, Month(s, month));
+ f.Advance(id, Month(s, month));
+ Assert.Equal(1, l.Get(id).Assignment.ProgressTicks); Assert.Equal(CivilianTier.Novice, l.Get(id).Tier);
+ }
+
+ // R-CRAFT-003, #1698 Done when: "The course adds no mentor population unit (ledger count unchanged)." No teacher is read
+ // or created at any step, and an inventory with a teaching record at a craftsman course is refused.
+ [Fact] public void CourseAddsNoMentorRecord()
+ {
+ var c = Catalogue(); var s = State(c); var l = s.PopulationLedger; var f = new Gdd03CraftCourseFixture(c, s, Courses);
+ int count = l.Units.Count, next = l.NextPopulationId; var ids = l.Units.Select(p => p.Id).ToArray();
+ void Same()
+ {
+ Assert.Equal(count, l.Units.Count); Assert.Equal(next, l.NextPopulationId);
+ Assert.Equal(ids, l.Units.Select(p => p.Id)); l.Reconcile();
+ Assert.DoesNotContain(l.Units, p => p.Assignment.Kind == PopulationAssignmentKind.Teaching);
+ Assert.DoesNotContain(l.Units, p => p.Assignment.TeacherId != null);
+ }
+ var m0 = Month(s, 0);
+ f.Start(Free, CraftA, m0); Same();
+ f.Start(NoviceFarmer, CraftA, m0); Same();
+ f.Advance(Free, m0); f.Advance(NoviceFarmer, m0); Same();
+ f.Cancel(NoviceFarmer); Same();
+ f.Advance(Free, Month(s, 1)); f.Advance(Free, Month(s, 2)); Same();
+ Assert.Equal(CivilianTier.Apprentice, l.Get(Free).Tier);
+
+ foreach (var mentor in new[] {
+ Person(CivilianProfession.Farmer, CivilianTier.Veteran, "tools-m", assignment: new PopulationAssignment(PopulationAssignmentKind.Teaching, CraftA)),
+ Person(CivilianProfession.Craftsman, CivilianTier.Novice, null, assignment: new PopulationAssignment(PopulationAssignmentKind.Teaching, CraftA)) })
+ {
+ var withMentor = State(c, mentor);
+ Unchanged(withMentor, () => new Gdd03CraftCourseFixture(c, withMentor, Courses), typeof(ArgumentException));
+ }
+ }
+
+ // R-CRAFT-003: the Agreed course length is read from craft.course_turns, not a literal and not profession.course_turns.
+ [Fact] public void CourseLengthComesFromTheCatalogue()
+ {
+ var c = Catalogue("craft.course_turns", Agreed(4)); var s = State(c); var l = s.PopulationLedger;
+ var f = new Gdd03CraftCourseFixture(c, s, Courses);
+ var m0 = Month(s, 0);
+ f.Start(NoviceFarmer, CraftA, m0); f.Advance(NoviceFarmer, m0); f.Advance(NoviceFarmer, Month(s, 1)); f.Advance(NoviceFarmer, Month(s, 2));
+ Assert.Equal(3, l.Get(NoviceFarmer).Assignment.ProgressTicks);
+ Assert.Equal(CivilianTier.Novice, l.Get(NoviceFarmer).Tier); Assert.Equal(PopulationStatus.Trainee, l.Get(NoviceFarmer).Status);
+ f.Advance(NoviceFarmer, Month(s, 3));
+ Assert.Equal(CivilianTier.Apprentice, l.Get(NoviceFarmer).Tier);
+
+ var c2 = Catalogue("profession.course_turns", Agreed(2)); var s2 = State(c2); var f2 = new Gdd03CraftCourseFixture(c2, s2, Courses);
+ var n0 = Month(s2, 0);
+ f2.Start(Free, CraftA, n0); f2.Advance(Free, n0); f2.Advance(Free, Month(s2, 1));
+ Assert.Equal(CivilianTier.Novice, s2.PopulationLedger.Get(Free).Tier);
+ f2.Advance(Free, Month(s2, 2));
+ Assert.Equal(CivilianTier.Apprentice, s2.PopulationLedger.Get(Free).Tier);
+ }
+
+ // R-CRAFT-003, Q43(a) as in #2391: one month ordinal counts once, the enrolment month included; an earlier ordinal is
+ // refused; a later month counts only when its opening already holds the course.
+ [Fact] public void AMonthCountsOnceAndLaterMonthsNeedTheCourseAtTheirOpening()
+ {
+ var c = Catalogue("craft.course_turns", Agreed(4)); var s = State(c); var l = s.PopulationLedger;
+ var f = new Gdd03CraftCourseFixture(c, s, Courses);
+ var preStart = Month(s, 2);
+ var m1 = Month(s, 1);
+ f.Start(Free, CraftA, m1);
+ Unchanged(s, () => f.Advance(Free, Month(s, 0)), typeof(ArgumentException));
+ Unchanged(s, () => f.Advance(Free, preStart), typeof(ArgumentException), CourseAtOpening);
+ f.Advance(Free, m1);
+ Assert.Equal(1, l.Get(Free).Assignment.ProgressTicks);
+ Unchanged(s, () => f.Advance(Free, m1), typeof(ArgumentException));
+ Unchanged(s, () => f.Advance(Free, Month(s, 1)), typeof(ArgumentException));
+ var m2 = Month(s, 2); f.Advance(Free, m2);
+ Unchanged(s, () => f.Advance(Free, m2), typeof(ArgumentException));
+ f.Advance(Free, Month(s, 4));
+ Unchanged(s, () => f.Advance(Free, Month(s, 3)), typeof(ArgumentException));
+ Assert.Equal(3, l.Get(Free).Assignment.ProgressTicks);
+ }
+
+ // R-CRAFT-003, Q52 ("An Industry course loses its slot ... | The course is cancelled like CancelTraining."): decided,
+ // not built here (the Industry slot is #1692's). A course turn when the course is not available at the month's freeze is
+ // refused Deferred with the state unchanged; the next available month counts as normal.
+ [Fact] public void AnUnavailableCourseStaysDeferred()
+ {
+ var c = Catalogue(); var s = State(c); var l = s.PopulationLedger; var f = new Gdd03CraftCourseFixture(c, s, Courses);
+ f.Start(Free, CraftA, Month(s, 0));
+ Unchanged(s, () => f.Advance(Free, Month(s, 0, coursesAvailable: false)), typeof(NotSupportedException), SlotDeferred);
+ Unchanged(s, () => f.Advance(Free, Month(s, 1, coursesAvailable: false)), typeof(NotSupportedException), SlotDeferred);
+ f.Advance(Free, Month(s, 1));
+ Assert.Equal(1, l.Get(Free).Assignment.ProgressTicks);
+ }
+
+ // R-CRAFT-003: exact gdd-0.3 only; legacy and gdd-0.1 states are refused and unchanged.
+ [Fact] public void OtherIdentitiesAndUninitializedStatesAreRefused()
+ {
+ foreach (var identity in new[] { SaveGame.LegacyRuleset, SaveGame.GddRuleset })
+ {
+ var c = Catalogue(ruleset: identity); var s = new GameState(c); var before = s.Describe();
+ Assert.Throws<InvalidOperationException>(() => new Gdd03CraftCourseFixture(c, s, Courses));
+ Assert.Equal(before, s.Describe());
+ }
+ var g = Catalogue(); var empty = new GameState(g);
+ Assert.Throws<InvalidOperationException>(() => new Gdd03CraftCourseFixture(g, empty, Courses));
+ }
+
+ // R-CRAFT-003: a missing or Deferred craft.course_turns fails closed, with no legacy fallback.
+ [Fact] public void MissingOrDeferredCourseTurnsFailClosed()
+ {
+ foreach (var replacement in new[] { null, Deferred() })
+ {
+ var c = Catalogue("craft.course_turns", replacement); var s = State(Catalogue());
+ Assert.Throws<ContentException>(() => new Gdd03CraftCourseFixture(c, s, Courses));
+ }
+ }
+
+ // R-CRAFT-003: course ids are explicit and unique, and an inventory pupil at a craftsman course must be a craftsman
+ // (a novice, or a re-enrolled apprentice or expert: owner, 4 November 2026, "Keep their level (Recommended)") with no
+ // teacher and an unfinished course.
+ [Fact] public void CourseInputsAreValidated()
+ {
+ var c = Catalogue(); var s = State(c);
+ Assert.Throws<ArgumentException>(() => new Gdd03CraftCourseFixture(c, s, new[] { CraftA, " " }));
+ Assert.Throws<ArgumentException>(() => new Gdd03CraftCourseFixture(c, s, new[] { CraftA, CraftA }));
+ Assert.Throws<ArgumentNullException>(() => new Gdd03CraftCourseFixture(c, s, null!));
+ var farmerPupil = Person(CivilianProfession.Farmer, CivilianTier.Novice, "tools-p", PopulationStatus.Trainee,
+ assignment: new PopulationAssignment(PopulationAssignmentKind.Course, CraftA));
+ var bad = State(c, farmerPupil);
+ Assert.Throws<ArgumentException>(() => new Gdd03CraftCourseFixture(c, bad, Courses));
+ // The same record at a course the fixture does not own is not its business.
+ new Gdd03CraftCourseFixture(c, bad, new[] { CraftB });
+ var pupil = Person(CivilianProfession.Craftsman, CivilianTier.Novice, null, PopulationStatus.Trainee,
+ assignment: new PopulationAssignment(PopulationAssignmentKind.Course, CraftA, 2));
+ var good = State(c, pupil); var f = new Gdd03CraftCourseFixture(c, good, Courses);
+ // An inventory pupil not started by this fixture counts a month whose opening holds the course.
+ f.Advance(12, Month(good, 5));
+ Assert.Equal(CivilianTier.Apprentice, good.PopulationLedger.Get(12).Tier);
+ var expertPupil = Person(CivilianProfession.Craftsman, CivilianTier.Expert, null, PopulationStatus.Trainee,
+ assignment: new PopulationAssignment(PopulationAssignmentKind.Course, CraftA, 2));
+ var expert = State(c, expertPupil); var fe = new Gdd03CraftCourseFixture(c, expert, Courses);
+ fe.Advance(12, Month(expert, 5));
+ Assert.Equal(CivilianTier.Expert, expert.PopulationLedger.Get(12).Tier);
+ }
+}
diff --git a/sim/Statecraft.Sim.Tests/PopulationLedgerTests.cs b/sim/Statecraft.Sim.Tests/PopulationLedgerTests.cs
index 7707e6dca..ea7f6444f 100644
--- a/sim/Statecraft.Sim.Tests/PopulationLedgerTests.cs
+++ b/sim/Statecraft.Sim.Tests/PopulationLedgerTests.cs
@@ -221,4 +221,41 @@ public class PopulationLedgerTests
Assert.Throws<NotSupportedException>(()=>Simulation.DelegatedTo(c,s,Array.Empty<Command>(),"missing"));
Assert.Equal(hash,s.Hash());
}
+
+ static PopulationUnit WithTier(CivilianProfession profession, CivilianTier tier, int workXp = 0) => new PopulationUnit(0,
+ PopulationStatus.FreeCivilian, 1, new PopulationLocation("north", 0, 0, "camp"), PopulationAssignment.Unassigned,
+ profession, tier, workXp, "basic", 9, new PopulationEquipment("tools", true, "arms", true));
+
+ // R-POP-002, R-CRAFT-003 (#1698 follow-up, the 1 November 2026 answers the owner approved: the novice craftsman label
+ // starts with the craftsman course): a craftsman may be a novice. Accepted outside a course too, a maintainer reading
+ // of Q55 ("workshop work by a novice craftsman"), not an owner ruling.
+ [Fact] public void NoviceCraftsmanIsAValidLedgerTier()
+ {
+ var s = State(Row("start", 0, WithTier(CivilianProfession.Craftsman, CivilianTier.Novice))); var l = s.PopulationLedger;
+ l.Reconcile(); Assert.Equal(CivilianTier.Novice, l.Get(0).Tier);
+ l.Transition(0, PopulationStatus.Trainee, l.Get(0).Location, new PopulationAssignment(PopulationAssignmentKind.Course, "course", 2));
+ l.Reconcile(); Assert.Equal(CivilianProfession.Craftsman, l.Get(0).Profession);
+ var farmer = State(Row()); farmer.PopulationLedger.Replace(WithTier(CivilianProfession.Craftsman, CivilianTier.Novice));
+ Assert.Equal(CivilianTier.Novice, farmer.PopulationLedger.Get(0).Tier);
+ }
+
+ // R-POP-002: tiers of other professions stay refused, at creation and on replacement, with the state unchanged.
+ [Theory]
+ [InlineData(CivilianProfession.Craftsman, CivilianTier.None)]
+ [InlineData(CivilianProfession.Craftsman, CivilianTier.Trained)]
+ [InlineData(CivilianProfession.Craftsman, CivilianTier.Veteran)]
+ [InlineData(CivilianProfession.Farmer, CivilianTier.None)]
+ [InlineData(CivilianProfession.Farmer, CivilianTier.Apprentice)]
+ [InlineData(CivilianProfession.Farmer, CivilianTier.Expert)]
+ [InlineData(CivilianProfession.Pioneer, CivilianTier.Apprentice)]
+ [InlineData(CivilianProfession.Pioneer, CivilianTier.Expert)]
+ [InlineData(CivilianProfession.None, CivilianTier.Novice)]
+ [InlineData(CivilianProfession.None, CivilianTier.Apprentice)]
+ public void TiersOfOtherProfessionsAreStillRefused(CivilianProfession profession, CivilianTier tier)
+ {
+ Assert.Throws<ArgumentException>(() => State(Row("start", 0, WithTier(profession, tier))));
+ var s = State(Row()); var before = s.Describe();
+ Assert.Throws<ArgumentException>(() => s.PopulationLedger.Replace(WithTier(profession, tier)));
+ Assert.Equal(before, s.Describe());
+ }
}
diff --git a/sim/Statecraft.Sim/Gdd03CraftCourseFixture.cs b/sim/Statecraft.Sim/Gdd03CraftCourseFixture.cs
new file mode 100644
index 000000000..3df319c90
--- /dev/null
+++ b/sim/Statecraft.Sim/Gdd03CraftCourseFixture.cs
@@ -0,0 +1,160 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Statecraft.Sim
+{
+ /// <summary>R-CRAFT-003: gdd-0.3 craftsman course over the #1689 population ledger, synthetic fixtures only (#1698). No
+ /// command, save, loader, resolver, Money, Food, Industry capacity, course income or UI caller; the Industry slot and
+ /// the course income stay with #1692. The test supplies the course ids, Course targets of the ledger bindings. Course
+ /// turns follow Gdd03TrainingCentreFixture's Q43 timing (#2391; docs/GDD.md:372, from the 1 November 2026 answers the
+ /// owner approved): the enrolment month is course turn 1, and the turn that reaches Agreed `craft.course_turns` makes
+ /// an apprentice, released at once. No teacher is read or created ("The course adds no mentor population unit").
+ /// Cases not built here (decided or not ruled) are refused with a "Deferred:" NotSupportedException.</summary>
+ internal sealed class Gdd03CraftCourseFixture
+ {
+ readonly GameState state;
+ readonly SortedSet<string> courses = new SortedSet<string>(StringComparer.Ordinal);
+ readonly int courseTurns;
+ // Per fixture instance only (not saved), as in Gdd03TrainingCentreFixture: month ordinals of each pupil's enrolment
+ // and last counted course turn (-1 before the first), and of the month in which a graduation released each person.
+ readonly SortedDictionary<int, (int enrolment, int lastCounted)> months = new SortedDictionary<int, (int, int)>();
+ readonly SortedDictionary<int, int> graduated = new SortedDictionary<int, int>();
+
+ internal Gdd03CraftCourseFixture(Content content, GameState state, IEnumerable<string> courseIds)
+ {
+ if (!content.UsesPopulationLedger || !state.UsesPopulationLedger || !state.PopulationLedger.IsInitialized)
+ throw new InvalidOperationException("Craftsman courses require an initialized gdd-0.3 synthetic fixture.");
+ this.state = state;
+ courseTurns = content.RequirePopulationInteger("craft.course_turns");
+ foreach (var id in courseIds ?? throw new ArgumentNullException(nameof(courseIds)))
+ {
+ if (string.IsNullOrWhiteSpace(id)) throw new ArgumentException("A craftsman course needs a course target id.");
+ PopulationText.ValidateText(id);
+ if (!courses.Add(id)) throw new ArgumentException("Duplicate craftsman course id.");
+ }
+ ValidateInventory();
+ }
+
+ static NotSupportedException Deferred(string question) => new NotSupportedException("Deferred: " + question);
+ // The owner's 4 November 2026 re-enrolment answer covers an apprentice or expert craftsman, not a novice outside a course.
+ const string NoviceCraftsman = "#1698 (not ruled: a novice craftsman outside a course starting the craftsman course; the owner's 4 November 2026 answer, \"Keep their level (Recommended)\", covers an apprentice or expert craftsman).";
+ const string Q52 = "#1668 Q52 (decided, not built here: a course whose Industry slot is lost is cancelled like CancelTraining; the slot is #1692's).";
+ internal const string CourseAtOpeningReason = "After the enrolment month, a course turn counts only when the month's opening holds the course (#1668 Q43(a), GDD 1 Nov 2026).";
+
+ IEnumerable<PopulationUnit> AtCourses()
+ => state.PopulationLedger.Units.Where(p => p.Assignment.Target != null && courses.Contains(p.Assignment.Target));
+
+ void ValidateInventory()
+ {
+ state.PopulationLedger.Reconcile();
+ foreach (var p in AtCourses())
+ if (p.Assignment.Kind != PopulationAssignmentKind.Course || p.Assignment.TeacherId != null
+ || p.Profession != CivilianProfession.Craftsman || p.Assignment.ProgressTicks >= courseTurns)
+ throw new ArgumentException("A craftsman course holds only craftsmen, with no teacher and an unfinished course.");
+ }
+
+ string CourseOf(PopulationUnit pupil)
+ {
+ if (pupil.Status != PopulationStatus.Trainee || pupil.Assignment.Kind != PopulationAssignmentKind.Course
+ || pupil.Assignment.Target == null || !courses.Contains(pupil.Assignment.Target))
+ throw new ArgumentException("Not a pupil of a fixture craftsman course.");
+ return pupil.Assignment.Target;
+ }
+
+ static PopulationUnit Opening(Gdd03SyntheticMonthContext month, int id)
+ => (month ?? throw new ArgumentNullException(nameof(month))).OpeningPeople.FirstOrDefault(p => p.Id == id)
+ ?? throw new ArgumentException("Participant is not in the month's opening snapshot.");
+
+ static PopulationUnit WithProfession(PopulationUnit p, PopulationStatus status, PopulationAssignment assignment,
+ CivilianProfession profession, CivilianTier tier, int workXp)
+ => new PopulationUnit(p.Id, status, p.ReceptionTicks, p.Location, assignment, profession, tier, workXp,
+ p.Qualification, p.CombatXp, p.Equipment, p.Captor, p.Home);
+
+ /// <summary>R-CRAFT-003: a free civilian with no profession, or a novice farmer or pioneer (27M-3), starts
+ /// the course as a novice craftsman (#1698 follow-up) under the same id. Work XP resets to 0 because the course
+ /// replaces the novice profession (a maintainer call); tools and their paid fact are kept (27M-3, Q44). A trained or
+ /// veteran farmer or pioneer starts the same way and loses that level (R-QUAL-006; owner, 4 November 2026: "Yes,
+ /// lose old level (Recommended)"). An apprentice or expert craftsman re-enrols (27M-5) keeping tier and work XP
+ /// (owner, 4 November 2026: "Keep their level (Recommended)"); a novice craftsman outside a course is Deferred. A job held
+ /// now is released in the same commit, and what the person held at the month's opening is no bar: a maintainer
+ /// reading of docs/gdd/cities.md:42 ("Reassignment releases old capacity atomically.") with docs/GDD.md:372
+ /// Q43(b)/(c), as #1697's second slice reads them, not an owner ruling. A person released by a graduation cannot
+ /// start in that month (Q43(b), as in #2391).</summary>
+ internal void Start(int traineeId, string courseId, Gdd03SyntheticMonthContext month)
+ {
+ ValidateInventory();
+ if (courseId == null || !courses.Contains(courseId)) throw new ArgumentException("Unknown fixture craftsman course.");
+ var ledger = state.PopulationLedger; var p = ledger.Get(traineeId);
+ Opening(month, p.Id); // the person must be in the month's opening snapshot, as in #2391
+ if (graduated.TryGetValue(p.Id, out var g) && month.MonthOrdinal <= g)
+ throw new ArgumentException(Gdd03TrainingCentreFixture.GraduationMonthReason);
+ // Any free civilian, whatever their reception progress, as the #2413 training-centre fixture (R-TRAIN-005;
+ // docs/GDD.md:374: "Refugees cannot train until they become civilians").
+ if (p.Status != PopulationStatus.FreeCivilian)
+ throw new ArgumentException("The pupil must be a free civilian.");
+ // A course or teaching would have to be cancelled by the new start (docs/gdd/training.md:66); not done here.
+ if (p.Assignment.Kind != PopulationAssignmentKind.Unassigned && p.Assignment.Kind != PopulationAssignmentKind.Work)
+ throw new ArgumentException("Only a free civilian without a job or with a job can start the craftsman course.");
+ bool reEnrolment = p.Profession == CivilianProfession.Craftsman;
+ if (reEnrolment && p.Tier == CivilianTier.Novice) throw Deferred(NoviceCraftsman);
+
+ var course = new PopulationAssignment(PopulationAssignmentKind.Course, courseId);
+ ledger.Replace(reEnrolment
+ ? WithProfession(p, PopulationStatus.Trainee, course, CivilianProfession.Craftsman, p.Tier, p.WorkXp)
+ : WithProfession(p, PopulationStatus.Trainee, course, CivilianProfession.Craftsman, CivilianTier.Novice, 0));
+ months[p.Id] = (month.MonthOrdinal, -1);
+ }
+
+ /// <summary>R-CRAFT-003: count one course turn, once per month ordinal: in the enrolment month (Q43(a)), or in a later
+ /// month whose opening already holds the course. The turn that reaches Agreed `craft.course_turns` makes a novice an
+ /// apprentice craftsman (a re-enrolled apprentice or expert keeps the level: owner, 4 November 2026, "Keep their
+ /// level (Recommended)"), released in that turn as a civilian without a job (Q43(b)); work starts the next month.</summary>
+ internal void Advance(int traineeId, Gdd03SyntheticMonthContext month)
+ {
+ ValidateInventory();
+ var ledger = state.PopulationLedger; var p = ledger.Get(traineeId); var course = CourseOf(p);
+ var opening = Opening(month, p.Id);
+ bool tracked = months.TryGetValue(p.Id, out var known);
+ bool enrolmentMonth = tracked && month.MonthOrdinal == known.enrolment;
+ if (!enrolmentMonth && (opening.Status != PopulationStatus.Trainee || opening.Assignment.Kind != PopulationAssignmentKind.Course
+ || !string.Equals(opening.Assignment.Target, course, StringComparison.Ordinal)))
+ throw new ArgumentException(CourseAtOpeningReason);
+ if (tracked && (month.MonthOrdinal < known.enrolment || month.MonthOrdinal <= known.lastCounted))
+ throw new ArgumentException("This month ordinal was already counted or is earlier.");
+ if (enrolmentMonth
+ ? !month.Facilities.Any(f => string.Equals(f.Id, course, StringComparison.Ordinal) && f.AvailableAtMonthFreeze && f.OpeningCapacity > 0)
+ : !month.CourseEligibleIds.Contains(p.Id))
+ throw Deferred(Q52);
+ if (!enrolmentMonth && p.Assignment.ProgressTicks != opening.Assignment.ProgressTicks)
+ throw new ArgumentException("This month's course turn was already counted.");
+
+ int progress = checked(p.Assignment.ProgressTicks + 1);
+ if (progress < courseTurns)
+ {
+ ledger.Replace(p.WithPlacement(p.Status, p.Location,
+ new PopulationAssignment(PopulationAssignmentKind.Course, course, progress), p.Captor, p.Home));
+ if (tracked) months[p.Id] = (known.enrolment, month.MonthOrdinal);
+ return;
+ }
+ ledger.Replace(WithProfession(p, PopulationStatus.FreeCivilian, PopulationAssignment.Unassigned,
+ CivilianProfession.Craftsman, p.Tier == CivilianTier.Novice ? CivilianTier.Apprentice : p.Tier, p.WorkXp));
+ months.Remove(p.Id);
+ graduated[p.Id] = month.MonthOrdinal;
+ }
+
+ /// <summary>R-CRAFT-003: cancelling before qualifying makes an ordinary civilian again (#1698 follow-up): profession
+ /// and tier none, work XP 0, released at once as a civilian without a job (Q43(b)). Same id; tools and their paid
+ /// fact are kept and nothing is refunded (27M-4, Q44). A re-enrolled apprentice or expert keeps the craftsman tier and
+ /// work XP (owner, 4 November 2026: "Keep their level (Recommended)").</summary>
+ internal void Cancel(int traineeId)
+ {
+ ValidateInventory();
+ var ledger = state.PopulationLedger; var p = ledger.Get(traineeId); CourseOf(p);
+ ledger.Replace(p.Tier == CivilianTier.Novice
+ ? WithProfession(p, PopulationStatus.FreeCivilian, PopulationAssignment.Unassigned, CivilianProfession.None, CivilianTier.None, 0)
+ : WithProfession(p, PopulationStatus.FreeCivilian, PopulationAssignment.Unassigned, CivilianProfession.Craftsman, p.Tier, p.WorkXp));
+ months.Remove(p.Id);
+ }
+ }
+}
diff --git a/sim/Statecraft.Sim/PopulationLedger.cs b/sim/Statecraft.Sim/PopulationLedger.cs
index 8294e8951..1eabe096d 100644
--- a/sim/Statecraft.Sim/PopulationLedger.cs
+++ b/sim/Statecraft.Sim/PopulationLedger.cs
@@ -211,7 +211,9 @@ namespace Statecraft.Sim
var tierValid = p.Profession switch {
CivilianProfession.None => p.Tier == CivilianTier.None && p.WorkXp == 0,
CivilianProfession.Farmer or CivilianProfession.Pioneer => p.Tier == CivilianTier.Novice || p.Tier == CivilianTier.Trained || p.Tier == CivilianTier.Veteran,
- CivilianProfession.Craftsman => p.Tier == CivilianTier.Apprentice || p.Tier == CivilianTier.Expert,
+ // R-CRAFT-003 (#1698 follow-up): a novice craftsman from the course start. Valid outside a course too,
+ // a maintainer reading of Q55 ("workshop work by a novice craftsman"), not an owner ruling.
+ CivilianProfession.Craftsman => p.Tier == CivilianTier.Novice || p.Tier == CivilianTier.Apprentice || p.Tier == CivilianTier.Expert,
_ => false };
if (!tierValid) throw new ArgumentException("Tier does not belong to the civilian profession.");
if (p.Home != null) bindings.ValidateLocation(p.Home);