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: synthetic builder rules over the project catalogue (Refs #1700) (#2132)
Beri918853f5beb4
diff --git a/changelog.d/1700-builder-rules.md b/changelog.d/1700-builder-rules.mdnew file mode 100644index 000000000..139e0e9d7--- /dev/null+++ b/changelog.d/1700-builder-rules.md@@ -0,0 +1,5 @@+- GDD 0.3 groundwork, not yet in the game (#1700): synthetic builder rules over the project catalogue. A project pays+ its full cost up front, borrowing what Money lacks, and then advances only by its assigned builders (up to 3, at 1,+ 1.5 or 3 work a turn), so a project with no builders never finishes and extra Money never brings it forward; a+ finished project owes the MVP upkeep of IL 0m every turn from the turn it finishes, empty or not. The game keeps its+ current projects and IL 0m upkeep.diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex 829e9e8ef..f1ebe8f3e 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -152,6 +152,8 @@ R-PROJ-004: In the GDD loop a map action (`map_action`, the legacy transit campR-PROJ-005: A specialised project is allowed only in a city that has its resource (D-D8: "A winery requires areas for grapes"; Phase 3 PR 6, #737). A `projects.yaml` kind may name a `requires:` resource; a `cities.yaml` city lists its `resources:`, each with an id and sources (a url and a checked date each), and may say what the sources leave open (`to_verify`). `StartProject` of such a kind in a city without the resource is refused like the other R-PROJ-001 refusals, before the hex checks; a city founded in play has no resources. The loader refuses a resource without sources and a kind whose resource no city has. Otherwise the kind is an ordinary city project (R-PROJ-003). The one such kind is the winery, which needs vineyards, in Rishon LeZion with its vineyards flagged `to_verify` (owner, 20 October 2026, on #737, as GDD v0.2 says; this replaces the 18 October default of Zikhron Ya'akov, which has no winery).+For R-PROJ-001 and R-PROJ-003, the preceding rules and the IL 0m upkeep of R-MONEY-002 remain unchanged in the game. The inactive gdd-0.3 addition is `Gdd03ProjectBuildFixture`, synthetic builder rules over the #1963 project catalogue (#1700; no command, save, loader, resolver or UI caller). A start pays the kind's full catalogue cost up front; when Money is short the start goes ahead and the shortfall is borrowed as R-MONEY-003 says, Money stopping at 0 and the rest moving to the fixture's debt (owner, 1 November 2026, D1: "Approve all six (Recommended)"). The record holds work done, not turns left. Each turn only assigned builders add work, at the catalogue's ordinary-or-novice, apprentice or expert rate (1, 1.5, 3), at most `builder.slots_per_project` (3) on one project; a project with no builders makes no progress. Money is not an input to progress, so extra Money never changes the completion turn (Amir, 28 October 2026, recorded on #1668: "Extra Money cannot replace work or speed completion. Housing and improvements also require Money for upkeep."). Work past the kind's `work` is discarded and the project completes that turn; builders are then released, and an order to a completed project is refused. From the completion turn on, every turn, a completed project is charged R-MONEY-002's MVP rate, IL 0m, vacant or not, so Money does not change; the catalogue's non-zero `upkeep` is post-MVP and unused (owner's 30 October 2026 "Keep ruling" on UPKEEP, kept on #1700 on 1 November 2026). The national start allowance, cancel, housing repair, completion effects and the live integration are other #1700 slices.+## TrainingTraining is step 4 of the turn in the approved order (§2.3, D-A6): it runs before production. One military camp and one Hakhshara exist in Tel Aviv at the start, a labelled design assumption (D-D5); pioneers build more at camp sites (R-CAMP-001).diff --git a/sim/Statecraft.Sim.Tests/Gdd03ProjectBuildFixtureTests.cs b/sim/Statecraft.Sim.Tests/Gdd03ProjectBuildFixtureTests.csnew file mode 100644index 000000000..42a097d4e--- /dev/null+++ b/sim/Statecraft.Sim.Tests/Gdd03ProjectBuildFixtureTests.cs@@ -0,0 +1,88 @@+using System.Collections.Generic;+using Statecraft.Sim;++// R-PROJ-001, R-PROJ-003: #1700 builder rules over the #1963 catalogue, synthetic fixtures only.+// Amir, 28 Oct 2026 (#1668): "Extra Money cannot replace work or speed completion. Housing and improvements also+// require Money for upkeep."+public class Gdd03ProjectBuildFixtureTests+{+ static Gdd03ProjectCatalogue Catalogue()+ {+ var content = ContentLoader.Load(RealContentTests.ContentRoot());+ // Synthetic identity selection only; no scenario, region or facility binding.+ content.Eras = new() { new Era { Systems = new EraSystems { Loop = EraSystems.Gdd, Ruleset = SaveGame.Gdd03Ruleset } } };+ return Gdd03ProjectCatalogue.Read(content);+ }++ static readonly IReadOnlyDictionary<int, Gdd03BuilderTier[]> Nobody = new Dictionary<int, Gdd03BuilderTier[]>();+ static IReadOnlyDictionary<int, Gdd03BuilderTier[]> On(int id, params Gdd03BuilderTier[] tiers)+ => new Dictionary<int, Gdd03BuilderTier[]> { [id] = tiers };++ [Fact]+ public void AFundedProjectWithNoBuildersMakesNoProgress()+ {+ var f = new Gdd03ProjectBuildFixture(Catalogue(), 5m);+ var id = f.Start("maabara"); // 5 Money, 1 work+ Assert.Equal(0m, f.Money); // the full cost up front (R-PROJ-001)+ for (var i = 0; i < 10; i++) f.EndTurn(Nobody);+ var p = Assert.Single(f.Projects);+ Assert.Equal(id, p.Id);+ Assert.Equal(0m, p.WorkDone);+ Assert.Null(p.CompletedTurn);+ Assert.Equal(0m, f.Money); // an unfinished project owes no upkeep+ }++ [Fact]+ public void ExtraMoneyDoesNotChangeTheCompletionTurn()+ {+ int? Completion(decimal money)+ {+ var f = new Gdd03ProjectBuildFixture(Catalogue(), money);+ var id = f.Start("permanent_housing"); // 15 Money, 3 work+ // Builders are released on completion, so they work only while the project is open.+ for (var i = 0; i < 10 && f.Projects[0].CompletedTurn == null; i++) f.EndTurn(On(id, Gdd03BuilderTier.OrdinaryOrNovice));+ return f.Projects[0].CompletedTurn;+ }+ Assert.Equal(3, Completion(15m)); // one ordinary builder: 1 work a turn+ Assert.Equal(3, Completion(1000m));+ }++ [Fact]+ public void ACompletedImprovementChargesItsUpkeepEachTurnEvenVacant()+ {+ var f = new Gdd03ProjectBuildFixture(Catalogue(), 20m);+ var id = f.Start("industry"); // 10 Money, 3 work; the catalogue's 0.25 upkeep is post-MVP+ Assert.Equal(10m, f.Money);+ f.EndTurn(On(id, Gdd03BuilderTier.Expert)); // 3 work: complete on turn 1+ Assert.Equal(1, f.Projects[0].CompletedTurn);+ Assert.Equal(10m, f.Money); // charged the MVP rate, IL 0m (R-MONEY-002), from the completion turn+ f.EndTurn(Nobody);+ f.EndTurn(Nobody);+ Assert.Equal(10m, f.Money); // and every turn after, with no one working there+ Assert.Equal(0m, f.Debt);+ Assert.Equal(3m, f.Projects[0].WorkDone);+ }++ [Fact]+ public void AShortStartBorrowsAndBuildersAreCappedAtTheSlots()+ {+ var f = new Gdd03ProjectBuildFixture(Catalogue(), 14m);+ f.Start("permanent_housing"); // 15 Money: the 1 short is borrowed (D1, R-MONEY-003)+ Assert.Equal(0m, f.Money);+ Assert.Equal(1m, f.Debt);+ var id = f.Start("industry"); // 10 Money, all borrowed+ Assert.Equal(0m, f.Money);+ Assert.Equal(11m, f.Debt);+ Assert.Equal(2, f.Projects.Count);+ var four = On(id, Gdd03BuilderTier.OrdinaryOrNovice, Gdd03BuilderTier.OrdinaryOrNovice,+ Gdd03BuilderTier.OrdinaryOrNovice, Gdd03BuilderTier.OrdinaryOrNovice);+ Assert.Throws<System.InvalidOperationException>(() => f.EndTurn(four));+ Assert.Equal(0m, f.Projects[1].WorkDone);+ Assert.Throws<System.InvalidOperationException>(() => f.EndTurn(On(id, (Gdd03BuilderTier)7))); // no such tier+ Assert.Equal(0m, f.Projects[1].WorkDone);+ Assert.Equal(0, f.Turn);+ f.EndTurn(On(id, Gdd03BuilderTier.Apprentice)); // 1.5 of 3+ Assert.Equal(1.5m, f.Projects[1].WorkDone);+ Assert.Null(f.Projects[1].CompletedTurn);+ }+}diff --git a/sim/Statecraft.Sim/Gdd03ProjectBuildFixture.cs b/sim/Statecraft.Sim/Gdd03ProjectBuildFixture.csnew file mode 100644index 000000000..6ca43098a--- /dev/null+++ b/sim/Statecraft.Sim/Gdd03ProjectBuildFixture.cs@@ -0,0 +1,95 @@+using System;+using System.Collections.Generic;+using System.Linq;++namespace Statecraft.Sim+{+ internal enum Gdd03BuilderTier { OrdinaryOrNovice, Apprentice, Expert }++ /// <summary>One synthetic city project record: work done instead of turns left (#1700).</summary>+ internal sealed class Gdd03FixtureProject+ {+ internal int Id { get; }+ internal Gdd03ProjectCatalogue.Project Kind { get; }+ internal decimal WorkDone { get; set; }+ internal int? CompletedTurn { get; set; }+ internal Gdd03FixtureProject(int id, Gdd03ProjectCatalogue.Project kind) { Id = id; Kind = kind; }+ }++ /// <summary>Builder rules over the #1963 catalogue (#1700), synthetic fixtures only: no command, save, loader,+ /// resolver or UI caller, so the game keeps R-PROJ-001..003 and its IL 0m upkeep (R-MONEY-002).</summary>+ internal sealed class Gdd03ProjectBuildFixture+ {+ // R-MONEY-002's MVP rate for a completed project (owner, 30 October 2026 "Keep ruling", kept on #1700 on+ // 1 November). The catalogue's non-zero Upkeep is post-MVP, so it is not read here.+ const decimal MvpUpkeep = 0m;+ readonly Gdd03ProjectCatalogue catalogue;+ readonly List<Gdd03FixtureProject> projects = new List<Gdd03FixtureProject>();+ internal decimal Money { get; private set; }+ internal decimal Debt { get; private set; }+ internal int Turn { get; private set; }+ internal IReadOnlyList<Gdd03FixtureProject> Projects => projects;++ internal Gdd03ProjectBuildFixture(Gdd03ProjectCatalogue catalogue, decimal money)+ {+ this.catalogue = catalogue ?? throw new ArgumentNullException(nameof(catalogue));+ Money = money;+ }++ /// <summary>Pays the kind's full cost up front, borrowing any shortfall (D1, R-MONEY-003). The national+ /// start allowance, cancel and housing repair are other #1700 slices.</summary>+ internal int Start(string key)+ {+ var kind = catalogue.Projects.SingleOrDefault(p => p.Key == key)+ ?? throw new InvalidOperationException("Unknown project kind: " + key);+ Pay(kind.Cost.Amount);+ var project = new Gdd03FixtureProject(projects.Count + 1, kind);+ projects.Add(project);+ return project.Id;+ }++ /// <summary>Resolves one turn. Only assigned builders add work, at their tier's rate, at most the catalogue's+ /// slots per project; Money is not an input, so extra Money cannot speed a project. Excess work is discarded.+ /// Then every completed project, the one completed this turn included and vacant or not, is charged the MVP+ /// upkeep rate, IL 0m.</summary>+ internal void EndTurn(IReadOnlyDictionary<int, Gdd03BuilderTier[]> builders)+ {+ // Validate everything first so a refused turn changes nothing; key order makes the first error deterministic.+ foreach (var entry in builders.OrderBy(e => e.Key))+ {+ var p = projects.SingleOrDefault(x => x.Id == entry.Key)+ ?? throw new InvalidOperationException("Unknown project " + entry.Key);+ if (p.CompletedTurn != null) throw new InvalidOperationException("Project " + entry.Key + " is complete");+ if (entry.Value.Length > catalogue.BuilderSlots.Amount)+ throw new InvalidOperationException("Project " + entry.Key + " has " + catalogue.BuilderSlots.Amount + " builder slots");+ foreach (var tier in entry.Value)+ if (!Enum.IsDefined(typeof(Gdd03BuilderTier), tier)) throw new InvalidOperationException("Unknown builder tier " + (int)tier);+ }+ Turn++;+ foreach (var p in projects)+ {+ if (p.CompletedTurn != null || !builders.TryGetValue(p.Id, out var tiers)) continue;+ p.WorkDone = Math.Min(p.Kind.Work.Amount, p.WorkDone + tiers.Sum(Rate));+ if (p.WorkDone == p.Kind.Work.Amount) p.CompletedTurn = Turn;+ }+ foreach (var p in projects)+ if (p.CompletedTurn != null) Pay(MvpUpkeep);+ }++ // R-MONEY-003: a cost above Money is paid, Money stops at 0 and the shortfall moves to debt.+ void Pay(decimal amount)+ {+ var paid = Math.Min(Money, amount);+ Money -= paid;+ Debt += amount - paid;+ }++ decimal Rate(Gdd03BuilderTier tier) => tier switch+ {+ Gdd03BuilderTier.Expert => catalogue.ExpertRate.Amount,+ Gdd03BuilderTier.Apprentice => catalogue.ApprenticeRate.Amount,+ Gdd03BuilderTier.OrdinaryOrNovice => catalogue.OrdinaryOrNoviceRate.Amount,+ _ => throw new InvalidOperationException("Unknown builder tier " + (int)tier) // refused in validation first+ };+ }+}