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 courses: count the enrolment month and graduate (Refs #1697) (#2391)
Eyal Golan5c89e6e64e6c
diff --git a/changelog.d/1697-course-graduation.md b/changelog.d/1697-course-graduation.mdnew file mode 100644index 000000000..2b00067c2--- /dev/null+++ b/changelog.d/1697-course-graduation.md@@ -0,0 +1,4 @@+- GDD 0.3 training centre courses in the sim test fixture (Refs #1697): the month a farmer or pioneer course starts now+ counts as its first course turn, and the third counted turn graduates the pupil to the trained tier, releasing the+ pupil and the teacher as civilians without a job. Neither can start a course again that month and the freed bed waits+ for the next month. Nothing in the game calls this fixture yet, so nothing changes for players and saves are unaffected.diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex 5fb441b59..282fe86c6 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -30,7 +30,7 @@ R-LOOP-005: Every balance number of the GDD loop (all of `cities.yaml` and `unitThe ID R-LOOP-003 (the Phase 1 overlay, `MvpSlice.Overlay`) is retired with the overlay at the cutover and is not reused.-Synthetic #1716 fixtures provide an internal immutable monthly snapshot for future gdd-0.3 work (R-LOOP-001/002; #1668, loop-switch.md:17-39 at 605277df). There is no shipping caller, resolver integration, persistence or activation. Consumers must revalidate eligibility; R-LOOP-004 is unchanged. The month's work and course snapshot is taken after that turn's orders (Amir's 28 October answers 4 and 5, [owner-relayed](https://github.com/eyalgolan/statecraft-israel/pull/1668#issuecomment-6465662174): "Training: occupies people from the turn training starts until it finishes"; "Job changes: take effect immediately. assigning the same job is a no op"). A job change made this turn is in this month's snapshot, a re-assignment to the same job leaves the state and its hash unchanged, and a course started this turn shows its pupil on the course and off work in the same snapshot (R-CITY-001/002, R-TRAIN-005, R-TRAIN-008). When a course end or a cancel releases people was answered on 1 November 2026 ([#1668 Q43(b)/(c)](https://github.com/eyalgolan/statecraft-israel/pull/1668#issuecomment-6553884547)). A cancel releases them at once: this month's snapshot shows the teacher and pupil without a job, a job given that turn is in it, and either may start another course that month (R-TRAIN-007, R-TRAIN-008). The graduation half (released in the turn the last course turn counts, work from the next turn) waits for graduation itself, which the fixture does not reach yet (R-TRAIN-006).+Synthetic #1716 fixtures provide an internal immutable monthly snapshot for future gdd-0.3 work (R-LOOP-001/002; #1668, loop-switch.md:17-39 at 605277df). There is no shipping caller, resolver integration, persistence or activation. Consumers must revalidate eligibility; R-LOOP-004 is unchanged. The month's work and course snapshot is taken after that turn's orders (Amir's 28 October answers 4 and 5, [owner-relayed](https://github.com/eyalgolan/statecraft-israel/pull/1668#issuecomment-6465662174): "Training: occupies people from the turn training starts until it finishes"; "Job changes: take effect immediately. assigning the same job is a no op"). A job change made this turn is in this month's snapshot, a re-assignment to the same job leaves the state and its hash unchanged, and a course started this turn shows its pupil on the course and off work in the same snapshot (R-CITY-001/002, R-TRAIN-005, R-TRAIN-008). When a course end or a cancel releases people was answered on 1 November 2026 ([#1668 Q43(b)/(c)](https://github.com/eyalgolan/statecraft-israel/pull/1668#issuecomment-6553884547)). A cancel releases them at once: this month's snapshot shows the teacher and pupil without a job, a job given that turn is in it, and either may start another course that month (R-TRAIN-007, R-TRAIN-008). Graduation releases them in the turn the last course turn counts: neither can start a course that month, and since the graduation month's snapshot still shows the course, work starts from the next month's snapshot (R-TRAIN-006, R-TRAIN-008).## Settlement control@@ -174,11 +174,11 @@ R-TRAIN-004: `Reinforce(unit, city, n)` (#1510; owner, 23 October 2026: "ReplaceR-TRAIN-005: In gdd-0.3 synthetic fixtures only (#1697; nothing in the game calls it), a farmer or pioneer course starts at a training centre whose parent reception camp operates and whose upgrade is complete. The teacher is a received free civilian, a veteran of the matching profession, with no other assignment; the trainee is a received, unassigned free civilian who is a novice of that profession with tools. The trainee takes one of the parent camp's own reception beds (Agreed `reception.capacity`, refugee or course-trainee beds per camp); another camp's beds or ordinary work places do not stand in, and the teacher's separate housing is not a reception bed. A teacher takes at most Agreed `profession.trainees_per_teacher` pupils (currently 1), so a busy teacher refuses another pupil. No Money is charged: the tools were paid on entry and a matching course does not charge them again. Teacher and trainee then hold exclusive Teaching and Course assignments, so other assignment paths refuse them. Every refusal leaves the state unchanged. Sources at `605277dfa511dc512562ececeb273b8393b21d35`: `docs/gdd/training.md:15`, "A later matching formal course does not charge tools again."; `:31`, "A training-centre upgrade needs an operating reception camp and a matching veteran teacher. It supplies separate teacher housing. The teacher is fully occupied and cannot work, fight, build, travel or teach another pupil simultaneously. The trainee occupies a reception bed."; `:33`, "A free civilian or matching equipped novice may train." Craftsmen, soldiers and refugees before `reception.turns` cannot enrol. Only exact gdd-0.3 states with an initialized population ledger are accepted; legacy and gdd-0.1 are refused unchanged.-R-TRAIN-006: In the same fixture, a course turn is counted only for a month whose opening snapshot (the #1716 synthetic month context) already holds that course with the same teacher, and at most once per month ordinal: an ordinal not above the last one counted for that pupil is refused. A counted turn keeps the same population id and every record field (work XP, reception progress, equipment, location, military history); no person is created, and teaching and the course earn no work XP (`docs/gdd/training.md:17` at `605277dfa511dc512562ececeb273b8393b21d35`, "Travel, idle time, teaching and courses do not count."). Graduation timing follows #1668 question 43(a), which is decided (GDD, 1 November 2026 answers: "A course occupies its people from its first turn"), but this fixture has not built that answer: the turn that would bring a course to `profession.course_turns` minus 1 counted turns (currently 2) is still refused (R-TRAIN-008) and no trained tier is granted in this slice. That refusal is an implementation gap, not an open design answer. The fixture also refuses a unit already trained, because Amir's proposal made a trained profession permanent (`docs/gdd/training.md:13` at the same commit, "Once trained, a civilian profession cannot be replaced."). That lock is post-MVP: D3 keeps two-way professions (R-QUAL-006), and the GDD's 1 November 2026 answers say "Graduates join their city's civilians and may re-enrol at any time" (27M-5).+R-TRAIN-006: In the same fixture, the enrolment month is course turn 1 (#1668 question 43(a); GDD, 1 November 2026 answers: "A course occupies its people from its first turn"), so a course turn is counted in the enrolment month, even with a snapshot taken before the course started, unless the centre was not available at that month's freeze, and in a later month only when its opening snapshot (the #1716 synthetic month context) already holds that course with the same teacher. It is counted at most once per month ordinal: an ordinal before the enrolment month, or not above the last one counted for that pupil, is refused. A counted turn keeps the same population id and every record field (work XP, reception progress, equipment, location, military history); no person is created, and teaching and the course earn no work XP (`docs/gdd/training.md:17` at `605277dfa511dc512562ececeb273b8393b21d35`, "Travel, idle time, teaching and courses do not count."). The turn that brings a course to Agreed `profession.course_turns` counted turns (currently 3) graduates it: the pupil takes the trained tier through R-QUAL-008's transform and keeps the same id, work XP, reception progress, equipment and the tools' payment fact, location and military history; the pupil and the teacher (when that was the teacher's last pupil) are released in that turn, in one change, as civilians without a job. Nothing is charged and no person is created. #1697: "A free civilian or a matching equipped novice may enrol; completion gives the trained tier." Release timing follows R-TRAIN-008. The fixture also refuses a unit already trained, because Amir's proposal made a trained profession permanent (`docs/gdd/training.md:13` at the same commit, "Once trained, a civilian profession cannot be replaced."). That lock is post-MVP: D3 keeps two-way professions (R-QUAL-006), and the GDD's 1 November 2026 answers say "Graduates join their city's civilians and may re-enrol at any time" (27M-5).-R-TRAIN-007: In the same fixture, cancelling a course at any turn this slice can reach keeps the population id, profession, novice tier, tools and their payment fact and reception progress. It grants no unfinished trained tier, clears the course progress and releases the teacher and the bed. Nothing is refunded and no one moves. The released teacher and pupil are civilians without a job at once, in that month's snapshot, and may take a job that month, or start another course that month where its camp had a bed free at the month's opening (#1716; #1668 question 43(b), owner-approved answer of 1 November 2026, [answers](https://github.com/eyalgolan/statecraft-israel/pull/1668#issuecomment-6553884547): "Cancellation: they are released at once, as civilians without a job."). The freed bed is not reused before the next month's opening (R-TRAIN-008). A second cancel, or a cancel of a unit not in a course, is refused unchanged, and a restart is a full new course with no second tools charge (`docs/gdd/training.md:49`, "Cancelled courses retain paid entry costs and earned reception credit but award no unfinished qualification." and "Unfinished course progress clears, and restarting needs a fresh course.").+R-TRAIN-007: In the same fixture, cancelling a course at any turn before its graduation keeps the population id, profession, novice tier, tools and their payment fact and reception progress. It grants no unfinished trained tier, clears the course progress and releases the teacher and the bed. Nothing is refunded and no one moves. The released teacher and pupil are civilians without a job at once, in that month's snapshot, and may take a job that month, or start another course that month where its camp had a bed free at the month's opening (#1716; #1668 question 43(b), owner-approved answer of 1 November 2026, [answers](https://github.com/eyalgolan/statecraft-israel/pull/1668#issuecomment-6553884547): "Cancellation: they are released at once, as civilians without a job."). The freed bed is not reused before the next month's opening (R-TRAIN-008). A second cancel, a cancel of a unit not in a course, or a cancel or further course turn for a graduate, is refused unchanged, and a restart is a full new course with no second tools charge (`docs/gdd/training.md:49`, "Cancelled courses retain paid entry costs and earned reception credit but award no unfinished qualification." and "Unfinished course progress clears, and restarting needs a fresh course.").-R-TRAIN-008: The fixture refuses, with a "Deferred:" reason and the state unchanged, every case this slice has not built, and chooses no default. Questions 42, 43(a) and 44 and the novice lock-in below are decided (GDD, 1 November 2026 answers, and D3), so those refusals are implementation gaps, not open design answers; Q42's answer is "One veteran teacher and one pupil per centre, the teacher housed in the centre's city". #1668 question 42 (teachers per centre and teacher housing): a second teacher at one centre, or a teaching teacher with no pupil. #1668 question 43 (course turn boundaries): counting the enrolment month, including a later snapshot with the enrolment month's ordinal; counting the turn that would bring a course to `profession.course_turns` minus 1 (graduation timing, 43(a)); starting in a month whose opening snapshot shows either participant on another assignment, except a pupil whose opening assignment was work and who was released from it this turn (an immediate job change; the course occupies them from its start turn, Q43(a), #1716; a teacher who worked at the opening and was released this turn stays Deferred), and except a pupil or teacher whose opening course or teaching was cancelled this turn (released at once, Q43(b), #1716; R-TRAIN-007); and starting a course when the parent camp's beds taken at the month's opening plus the courses already started in that camp this month fill its beds, so a bed freed after the opening, by a cancel or otherwise, is not reused that month (43(b), with #1668 question 41). #1668 question 44 and the GDD's novice lock-in decision: a free civilian without a profession, or a novice of another profession, entering a course. #1668, 27 October list, question 9: a course turn or cancellation after the parent camp or the centre stops operating. Graduation release under question 43(b) and (c) (answered 1 November 2026: released in the turn the last course turn counts, assignable from the next turn's planning; a person whose course ends this turn starts work the next turn) is not built, because this fixture reaches no graduation while the enrolment-month count (43(a)) is not built here. Real centres, hosts, regions, map bindings, Money and Food settlement, saves and commands remain held with their owners (#1691, #1696, #1700, #1702, #1713, #1716; #1690 closed on 2 November 2026, its post-MVP regional pools moved to #2233).+R-TRAIN-008: The fixture refuses, with a "Deferred:" reason and the state unchanged, every case this slice has not built, and chooses no default. Questions 42, 43 and 44 and the novice lock-in below are decided (GDD, 1 November 2026 answers, and D3), so those refusals are implementation gaps, not open design answers; Q42's answer is "One veteran teacher and one pupil per centre, the teacher housed in the centre's city". #1668 question 42 (teachers per centre and teacher housing): a second teacher at one centre, or a teaching teacher with no pupil. #1668 question 43, the one case not built here: starting in a month whose opening snapshot shows either participant on another assignment, except a pupil whose opening assignment was work and who was released from it this turn (an immediate job change; the course occupies them from its start turn, Q43(a), #1716; a teacher who worked at the opening and was released this turn stays Deferred), and except a pupil or teacher whose opening course or teaching was cancelled this turn (released at once, Q43(b), #1716; R-TRAIN-007). The ruled question 43 limits are refused unchanged with a plain reason that cites the ruling, not as Deferred: counting a month after the enrolment month whose opening snapshot does not hold the course with the same teacher (43(a)); and starting a course when the parent camp's beds taken at the month's opening plus the courses already started in that camp this month fill its beds, so a bed freed after the opening, by a cancel, a graduation or otherwise, is not reused that month, and a course started and cancelled in the same month still counts against that month's beds (43(b), with #1668 question 41). #1668 question 44 and the GDD's novice lock-in decision: a free civilian without a profession, or a novice of another profession, entering a course. #1668, 27 October list, question 9: a course turn or cancellation after the parent camp or the centre stops operating. Graduation release under question 43(b) and (c) is built and is not Deferred (#1697 body, owner answers of 1 November 2026: "on graduation the people are released in the turn the last course turn counts and can be assigned from the next turn's planning" and "a person whose course ends this turn starts work the next turn"): a graduate and a teacher released by the graduation cannot start a course in the graduation month (refused unchanged with a plain reason, not Deferred) and can from the next month; the bed the graduate held is not reused before the next month's opening, as above; and work eligibility is read from the month's opening snapshot (#1716), where the graduate still holds the course, so a job given after graduation counts from the next month. Real centres, hosts, regions, map bindings, Money and Food settlement, saves and commands remain held with their owners (#1691, #1696, #1700, #1702, #1713, #1716; #1690 closed on 2 November 2026, its post-MVP regional pools moved to #2233).## Craftsmendiff --git a/sim/Statecraft.Sim.Tests/Gdd03TrainingCentreFixtureTests.cs b/sim/Statecraft.Sim.Tests/Gdd03TrainingCentreFixtureTests.csindex d675e4bd2..4ab651ae9 100644--- a/sim/Statecraft.Sim.Tests/Gdd03TrainingCentreFixtureTests.cs+++ b/sim/Statecraft.Sim.Tests/Gdd03TrainingCentreFixtureTests.cs@@ -65,29 +65,39 @@ public class Gdd03TrainingCentreFixtureTestsArray.Empty<int>(), Array.Empty<Gdd03SyntheticHousingSnapshot>(), Array.Empty<Gdd03SyntheticPendingEntry>());static (int teacher, int trainee) Pair(CivilianProfession p) => p == CivilianProfession.Farmer ? (0, 1) : (2, 3);- static void Unchanged(GameState s, Action act, Type expected, string? deferredPrefix = null)+ // A ruled #1668 Q43 refusal is a plain ArgumentException with its reason; only unbuilt cases say "Deferred:".+ const string BedWaits = Gdd03TrainingCentreFixture.BedWaitsReason;+ const string GraduationMonth = Gdd03TrainingCentreFixture.GraduationMonthReason;+ const string CourseAtOpening = Gdd03TrainingCentreFixture.CourseAtOpeningReason;++ static void Unchanged(GameState s, Action act, Type expected, string? messagePrefix = null){var before = s.Describe();var ex = Assert.Throws(expected, act);- if (deferredPrefix != null) Assert.StartsWith(deferredPrefix, ex.Message, StringComparison.Ordinal);+ 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());}- // R-TRAIN-005, R-TRAIN-006, R-TRAIN-008: a matching equipped novice and veteran teacher start a course; a counted course- // turn keeps the same id and every record field, creates no person and earns no work XP. The turn that would bring the- // course within one turn of its end (the first one where the two answers to #1668 Q43(a) differ) is Deferred.+ // R-TRAIN-005, R-TRAIN-006, R-QUAL-008: a matching equipped novice and veteran teacher start a course; a counted course+ // turn keeps the same id and every record field, creates no person and earns no work XP. GDD 0.3 (docs/GDD.md:372): "A+ // course occupies its people from its first turn (Q43(a)); they are released in the turn its last course turn counts and+ // can be assigned from the next planning, or at once on cancellation, and work starts the turn after (Q43(b), Q43(c))."+ // #1697: "A free civilian or a matching equipped novice may enrol; completion gives the trained tier." So the enrolment+ // month is course turn 1 and the third counted turn graduates: the pupil takes the trained tier and pupil and teacher+ // are released as civilians without a job, keeping their ids and every other record field.[Theory][InlineData(CivilianProfession.Farmer)][InlineData(CivilianProfession.Pioneer)]- public void MatchingNoviceCountsTurnsUntilGraduationTimingIsDeferred(CivilianProfession profession)+ public void MatchingNoviceCountsThreeTurnsFromEnrolmentAndGraduates(CivilianProfession profession){var c = Catalogue(); var s = State(c); var f = new Gdd03TrainingCentreFixture(c, s, Centres());var (teacher, trainee) = Pair(profession); var l = s.PopulationLedger;var before = l.Get(trainee); var teacherBefore = l.Get(teacher);int count = l.Units.Count, next = l.NextPopulationId; var people = l.TotalPeople;- f.Start(trainee, teacher, CentreA, Month(s, 0));+ var enrolment = Month(s, 0);+ f.Start(trainee, teacher, CentreA, enrolment);var p = l.Get(trainee);Assert.Equal(PopulationStatus.Trainee, p.Status);Assert.Equal(PopulationAssignmentKind.Course, p.Assignment.Kind);@@ -95,7 +105,7 @@ public class Gdd03TrainingCentreFixtureTestsAssert.Equal(PopulationAssignmentKind.Teaching, l.Get(teacher).Assignment.Kind);Assert.Equal(CentreA, l.Get(teacher).Assignment.Target);- f.Advance(trainee, Month(s, 1));+ f.Advance(trainee, enrolment);var after = l.Get(trainee); var teacherAfter = l.Get(teacher);Assert.Equal(1, after.Assignment.ProgressTicks); Assert.Equal(PopulationStatus.Trainee, after.Status);Assert.Equal(CivilianTier.Novice, after.Tier); Assert.Equal(profession, after.Profession);@@ -105,45 +115,72 @@ public class Gdd03TrainingCentreFixtureTestsAssert.Equal(CivilianTier.Veteran, teacherAfter.Tier); Assert.Equal(teacherBefore.WorkXp, teacherAfter.WorkXp);Assert.Equal(count, l.Units.Count); Assert.Equal(next, l.NextPopulationId); Assert.Equal(people, l.TotalPeople);- Unchanged(s, () => f.Advance(trainee, Month(s, 2)), typeof(NotSupportedException), "Deferred: #1668 Q43");- Assert.Equal(CivilianTier.Novice, l.Get(trainee).Tier);+ f.Advance(trainee, Month(s, 1));+ Assert.Equal(2, l.Get(trainee).Assignment.ProgressTicks);+ Assert.Equal(PopulationStatus.Trainee, l.Get(trainee).Status); Assert.Equal(CivilianTier.Novice, l.Get(trainee).Tier);++ f.Advance(trainee, Month(s, 2));+ var graduate = l.Get(trainee); var released = l.Get(teacher);+ Assert.Equal(PopulationStatus.FreeCivilian, graduate.Status); Assert.Same(PopulationAssignment.Unassigned, graduate.Assignment);+ Assert.Equal(CivilianTier.Trained, graduate.Tier); Assert.Equal(profession, graduate.Profession);+ Assert.Equal(before.WorkXp, graduate.WorkXp); Assert.Equal(before.ReceptionTicks, graduate.ReceptionTicks);+ Assert.Same(before.Equipment, graduate.Equipment); Assert.True(graduate.Equipment.ToolsPaid);+ Assert.Same(before.Location, graduate.Location);+ Assert.Equal(before.CombatXp, graduate.CombatXp); Assert.Equal(before.Qualification, graduate.Qualification);+ Assert.Equal(PopulationStatus.FreeCivilian, released.Status); Assert.Same(PopulationAssignment.Unassigned, released.Assignment);+ Assert.Equal(CivilianTier.Veteran, released.Tier); Assert.Equal(teacherBefore.WorkXp, released.WorkXp);+ Assert.Equal(teacherBefore.Equipment, released.Equipment); Assert.Same(teacherBefore.Location, released.Location);+ Assert.Equal(count, l.Units.Count); Assert.Equal(next, l.NextPopulationId); Assert.Equal(people, l.TotalPeople);l.Reconcile();}- // R-TRAIN-006: the Agreed course length is read from the catalogue, not a literal: with a synthetic 4, two turns- // count before the Deferred graduation-timing turn.+ // R-TRAIN-006: the Agreed course length is read from the catalogue, not a literal: with a synthetic 4, the course+ // graduates on its fourth counted turn, the enrolment month included (Q43(a), docs/GDD.md:372: "A course occupies its+ // people from its first turn"), not on the third.[Fact] public void CourseLengthComesFromTheCatalogue(){- var c = Catalogue("profession.course_turns", Agreed(4)); var s = State(c);+ var c = Catalogue("profession.course_turns", Agreed(4)); var s = State(c); var l = s.PopulationLedger;var f = new Gdd03TrainingCentreFixture(c, s, Centres());f.Start(1, 0, CentreA, Month(s, 0));- f.Advance(1, Month(s, 1)); f.Advance(1, Month(s, 2));- Assert.Equal(2, s.PopulationLedger.Get(1).Assignment.ProgressTicks);- Unchanged(s, () => f.Advance(1, Month(s, 3)), typeof(NotSupportedException), "Deferred: #1668 Q43");+ f.Advance(1, Month(s, 0)); f.Advance(1, Month(s, 1)); f.Advance(1, Month(s, 2));+ Assert.Equal(3, l.Get(1).Assignment.ProgressTicks);+ Assert.Equal(PopulationStatus.Trainee, l.Get(1).Status); Assert.Equal(CivilianTier.Novice, l.Get(1).Tier);+ f.Advance(1, Month(s, 3));+ Assert.Equal(PopulationStatus.FreeCivilian, l.Get(1).Status); Assert.Equal(CivilianTier.Trained, l.Get(1).Tier);}- // R-TRAIN-006: one month counts once; a stale or repeated snapshot cannot add a second course turn.+ // R-TRAIN-006: one month counts once, the enrolment month included (Q43(a)); a stale or repeated snapshot cannot add+ // a second course turn.[Fact] public void AMonthCountsOnceForACourse(){var c = Catalogue("profession.course_turns", Agreed(5)); var s = State(c); var f = new Gdd03TrainingCentreFixture(c, s, Centres());- f.Start(1, 0, CentreA, Month(s, 0));- var m1 = Month(s, 1); f.Advance(1, m1);+ var m0 = Month(s, 0);+ f.Start(1, 0, CentreA, m0);+ f.Advance(1, m0);Assert.Equal(1, s.PopulationLedger.Get(1).Assignment.ProgressTicks);+ Unchanged(s, () => f.Advance(1, m0), typeof(ArgumentException));+ Unchanged(s, () => f.Advance(1, Month(s, 0)), typeof(ArgumentException));+ var m1 = Month(s, 1); f.Advance(1, m1);+ Assert.Equal(2, s.PopulationLedger.Get(1).Assignment.ProgressTicks);Unchanged(s, () => f.Advance(1, m1), typeof(ArgumentException));// A fresh snapshot with an ordinal that was already counted, or an earlier one, is refused too.Unchanged(s, () => f.Advance(1, Month(s, 1)), typeof(ArgumentException));f.Advance(1, Month(s, 3));Unchanged(s, () => f.Advance(1, Month(s, 2)), typeof(ArgumentException));- Assert.Equal(2, s.PopulationLedger.Get(1).Assignment.ProgressTicks);+ Assert.Equal(3, s.PopulationLedger.Get(1).Assignment.ProgressTicks);}- // R-TRAIN-008: a snapshot taken after enrolment but carrying the enrolment month's ordinal is still the enrolment- // month, so it is not counted (#1668 Q43(a)).- [Fact] public void TheEnrolmentOrdinalIsNeverCounted()+ // R-TRAIN-006: a snapshot taken after enrolment but carrying the enrolment month's ordinal is still the enrolment+ // month, so it counts once, as course turn 1 (#1668 Q43(a), docs/GDD.md:372: "A course occupies its people from its+ // first turn"). A snapshot with an ordinal before the enrolment month is refused.+ [Fact] public void TheEnrolmentOrdinalCountsOnce(){var c = Catalogue(); var s = State(c); var f = new Gdd03TrainingCentreFixture(c, s, Centres());- f.Start(1, 0, CentreA, Month(s, 0));- Unchanged(s, () => f.Advance(1, Month(s, 0)), typeof(NotSupportedException), "Deferred: #1668 Q43");+ f.Start(1, 0, CentreA, Month(s, 1));+ Unchanged(s, () => f.Advance(1, Month(s, 0)), typeof(ArgumentException));+ f.Advance(1, Month(s, 1));+ Assert.Equal(1, s.PopulationLedger.Get(1).Assignment.ProgressTicks);+ Unchanged(s, () => f.Advance(1, Month(s, 1)), typeof(ArgumentException));}// R-TRAIN-005: a busy teacher refuses a second pupil (Agreed profession.trainees_per_teacher = 1).@@ -224,13 +261,15 @@ public class Gdd03TrainingCentreFixtureTestsUnchanged(s, () => f.Start(trainee, teacher, centre, Month(s, 0)), typeof(ArgumentException));}- // R-TRAIN-007: cancel at every course turn this slice can reach keeps id, tools, payment fact and reception credit;+ // R-TRAIN-007: cancel at every course turn before graduation keeps id, tools, payment fact and reception credit;// grants nothing unfinished; clears progress; releases the teacher and the bed; moves no one.[Theory][InlineData(CivilianProfession.Farmer, 0)][InlineData(CivilianProfession.Farmer, 1)]+ [InlineData(CivilianProfession.Farmer, 2)][InlineData(CivilianProfession.Pioneer, 0)][InlineData(CivilianProfession.Pioneer, 1)]+ [InlineData(CivilianProfession.Pioneer, 2)]public void CancelAtEveryTurnRetainsPaidStateAndReleasesTeacherAndBed(CivilianProfession profession, int counted){var c = Catalogue(); var s = State(c, Refugee(), Refugee()); var l = s.PopulationLedger;@@ -266,7 +305,9 @@ public class Gdd03TrainingCentreFixtureTestsAssert.Equal(0, l.Get(1).Assignment.ProgressTicks);f.Advance(1, Month(s, 3));Assert.Equal(1, l.Get(1).Assignment.ProgressTicks);- Unchanged(s, () => f.Advance(1, Month(s, 4)), typeof(NotSupportedException), "Deferred: #1668 Q43");+ // The restart's count starts again: the old course's turn does not carry over, so month 4 does not graduate.+ f.Advance(1, Month(s, 4));+ Assert.Equal(2, l.Get(1).Assignment.ProgressTicks); Assert.Equal(CivilianTier.Novice, l.Get(1).Tier);}// R-TRAIN-005: teacher and trainee hold exclusive assignments; other assignment paths refuse them.@@ -295,14 +336,123 @@ public class Gdd03TrainingCentreFixtureTestsUnchanged(idle, () => new Gdd03TrainingCentreFixture(c, idle, Centres()), typeof(NotSupportedException), "Deferred: #1668 Q42");}- // R-TRAIN-008: #1668 Q43(a) is not built in this fixture: the enrolment month is not counted.- [Fact] public void CourseTurnBoundariesStayDeferred()+ // R-TRAIN-006, R-TRAIN-008: #1668 Q43(a) (docs/GDD.md:372: "A course occupies its people from its first turn"). The+ // enrolment month counts once even though its opening snapshot predates the course, unless the centre was not+ // available at that month's freeze (27 Oct list Q9 stays Deferred). Every later month still needs the course at its+ // opening: a month-1 snapshot taken before the course started is refused with the Q43(a) reason (a ruled rule).+ [Fact] public void TheEnrolmentMonthCountsAndLaterMonthsNeedTheCourseAtTheirOpening(){var c = Catalogue(); var s = State(c);var f = new Gdd03TrainingCentreFixture(c, s, Centres());- var enrolment = Month(s, 0);+ var enrolment = Month(s, 0); var closedEnrolment = Month(s, 0, centresAvailable: false); var staleLater = Month(s, 1);f.Start(1, 0, CentreA, enrolment);- Unchanged(s, () => f.Advance(1, enrolment), typeof(NotSupportedException), "Deferred: #1668 Q43");+ Unchanged(s, () => f.Advance(1, closedEnrolment), typeof(NotSupportedException), "Deferred: #1668 27 Oct list Q9");+ Unchanged(s, () => f.Advance(1, staleLater), typeof(ArgumentException), CourseAtOpening);+ f.Advance(1, enrolment);+ Assert.Equal(1, s.PopulationLedger.Get(1).Assignment.ProgressTicks);+ Unchanged(s, () => f.Advance(1, enrolment), typeof(ArgumentException));+ Unchanged(s, () => f.Advance(1, staleLater), typeof(ArgumentException), CourseAtOpening);+ }++ // R-TRAIN-006, 27 Oct list Q9: in the enrolment month the centre's availability is read from the month's facility+ // list (the opening may predate the course). A centre listed with no free place (opening capacity 0) at that month's+ // freeze counts no course turn: refused Deferred, state unchanged; the next month with a place counts as before.+ [Fact] public void TheEnrolmentMonthCountsNothingWhenTheCentreHasNoPlace()+ {+ var c = Catalogue(); var s = State(c); var f = new Gdd03TrainingCentreFixture(c, s, Centres());+ var noPlace = Gdd03SyntheticMonthContext.CreateSynthetic(SaveGame.Gdd03Ruleset, 0, s.PopulationLedger.Units,+ Facilities.Select(id => new Gdd03SyntheticFacilitySnapshot(id, true, id == CentreA ? 0 : 1)),+ Array.Empty<int>(), Array.Empty<Gdd03SyntheticHousingSnapshot>(), Array.Empty<Gdd03SyntheticPendingEntry>());+ f.Start(1, 0, CentreA, Month(s, 0));+ Unchanged(s, () => f.Advance(1, noPlace), typeof(NotSupportedException), "Deferred: #1668 27 Oct list Q9");+ Assert.Equal(0, s.PopulationLedger.Get(1).Assignment.ProgressTicks);+ f.Advance(1, Month(s, 1));+ Assert.Equal(1, s.PopulationLedger.Get(1).Assignment.ProgressTicks);+ }++ // R-TRAIN-006, R-QUAL-008: graduation reuses the trained-tier transform and charges nothing; a teacher who still has+ // another pupil keeps teaching. Two pupils per teacher is a synthetic value (the catalogue's is 1).+ [Fact] public void AGraduationKeepsATeacherWhoStillHasAPupil()+ {+ var c = Catalogue("profession.trainees_per_teacher", Agreed(2)); var s = State(c); var l = s.PopulationLedger;+ var f = new Gdd03TrainingCentreFixture(c, s, Centres());+ var m0 = Month(s, 0);+ f.Start(1, 0, CentreA, m0); f.Advance(1, m0);+ f.Start(5, 0, CentreA, Month(s, 1)); f.Advance(1, Month(s, 1));+ f.Advance(1, Month(s, 2));+ Assert.Equal(CivilianTier.Trained, l.Get(1).Tier); Assert.Same(PopulationAssignment.Unassigned, l.Get(1).Assignment);+ Assert.Equal(PopulationAssignmentKind.Teaching, l.Get(0).Assignment.Kind); Assert.Equal(CentreA, l.Get(0).Assignment.Target);+ Assert.Equal(PopulationStatus.Trainee, l.Get(5).Status); Assert.Equal(0, l.Get(5).Assignment.TeacherId);+ f.Cancel(5);+ Assert.Same(PopulationAssignment.Unassigned, l.Get(0).Assignment);+ l.Reconcile();+ }++ // R-TRAIN-007, R-TRAIN-008, #1668 Q43(b) (#1697: "on graduation the people are released in the turn the last course+ // turn counts and can be assigned from the next turn's planning"): in the graduation month neither the graduate nor the+ // released teacher can start a course, with any snapshot of that month; from the next month the teacher can.+ [Fact] public void GraduatesAndTheirTeacherCannotStartACourseInTheGraduationMonth()+ {+ var c = Catalogue(); var s = State(c); var l = s.PopulationLedger; var f = new Gdd03TrainingCentreFixture(c, s, Centres());+ var m0 = Month(s, 0);+ f.Start(1, 0, CentreA, m0); f.Advance(1, m0); f.Advance(1, Month(s, 1));+ var graduation = Month(s, 2);+ f.Advance(1, graduation);+ Assert.Equal(CivilianTier.Trained, l.Get(1).Tier);+ Unchanged(s, () => f.Start(5, 0, CentreB, graduation), typeof(ArgumentException), GraduationMonth);+ Unchanged(s, () => f.Start(5, 0, CentreB, Month(s, 2)), typeof(ArgumentException), GraduationMonth);+ Unchanged(s, () => f.Start(5, 0, CentreA, Month(s, 2)), typeof(ArgumentException), GraduationMonth);+ Unchanged(s, () => f.Start(5, 0, CentreB, Month(s, 1)), typeof(ArgumentException), GraduationMonth);+ // The graduate is trained now, so no course takes them as a pupil (R-TRAIN-006), this month or later.+ Unchanged(s, () => f.Start(1, 4, CentreB, graduation), typeof(ArgumentException));+ Unchanged(s, () => f.Start(1, 4, CentreB, Month(s, 3)), typeof(ArgumentException));+ f.Start(5, 0, CentreB, Month(s, 3));+ Assert.Equal(PopulationStatus.Trainee, l.Get(5).Status); Assert.Equal(0, l.Get(5).Assignment.TeacherId);+ }++ // #1716 month snapshot, #1668 Q43(c) (#1697: "a person whose course ends this turn starts work the next turn"): the+ // graduation month's opening snapshot still has the graduate on the course, not at work; a job given after the+ // graduation is in the next month's snapshot.+ [Fact] public void AGraduateWorksFromTheNextMonthsSnapshot()+ {+ var c = Catalogue(); var s = State(c); var f = new Gdd03TrainingCentreFixture(c, s, Centres());+ var work = new Gdd03AssignmentFixture(c, s, new[] { new Gdd03FixtureSlot(Field, Gdd03FixtureWork.Farm, 2, "fixture") });+ var m0 = Month(s, 0);+ f.Start(1, 0, CentreA, m0); f.Advance(1, m0); f.Advance(1, Month(s, 1));+ var graduation = Month(s, 2);+ f.Advance(1, graduation);+ Assert.DoesNotContain(1, graduation.WorkEligibleIds); Assert.Contains(1, graduation.CourseEligibleIds);+ Assert.Equal(Gdd03FixtureAssignmentResult.Applied, work.Assign(1, Field));+ Assert.Equal(Gdd03FixtureAssignmentResult.Applied, work.Assign(0, Field));+ var next = Month(s, 3);+ Assert.Contains(1, next.WorkEligibleIds); Assert.Contains(0, next.WorkEligibleIds);+ Assert.DoesNotContain(1, next.CourseEligibleIds);+ }++ // R-TRAIN-008, #1668 Q43(b) with Q41: a bed freed by a graduation is not reused that month. Camp A is full at the+ // graduation month's opening (two refugees and the pupil); the next month a new course takes the bed.+ [Fact] public void ABedFreedByGraduationIsNotReusedThatMonth()+ {+ var c = Catalogue(); var s = State(c, Refugee(), Refugee()); var f = new Gdd03TrainingCentreFixture(c, s, Centres());+ var m0 = Month(s, 0);+ f.Start(1, 0, CentreA, m0); f.Advance(1, m0); f.Advance(1, Month(s, 1));+ var graduation = Month(s, 2);+ f.Advance(1, graduation);+ Unchanged(s, () => f.Start(5, 4, CentreA, graduation), typeof(ArgumentException), BedWaits);+ f.Start(5, 4, CentreA, Month(s, 3));+ Assert.Equal(PopulationStatus.Trainee, s.PopulationLedger.Get(5).Status);+ }++ // R-TRAIN-007: a graduate is no longer a pupil, so a further course turn or a cancel is refused unchanged, and the+ // released teacher leaves no idle Teaching assignment behind (a new fixture over the state validates).+ [Fact] public void AGraduateIsNoLongerAPupil()+ {+ var c = Catalogue(); var s = State(c); var f = new Gdd03TrainingCentreFixture(c, s, Centres());+ var m0 = Month(s, 0);+ f.Start(1, 0, CentreA, m0); f.Advance(1, m0); f.Advance(1, Month(s, 1)); f.Advance(1, Month(s, 2));+ Unchanged(s, () => f.Advance(1, Month(s, 3)), typeof(ArgumentException));+ Unchanged(s, () => f.Cancel(1), typeof(ArgumentException));+ _ = new Gdd03TrainingCentreFixture(c, s, Centres());}// #1716 Q43(b) release, R-TRAIN-007, R-TRAIN-008 (owner-approved answer, 1 Nov 2026, #1668 Q43(b): "Cancellation: they@@ -336,7 +486,8 @@ public class Gdd03TrainingCentreFixtureTests// #1716 Q43(b) release, R-TRAIN-005, R-TRAIN-007, R-TRAIN-008 (owner-approved answer, 1 Nov 2026, #1668 Q43(b):// "Cancellation: they are released at once"). Both people of a course held at the month's opening and cancelled this// turn may start a new course in the same month: the pupil restarts as a full new course with another teacher, and the- // teacher takes another pupil at another centre. The restart's own enrolment month is still not counted (Q43(a)).+ // teacher takes another pupil at another centre. The restart's own enrolment month counts as its first course turn+ // (Q43(a), docs/GDD.md:372: "A course occupies its people from its first turn"), once.[Fact] public void PeopleReleasedByACancelMayStartAnotherCourseThatMonth(){var c = Catalogue(); var s = State(c); var l = s.PopulationLedger; var f = new Gdd03TrainingCentreFixture(c, s, Centres());@@ -355,14 +506,17 @@ public class Gdd03TrainingCentreFixtureTests}var month = Month(s, 1);Assert.Contains(1, month.CourseEligibleIds); Assert.Contains(5, month.CourseEligibleIds);- Unchanged(s, () => f.Advance(1, month), typeof(NotSupportedException), "Deferred: #1668 Q43");- f.Advance(1, Month(s, 2));+ f.Advance(1, month);Assert.Equal(1, l.Get(1).Assignment.ProgressTicks);+ Unchanged(s, () => f.Advance(1, month), typeof(ArgumentException));+ f.Advance(1, Month(s, 2));+ Assert.Equal(2, l.Get(1).Assignment.ProgressTicks);}// #1716 Q43(b) release, R-TRAIN-006, R-TRAIN-007: the same pupil restarts with the same teacher at the same centre in- // the month of the cancel. It is a full new course, and its enrolment month is still not counted (Q43(a)), even with- // the month snapshot taken before the cancel, which still shows the old course.+ // the month of the cancel. It is a full new course, and its enrolment month counts once as its first course turn+ // (Q43(a), docs/GDD.md:372: "A course occupies its people from its first turn"), even with the month snapshot taken+ // before the cancel, which still shows the old course.[Fact] public void TheSamePupilAndTeacherRestartAtTheSameCentreAfterACancel(){var c = Catalogue(); var s = State(c); var l = s.PopulationLedger; var f = new Gdd03TrainingCentreFixture(c, s, Centres());@@ -375,7 +529,9 @@ public class Gdd03TrainingCentreFixtureTestsAssert.Equal(PopulationStatus.Trainee, p.Status); Assert.Equal(CentreA, p.Assignment.Target);Assert.Equal(0, p.Assignment.TeacherId); Assert.Equal(0, p.Assignment.ProgressTicks);Assert.Equal(tools, p.Equipment);- Unchanged(s, () => f.Advance(1, opening), typeof(NotSupportedException), "Deferred: #1668 Q43");+ f.Advance(1, opening);+ Assert.Equal(1, l.Get(1).Assignment.ProgressTicks);+ Unchanged(s, () => f.Advance(1, opening), typeof(ArgumentException));}// R-TRAIN-005, R-TRAIN-007: only a cancel ends a course here. A teacher still teaching and a pupil still on a course@@ -403,7 +559,7 @@ public class Gdd03TrainingCentreFixtureTestsvar opening = Month(s, 1); // camp A: pupil 1 and refugee 6 hold 2 of its 3 bedsf.Cancel(1);f.Start(1, 0, CentreA, opening); // the one bed free at the opening- Unchanged(s, () => f.Start(5, 0, CentreA, opening), typeof(NotSupportedException), "Deferred: #1668 Q43");+ Unchanged(s, () => f.Start(5, 0, CentreA, opening), typeof(ArgumentException), BedWaits);}// R-TRAIN-008, #1716 Q43(b): with the camp full at the month's opening, a cancelled pupil's own bed waits for the@@ -415,7 +571,7 @@ public class Gdd03TrainingCentreFixtureTestsf.Start(1, 0, CentreA, Month(s, 0));var opening = Month(s, 1); // camp A: pupil 1 and refugees 6 and 7 hold all 3 bedsf.Cancel(1);- Unchanged(s, () => f.Start(1, 0, CentreA, opening), typeof(NotSupportedException), "Deferred: #1668 Q43");+ Unchanged(s, () => f.Start(1, 0, CentreA, opening), typeof(ArgumentException), BedWaits);f.Start(1, 0, CentreA, Month(s, 2));Assert.Equal(PopulationStatus.Trainee, s.PopulationLedger.Get(1).Status);}@@ -489,6 +645,22 @@ public class Gdd03TrainingCentreFixtureTestsUnchanged(s, () => f.Start(5, 6, CentreB, opening), typeof(NotSupportedException), "Deferred: #1668 Q43");}+ // R-TRAIN-008 (with #1668 Q41): a course started and cancelled in the same month still counts against that month's+ // beds, so the bed it freed is not reused that month, by another pupil or by the same one; the next month it is.+ // Camp A has two refugees, so one of its three beds is free at the month's opening.+ [Fact] public void ACourseStartedAndCancelledThisMonthStillHoldsItsBedThatMonth()+ {+ var c = Catalogue(); var s = State(c, Refugee(), Refugee()); var f = new Gdd03TrainingCentreFixture(c, s, Centres());+ var m0 = Month(s, 0);+ f.Start(1, 0, CentreA, m0);+ f.Cancel(1);+ Unchanged(s, () => f.Start(5, 4, CentreA, m0), typeof(ArgumentException), BedWaits);+ Unchanged(s, () => f.Start(1, 0, CentreA, m0), typeof(ArgumentException), BedWaits);+ Unchanged(s, () => f.Start(5, 4, CentreA, Month(s, 0)), typeof(ArgumentException), BedWaits);+ f.Start(5, 4, CentreA, Month(s, 1));+ Assert.Equal(PopulationStatus.Trainee, s.PopulationLedger.Get(5).Status);+ }+// R-TRAIN-008: #1668 Q43(b) and Q41: a bed freed after the month's opening (here by a cancel) is not reused that month.[Fact] public void ABedFreedAfterTheOpeningIsNotReusedThatMonth(){@@ -496,7 +668,7 @@ public class Gdd03TrainingCentreFixtureTestsf.Start(1, 0, CentreA, Month(s, 0));var m1 = Month(s, 1);f.Cancel(1);- Unchanged(s, () => f.Start(5, 4, CentreA, m1), typeof(NotSupportedException), "Deferred: #1668 Q43");+ Unchanged(s, () => f.Start(5, 4, CentreA, m1), typeof(ArgumentException), BedWaits);f.Start(5, 4, CentreA, Month(s, 2));Assert.Equal(PopulationStatus.Trainee, s.PopulationLedger.Get(5).Status);}diff --git a/sim/Statecraft.Sim/Gdd03TrainingCentreFixture.cs b/sim/Statecraft.Sim/Gdd03TrainingCentreFixture.csindex 00d1cd4f8..e909e9f22 100644--- a/sim/Statecraft.Sim/Gdd03TrainingCentreFixture.cs+++ b/sim/Statecraft.Sim/Gdd03TrainingCentreFixture.cs@@ -22,25 +22,32 @@ namespace Statecraft.Sim}/// <summary>R-TRAIN-005 to R-TRAIN-008: gdd-0.3 farmer/pioneer course lifecycle over the #1689 population ledger,- /// synthetic fixtures only. No command, save, loader, resolver, Money, Food or UI caller. Graduation is not reachable:- /// #1668 Q43(a) is decided (GDD, 1 November 2026 answers: "A course occupies its people from its first turn"), but this- /// fixture has not built that answer, so no turn that would bring a course within one turn of its end is counted. Cases- /// this slice has not built (#1668 Q42, Q43 and Q44, decided in the GDD's 1 November 2026 answers, so these refusals are- /// implementation gaps, not open design answers; and the 27 Oct list Q9) are refused with a "Deferred:"+ /// synthetic fixtures only. No command, save, loader, resolver, Money, Food or UI caller. GDD 0.3 (docs/GDD.md, 1 November+ /// 2026 answers): "A course occupies its people from its first turn (Q43(a)); they are released in the turn its last+ /// course turn counts and can be assigned from the next planning, or at once on cancellation, and work starts the turn+ /// after (Q43(b), Q43(c))." So the enrolment month is course turn 1 and the last counted turn graduates. Cases this+ /// slice has not built (#1668 Q42, the rest of Q43 and Q44, decided in the GDD's 1 November 2026 answers, so these+ /// refusals are implementation gaps, not open design answers; and the 27 Oct list Q9) are refused with a "Deferred:"/// NotSupportedException.</summary>internal sealed class Gdd03TrainingCentreFixture{+ readonly Content content;readonly GameState state;readonly SortedDictionary<string, Gdd03FixtureTrainingCentre> centres;readonly int courseTurns, pupilsPerTeacher, bedsPerCamp, receptionTurns;- // Per fixture instance only (not saved): month ordinals of each pupil's enrolment and last counted course turn.+ // Per fixture instance only (not saved): 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>();+ // Per fixture instance only: the month ordinal and parent camp of every course started, kept after a cancel or a+ // graduation, so a bed a course took this month is not reused that month (R-TRAIN-008).+ readonly List<(int month, string camp)> starts = new List<(int, string)>();internal Gdd03TrainingCentreFixture(Content content, GameState state, IEnumerable<Gdd03FixtureTrainingCentre> centres){if (!content.UsesPopulationLedger || !state.UsesPopulationLedger || !state.PopulationLedger.IsInitialized)throw new InvalidOperationException("Training centre courses require an initialized gdd-0.3 synthetic fixture.");- this.state = state;+ this.content = content; this.state = state;courseTurns = content.RequirePopulationInteger("profession.course_turns");pupilsPerTeacher = content.RequirePopulationInteger("profession.trainees_per_teacher");bedsPerCamp = content.RequirePopulationInteger("reception.capacity");@@ -60,7 +67,13 @@ namespace Statecraft.Simstatic NotSupportedException Deferred(string question) => new NotSupportedException("Deferred: " + question);const string Q42 = "#1668 Q42 (teachers per centre and an idle centre's teacher housing).";- const string Q43 = "#1668 Q43 (course turn boundaries: whether the enrolment turn counts, and in which month's snapshot participants stop or resume other assignments).";+ // Q43 is decided (GDD, 1 November 2026 answers). The one Q43 case left Deferred is not built here: a person who held+ // another assignment at the month's opening (other than a pupil released from work, or a cancelled course or teaching)+ // starting a course that month. The ruled Q43 refusals below are plain ArgumentExceptions citing the ruling.+ const string Q43 = "#1668 Q43 (decided, not built here: starting a course after holding another assignment at the month's opening).";+ internal const string BedWaitsReason = "No reception bed was free at the month's opening: a bed freed this month is reused from the next month (#1668 Q43(b) with Q41, GDD 1 Nov 2026).";+ internal const string GraduationMonthReason = "A person released by a graduation can start a course from the next month (#1668 Q43(b), GDD 1 Nov 2026).";+ internal const string CourseAtOpeningReason = "After the enrolment month, a course turn counts only when the month's opening holds the course with the same teacher (#1668 Q43(a), GDD 1 Nov 2026).";const string Q44 = "#1668 Q44 and the GDD novice lock-in decision (when a free entrant becomes a novice; profession change after a cancelled course).";const string Q9 = "#1668 27 Oct list Q9 (return after cancellation or camp loss).";@@ -150,13 +163,18 @@ namespace Statecraft.Simif (BedsTaken(centre) >= bedsPerCamp) throw new ArgumentException("No free reception bed in the centre's parent camp.");var traineeOpening = Opening(month, trainee.Id); var teacherOpening = Opening(month, teacher.Id);+ // #1668 Q43(b) (#1697, 1 Nov 2026): "on graduation the people are released in the turn the last course turn+ // counts and can be assigned from the next turn's planning", so neither starts a course in that month.+ if (graduated.TryGetValue(trainee.Id, out var g) && month.MonthOrdinal <= g+ || graduated.TryGetValue(teacher.Id, out g) && month.MonthOrdinal <= g)+ throw new ArgumentException(GraduationMonthReason);// #1716 month snapshot (owner-relayed Q43(a) and Q34, 28 Oct 2026): a course occupies the pupil from the turn it// starts and a job change is immediate, so a pupil who worked at the opening and was released this turn may start,// and this month's work/course snapshot shows the course. #1716 Q43(b) release (owner-approved answer, 1 Nov 2026,// #1668): "Cancellation: they are released at once, as civilians without a job." A pupil who held a course, or a// teacher who taught, at the opening and is free now was released by a cancel this turn (only Cancel ends those// exclusive assignments here), so either may start again this month. A teacher who worked at the opening and was- // released this turn stays Deferred.+ // released this turn is not built here and stays Deferred.if ((traineeOpening.Assignment.Kind != PopulationAssignmentKind.Unassigned&& traineeOpening.Assignment.Kind != PopulationAssignmentKind.Work&& traineeOpening.Assignment.Kind != PopulationAssignmentKind.Course)@@ -169,47 +187,62 @@ namespace Statecraft.Sim&& string.Equals(p.Assignment.Target, centre.ParentCamp, StringComparison.Ordinal))|| (p.Assignment.Kind == PopulationAssignmentKind.Course&& string.Equals(p.Assignment.Target, centre.Id, StringComparison.Ordinal)));- int startedThisMonth = months.Count(m => m.Value.enrolment == month.MonthOrdinal- && string.Equals(CentreOf(ledger.Get(m.Key)).ParentCamp, centre.ParentCamp, StringComparison.Ordinal));- if (openingBeds + startedThisMonth >= bedsPerCamp) throw Deferred(Q43);+ int startedThisMonth = starts.Count(x => x.month == month.MonthOrdinal+ && string.Equals(x.camp, centre.ParentCamp, StringComparison.Ordinal));+ if (openingBeds + startedThisMonth >= bedsPerCamp) throw new ArgumentException(BedWaitsReason);var course = new PopulationAssignment(PopulationAssignmentKind.Course, centre.Id, 0, teacher.Id);var pupil = trainee.WithPlacement(PopulationStatus.Trainee, trainee.Location, course, trainee.Captor, trainee.Home);if (teachingHere) Commit(pupil);else Commit(teacher.WithPlacement(teacher.Status, teacher.Location,new PopulationAssignment(PopulationAssignmentKind.Teaching, centre.Id), teacher.Captor, teacher.Home), pupil);- months[trainee.Id] = (month.MonthOrdinal, month.MonthOrdinal);+ months[trainee.Id] = (month.MonthOrdinal, -1);+ starts.Add((month.MonthOrdinal, centre.ParentCamp));}- /// <summary>R-TRAIN-006: count one completed course turn for a course already held at the month's opening, once per- /// month ordinal. #1668 Q43(a) is decided (GDD, 1 November 2026 answers: "A course occupies its people from its first- /// turn"), but this fixture has not built that answer, so the turn that would leave one turn or none to go is still- /// refused, an implementation gap, not an open design answer, and no trained tier is granted here.</summary>+ /// <summary>R-TRAIN-006: count one completed course turn, once per month ordinal: in the enrolment month (Q43(a), "A+ /// course occupies its people from its first turn"), or in a later month whose opening already holds the course with+ /// the same teacher. The turn that reaches Agreed `profession.course_turns` graduates: the pupil takes the trained+ /// tier (R-QUAL-008), and pupil and teacher are released in that turn as civilians without a job (Q43(b)).</summary>internal void Advance(int traineeId, Gdd03SyntheticMonthContext month){ValidateInventory();var ledger = state.PopulationLedger; var trainee = ledger.Get(traineeId); var centre = CentreOf(trainee);if (!centre.ParentOperating || !centre.UpgradeComplete) throw Deferred(Q9);var opening = Opening(month, trainee.Id);- if (opening.Status != PopulationStatus.Trainee || opening.Assignment.Kind != PopulationAssignmentKind.Course- || !string.Equals(opening.Assignment.Target, centre.Id, StringComparison.Ordinal)- || opening.Assignment.TeacherId != trainee.Assignment.TeacherId)- throw Deferred(Q43);bool tracked = months.TryGetValue(trainee.Id, out var known);- if (tracked)- {- if (month.MonthOrdinal == known.enrolment) throw Deferred(Q43);- if (month.MonthOrdinal <= known.lastCounted) throw new ArgumentException("This month ordinal was already counted or is earlier.");- }- if (!month.CourseEligibleIds.Contains(trainee.Id)) throw Deferred(Q9);- if (trainee.Assignment.ProgressTicks != opening.Assignment.ProgressTicks)+ // Q43(a): the enrolment month counts, though its opening snapshot was taken before the course started.+ bool enrolmentMonth = tracked && month.MonthOrdinal == known.enrolment;+ if (!enrolmentMonth && (opening.Status != PopulationStatus.Trainee || opening.Assignment.Kind != PopulationAssignmentKind.Course+ || !string.Equals(opening.Assignment.Target, centre.Id, StringComparison.Ordinal)+ || opening.Assignment.TeacherId != trainee.Assignment.TeacherId))+ 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, centre.Id, StringComparison.Ordinal) && f.AvailableAtMonthFreeze && f.OpeningCapacity > 0)+ : !month.CourseEligibleIds.Contains(trainee.Id))+ throw Deferred(Q9);+ if (!enrolmentMonth && trainee.Assignment.ProgressTicks != opening.Assignment.ProgressTicks)throw new ArgumentException("This month's course turn was already counted.");int progress = checked(trainee.Assignment.ProgressTicks + 1);- if (progress > courseTurns - 2) throw Deferred(Q43);- Commit(trainee.WithPlacement(trainee.Status, trainee.Location, new PopulationAssignment(PopulationAssignmentKind.Course,- centre.Id, progress, trainee.Assignment.TeacherId), trainee.Captor, trainee.Home));- if (tracked) months[trainee.Id] = (known.enrolment, month.MonthOrdinal);+ if (progress < courseTurns)+ {+ Commit(trainee.WithPlacement(trainee.Status, trainee.Location, new PopulationAssignment(PopulationAssignmentKind.Course,+ centre.Id, progress, trainee.Assignment.TeacherId), trainee.Captor, trainee.Home));+ if (tracked) months[trainee.Id] = (known.enrolment, month.MonthOrdinal);+ return;+ }+ // Graduation (Q43(b)): the trained tier from the pupil's pre-release course record, then pupil and teacher are+ // released in one commit, so no teacher is left teaching with no pupil.+ var graduate = Released(CivilianProfessionRules.AfterMatchingCourse(content, state, trainee.Id, trainee.Profession));+ var teacher = ledger.Get(trainee.Assignment.TeacherId!.Value);+ bool teacherReleased = Pupils(teacher.Id) == 1;+ if (teacherReleased) Commit(graduate, Released(teacher)); else Commit(graduate);+ months.Remove(trainee.Id);+ graduated[trainee.Id] = month.MonthOrdinal;+ if (teacherReleased) graduated[teacher.Id] = month.MonthOrdinal;}/// <summary>R-TRAIN-007: cancel keeps the id, profession, tier, tools and their payment fact and reception credit;