Skip to content

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

sim: GDD Phase 3 PR 4 (first slice), city projects: housing types and industry (R-PROJ-001 to R-PROJ-003, refs #735) (#982)

Beribc5d9efc1e27
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d617adb71..a73f464ef 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,12 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
sim or the save, so the goldens do not move. `?nofallback`, `?shot`, `?profile` and `?vprofile` (on the desktop
`-shot`, `-profile` and `-vprofile`) still get the tier's own look whatever is stored. The Mobile tier now ships in
desktop builds too (`QualitySettings`), so Low works there.
+- City projects in the GDD loop: `StartProject(kind, city, q, r)` builds permanent housing (IL 6m, 6 turns, +5
+ capacity, +0.03 condition), a transit camp (IL 1.5m, 1 turn, +5 capacity, -0.02 condition; needs the ma'abarot
+ policy) or industry (IL 2m, 6 turns, +5 job slots) on a land hex next to the city, paid at the start and borrowed if
+ short, at most 2 starts a turn; `CancelProject(id)` returns no Money. The kinds are labelled design values in the new
+ `content/projects.yaml` (Q-PROJ-1 to Q-PROJ-5, Q-HOUSE-3; R-PROJ-001 to R-PROJ-003; refs #735). The reference player
+ starts a housing project, one at a time, where the overflow is largest, so `hash1950`, `hash1952` and `mvp-end` move.
### Changed
- The population-tier badge on the twelve city and town pills keeps the values it shipped with, now owner-approved: tiers 1
diff --git a/content/projects.yaml b/content/projects.yaml
new file mode 100644
index 000000000..6e955d3bc
--- /dev/null
+++ b/content/projects.yaml
@@ -0,0 +1,19 @@
+# City projects (GDD "Cities and construction", city projects; docs/rules/mvp.md R-PROJ-001 to R-PROJ-003). The GDD loop
+# only. A project is started in a city on a land hex within rules.yaml map_action_max_distance of the city's settlement hex
+# (Q-PROJ-2), paid in full at the start and borrowed if the Treasury is short (Q-PROJ-1, Q-MONEY-3), needs no workers
+# (Q-PROJ-3), and when its turns are done adds its capacity, condition and job slots to the city once (R-PROJ-003).
+# A transit camp also needs the ma'abarot policy (Q-HOUSE-3, D-D3), which carries its sourced date (rules.yaml map actions).
+#
+# Every number here is a DESIGN VALUE, not a historical figure. Agents proposed them under "Agents propose design values"
+# (owner, 15 October 2026, #375; plan docs/superpowers/plans/2026-10-15-gdd-phase-3.md, PR 0, Q-PROJ-1); the owner may
+# override them. Costs are IL millions, turns are monthly turns (the turn of the order is the first), capacity and job
+# slots are population units, condition is the change to the city's housing condition (0 to 1, R-HOUSE-001).
+# housing: the `housing` map action's cost and +0.03 (rules.yaml map_actions), and build_yishuv_turns' 6 turns.
+# transit_camp: the `transit_camp` map action's cost; built in one turn, as the map action is; its +0.02 housing turned
+# into a condition cost, since D-D3 makes the camp low-condition.
+# industry: the Mefalsim build's pair (build_yishuv_cost 2, build_yishuv_turns 6).
+# name: the phrase the player reads in a sentence ("a transit camp").
+projects:
+ - { id: housing, name: a housing project, cost: 6, turns: 6, capacity: 5, condition: 0.03, job_slots: 0 } # DESIGN VALUE: owner-set balance, not a historical figure (D-C6, D-A3, D-D3; Q-PROJ-1, Q-HOUSE-3: permanent housing)
+ - { id: transit_camp, name: a transit camp, cost: 1.5, turns: 1, capacity: 5, condition: -0.02, job_slots: 0 } # DESIGN VALUE: owner-set balance, not a historical figure (D-C6, D-A3, D-D3; Q-PROJ-1, Q-HOUSE-3: the low-condition type)
+ - { id: industry, name: an industry project, cost: 2, turns: 6, capacity: 0, condition: 0, job_slots: 5 } # DESIGN VALUE: owner-set balance, not a historical figure (D-C6, D-A3; Q-PROJ-1: job slots)
diff --git a/content/rules.yaml b/content/rules.yaml
index 6f42f2f8c..326bfe24b 100644
--- a/content/rules.yaml
+++ b/content/rules.yaml
@@ -17,6 +17,8 @@ attention_cost:
cancel_training: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6)
pioneer_work: 0 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6: unit orders are free)
stop_work: 0 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6: unit orders are free)
+ start_project: 1 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6, D-C5, Q-PROJ-5: the map action's cost)
+ cancel_project: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-A6, D-C5, Q-PROJ-5: cancel_training's cost)
# Turn length on each security rung, rungs 1 to 5 (R-TURN-001). The GDD MVP plays monthly turns on every rung (D-B1), so
# turns from 15 May 1948 end on the 15th of each month.
turn_lengths: [month, month, month, month, month]
diff --git a/docs/RELEASING.md b/docs/RELEASING.md
index b9167ac52..e7efa2858 100644
--- a/docs/RELEASING.md
+++ b/docs/RELEASING.md
@@ -19,8 +19,8 @@ GitHub Releases page (and, from M4, on itch.io). Steps 1–3 are a normal pull r
"$UNITY" -batchmode -CI false -GITHUB_ACTIONS false -TF_BUILD false -quit -projectPath unity -buildTarget WebGL -executeMethod Statecraft.Game.EditorTools.Build.Web -compression gzip -shareable -logFile "$PWD/unity-build-web-gz.log"
git checkout -- unity/Assets/Settings unity/ProjectSettings/ProjectSettings.asset
golden_expect=(); while read -r name hash; do [[ -z "$name" || "$name" == \#* ]] || golden_expect+=(--expect "GOLDEN OK $name $hash"); done < sim/Statecraft.Sim.Tests/golden/manifest.txt
- # one GOLDEN OK line per manifest golden (#394), e.g. "GOLDEN OK hash1950 69ac13846f1420619e9578b119f56e8927e64eb472b8c4f14f2a8d0dc4f70eb1"
- # and "GOLDEN OK hash1952 b34faec68a0a76fc046c6015fbfbfe70a2c56258a71b021214522d0a30379d04"
+ # one GOLDEN OK line per manifest golden (#394), e.g. "GOLDEN OK hash1950 9922495a92307f87d7b5338cd8501fb60ad0424ea6b19ef2d1ec55c44a8bdfb8"
+ # and "GOLDEN OK hash1952 548a6acce93c677f566e7d6febdeb50ed6aeba0e4f61a884708ef0fc38774d87"
uv run tools/web_check.py unity/Builds/Web-gzip --query "golden&smoke=5" "${golden_expect[@]}" \
--expect "SMOKE OK 5 turns 1948-10-15 3005405d64abc6e7418fa1f0d35c36ce5f64ed3af7c5a4c24a73d5dfdb16121f"
uv run tools/web_check.py unity/Builds/Web-gzip --startscreen new --timeout 300 --stall 90
diff --git a/docs/determinism.md b/docs/determinism.md
index bd5d962b6..1130263f1 100644
--- a/docs/determinism.md
+++ b/docs/determinism.md
@@ -28,9 +28,9 @@ final `GameState.Hash()` is pinned:
| Run | Ends | Hash |
|---|---|---|
-| to 1950-01-01 (`Hash1950`) | 1950-01-15, turn 20 | `69ac13846f1420619e9578b119f56e8927e64eb472b8c4f14f2a8d0dc4f70eb1` |
-| to 1952-01-01 (`Hash1952`) | 1952-01-15, turn 44 (the game's end) | `b34faec68a0a76fc046c6015fbfbfe70a2c56258a71b021214522d0a30379d04` |
-| to the game's end (`mvp-end`) | 1952-01-15, turn 44 | `b34faec68a0a76fc046c6015fbfbfe70a2c56258a71b021214522d0a30379d04` |
+| to 1950-01-01 (`Hash1950`) | 1950-01-15, turn 20 | `9922495a92307f87d7b5338cd8501fb60ad0424ea6b19ef2d1ec55c44a8bdfb8` |
+| to 1952-01-01 (`Hash1952`) | 1952-01-15, turn 44 (the game's end) | `548a6acce93c677f566e7d6febdeb50ed6aeba0e4f61a884708ef0fc38774d87` |
+| to the game's end (`mvp-end`) | 1952-01-15, turn 44 | `548a6acce93c677f566e7d6febdeb50ed6aeba0e4f61a884708ef0fc38774d87` |
`hash1952` stops at the first turn on or after 1 January 1952, which is the game's last turn, so it is the same run as
`mvp-end` (`DeterminismTests.TheWholeGameToItsEndIsFixed`). Both names are kept (spec 2026-10-12 section 3 step 6): a
@@ -289,3 +289,6 @@ The hash reads the state keys, so it never sees a record outside its window. An
| GDD Phase 4 PR 1 (Kiryat Shmona, Beit Shemesh) | 1950 | `69ac1384` | Kiryat Shmona and Beit Shemesh join the yishuv sites (Q-SITE-1, owner, #782 and #785), re-pinned on main after #871, #855 and #968. The reference player takes the yishuv sites in ordinal id order before any field or camp, so its veteran builds Beit Shemesh on 1949-06-15, Gilat on 1949-09-15 and Kiryat Shmona on 1949-12-15, and is building Mefalsim at the cut (`mefalsim=b,1,4`; it was plowing Beit Kama's field). The first-new-yishuv objective no longer completes inside the run, so its card does not fire and the score is 0 (was 100); the debt is IL 1.5m higher (IL 2m for the build in progress instead of IL 0.5m for the field) (was `7cf678b6`) |
| GDD Phase 4 PR 1 (Kiryat Shmona, Beit Shemesh) | 1952 | `b34faec6` | same; Mefalsim is built on 1950-03-15 (was 1949-09-15) and Re'im on 1950-06-15 (was 1949-12-15). The six fields are plowed after them, in ordinal id order: Beit Kama 1950-08-15, Beit Shemesh 1950-10-15, Gilat 1950-12-15, Kiryat Shmona 1951-02-15, Mefalsim 1951-04-15 and Re'im 1951-06-15, so Camp 80 is built on 1951-09-15 (was 1950-11-15) and Tzrifin on 1951-12-15 (was 1951-02-15). The objective completes on 1950-03-15, after its reference date, so the score (100) does not change. The debt is IL 5m higher (2 x IL 2m for the yishuvim, 2 x IL 0.5m for their fields), and the Food stock ends 2 units higher (2738, was 2736), which lifts food_supply in the fifth decimal and stability in the sixth (was `f9f47f5c`) |
| GDD Phase 4 PR 1 (Kiryat Shmona, Beit Shemesh) | mvp-end | `b34faec6` | same; the same run as hash1952 (was `f9f47f5c`) |
+| GDD Phase 3 PR 4 | 1950 | `9922495a` | city projects (R-PROJ-001 to R-PROJ-003, #735; Q-PROJ-1 to Q-PROJ-5, Q-HOUSE-3, owner, 15 October 2026, #375): the reference player's stated policy (D-A7) now starts a housing project, one at a time, in the city with the most overflow, on the first free hex next to it, borrowing as its other orders do. Its first start is on 1949-03-15 in Tel Aviv, built on 1949-08-15 (+5 capacity, +0.03 condition); the second is being built. `cproj[...]` joins the state; `mapturn` now counts the turn's project starts. Tel Aviv's capacity 253 (was 248) and condition 0.0168 (was 0), so `housing` 0.0932 (was 0.0850), `morale` 0.5018 (was 0.4990), stability 0.5002 (was 0.4970); debt IL 91.5m (was 79.5m, 2 x IL 6m); rebased on Kiryat Shmona and Beit Shemesh (#944) and the event city effect (#1001) (was `69ac1384`) |
+| GDD Phase 3 PR 4 | 1952 | `548a6acc` | same; five Tel Aviv projects built (1949-08-15 to 1951-08-15; capacity 273, was 248) and a sixth, in Haifa, being built. Every city is back at condition 0 by the end, so `housing` is unchanged and `morale` moves only in the 10th decimal; debt IL 223.9m (was 187.9m, 6 x IL 6m), inside invariants.yaml's 100 to 300 band; stability 0.4432 (unchanged to 4 places) (was `b34faec6`) |
+| GDD Phase 3 PR 4 | mvp-end | `548a6acc` | same; the same run as hash1952 (was `b34faec6`) |
diff --git a/docs/gdd/city-projects.md b/docs/gdd/city-projects.md
new file mode 100644
index 000000000..88fc77e68
--- /dev/null
+++ b/docs/gdd/city-projects.md
@@ -0,0 +1,45 @@
+# City projects: housing types and industry
+
+## Player story
+
+As a player of the MVP, I want to build housing and industry in a city over several turns, so that the people arriving have homes and work (GDD "Cities and construction" [S1]; decisions D-A3, D-C6, D-D3 [S2]; the owner's answers [S3]).
+
+## Rules
+
+- Three kinds, in `content/projects.yaml`: permanent housing, the transit camp and industry. Their numbers are design values agents proposed and the owner may override [S3][S4].
+- Permanent housing costs IL 6m, takes 6 turns and adds 5 units of capacity (5,000 people) and 0.03 housing condition, on its 0-to-1 scale (unitless) (R-PROJ-003).
+- A transit camp costs IL 1.5m, takes 1 turn and adds 5 units of capacity but lowers the condition by 0.02 (unitless). It needs the ma'abarot policy, which carries its sourced date [S4] (R-PROJ-001).
+- Industry costs IL 2m, takes 6 turns and adds 5 units of job slots (R-PROJ-003).
+- `StartProject(kind, city, q, r)` goes on a land hex within 1 hex of the city's settlement hex that has no placement or other project. It is paid at once and borrows what the Treasury lacks. At most 2 projects (unitless) start a turn, nationally. It costs 1 Attention (R-PROJ-001).
+- A project needs no workers (R-PROJ-001).
+- `CancelProject(id)` stops a project being built; the Money is not returned. It costs 0.5 Attention (R-PROJ-002).
+- Construction resolves on the turn's construction step, after the pioneer work; the turn of the order counts. A finished project adds its capacity, condition and job slots once (R-PROJ-003).
+
+## Data touched
+
+- `content/projects.yaml` (new; design values), read only in the GDD loop.
+- `rules.yaml` `attention_cost.start_project` and `cancel_project`.
+- `GameState.CityProjects`, hashed as `cproj[...]` when there are some; the map actions' per-turn counter; the city's capacity, condition and job slots; `Treasury` and `Debt`.
+- Save files: the `project KIND CITY Q R` and `unproject ID` lines. Scenarios: `start_project` and `cancel_project`.
+
+## Done when
+
+- `dotnet test sim/Statecraft.sln` passes, including `CityProjectsTests`, `DesignValuesTests`, `CommandGuardTests` and `SaveGameTests`.
+- The goldens `hash1950`, `hash1952` and `mvp-end` (unitless) are re-pinned with a history row in docs/determinism.md.
+
+## Out of scope
+
+- Refusing the legacy map actions in the GDD loop (R-PROJ-004), a separate PR.
+- The buttons and the drawing of projects on the map (Phase 3 PR 8).
+- The craftsman (PR 5) and the winery (PR 6).
+
+## Sources
+
+- [S1] The game design of record, docs/GDD.md
+- [S2] GDD v0.1 impact analysis and phased plan, section 5, docs/superpowers/specs/2026-10-12-gdd-v0.1-impact-and-plan.md
+- [S3] GDD Phase 3 plan, PR 0's recommended answers and PR 4, docs/superpowers/plans/2026-10-15-gdd-phase-3.md
+- [S4] The ma'abara date and the map action costs, content/rules.yaml
+
+## Open questions
+
+- None for this slice: the owner took every recommendation on #375; the values remain his to override.
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index ccb361978..92a6db925 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -62,6 +62,16 @@ R-HOUSE-003: The people who take a city's housing (`housed`) are its civilians,
R-HOUSE-004: In the GDD loop the base of the national `housing` indicator is the people-weighted mean of the cities' housing condition, each city weighed by its housed people (R-HOUSE-003): `sum(condition * housed) / sum(housed)`. Policy effects, map actions and events still act on top, as on any indicator. Decided (owner, 17 Oct 2026, option (a) of Q-PR3-A, relayed on [#855 at 06:33Z](https://github.com/eyalgolan/statecraft-israel/pull/855#issuecomment-6230731177)): the national housing base is the people-weighted mean of city condition, with policy, map actions and events still applied on top. When no city houses anybody the mean is undefined, and the base is `model.yaml`'s. Capacity reaches the level through overflow and condition (R-HOUSE-002).
+## City projects
+
+A city project is built in a city (GDD "Cities and construction"; Phase 3 PR 4, #735). The kinds are in `content/projects.yaml`, every number a design value (Q-PROJ-1, Q-PROJ-5, owner, 15 October 2026, #375: "Take all recommendations", with agent-proposed values the owner may override): permanent housing (`housing`), the transit camp (`transit_camp`, D-D3, Q-HOUSE-3) and `industry`. The legacy map actions still run beside them; refusing them in the GDD loop (R-PROJ-004) is a separate PR. Until then a map action does not check the city projects, so one can still be placed on a project's hex; R-PROJ-004 removes that path.
+
+R-PROJ-001: `StartProject(kind, city, q, r)` starts a city project of a `projects.yaml` kind for a city on hex (q, r). The Treasury pays the kind's cost at once and borrows what it lacks (Q-PROJ-1, Q-MONEY-3, "Allow borrowing"); the project takes the next id and the kind's turns, the turn of the order the first (D-A3). It needs no workers (Q-PROJ-3). It is refused, state and Attention unchanged, for an unknown kind or city; a transit camp without the `maabarot` policy at 0.5 or more (Q-HOUSE-3: the policy carries the camp's sourced date, and the map actions' 1 January 1950 window does not apply); a hex that is not land, is more than `map_action_max_distance` from the city's settlement hex, or holds a map-action placement or another city project, built or not (Q-PROJ-2); and once `map_actions_per_turn` projects were started this turn, counted nationally with the map actions (Q-PROJ-4). The legacy loop refuses it before charging Attention. Its Attention cost is `attention_cost.start_project` (1, Q-PROJ-5).
+
+R-PROJ-002: `CancelProject(id)` removes a city project that is being built. The Money paid is not returned, and there are no people to return (D-A3, Q-PROJ-3). An unknown or built project is refused with the state unchanged. Its Attention cost is `attention_cost.cancel_project` (0.5, Q-PROJ-5).
+
+R-PROJ-003: On step 5 of the turn (D-A6), after the pioneer work, every city project being built has one turn less to go, in ascending id. One that reaches 0 is built on the turn's end date and adds its kind's `capacity` to the city's housing capacity, its `condition` to the city's housing condition (kept from 0 to 1, R-HOUSE-001) and its `job_slots` to the city's job slots, once: a built project keeps its record, with its hex, and is never advanced again. `GameState.CityProjects` is hashed as `cproj[...]` only when it has a project (R-LOOP-002).
+
## Training
Training is step 4 of the turn in the approved order (§2.3, D-A6): it runs before production. One military camp and one Hakhshara exist in Tel Aviv at the start, a labelled design assumption (D-D5); pioneers build more at camp sites (R-CAMP-001).
diff --git a/sim/Statecraft.Sim.Tests/CityProjectsTests.cs b/sim/Statecraft.Sim.Tests/CityProjectsTests.cs
new file mode 100644
index 000000000..707044c78
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/CityProjectsTests.cs
@@ -0,0 +1,257 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Statecraft.Sim;
+using Statecraft.Sim.Reference;
+
+/// <summary>GDD Phase 3 PR 4's city projects (plan docs/superpowers/plans/2026-10-15-gdd-phase-3.md, "PR 4"; owner, 15 October
+/// 2026, #375, "Take all recommendations"): StartProject (R-PROJ-001), CancelProject (R-PROJ-002) and construction in step 5
+/// (R-PROJ-003). The fixture's town_a is on (1, 0); (1, 1) and (2, 0) are land next to it, (0, 0) is sea and (3, 0) is two
+/// hexes away. Its kinds: housing (IL 3m, 2 turns, +4 capacity, +0.1 condition), transit_camp (IL 1m, 1 turn, +3, -0.1) and
+/// industry (IL 2m, 2 turns, +3 job slots).</summary>
+public class CityProjectsTests
+{
+ static Content Town() => ContentLoader.Load(Fixture.Write(Fixture.Gdd()));
+
+ static StepResult Step(Content c, GameState s, params Command[] commands) => Simulation.Step(c, s, commands);
+
+ static GameState New(Content c) => Simulation.NewGame(c, 1, Mode.Historical);
+
+ static StartProject Housing(int q = 1, int r = 1) => new StartProject("housing", "town_a", q, r);
+
+ // R-PROJ-003 (Review focus 5)
+ [Fact]
+ public void AHousingProjectAddsCapacityOnceWhenDone()
+ {
+ var c = Town();
+ var s = New(c);
+ var one = Step(c, s, Housing());
+ Assert.Empty(one.Rejected);
+ var p = one.State.CityProjects.Values.Single();
+ Assert.Equal(("housing", "town_a", 1, 1, 1, (DateTime?)null), (p.Kind, p.City, p.Q, p.R, p.TurnsLeft, p.BuiltOn)); // 2 turns, this one the first
+ Assert.Equal(Step(c, s).State.Treasury - 3, one.State.Treasury, 9); // paid in full at the start (Q-PROJ-1)
+ Assert.Contains(one.Why, x => x.System == "city" && x.Message == "Town A: a housing project began, cost IL 3.0m");
+ Assert.Equal(s.Cities["town_a"].HousingCapacity, one.State.Cities["town_a"].HousingCapacity); // nothing yet
+
+ var two = Step(c, one.State);
+ Assert.Equal(two.State.Date, two.State.CityProjects[p.Id].BuiltOn); // built on the turn's end date
+ Assert.Equal(one.State.Cities["town_a"].HousingCapacity + 4, two.State.Cities["town_a"].HousingCapacity);
+ Assert.Contains(two.Why, x => x.System == "city" && x.Message == "Town A: a housing project was finished");
+
+ var later = two.State;
+ for (int i = 0; i < 3; i++) later = Step(c, later).State;
+ Assert.Equal(two.State.Cities["town_a"].HousingCapacity, later.Cities["town_a"].HousingCapacity); // once, not every turn
+ }
+
+ // R-PROJ-003
+ [Fact]
+ public void AnIndustryProjectAddsJobSlotsOnceWhenDone()
+ {
+ var c = Town();
+ var s = New(c);
+ var built = Step(c, Step(c, s, new StartProject("industry", "town_a", 2, 0)).State).State;
+ Assert.Equal(s.Cities["town_a"].JobSlots + 3, built.Cities["town_a"].JobSlots);
+ Assert.Equal(s.Cities["town_a"].JobSlots + 3, Step(c, built).State.Cities["town_a"].JobSlots);
+ }
+
+ // R-PROJ-003, R-HOUSE-001: a project's condition change is added once and kept on the 0 to 1 scale.
+ [Theory]
+ [InlineData("housing", 0.5, 0.6)]
+ [InlineData("housing", 0.95, 1.0)]
+ [InlineData("transit_camp", 0.5, 0.4)]
+ [InlineData("transit_camp", 0.05, 0.0)]
+ public void TheConditionMovesOnceAndStaysFrom0To1(string kind, double before, double after)
+ {
+ var c = Town();
+ var s = New(c);
+ var x = s.Cities["town_a"];
+ s.Cities["town_a"] = x.WithCondition(before);
+ s.CityProjects.Add(7, new CityProject(7, kind, "town_a", 1, 1, 1));
+ Projects.AdvanceCity(c, s, s.Date.AddMonths(1), new List<Cause>());
+ Assert.Equal(after, s.Cities["town_a"].Condition!.Value, 9);
+ Projects.AdvanceCity(c, s, s.Date.AddMonths(2), new List<Cause>());
+ Assert.Equal(after, s.Cities["town_a"].Condition!.Value, 9); // a built project is not advanced again
+ }
+
+ public static IEnumerable<object[]> Refusals() => new List<object[]>
+ {
+ new object[] { "unknown kind", "There is no such city project" },
+ new object[] { "unknown city", "There is no such city" },
+ new object[] { "camp without the policy", "Transit camps need the ma'abarot policy" },
+ new object[] { "sea", "This hex is not land" },
+ new object[] { "too far", "This hex is more than 1 hex from Town A" },
+ new object[] { "a project there", "This hex already has a housing project" },
+ new object[] { "a placement there", "This hex already has a transit camp" },
+ };
+
+ // R-PROJ-001: each refusal leaves the state as if the order had not been given, Attention refunded.
+ [Theory]
+ [MemberData(nameof(Refusals))]
+ public void TheLimitsAreRefusedAndChangeNothing(string why, string reason)
+ {
+ var c = Town();
+ var s = New(c);
+ if (why == "a project there") s.CityProjects.Add(s.NextId, new CityProject(s.NextId++, "housing", "town_a", 1, 1, 2));
+ if (why == "a placement there") s.Placements.Add(new Placement(MapActions.TransitCamp, 1, 1, s.Date));
+ Command order = why switch
+ {
+ "unknown kind" => new StartProject("harbour", "town_a", 1, 1),
+ "unknown city" => new StartProject("housing", "atlantis", 1, 1),
+ "camp without the policy" => new StartProject("transit_camp", "town_a", 1, 1),
+ "sea" => Housing(0, 0),
+ "too far" => Housing(3, 0),
+ _ => Housing(),
+ };
+ var r = Step(c, s, order);
+ Assert.Equal(reason, Assert.Single(r.Rejected).Reason);
+ Assert.Equal(Step(c, s).State.Hash(), r.State.Hash());
+ }
+
+ // R-PROJ-001 (Q-PROJ-4): map_actions_per_turn starts a turn, nationally; the next turn starts from zero.
+ [Fact]
+ public void AThirdStartInOneTurnIsRefused()
+ {
+ var c = Town();
+ var s = New(c);
+ s.Attention = 10;
+ var two = new Command[] { Housing(1, 1), new StartProject("industry", "town_a", 2, 0) };
+ var r = Step(c, s, two.Append(new StartProject("industry", "town_a", 0, 1)).ToArray());
+ Assert.Equal("No more than 2 map actions and city projects in one turn", Assert.Single(r.Rejected).Reason);
+ Assert.Equal(Step(c, s, two).State.Hash(), r.State.Hash());
+ Assert.Empty(Step(c, r.State, new StartProject("industry", "town_a", 0, 1)).Rejected);
+ }
+
+ // R-PROJ-001 (Q-PROJ-4): the cap counts map actions too, so two map actions leave no start for a project.
+ [Fact]
+ public void TwoMapActionsUseUpTheTurnsStarts()
+ {
+ var c = Town();
+ var s = New(c);
+ s.Attention = 10;
+ s.Date = new DateTime(1948, 6, 1); // map_actions_from in the fixture
+ var two = new Command[] { new MapAction("housing", 1, 1), new MapAction("housing", 2, 0) };
+ var r = Step(c, s, two.Append(new StartProject("industry", "town_a", 0, 1)).ToArray());
+ Assert.Equal("No more than 2 map actions and city projects in one turn", Assert.Single(r.Rejected).Reason);
+ Assert.Equal(Step(c, s, two).State.Hash(), r.State.Hash());
+ }
+
+ // R-PROJ-001 (Q-MONEY-3): a short Treasury borrows, it is not refused.
+ [Fact]
+ public void AShortTreasuryBorrows()
+ {
+ var c = Town();
+ var s = New(c);
+ s.Treasury = 1;
+ var r = Step(c, s, Housing());
+ Assert.Empty(r.Rejected);
+ Assert.Contains(r.Why, x => x.System == "economy" && x.Message == "Borrowed IL 2.0m to build a housing project");
+ }
+
+ // R-PROJ-001 (Q-HOUSE-3, D-D3): the transit camp keeps the ma'abarot policy gate, which carries its sourced date; with the
+ // policy it is accepted and, built in one turn, adds its capacity at the end of the same turn.
+ [Fact]
+ public void ATransitCampOpensWithTheMaabarotPolicy()
+ {
+ var c = Town();
+ var s = New(c);
+ var camp = new StartProject("transit_camp", "town_a", 1, 1);
+ Assert.Equal("Transit camps need the ma'abarot policy", Assert.Single(Step(c, s, camp).Rejected).Reason);
+ s.Policies[MapActions.MaabarotPolicy] = 1;
+ var r = Step(c, s, camp);
+ Assert.Empty(r.Rejected);
+ Assert.Equal(r.State.Date, r.State.CityProjects.Values.Single().BuiltOn);
+ Assert.Equal(s.Cities["town_a"].HousingCapacity + 3, r.State.Cities["town_a"].HousingCapacity);
+ }
+
+ // R-PROJ-002 (D-A3): cancelling returns no Money (and, with no workers, no people) and the project adds nothing.
+ [Fact]
+ public void CancellingReturnsPeopleNotMoney()
+ {
+ var c = Town();
+ var s = New(c);
+ var started = Step(c, s, Housing()).State;
+ var id = started.CityProjects.Keys.Single();
+ var r = Step(c, started, new CancelProject(id));
+ Assert.Empty(r.Rejected);
+ Assert.Empty(r.State.CityProjects);
+ Assert.Equal(Step(c, started).State.Treasury, r.State.Treasury, 9); // the Money spent is not returned
+ Assert.Equal(Step(c, started).State.Cities["town_a"].Civilians, r.State.Cities["town_a"].Civilians); // no workers to return (Q-PROJ-3)
+ Assert.Equal(started.Cities["town_a"].HousingCapacity, Step(c, r.State).State.Cities["town_a"].HousingCapacity);
+ Assert.Contains(r.Why, x => x.Message == "Town A: a housing project was cancelled; the Money spent is not returned");
+ }
+
+ // R-PROJ-002
+ [Fact]
+ public void CancellingAnUnknownOrBuiltProjectIsRefused()
+ {
+ var c = Town();
+ var s = New(c);
+ Assert.Equal("There is no such city project", Assert.Single(Step(c, s, new CancelProject(42)).Rejected).Reason);
+ var built = Step(c, Step(c, s, Housing()).State).State;
+ var r = Step(c, built, new CancelProject(built.CityProjects.Keys.Single()));
+ Assert.Equal("A housing project is already built", Assert.Single(r.Rejected).Reason);
+ Assert.Equal(Step(c, built).State.Hash(), r.State.Hash());
+ }
+
+ // R-PROJ-001: the legacy loop refuses both orders before charging Attention.
+ [Fact]
+ public void TheLegacyLoopRefusesTheOrders()
+ {
+ var c = ContentLoader.Load(Fixture.Write());
+ var s = New(c);
+ var r = Step(c, s, Housing(), new CancelProject(1));
+ Assert.All(r.Rejected, x => Assert.Equal("That order is not available in this game", x.Reason));
+ Assert.Equal(2, r.Rejected.Count);
+ }
+
+ [Fact]
+ public void BothOrdersRoundTripThroughASaveAndReplay()
+ {
+ var c = Town();
+ var g = GameSession.New(c, 1, Mode.Historical);
+ g.Step(new Command[] { Housing() });
+ g.Step(new Command[] { new CancelProject(g.State.CityProjects.Keys.Single()) });
+ var text = g.Save.Write();
+ Assert.Contains("\nproject housing town_a 1 1\n", text);
+ Assert.Contains("\nunproject ", text);
+ Assert.Equal(text, SaveGame.Parse(text).Write());
+ Assert.Equal(g.State.Hash(), GameSession.Load(c, text, out _).State.Hash());
+ }
+
+ [Fact]
+ public void CloneIsIndependentAndTheHashOmitsAnEmptyList()
+ {
+ var c = Town();
+ var s = New(c);
+ Assert.DoesNotContain("cproj", s.Describe()); // omit-when-empty (R-LOOP-002's rule)
+ var before = s.Hash();
+ var copy = s.Clone();
+ copy.CityProjects.Add(1, new CityProject(1, "housing", "town_a", 1, 1, 2));
+ Assert.Empty(s.CityProjects);
+ Assert.Equal(before, s.Hash());
+ Assert.Contains("cproj[", copy.Describe());
+ Assert.NotEqual(before, copy.Hash());
+ }
+
+ // D-A7: the reference player's stated policy starts a housing project, one at a time, in the city with the most overflow.
+ [Fact]
+ public void TheReferencePlayerStartsHousingWhereTheOverflowIsLargest()
+ {
+ var c = Town();
+ var s = New(c);
+ s.Attention = 10; // the fixture's rung 5 doubles every price
+ Assert.DoesNotContain(ReferencePlayer.Commands(c, s), x => x is StartProject); // no overflow, nothing to build
+ var x = s.Cities["town_a"];
+ s.Cities["town_a"] = x.WithCounts(x.HousingCapacity + 2, x.Employed, x.Refugees);
+ var start = Assert.Single(ReferencePlayer.Commands(c, s).OfType<StartProject>());
+ Assert.Equal(("housing", "town_a"), (start.ProjectKind, start.City));
+ Assert.Null(Projects.CheckCity(c, s, start.ProjectKind, start.City, start.Q, start.R));
+ s.Treasury = 0; // it borrows, as the reference player's other orders do
+ Assert.Single(ReferencePlayer.Commands(c, s).OfType<StartProject>());
+ s.Attention = 1; // but not past the turn's Attention
+ Assert.DoesNotContain(ReferencePlayer.Commands(c, s), x => x is StartProject);
+ s.Attention = 10;
+ s.CityProjects.Add(9, new CityProject(9, "industry", "town_a", 2, 0, 1)); // one at a time
+ Assert.DoesNotContain(ReferencePlayer.Commands(c, s), x => x is StartProject);
+ }
+}
diff --git a/sim/Statecraft.Sim.Tests/CommandGuardTests.cs b/sim/Statecraft.Sim.Tests/CommandGuardTests.cs
index 8a4463fd6..9e75c7671 100644
--- a/sim/Statecraft.Sim.Tests/CommandGuardTests.cs
+++ b/sim/Statecraft.Sim.Tests/CommandGuardTests.cs
@@ -23,6 +23,8 @@ public class CommandGuardTests
[typeof(CancelTraining)] = new CancelTraining(1),
[typeof(PioneerWork)] = new PioneerWork(1, "build_yishuv", "mefalsim"),
[typeof(StopWork)] = new StopWork(1),
+ [typeof(StartProject)] = new StartProject("housing", "tel_aviv", 1, 0),
+ [typeof(CancelProject)] = new CancelProject(1),
};
static IEnumerable<Type> CommandTypes() =>
diff --git a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs
index 0fe61331f..bc22afe93 100644
--- a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs
+++ b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs
@@ -89,18 +89,36 @@ public class DesignValuesTests
("model.yaml", "situations[low_cohesion].off_above"),
("model.yaml", "situations[low_intl_support].on_below"),
("model.yaml", "situations[low_intl_support].off_above"),
+ // City projects (Phase 3 PR 4; Q-PROJ-1, Q-PROJ-5): agent-proposed under "Agents propose design values" (#375).
+ ("rules.yaml", "attention_cost.start_project"),
+ ("rules.yaml", "attention_cost.cancel_project"),
+ ("projects.yaml", "projects[housing].cost"),
+ ("projects.yaml", "projects[housing].turns"),
+ ("projects.yaml", "projects[housing].capacity"),
+ ("projects.yaml", "projects[housing].condition"),
+ ("projects.yaml", "projects[housing].job_slots"),
+ ("projects.yaml", "projects[transit_camp].cost"),
+ ("projects.yaml", "projects[transit_camp].turns"),
+ ("projects.yaml", "projects[transit_camp].capacity"),
+ ("projects.yaml", "projects[transit_camp].condition"),
+ ("projects.yaml", "projects[transit_camp].job_slots"),
+ ("projects.yaml", "projects[industry].cost"),
+ ("projects.yaml", "projects[industry].turns"),
+ ("projects.yaml", "projects[industry].capacity"),
+ ("projects.yaml", "projects[industry].condition"),
+ ("projects.yaml", "projects[industry].job_slots"),
};
- /// <summary>Every number in the GDD files and blocks, as (file, key path, the line it is on). Scope: all of cities.yaml and
- /// unit_types.yaml, rules.yaml mvp:, and the GDD kinds under rules.yaml attention_cost. A value whose own mapping says
+ /// <summary>Every number in the GDD files and blocks, as (file, key path, the line it is on). Scope: all of cities.yaml,
+ /// unit_types.yaml and projects.yaml, rules.yaml mvp:, and the GDD kinds under rules.yaml attention_cost. A value whose own mapping says
/// `status: sourced`, `derived` or `wikipedia-only` is a historical figure, not balance: the loader holds it to its
/// sources and date instead (cities.yaml, R-CITY-006), so it is left out. model.yaml predates the rule (its header calls
/// every number there a design value), so only its tagged lines are in scope: the numbers Phase 2 PR 4 added.</summary>
public static List<(string File, string Key, string Line)> Numbers(string root)
{
var found = new List<(string, string, string)>();
- foreach (var file in new[] { "rules.yaml", "cities.yaml", "unit_types.yaml", "model.yaml" })
+ foreach (var file in new[] { "rules.yaml", "cities.yaml", "unit_types.yaml", "model.yaml", "projects.yaml" })
{
var path = Path.Combine(root, file);
if (!File.Exists(path)) continue;
diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.cs
index c6a17fa49..ce1887fe0 100644
--- a/sim/Statecraft.Sim.Tests/Fixture.cs
+++ b/sim/Statecraft.Sim.Tests/Fixture.cs
@@ -207,13 +207,14 @@ series:
["cities.yaml"] = GddCities,
["unit_types.yaml"] = GddUnitTypes,
["sites.yaml"] = GddSites,
+ ["projects.yaml"] = GddProjects,
};
if (extra != null) foreach (var kv in extra) o[kv.Key] = kv.Value;
return o;
}
/// <summary>The fixture's attention_cost line with the GDD command kinds added (replaces "map_action: 1 }").</summary>
- public const string GddCosts = "map_action: 1, assign_workers: 1, train: 1, cancel_training: 1, pioneer_work: 0, stop_work: 0 }";
+ public const string GddCosts = "map_action: 1, assign_workers: 1, train: 1, cancel_training: 1, pioneer_work: 0, stop_work: 0, start_project: 1, cancel_project: 0.5 }";
public const string GddRules = @"
mvp:
@@ -255,6 +256,14 @@ types:
- { id: halutz, kind: unit, facility: hakhshara, training_turns: 3, training_cost: 0.25 }
";
+ /// <summary>The three city project kinds (R-PROJ-001). Fixture values, not the game's.</summary>
+ public const string GddProjects = @"
+projects:
+ - { id: housing, name: a housing project, cost: 3, turns: 2, capacity: 4, condition: 0.1, job_slots: 0 }
+ - { id: transit_camp, name: a transit camp, cost: 1, turns: 1, capacity: 3, condition: -0.1, job_slots: 0 }
+ - { id: industry, name: an industry project, cost: 2, turns: 2, capacity: 0, condition: 0, job_slots: 3 }
+";
+
/// <summary>One designated site on a land hex next to town_a, with no settlement on it. Fixture values, not history.</summary>
public const string GddSites = @"
sites:
diff --git a/sim/Statecraft.Sim.Tests/ProjectsContentTests.cs b/sim/Statecraft.Sim.Tests/ProjectsContentTests.cs
new file mode 100644
index 000000000..747a2ec73
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/ProjectsContentTests.cs
@@ -0,0 +1,34 @@
+using System.Collections.Generic;
+using System.Linq;
+using Statecraft.Sim;
+
+/// <summary>content/projects.yaml (R-PROJ-001): the real kinds load with the owner's proposed design values (Q-PROJ-1,
+/// Q-HOUSE-3), and the loader refuses a kind that could not be built, would cost less than nothing, or would move a condition
+/// out of its 0 to 1 scale in one step.</summary>
+public class ProjectsContentTests
+{
+ [Fact]
+ public void TheRealKindsLoad()
+ {
+ var c = ContentLoader.Load(RealContentTests.ContentRoot());
+ Assert.Equal(new[] { ("housing", 6.0, 6, 5, 0.03, 0), ("transit_camp", 1.5, 1, 5, -0.02, 0), ("industry", 2.0, 6, 0, 0.0, 5) },
+ c.ProjectKinds.Select(k => (k.Id, k.Cost, k.Turns, k.Capacity, k.Condition, k.JobSlots)));
+ Assert.Equal((1.0, 0.5), (c.Rules.AttentionCost["start_project"], c.Rules.AttentionCost["cancel_project"])); // Q-PROJ-5
+ }
+
+ [Theory]
+ [InlineData("id: housing, name: a housing project", "id: transit_camp, name: a housing project", "projects[transit_camp].id")] // duplicate id
+ [InlineData("name: a housing project", "name: ''", "projects[housing].name")]
+ [InlineData("cost: 3, turns: 2", "cost: -1, turns: 2", "projects[housing].cost")]
+ [InlineData("cost: 3, turns: 2", "cost: 3, turns: 0", "projects[housing].turns")]
+ [InlineData("capacity: 4", "capacity: -1", "projects[housing].capacity")]
+ [InlineData("condition: 0.1, job_slots: 0 }\n - { id: transit_camp", "condition: 1.5, job_slots: 0 }\n - { id: transit_camp", "projects[housing].condition")]
+ [InlineData("job_slots: 3", "job_slots: -3", "projects[industry].job_slots")]
+ public void ABadKindIsRefused(string from, string to, string where)
+ {
+ Assert.Contains(from, Fixture.GddProjects);
+ var dir = Fixture.Write(Fixture.Gdd(new Dictionary<string, string> { ["projects.yaml"] = Fixture.GddProjects.Replace(from, to) }));
+ var e = Assert.Throws<ContentException>(() => ContentLoader.Load(dir));
+ Assert.Contains(where, e.Message);
+ }
+}
diff --git a/sim/Statecraft.Sim.Tests/SaveGameTests.cs b/sim/Statecraft.Sim.Tests/SaveGameTests.cs
index 4fa7a19e7..87340dfe7 100644
--- a/sim/Statecraft.Sim.Tests/SaveGameTests.cs
+++ b/sim/Statecraft.Sim.Tests/SaveGameTests.cs
@@ -29,7 +29,7 @@ public class SaveGameTests
new Command[] { new SetPolicy("odd id with spaces%", 0.5), new MapAction("transit_camp", 4, 0) },
new Command[] { new AssignWorkers("town_a", "job", 1) }, // a GDD order: the legacy fixture refuses it
new Command[] { new Train("town_a", "halutz", 1), new CancelTraining(1) }, // GDD orders too
- new Command[] { new PioneerWork(1, "build_yishuv", "site_a"), new StopWork(1) },
+ new Command[] { new PioneerWork(1, "build_yishuv", "site_a"), new StopWork(1), new StartProject("housing", "town_a", 1, 1), new CancelProject(1) },
new Command[] { new SecurityOrder(1) }, new Command[0],
};
foreach (var o in orders) g.Step(o);
diff --git a/sim/Statecraft.Sim.Tests/golden/hash1950.txt b/sim/Statecraft.Sim.Tests/golden/hash1950.txt
index 9b8447a9d..513072050 100644
--- a/sim/Statecraft.Sim.Tests/golden/hash1950.txt
+++ b/sim/Statecraft.Sim.Tests/golden/hash1950.txt
@@ -1,9 +1,9 @@
1950-01-15;1948;Historical;20;
ind{
food_supply=0.8886718750000001 [3FEC700000000001]
- housing=0.08498850862930471 [3FB5C1CE911942EE]
+ housing=0.09316824128271463 [3FB7D9DFB555C8E1]
intl_standing=0.8100000000000003 [3FE9EB851EB851EE]
- morale=0.4990244920977924 [3FDFF0046C5DA244]
+ morale=0.5017933100237988 [3FE00EB0D7FCEBF8]
security=0.5042220244102726 [3FE022963A187B2A]
pol{
border_settlement=0.2 [3FC999999999999A]
@@ -14,7 +14,7 @@ eff{
border_villages_secure=0.03922202441027243 [3FA414E8C040046D]
building_houses=0.08452919104400287 [3FB5A3B47F17614D]
food_lifts_cohesion=0.08774605560302737 [3FB67686872B020E]
- homes_lift_morale=0.022428056459524053 [3F96F7616406A73E]
+ homes_lift_morale=0.025196874385530456 [3F99CD359DCA020A]
rationing_feeds=0.33867187500000007 [3FD5ACCCCCCCCCCE]
rationing_grates=-0.15 [BFC3333333333333]
safety_lifts_morale=0.050367774522404846 [3FA9C9CE10B12AF4]
@@ -44,11 +44,11 @@ pop{
sit[
housing_crisis
treasury=0 [0000000000000000]
-debt=79.50032828298673 [4053E00560EB2C47]
+debt=91.50032828298674 [4056E00560EB2C48]
fx=94.52989672613671 [4057A1E9D3F540F0]
rung=2;cf=0;
mob=0.05 [3FA999999999999A]
-stab=0.49698450107475844 [3FDFCE9814AF09A8]
+stab=0.5002035568980255 [3FE001AAE3C70961]
att=4 [4010000000000000]
fired[
altalena
@@ -98,7 +98,7 @@ chosen{
appt{
under=;
map[
-mapturn=0001-01-01:0;
+mapturn=1949-08-15:1;
over=
city{
hadera=12,5,18,5,0,c0 [0000000000000000]
@@ -110,7 +110,7 @@ city{
rishon_lezion=10,5,15,5,1,c0 [0000000000000000]
rosh_pinna=1,0,1,0,0,c0.35 [3FD6666666666666]
safed=2,1,3,1,0,c0 [0000000000000000]
- tel_aviv=248,106,370,106,9,c0 [0000000000000000]
+ tel_aviv=253,106,370,106,9,c0.016845827788914483 [3F9140085DB5B1B4]
tiberias=6,2,9,2,0,c0 [0000000000000000]
zikhron_yaakov=2,1,3,1,0,c0 [0000000000000000]
units[
@@ -121,5 +121,8 @@ site{
gilat=done,1949-09-15
kiryat_shmona=done,1949-12-15
mefalsim=b,1,4
-next=2
+cproj[
+ 2:housing@tel_aviv,-4,20/done,1949-08-15
+ 3:housing@tel_aviv,-3,19/1
+next=4
food=3003,1001,0
\ No newline at end of file
diff --git a/sim/Statecraft.Sim.Tests/golden/hash1952.txt b/sim/Statecraft.Sim.Tests/golden/hash1952.txt
index 79950825e..a8b700821 100644
--- a/sim/Statecraft.Sim.Tests/golden/hash1952.txt
+++ b/sim/Statecraft.Sim.Tests/golden/hash1952.txt
@@ -3,7 +3,7 @@ ind{
food_supply=0.8556594723429 [3FEB618FF947363F]
housing=0.08504947742483628 [3FB5C5CD7414E141]
intl_standing=0.8300000000000003 [3FEA8F5C28F5C292]
- morale=0.49156077649131324 [3FDF75BB54C1B318]
+ morale=0.4915607767294802 [3FDF75BB55032A9A]
security=0.5061322526321603 [3FE0323C441030A6]
pol{
border_settlement=0.2 [3FC999999999999A]
@@ -14,7 +14,7 @@ eff{
border_villages_secure=0.04113225263216018 [3FA50F495FBB5C36]
building_houses=0.08504947742483629 [3FB5C5CD7414E142]
food_lifts_cohesion=0.08899999973526929 [3FB6C8B43834FD50]
- homes_lift_morale=0.012767196348836194 [3F8A25B0163D2852]
+ homes_lift_morale=0.01276719658700311 [3F8A25B01E6C188A]
rationing_feeds=0.3399999999208376 [3FD5C28F5C133334]
rationing_grates=-0.15 [BFC3333333333333]
safety_lifts_morale=0.05054370052651369 [3FA9E0DD298F75A0]
@@ -45,11 +45,11 @@ sit[
fx_crisis
housing_crisis
treasury=0 [0000000000000000]
-debt=187.89012071283815 [40677C7BDE6EE43A]
+debt=223.89012071283815 [406BFC7BDE6EE43A]
fx=-12.990431328096559 [C029FB19D0A63796]
rung=2;cf=0;
mob=0.05 [3FA999999999999A]
-stab=0.443175596528242 [3FDC5CFD2D5E5780]
+stab=0.44322174400235587 [3FDC5DBEBBD76FDD]
att=4 [4010000000000000]
fired[
altalena
@@ -119,7 +119,7 @@ chosen{
appt{
under=;
map[
-mapturn=0001-01-01:0;
+mapturn=1951-08-15:1;
over=mvp_ended
city{
hadera=12,5,26,5,0,c0 [0000000000000000]
@@ -131,7 +131,7 @@ city{
rishon_lezion=10,5,22,5,0,c0 [0000000000000000]
rosh_pinna=1,0,2,0,0,c0 [0000000000000000]
safed=2,1,5,1,0,c0 [0000000000000000]
- tel_aviv=248,106,540,106,4,c0 [0000000000000000]
+ tel_aviv=273,106,540,106,4,c0 [0000000000000000]
tiberias=6,2,13,2,0,c0 [0000000000000000]
zikhron_yaakov=2,1,4,1,0,c0 [0000000000000000]
units[
@@ -151,7 +151,14 @@ site{
reim=done,1950-06-15
reim_field=done,1951-06-15
tzrifin=done,1951-12-15
-next=2
+cproj[
+ 2:housing@tel_aviv,-4,20/done,1949-08-15
+ 3:housing@tel_aviv,-3,19/done,1950-02-15
+ 4:housing@tel_aviv,-3,20/done,1950-08-15
+ 5:housing@tel_aviv,-2,18/done,1951-02-15
+ 6:housing@tel_aviv,-2,19/done,1951-08-15
+ 7:housing@haifa,4,9/1
+next=8
obj{
first_new_yishuv=1950-03-15
score=100
diff --git a/sim/Statecraft.Sim.Tests/golden/manifest.txt b/sim/Statecraft.Sim.Tests/golden/manifest.txt
index edf9442fb..238eda44b 100644
--- a/sim/Statecraft.Sim.Tests/golden/manifest.txt
+++ b/sim/Statecraft.Sim.Tests/golden/manifest.txt
@@ -2,10 +2,10 @@
# Tests read this file. To accept a deliberate change: STATECRAFT_UPDATE_GOLDEN=1 dotnet test sim/Statecraft.sln
# rewrites this file, the snapshots and the GoldenRun.cs constants; then update docs/determinism.md and tools/web_check.py
# (GoldenManifestTests names any place that is out of date) and add a row to the rebaseline history.
-hash1950 69ac13846f1420619e9578b119f56e8927e64eb472b8c4f14f2a8d0dc4f70eb1
-hash1952 b34faec68a0a76fc046c6015fbfbfe70a2c56258a71b021214522d0a30379d04
+hash1950 9922495a92307f87d7b5338cd8501fb60ad0424ea6b19ef2d1ec55c44a8bdfb8
+hash1952 548a6acce93c677f566e7d6febdeb50ed6aeba0e4f61a884708ef0fc38774d87
smoke5 3005405d64abc6e7418fa1f0d35c36ce5f64ed3af7c5a4c24a73d5dfdb16121f
scenario-reckless 8041988a2c6b5b72a8351fd79ab07c2afca0672f686586cc8b7f9777c2061038
scenario-cautious 6507ddc31437eaf8b0a8858a84c539860dcd7a6febacb0f1d142cb59489e2a9f
scenario-mvp-absorb-first a77a8f20063c741a680a964e3824946dfee27b5675b9cead5e23bbf4bd146183
-mvp-end b34faec68a0a76fc046c6015fbfbfe70a2c56258a71b021214522d0a30379d04
+mvp-end 548a6acce93c677f566e7d6febdeb50ed6aeba0e4f61a884708ef0fc38774d87
diff --git a/sim/Statecraft.Sim.Tests/golden/mvp-end.txt b/sim/Statecraft.Sim.Tests/golden/mvp-end.txt
index 79950825e..a8b700821 100644
--- a/sim/Statecraft.Sim.Tests/golden/mvp-end.txt
+++ b/sim/Statecraft.Sim.Tests/golden/mvp-end.txt
@@ -3,7 +3,7 @@ ind{
food_supply=0.8556594723429 [3FEB618FF947363F]
housing=0.08504947742483628 [3FB5C5CD7414E141]
intl_standing=0.8300000000000003 [3FEA8F5C28F5C292]
- morale=0.49156077649131324 [3FDF75BB54C1B318]
+ morale=0.4915607767294802 [3FDF75BB55032A9A]
security=0.5061322526321603 [3FE0323C441030A6]
pol{
border_settlement=0.2 [3FC999999999999A]
@@ -14,7 +14,7 @@ eff{
border_villages_secure=0.04113225263216018 [3FA50F495FBB5C36]
building_houses=0.08504947742483629 [3FB5C5CD7414E142]
food_lifts_cohesion=0.08899999973526929 [3FB6C8B43834FD50]
- homes_lift_morale=0.012767196348836194 [3F8A25B0163D2852]
+ homes_lift_morale=0.01276719658700311 [3F8A25B01E6C188A]
rationing_feeds=0.3399999999208376 [3FD5C28F5C133334]
rationing_grates=-0.15 [BFC3333333333333]
safety_lifts_morale=0.05054370052651369 [3FA9E0DD298F75A0]
@@ -45,11 +45,11 @@ sit[
fx_crisis
housing_crisis
treasury=0 [0000000000000000]
-debt=187.89012071283815 [40677C7BDE6EE43A]
+debt=223.89012071283815 [406BFC7BDE6EE43A]
fx=-12.990431328096559 [C029FB19D0A63796]
rung=2;cf=0;
mob=0.05 [3FA999999999999A]
-stab=0.443175596528242 [3FDC5CFD2D5E5780]
+stab=0.44322174400235587 [3FDC5DBEBBD76FDD]
att=4 [4010000000000000]
fired[
altalena
@@ -119,7 +119,7 @@ chosen{
appt{
under=;
map[
-mapturn=0001-01-01:0;
+mapturn=1951-08-15:1;
over=mvp_ended
city{
hadera=12,5,26,5,0,c0 [0000000000000000]
@@ -131,7 +131,7 @@ city{
rishon_lezion=10,5,22,5,0,c0 [0000000000000000]
rosh_pinna=1,0,2,0,0,c0 [0000000000000000]
safed=2,1,5,1,0,c0 [0000000000000000]
- tel_aviv=248,106,540,106,4,c0 [0000000000000000]
+ tel_aviv=273,106,540,106,4,c0 [0000000000000000]
tiberias=6,2,13,2,0,c0 [0000000000000000]
zikhron_yaakov=2,1,4,1,0,c0 [0000000000000000]
units[
@@ -151,7 +151,14 @@ site{
reim=done,1950-06-15
reim_field=done,1951-06-15
tzrifin=done,1951-12-15
-next=2
+cproj[
+ 2:housing@tel_aviv,-4,20/done,1949-08-15
+ 3:housing@tel_aviv,-3,19/done,1950-02-15
+ 4:housing@tel_aviv,-3,20/done,1950-08-15
+ 5:housing@tel_aviv,-2,18/done,1951-02-15
+ 6:housing@tel_aviv,-2,19/done,1951-08-15
+ 7:housing@haifa,4,9/1
+next=8
obj{
first_new_yishuv=1950-03-15
score=100
diff --git a/sim/Statecraft.Sim/AttentionSystem.cs b/sim/Statecraft.Sim/AttentionSystem.cs
index b8d72bc46..554422b3a 100644
--- a/sim/Statecraft.Sim/AttentionSystem.cs
+++ b/sim/Statecraft.Sim/AttentionSystem.cs
@@ -7,11 +7,11 @@ namespace Statecraft.Sim
public static class AttentionSystem
{
static readonly HashSet<string> Kinds = new HashSet<string>
- { "set_policy", "allocate_budget", "choose_event_option", "set_mobilization", "security_order", "appoint", "map_action", "assign_workers", "train", "cancel_training", "pioneer_work", "stop_work" };
+ { "set_policy", "allocate_budget", "choose_event_option", "set_mobilization", "security_order", "appoint", "map_action", "assign_workers", "train", "cancel_training", "pioneer_work", "stop_work", "start_project", "cancel_project" };
/// <summary>The kinds only the GDD v0.1 loop runs. Rules price them only when systems.loop is gdd, and the legacy loop
/// refuses them before charging Attention.</summary>
- static readonly HashSet<string> GddKinds = new HashSet<string> { "assign_workers", "train", "cancel_training", "pioneer_work", "stop_work" };
+ static readonly HashSet<string> GddKinds = new HashSet<string> { "assign_workers", "train", "cancel_training", "pioneer_work", "stop_work", "start_project", "cancel_project" };
public static IReadOnlyCollection<string> CommandKinds => Kinds;
diff --git a/sim/Statecraft.Sim/Commands.cs b/sim/Statecraft.Sim/Commands.cs
index 2202d9417..fb3d15276 100644
--- a/sim/Statecraft.Sim/Commands.cs
+++ b/sim/Statecraft.Sim/Commands.cs
@@ -103,6 +103,24 @@ namespace Statecraft.Sim
public StopWork(int unit) { Unit = unit; }
}
+ /// <summary>Starts city project <see cref="ProjectKind"/> (a projects.yaml id) for <see cref="City"/> on hex (<see cref="Q"/>,
+ /// <see cref="R"/>) (Projects.StartCity, R-PROJ-001). GDD v0.1 loop only.</summary>
+ public sealed class StartProject : Command
+ {
+ public override string Kind => Projects.StartProjectKind;
+ public string ProjectKind { get; } public string City { get; } public int Q { get; } public int R { get; }
+ public StartProject(string projectKind, string city, int q, int r) { ProjectKind = projectKind; City = city; Q = q; R = r; }
+ }
+
+ /// <summary>Cancels city project <see cref="Project"/> while it is being built: the Money spent is not returned
+ /// (Projects.CancelCity, R-PROJ-002, D-A3). GDD v0.1 loop only.</summary>
+ public sealed class CancelProject : Command
+ {
+ public override string Kind => Projects.CancelProjectKind;
+ public int Project { get; }
+ public CancelProject(int project) { Project = project; }
+ }
+
public sealed class Rejection
{
public Command Command { get; } public string Reason { get; }
@@ -136,6 +154,8 @@ namespace Statecraft.Sim
case CancelTraining _: break;
case PioneerWork p: Text(p.Action, "Action"); Text(p.Site, "Site"); break;
case StopWork _: break;
+ case StartProject p: Text(p.ProjectKind, "ProjectKind"); Text(p.City, "City"); break;
+ case CancelProject _: break;
case SetMobilization _: case SecurityOrder _: break;
default: throw new ArgumentException("unknown command type " + cmd.GetType().Name, "commands");
}
diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.cs
index 07040104b..a4b8c9235 100644
--- a/sim/Statecraft.Sim/Content.cs
+++ b/sim/Statecraft.Sim/Content.cs
@@ -521,6 +521,25 @@ namespace Statecraft.Sim
public double? OverflowConditionLoss { get; set; }
}
+ /// <summary>A kind of city project (projects.yaml; GDD "Cities and construction"; R-PROJ-001 to R-PROJ-003): permanent
+ /// housing, the transit camp (D-D3, Q-HOUSE-3) or industry. Every number is a design value (Q-PROJ-1).</summary>
+ public sealed class ProjectKind
+ {
+ public string Id { get; set; } = "";
+ /// <summary>The phrase the player reads in a sentence ("a transit camp").</summary>
+ public string Name { get; set; } = "";
+ /// <summary>IL millions, paid in full at the start (Q-PROJ-1).</summary>
+ public double Cost { get; set; }
+ /// <summary>Turns to build, the turn of the order the first (D-A3).</summary>
+ public int Turns { get; set; }
+ /// <summary>Housing capacity added to the city when done, in population units.</summary>
+ public int Capacity { get; set; }
+ /// <summary>The change to the city's housing condition when done (R-HOUSE-001; kept from 0 to 1).</summary>
+ public double Condition { get; set; }
+ /// <summary>Job slots added to the city when done, in population units.</summary>
+ public int JobSlots { get; set; }
+ }
+
/// <summary>A designated site (sites.yaml; docs/GDD.md "Pioneer work": building is allowed only at designated spots, and a
/// new yishuv takes its site's name). Sourced facts only: the balance values of building are rules (MvpRules).</summary>
public sealed class Site
@@ -972,6 +991,8 @@ namespace Statecraft.Sim
public List<UnitType> UnitTypes = new List<UnitType>();
/// <summary>The GDD designated sites (sites.yaml), in file order. Empty in the legacy loop.</summary>
public List<Site> Sites = new List<Site>();
+ /// <summary>The GDD city project kinds (projects.yaml), in file order. Empty in the legacy loop.</summary>
+ public List<ProjectKind> ProjectKinds = new List<ProjectKind>();
/// <summary>The objectives (objectives.yaml), ordered by id. Read in both loops, since their cards are events; only the
/// GDD loop completes them. Empty when the content has no objectives.yaml.</summary>
public List<Objective> Objectives = new List<Objective>();
diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.cs
index a065413cf..2848192c9 100644
--- a/sim/Statecraft.Sim/ContentLoader.cs
+++ b/sim/Statecraft.Sim/ContentLoader.cs
@@ -48,6 +48,7 @@ namespace Statecraft.Sim
sealed class CitiesFile { public List<CityStart> Cities { get; set; } = new List<CityStart>(); }
sealed class UnitTypesFile { public List<UnitType> Types { get; set; } = new List<UnitType>(); }
sealed class SitesFile { public List<Site> Sites { get; set; } = new List<Site>(); }
+ sealed class ProjectsFile { public List<ProjectKind> Projects { get; set; } = new List<ProjectKind>(); }
sealed class ObjectivesFile { public List<Objective> Objectives { get; set; } = new List<Objective>(); }
public const string HexesFile = "map/hexes.json";
@@ -358,6 +359,7 @@ namespace Statecraft.Sim
c.Cities = Read<CitiesFile>(readFile, "cities.yaml").Cities;
c.UnitTypes = Read<UnitTypesFile>(readFile, "unit_types.yaml").Types;
c.Sites = Read<SitesFile>(readFile, "sites.yaml").Sites; // sourced facts (Phase 1 PR 5)
+ c.ProjectKinds = Read<ProjectsFile>(readFile, "projects.yaml").Projects; // design values (Phase 3 PR 4)
ValidateGdd(c, settlementIds);
}
EventRules.ValidateStructured(c); // R-EFX-006: after the GDD records it names are read
@@ -1119,6 +1121,7 @@ namespace Statecraft.Sim
ValidateSites(c);
ValidateObjectiveSites(c);
ValidateEventSites(c);
+ ValidateProjects(c);
}
/// <summary>An event's site (R-SWAMP-002): a designated swamp site, whose works the event is about. Only the GDD loop
@@ -1134,6 +1137,25 @@ namespace Statecraft.Sim
}
}
+ /// <summary>The city project kinds (projects.yaml, R-PROJ-001): unique ids, a name, a cost and turns, and what each adds.
+ /// The values are design values (Q-PROJ-1); the checks keep a typo from building a project that never finishes, costs
+ /// less than nothing or moves a condition out of its 0 to 1 scale in one step.</summary>
+ static void ValidateProjects(Content c)
+ {
+ const string pf = "projects.yaml";
+ Unique(pf, "projects", c.ProjectKinds.Select(x => x.Id));
+ foreach (var x in c.ProjectKinds)
+ {
+ var at = $"projects[{x.Id}]";
+ if (string.IsNullOrWhiteSpace(x.Name)) throw new ContentException(pf, at + ".name", "is required");
+ if (!(x.Cost >= 0 && !double.IsInfinity(x.Cost))) throw new ContentException(pf, at + ".cost", "must be a finite non-negative number");
+ if (x.Turns < 1) throw new ContentException(pf, at + ".turns", "must be at least 1");
+ if (x.Capacity < 0) throw new ContentException(pf, at + ".capacity", "must not be negative");
+ if (x.JobSlots < 0) throw new ContentException(pf, at + ".job_slots", "must not be negative");
+ if (!(x.Condition >= -1 && x.Condition <= 1)) throw new ContentException(pf, at + ".condition", "must be a number from -1 to 1");
+ }
+ }
+
/// <summary>An objective's site (R-OBJ-001): a designated site of kind yishuv, whose sourced founding date is the
/// objective's reference date, so the card and the site cannot disagree. Only the GDD loop reads sites.yaml, so only
/// it can check this; EventRules checks the rest of objectives.yaml in both loops.</summary>
diff --git a/sim/Statecraft.Sim/GameState.cs b/sim/Statecraft.Sim/GameState.cs
index 6229e8813..496e75682 100644
--- a/sim/Statecraft.Sim/GameState.cs
+++ b/sim/Statecraft.Sim/GameState.cs
@@ -66,7 +66,9 @@ namespace Statecraft.Sim
public SortedList<int, Cohort> Cohorts = new SortedList<int, Cohort>();
/// <summary>The designated sites being built or built, by site id (ordinal; R-SITE-001). An available site has no record.</summary>
public SortedDictionary<string, SiteWork> Sites = new SortedDictionary<string, SiteWork>(StringComparer.Ordinal);
- /// <summary>The next id a new unit or training cohort takes (they share it). Ids are never reused.</summary>
+ /// <summary>The city projects being built or built, by id (R-PROJ-001). A cancelled project leaves.</summary>
+ public SortedList<int, CityProject> CityProjects = new SortedList<int, CityProject>();
+ /// <summary>The next id a new unit, training cohort or city project takes (they share it). Ids are never reused.</summary>
public int NextId;
/// <summary>The date each completed objective was completed, by objective id (ordinal).</summary>
public SortedDictionary<string, DateTime> Objectives = new SortedDictionary<string, DateTime>(StringComparer.Ordinal);
@@ -101,6 +103,7 @@ namespace Statecraft.Sim
c.Units = new SortedList<int, Unit>(Units);
c.Cohorts = new SortedList<int, Cohort>(Cohorts);
c.Sites = new SortedDictionary<string, SiteWork>(Sites, StringComparer.Ordinal);
+ c.CityProjects = new SortedList<int, CityProject>(CityProjects);
c.Objectives = new SortedDictionary<string, DateTime>(Objectives, StringComparer.Ordinal);
return c;
}
@@ -188,6 +191,7 @@ namespace Statecraft.Sim
if (Units.Count > 0) Section("units", '[', ']', Units.Values.Select(x => x.Canonical()));
if (Cohorts.Count > 0) Section("train", '[', ']', Cohorts.Values.Select(x => x.Canonical()));
if (Sites.Count > 0) Section("site", '{', '}', Sites.Values.Select(x => x.Canonical()));
+ if (CityProjects.Count > 0) Section("cproj", '[', ']', CityProjects.Values.Select(x => x.Canonical()));
if (NextId != 0) { Sep(); Nl(); sb.Append("next=").Append(NextId.ToString(CultureInfo.InvariantCulture)); }
if (Objectives.Count > 0)
Section("obj", '{', '}', Objectives.Select(kv => kv.Key + "=" + kv.Value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)));
diff --git a/sim/Statecraft.Sim/GddState.cs b/sim/Statecraft.Sim/GddState.cs
index 627752305..6892f2a7b 100644
--- a/sim/Statecraft.Sim/GddState.cs
+++ b/sim/Statecraft.Sim/GddState.cs
@@ -127,4 +127,36 @@ namespace Statecraft.Sim
? Site + "=done," + on.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)
: string.Format(CultureInfo.InvariantCulture, "{0}=b,{1},{2}", Site, Unit, TurnsLeft);
}
+
+ /// <summary>A city project (projects.yaml; R-PROJ-001 to R-PROJ-003): <see cref="Kind"/> built for <see cref="City"/> on hex
+ /// (<see cref="Q"/>, <see cref="R"/>) with <see cref="TurnsLeft"/> more turns to go, or, once <see cref="BuiltOn"/> is set,
+ /// built on that date (its capacity, condition and slots added then, once). A built project keeps its record, so its hex
+ /// stays taken (Q-PROJ-2) and the map can draw it (Phase 3 PR 8). No workers (Q-PROJ-3). Immutable; a change replaces the
+ /// record.</summary>
+ public sealed class CityProject
+ {
+ public int Id { get; }
+ public string Kind { get; }
+ public string City { get; }
+ public int Q { get; }
+ public int R { get; }
+ public int TurnsLeft { get; }
+ /// <summary>The end date of the turn the project was built on; null while it is being built.</summary>
+ public DateTime? BuiltOn { get; }
+
+ public CityProject(int id, string kind, string city, int q, int r, int turnsLeft, DateTime? builtOn = null)
+ {
+ Id = id; Kind = kind; City = city; Q = q; R = r; TurnsLeft = turnsLeft; BuiltOn = builtOn;
+ }
+
+ /// <summary>The same project with <paramref name="turnsLeft"/> turns to go.</summary>
+ public CityProject WithTurnsLeft(int turnsLeft) => new CityProject(Id, Kind, City, Q, R, turnsLeft);
+
+ /// <summary>The same project, built on <paramref name="on"/>.</summary>
+ public CityProject Built(DateTime on) => new CityProject(Id, Kind, City, Q, R, 0, on);
+
+ /// <summary>The record as the state hash writes it: "id:KIND@CITY,Q,R/TURNSLEFT" while building, "/done,yyyy-MM-dd" once built.</summary>
+ public string Canonical() => string.Format(CultureInfo.InvariantCulture, "{0}:{1}@{2},{3},{4}/", Id, Kind, City, Q, R)
+ + (BuiltOn is DateTime on ? "done," + on.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) : TurnsLeft.ToString(CultureInfo.InvariantCulture));
+ }
}
diff --git a/sim/Statecraft.Sim/GoldenRun.cs b/sim/Statecraft.Sim/GoldenRun.cs
index fef820d03..66a02dac5 100644
--- a/sim/Statecraft.Sim/GoldenRun.cs
+++ b/sim/Statecraft.Sim/GoldenRun.cs
@@ -16,13 +16,13 @@ namespace Statecraft.Sim
/// <summary>Final hash of Play(content, Until1950). Changing it is a deliberate rules or content change: the value
/// is pinned in sim/Statecraft.Sim.Tests/golden/manifest.txt, and STATECRAFT_UPDATE_GOLDEN=1 dotnet test rewrites
/// both (docs/determinism.md). Say why in the commit message.</summary>
- public const string Hash1950 = "69ac13846f1420619e9578b119f56e8927e64eb472b8c4f14f2a8d0dc4f70eb1";
+ public const string Hash1950 = "9922495a92307f87d7b5338cd8501fb60ad0424ea6b19ef2d1ec55c44a8bdfb8";
public static readonly DateTime Until1950 = new DateTime(1950, 1, 1);
/// <summary>Final hash of Play(content, Until1952): the M3 content range (to 31 December 1951). The GDD game ends on
/// 15 January 1952 (R-LOOP-004), the first turn on or after Until1952, so this is also the mvp-end run.</summary>
- public const string Hash1952 = "b34faec68a0a76fc046c6015fbfbfe70a2c56258a71b021214522d0a30379d04";
+ public const string Hash1952 = "548a6acce93c677f566e7d6febdeb50ed6aeba0e4f61a884708ef0fc38774d87";
public static readonly DateTime Until1952 = new DateTime(1952, 1, 1);
diff --git a/sim/Statecraft.Sim/Projects.cs b/sim/Statecraft.Sim/Projects.cs
index 46c7fdc60..fdb8b1f4e 100644
--- a/sim/Statecraft.Sim/Projects.cs
+++ b/sim/Statecraft.Sim/Projects.cs
@@ -14,6 +14,9 @@ namespace Statecraft.Sim
{
public const string PioneerKind = "pioneer_work";
public const string StopKind = "stop_work";
+ /// <summary>The command kinds of the city projects (R-PROJ-001, R-PROJ-002).</summary>
+ public const string StartProjectKind = "start_project";
+ public const string CancelProjectKind = "cancel_project";
/// <summary>The one pioneer action Phase 1 has (GDD "Pioneer work": "Build yishuv").</summary>
public const string BuildYishuv = "build_yishuv";
/// <summary>The pioneer action that builds a military camp or a Hakhshara, as the site's kind says (GDD "Pioneer work":
@@ -162,5 +165,88 @@ namespace Statecraft.Sim
if (promoted) why.Add(new Cause("map", w.Site, 1, "A group of halutzim became veteran pioneers"));
}
}
+
+ /// <summary>The city project at hex (q, r), being built or built, or null (Q-PROJ-2: one project or placement a hex).</summary>
+ public static CityProject? CityProjectAt(GameState s, int q, int r) => s.CityProjects.Values.FirstOrDefault(p => p.Q == q && p.R == r);
+
+ /// <summary>R-PROJ-001: null when city project <paramref name="kind"/> may be started for <paramref name="city"/> on hex
+ /// (q, r) now, else the reason. Refused for an unknown kind or city; a transit camp without the ma'abarot policy
+ /// (Q-HOUSE-3, D-D3: the policy carries its sourced date); a hex that is not land, is further than
+ /// map_action_max_distance from the city's settlement hex, or holds a placement or another city project (Q-PROJ-2); and
+ /// once map_actions_per_turn map actions and city projects together were started this turn (Q-PROJ-4). A short
+ /// Treasury is not a reason: it borrows (Q-MONEY-3). The reference player asks this before it orders.</summary>
+ public static string? CheckCity(Content c, GameState s, string kind, string city, int q, int r)
+ {
+ var k = c.ProjectKinds.FirstOrDefault(x => x.Id == kind);
+ if (k == null) return "There is no such city project";
+ if (!s.Cities.ContainsKey(city)) return "There is no such city";
+ if (kind == MapActions.TransitCamp && !(s.Policies.TryGetValue(MapActions.MaabarotPolicy, out var m) && m >= 0.5))
+ return "Transit camps need the ma'abarot policy";
+ var hex = c.HexAt(q, r);
+ if (hex == null || !hex.Land) return "This hex is not land";
+ var rules = c.RulesAt(s.Date); // the era the turn starts in
+ var home = c.SettlementHexes.First(h => h.Id == city); // every city has one (ValidateGdd)
+ var max = rules.MapActionMaxDistance;
+ var name = PlayerText.Settlement(c, city);
+ if (MapActions.Distance(q, r, home.Q, home.R) > max)
+ return FormattableString.Invariant($"This hex is more than {max} {(max == 1 ? "hex" : "hexes")} from {name}");
+ if (MapActions.At(s, q, r) is Placement placed) return $"This hex already has {PlayerText.MapAction(c, placed.Action)}";
+ if (CityProjectAt(s, q, r) is CityProject other) return $"This hex already has {c.ProjectKinds.First(x => x.Id == other.Kind).Name}";
+ // Last, as for map actions, so a player over the cap still sees the specific reason an order is illegal. The count
+ // is the map actions' own (one national limit, Q-PROJ-4).
+ if ((s.MapActionsTurnDate == s.Date ? s.MapActionsThisTurn : 0) >= rules.MapActionsPerTurn)
+ return FormattableString.Invariant($"No more than {rules.MapActionsPerTurn} map actions and city projects in one turn");
+ return null;
+ }
+
+ /// <summary>R-PROJ-001: starts city project <paramref name="kind"/> for <paramref name="city"/> on hex (q, r), or returns
+ /// the reason (<see cref="CheckCity"/>; state untouched). The Treasury pays the kind's cost now and borrows what it lacks
+ /// (Q-PROJ-1, Q-MONEY-3); the project takes the next id and the kind's turns, the turn of the order the first (D-A3). It
+ /// needs no workers (Q-PROJ-3). Step has already refused it in the legacy loop.</summary>
+ public static string? StartCity(Content c, GameState s, string kind, string city, int q, int r, List<Cause> why)
+ {
+ var reason = CheckCity(c, s, kind, city, q, r);
+ if (reason != null) return reason;
+ var k = c.ProjectKinds.First(x => x.Id == kind);
+ if (s.MapActionsTurnDate != s.Date) { s.MapActionsTurnDate = s.Date; s.MapActionsThisTurn = 0; }
+ s.MapActionsThisTurn++;
+ var name = PlayerText.Settlement(c, city);
+ EconomySystem.PayOrBorrow(c, s, k.Cost, "to build " + k.Name, why);
+ var id = s.NextId++;
+ s.CityProjects.Add(id, new CityProject(id, kind, city, q, r, k.Turns));
+ why.Add(new Cause("city", city, 1, $"{name}: {k.Name} began, cost {PlayerText.Money(c, "treasury", k.Cost)}"));
+ return null;
+ }
+
+ /// <summary>R-PROJ-002 (D-A3): city project <paramref name="project"/> leaves the state; the Money spent is not returned,
+ /// and with no workers (Q-PROJ-3) there are no people to return. Refused, state untouched, for a project that does not
+ /// exist or is built. Step has already refused it in the legacy loop.</summary>
+ public static string? CancelCity(Content c, GameState s, int project, List<Cause> why)
+ {
+ if (!s.CityProjects.TryGetValue(project, out var p)) return "There is no such city project";
+ var k = c.ProjectKinds.First(x => x.Id == p.Kind);
+ if (p.BuiltOn != null) return $"{PlayerText.Capitalised(k.Name)} is already built";
+ s.CityProjects.Remove(project);
+ why.Add(new Cause("city", p.City, -1, $"{PlayerText.Settlement(c, p.City)}: {k.Name} was cancelled; the Money spent is not returned"));
+ return null;
+ }
+
+ /// <summary>R-PROJ-003, step 5 of the turn (D-A6), after the pioneer work: in ascending id, each city project being built
+ /// has one turn less to go. One that reaches 0 is built on <paramref name="next"/>, the turn's end date, and adds its
+ /// kind's housing capacity, condition (kept from 0 to 1) and job slots to its city, once: a built project is never
+ /// advanced again.</summary>
+ public static void AdvanceCity(Content c, GameState s, DateTime next, List<Cause> why)
+ {
+ foreach (var p in s.CityProjects.Values.Where(x => x.BuiltOn == null).ToList())
+ {
+ if (p.TurnsLeft > 1) { s.CityProjects[p.Id] = p.WithTurnsLeft(p.TurnsLeft - 1); continue; }
+ s.CityProjects[p.Id] = p.Built(next);
+ var k = c.ProjectKinds.First(x => x.Id == p.Kind);
+ var x = s.Cities[p.City];
+ var condition = x.Condition is double now ? Math.Min(1.0, Math.Max(0.0, now + k.Condition)) : (double?)null;
+ s.Cities[p.City] = new City(x.Id, x.HousingCapacity + k.Capacity, x.JobSlots + k.JobSlots, x.Civilians, x.Employed, x.Refugees, x.Recruits, condition);
+ why.Add(new Cause("city", p.City, 1, $"{PlayerText.Settlement(c, p.City)}: {k.Name} was finished"));
+ }
+ }
}
}
diff --git a/sim/Statecraft.Sim/Reference/ReferencePlayer.cs b/sim/Statecraft.Sim/Reference/ReferencePlayer.cs
index 5952a9fd3..2dd45efe5 100644
--- a/sim/Statecraft.Sim/Reference/ReferencePlayer.cs
+++ b/sim/Statecraft.Sim/Reference/ReferencePlayer.cs
@@ -5,7 +5,8 @@ using System.Linq;
namespace Statecraft.Sim.Reference
{
/// <summary>Test policy for the GDD goldens (D-A7): a stated simple policy, not game AI and not historical. It sends
- /// HistoricalAI's orders, then fills each city's jobs with as many civilians as there are jobs, then sends each idle halutz
+ /// HistoricalAI's orders, then fills each city's jobs with as many civilians as there are jobs, then, when no city
+ /// project is being built, starts a housing project in the city with the most overflow that has a hex for it, then sends each idle halutz
/// unit to the first available yishuv site (then to the first ready field, then to the first available camp site), then,
/// when there is no halutz and none in training, trains one halutz group in
/// the first city with a Hakhshara and a civilian left without work, while the turn's Attention lasts (both orders borrow). It lives in Statecraft.Sim only so Unity can replay the goldens (#394; GoldenRun); no game mode or UI may reach it
@@ -25,6 +26,7 @@ namespace Statecraft.Sim.Reference
list.Add(new AssignWorkers(city.Id, "job", want));
left -= cost;
}
+ House(c, s, list, ref left);
var halutz = c.UnitTypes.FirstOrDefault(t => t.Id == "halutz");
if (halutz == null) return list;
Build(c, s, list, ref left);
@@ -41,6 +43,33 @@ namespace Statecraft.Sim.Reference
return list;
}
+ /// <summary>Starts a housing project (R-PROJ-001) when none is being built, in the city with the most overflow (Cities.Overflow; the first
+ /// in ordinal id order on a tie) that has a hex left for it, on the first hex in (q, r) order that Projects.CheckCity accepts, when the turn's
+ /// Attention lasts. It borrows, as the other orders do.</summary>
+ static void House(Content c, GameState s, List<Command> list, ref double left)
+ {
+ var kind = c.ProjectKinds.FirstOrDefault(k => k.Id == MapActions.Housing);
+ // One at a time: the project borrows, and a start every turn would run the debt far past the run's plausibility band
+ // (golden/invariants.yaml debt-grows-through-the-run).
+ if (kind == null || s.CityProjects.Values.Any(p => p.BuiltOn == null)) return; // the legacy loop has no city projects
+ var cost = AttentionSystem.Cost(c, s, Projects.StartProjectKind);
+ if (cost > left + 1e-9) return; // a city project borrows (Q-MONEY-3), so the Treasury does not hold it back
+ var max = c.RulesAt(s.Date).MapActionMaxDistance;
+ // OrderBy is stable, so a tie keeps the cities' ordinal id order.
+ foreach (var city in s.Cities.Values.Where(x => Cities.Overflow(s, x) > 0).OrderByDescending(x => Cities.Overflow(s, x)))
+ {
+ var home = c.SettlementHexes.First(h => h.Id == city.Id);
+ for (int q = home.Q - max; q <= home.Q + max; q++)
+ for (int r = home.R - max; r <= home.R + max; r++)
+ if (Projects.CheckCity(c, s, kind.Id, city.Id, q, r) == null)
+ {
+ list.Add(new StartProject(kind.Id, city.Id, q, r));
+ left -= cost;
+ return;
+ }
+ }
+ }
+
/// <summary>Sends each idle halutz unit, veterans too, in id order, to the first yishuv site without a record, in ordinal id order,
/// and once every yishuv site has one, to plow the first ready field site without a record (R-FIELD-001), and when there
/// is none, to build the first camp site without a record (R-CAMP-001), while the turn's Attention lasts. Pioneer work
diff --git a/sim/Statecraft.Sim/SaveGame.cs b/sim/Statecraft.Sim/SaveGame.cs
index e0f22d023..1974fbbbd 100644
--- a/sim/Statecraft.Sim/SaveGame.cs
+++ b/sim/Statecraft.Sim/SaveGame.cs
@@ -38,7 +38,8 @@ namespace Statecraft.Sim
/// turn starts the next turn's command list (one per Simulation.Step)
/// &lt;command&gt; ... policy ID LEVEL | budget OFFICE=SHARE,... | event ID OPTION | mobilize LEVEL |
/// security DELTA | appoint OFFICE PERSON | map ACTION Q R | work CITY ROLE N |
- /// train CITY TRACK N | untrain COHORT | pioneer UNIT ACTION SITE | stop UNIT
+ /// train CITY TRACK N | untrain COHORT | pioneer UNIT ACTION SITE | stop UNIT |
+ /// project KIND CITY Q R | unproject PROJECT
/// end &lt;hex&gt; GameState.Hash() after the last turn (checks the replay)
/// Doubles are IEEE bit patterns in hex, so replays are exact; strings are percent-escaped (Uri.EscapeDataString).
/// </summary>
@@ -122,6 +123,8 @@ namespace Statecraft.Sim
CancelTraining t => $"untrain {Int(t.Cohort)}",
PioneerWork p => $"pioneer {Int(p.Unit)} {Esc(p.Action)} {Esc(p.Site)}",
StopWork w => $"stop {Int(w.Unit)}",
+ StartProject p => $"project {Esc(p.ProjectKind)} {Esc(p.City)} {Int(p.Q)} {Int(p.R)}",
+ CancelProject p => $"unproject {Int(p.Project)}",
_ => throw new ArgumentException($"Cannot save command kind '{cmd.Kind}'", nameof(cmd)),
};
@@ -215,6 +218,8 @@ namespace Statecraft.Sim
case "untrain": Arity(2); return new CancelTraining(I(f[1]));
case "pioneer": Arity(4); return new PioneerWork(I(f[1]), Str(f[2]), Str(f[3]));
case "stop": Arity(2); return new StopWork(I(f[1]));
+ case "project": Arity(5); return new StartProject(Str(f[1]), Str(f[2]), I(f[3]), I(f[4]));
+ case "unproject": Arity(2); return new CancelProject(I(f[1]));
default: throw new SaveException(line, $"unknown command '{f[0]}'");
}
}
diff --git a/sim/Statecraft.Sim/Scenario.cs b/sim/Statecraft.Sim/Scenario.cs
index 1f177c509..a036221c6 100644
--- a/sim/Statecraft.Sim/Scenario.cs
+++ b/sim/Statecraft.Sim/Scenario.cs
@@ -65,6 +65,7 @@ namespace Statecraft.Sim
["map_action"] = new[] { "action", "q", "r" }, ["assign_workers"] = new[] { "city", "role", "count" },
["train"] = new[] { "city", "track", "count" }, ["cancel_training"] = new[] { "cohort" },
["pioneer_work"] = new[] { "unit", "action", "site" }, ["stop_work"] = new[] { "unit" },
+ ["start_project"] = new[] { "project", "city", "q", "r" }, ["cancel_project"] = new[] { "project" },
};
public static IReadOnlyCollection<string> Kinds => Allowed.Keys;
@@ -94,6 +95,8 @@ namespace Statecraft.Sim
case "cancel_training": return new CancelTraining(Whole(c, "cohort"));
case "pioneer_work": return new PioneerWork(Whole(c, "unit"), Str(c, "action"), Str(c, "site"));
case "stop_work": return new StopWork(Whole(c, "unit"));
+ case "start_project": return new StartProject(Str(c, "project"), Str(c, "city"), Whole(c, "q"), Whole(c, "r"));
+ case "cancel_project": return new CancelProject(Whole(c, "project"));
default: throw new InvalidDataException($"command kind '{kind}' has no builder");
}
}
@@ -133,6 +136,7 @@ namespace Statecraft.Sim
SecurityOrder o => o.Delta.ToString(CultureInfo.InvariantCulture), Appoint a => $"{a.Office} {a.Person}", MapAction m => $"{m.Action} {m.Q},{m.R}",
AssignWorkers w => $"{w.City} {w.Role} {w.Count}", Train t => $"{t.City} {t.Track} {t.Count}", CancelTraining t => t.Cohort.ToString(CultureInfo.InvariantCulture),
PioneerWork p => FormattableString.Invariant($"{p.Unit} {p.Action} {p.Site}"), StopWork w => w.Unit.ToString(CultureInfo.InvariantCulture),
+ StartProject p => FormattableString.Invariant($"{p.ProjectKind} {p.City} {p.Q},{p.R}"), CancelProject p => p.Project.ToString(CultureInfo.InvariantCulture),
_ => c.Kind,
};
}
diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.cs
index 85807a577..27b793110 100644
--- a/sim/Statecraft.Sim/Simulation.cs
+++ b/sim/Statecraft.Sim/Simulation.cs
@@ -151,6 +151,10 @@ namespace Statecraft.Sim
return Projects.Start(c, s, p.Unit, p.Action, p.Site, why);
case StopWork w:
return Projects.Stop(c, s, w.Unit, why);
+ case StartProject p:
+ return Projects.StartCity(c, s, p.ProjectKind, p.City, p.Q, p.R, why);
+ case CancelProject p:
+ return Projects.CancelCity(c, s, p.Project, why);
case SecurityOrder o:
// long arithmetic: an extreme delta clamps to the ladder's end instead of wrapping around.
SecuritySystem.SetRung(c, s, (int)Math.Max(1L, Math.Min(5L, (long)s.Rung + o.Delta)), why);
diff --git a/sim/Statecraft.Sim/TurnResolver.cs b/sim/Statecraft.Sim/TurnResolver.cs
index 14c5b5423..eb60ed1e6 100644
--- a/sim/Statecraft.Sim/TurnResolver.cs
+++ b/sim/Statecraft.Sim/TurnResolver.cs
@@ -17,6 +17,7 @@ namespace Statecraft.Sim
// 1-3. Enemy orders, combat, capture: Phase 5.
Training.Progress(c, s, why); // 4. training
Projects.Advance(c, s, next, why); // 5. construction
+ Projects.AdvanceCity(c, s, next, why); // and the city projects (R-PROJ-003)
Cities.Produce(c, s, r, yearFraction, why); // 6. production
Pools.Harvest(c, s, r, why); // and the plowed fields' Food (R-FIELD-002)
Pools.Consume(c, s, r, why); // 7. consumption: the nation eats, then imports (R-FOOD-002)
diff --git a/tools/web_check.py b/tools/web_check.py
index 6792da6d6..d88656061 100644
--- a/tools/web_check.py
+++ b/tools/web_check.py
@@ -8,7 +8,7 @@ fail on a failure line or a timeout. Uses Chrome for Testing from the Playwright
--enable-logging=stderr --v=1 as INFO:CONSOLE... "text", source: ...
Usage (from the repo root):
- uv run tools/web_check.py unity/Builds/Web-disabled --query "golden" --expect "GOLDEN OK hash1950 69ac13846f1420619e9578b119f56e8927e64eb472b8c4f14f2a8d0dc4f70eb1" --expect "GOLDEN OK hash1952 b34faec68a0a76fc046c6015fbfbfe70a2c56258a71b021214522d0a30379d04"
+ uv run tools/web_check.py unity/Builds/Web-disabled --query "golden" --expect "GOLDEN OK hash1950 9922495a92307f87d7b5338cd8501fb60ad0424ea6b19ef2d1ec55c44a8bdfb8" --expect "GOLDEN OK hash1952 548a6acce93c677f566e7d6febdeb50ed6aeba0e4f61a884708ef0fc38774d87"
Options: --query Q (page URL query, without '?'), --expect TEXT (repeatable), --fail REGEX (default: GOLDEN FAIL|SMOKE FAIL|BOOT FAIL),
--timeout SECONDS (default 300), --stall SECONDS (fail when no console message arrives for that long; 0 = off),
--swiftshader (software WebGL when there is no GPU), --dpr N (default 1), --shots DIR (reassemble the player's
diff --git a/unity/Assets/Scripts/UI/SimBridge.cs b/unity/Assets/Scripts/UI/SimBridge.cs
index ae63ff754..d0ccf5742 100644
--- a/unity/Assets/Scripts/UI/SimBridge.cs
+++ b/unity/Assets/Scripts/UI/SimBridge.cs
@@ -59,6 +59,8 @@ namespace Statecraft.Game.UI
CancelTraining x => FormattableString.Invariant($"untrain:{x.Cohort}"),
PioneerWork w => FormattableString.Invariant($"unit:{w.Unit}"),
StopWork w => FormattableString.Invariant($"unit:{w.Unit}"),
+ StartProject p => FormattableString.Invariant($"project:{p.Q},{p.R}"),
+ CancelProject x => FormattableString.Invariant($"unproject:{x.Project}"),
_ => c.Kind,
};
@@ -110,6 +112,11 @@ namespace Statecraft.Game.UI
return Unknown("unit", w.Unit.ToString(System.Globalization.CultureInfo.InvariantCulture), State.Units.Keys.Select(k => k.ToString(System.Globalization.CultureInfo.InvariantCulture)))
?? Unknown("pioneer_work", w.Action, new[] { Projects.BuildYishuv }) ?? Unknown("site", w.Site, Content.Sites.Select(x => x.Id));
case StopWork w: return Unknown("unit", w.Unit.ToString(System.Globalization.CultureInfo.InvariantCulture), State.Units.Keys.Select(k => k.ToString(System.Globalization.CultureInfo.InvariantCulture)));
+ // City projects (#735): ids only; the sim refuses a far or taken hex, the policy gate and the turn's limit itself.
+ case StartProject p:
+ return Unknown("city_project", p.ProjectKind, Content.ProjectKinds.Select(x => x.Id)) ?? Unknown("city", p.City, Content.Cities.Select(x => x.Id));
+ case CancelProject x:
+ return Unknown("city_project", x.Project.ToString(System.Globalization.CultureInfo.InvariantCulture), State.CityProjects.Keys.Select(k => k.ToString(System.Globalization.CultureInfo.InvariantCulture)));
default: return text["order.invalid"];
}
}
diff --git a/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs b/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs
index 9d2ec1aa7..63e2030bc 100644
--- a/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs
+++ b/unity/Assets/Tests/EditMode/SimBridgeGuardTests.cs
@@ -31,6 +31,8 @@ public class SimBridgeGuardTests
[typeof(CancelTraining)] = new CancelTraining(1),
[typeof(PioneerWork)] = new PioneerWork(1, "build_yishuv", "mefalsim"),
[typeof(StopWork)] = new StopWork(1),
+ [typeof(StartProject)] = new StartProject("housing", "tel_aviv", 1, 0),
+ [typeof(CancelProject)] = new CancelProject(1),
};
static IEnumerable<Type> CommandTypes() =>
diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yaml
index da7b92655..b0eaf5391 100644
--- a/unity/Assets/UI/strings.en.yaml
+++ b/unity/Assets/UI/strings.en.yaml
@@ -101,6 +101,7 @@ order.kind.cohort: "cohort"
order.kind.unit: "unit"
order.kind.pioneer_work: "pioneer work"
order.kind.site: "site"
+order.kind.city_project: "city project"
order.invalid: "That order is not valid"
order.failed: "The turn could not run. Your orders were cleared. Give them again."
defence.rung1: "1 Routine threat: border incidents, deterrence upkeep"
diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yaml
index abd4ea70f..f186ecb4e 100644
--- a/unity/Assets/UI/strings.he.yaml
+++ b/unity/Assets/UI/strings.he.yaml
@@ -98,6 +98,8 @@ order.kind.cohort: "מחזור הכשרה"
order.kind.unit: "יחידה"
order.kind.pioneer_work: "עבודה חלוצית"
order.kind.site: "אתר"
+# A city project (#735; Q-UI-2's approved "מיזם דיור" for housing, with עירוני for any kind). For the native reviewer (#564).
+order.kind.city_project: "מיזם עירוני"
order.invalid: "הפקודה אינה תקפה"
# order.failed: the turn failed and SimBridge.EndTurn cleared the queue, so the player gives the orders again (#622;
# maintainer, 15 October 2026). For the native reviewer (#564).