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 2, the immigrants arrive in all twelve cities from the census day (refs #733) (#847)

Berif603c80b1b91
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5acb56f54..fcd2b0391 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,13 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
(he.wiki "גן הנוף הקיבוצי"). Nahalal's moshav ring and the moshavot are unchanged (their renders are pixel-identical),
and no other place moves; inside a kibbutz the hall's lot can take a plot. Yad Mordechai has no hall: no free ground is left near its heart, and a hall pushed to the edge
would take its houses.
+- The GDD game's immigrants arrive in all twelve cities (GDD Phase 3 PR 2, refs #733, #383; R-CITY-003, R-CITY-008),
+ split in proportion to each city's census population, one unit at a time to the largest remainder, ties to the lower
+ id (Q-ARRV-1). They used to land only in Tel Aviv. The cities take arrivals from the census day, 8 November 1948
+ (`mvp.city_arrivals_from`, CBS Statistical Abstract No. 14, Table 11), because their census start values already count
+ the people who came from 15 May: about 78 units were counted twice (Q-ARRV-3). The national head count still takes
+ every arrival from 15 May, so the CBS anchors are unchanged, and a test checks the cities never hold more people than
+ it (Q-ARRV-2). `mvp.arrivals_city` is gone. Every golden moves (docs/determinism.md, rebaseline history).
- The GDD game has its twelve cities (GDD Phase 3 PR 1, refs #732, #383; R-CITY-006, R-CITY-007): `content/cities.yaml`
holds the `city` and `town` rows of the 1948 settlements, each starting from its census population of 8 November 1948
(CBS Statistical Abstract No. 14, Table 11; Zikhron Ya'akov from No. 3; Rosh Pinna from Hebrew Wikipedia, as the owner
diff --git a/content/rules.yaml b/content/rules.yaml
index ae41280fc..d3f00f461 100644
--- a/content/rules.yaml
+++ b/content/rules.yaml
@@ -31,7 +31,10 @@ mvp:
income_per_job_per_year: 0.06 # DESIGN VALUE: owner-set balance, not a historical figure (D-C6: IL millions per employed unit a year)
cohesion_housing_weight: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-C1, until Phase 2 PR 4)
cohesion_jobs_weight: 0.5 # DESIGN VALUE: owner-set balance, not a historical figure (D-C1, until Phase 2 PR 4; the two weights sum to 1)
- arrivals_city: tel_aviv # the MVP has one city so far: every arrival lands there (R-CITY-003)
+ # The day the cities start taking arrivals (R-CITY-003; Q-ARRV-3, owner, 15 October 2026, #375): the census day of their
+ # start values, 8 November 1948 (CBS Statistical Abstract of Israel No. 14, Table 11, pp. 30-31). The census already
+ # counts the people who arrived from 15 May, so the cities take none before it; the national head count takes them all.
+ city_arrivals_from: 1948-11-08 # https://www.cbs.gov.il/he/publications/DocLib/shnaton_saruk/shnaton1963_num14.pdf, checked 2026-10-15
build_yishuv_turns: 6 # DESIGN VALUE: owner-set balance, not a historical figure (D-D6: turns a pioneer build takes)
build_yishuv_cost: 2 # DESIGN VALUE: owner-set balance, not a historical figure (D-D6: IL millions, paid at the start)
objective_points: 100 # DESIGN VALUE: owner-set balance, not a historical figure (D-B6: points per objective)
diff --git a/docs/RELEASING.md b/docs/RELEASING.md
index cabf60215..437ce1003 100644
--- a/docs/RELEASING.md
+++ b/docs/RELEASING.md
@@ -19,9 +19,9 @@ 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 brotli -shareable -logFile "$PWD/unity-build-web-br.log"
git checkout -- unity/Assets/Settings unity/ProjectSettings/ProjectSettings.asset
uv run tools/web_check.py unity/Builds/Web-brotli --query "golden&smoke=5" \
- --expect "GOLDEN OK 1950 ea730229392c12e007cdf30aa8b19e4668bcd1dfdbda0735dd8d7612301d5144" \
- --expect "GOLDEN OK 1952 ca887e45cd413a41d4368c604caa37c3c0e19022195ac614001f7bfc507489ca" \
- --expect "SMOKE OK 5 turns 1948-10-15 4104103f4e52fe4159f7b8d6acab9d2b651cd3c124952cfa74ebfd7333718ad5"
+ --expect "GOLDEN OK 1950 d22b369fa9d269a2311a51ab26ef8e0069c3e55f8febfa0376340dd03e012b8a" \
+ --expect "GOLDEN OK 1952 21029217387d875c8723f0a99e46f199fa3181ba979352ac8200c6d5045e1322" \
+ --expect "SMOKE OK 5 turns 1948-10-15 3f7a0fe0d5f22e83edd00c8a913a8d216b4420c36907b11e2ec9406baecdad56"
bash scripts/oss/package_web.sh unity/Builds/Web-brotli unity/Builds/statecraft-israel-vX.Y.Z-web.zip
```
diff --git a/docs/determinism.md b/docs/determinism.md
index 15c35995c..6792e3165 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 | `ea730229392c12e007cdf30aa8b19e4668bcd1dfdbda0735dd8d7612301d5144` |
-| to 1952-01-01 (`Hash1952`) | 1952-01-15, turn 44 (the game's end) | `ca887e45cd413a41d4368c604caa37c3c0e19022195ac614001f7bfc507489ca` |
-| to the game's end (`mvp-end`) | 1952-01-15, turn 44 | `ca887e45cd413a41d4368c604caa37c3c0e19022195ac614001f7bfc507489ca` |
+| to 1950-01-01 (`Hash1950`) | 1950-01-15, turn 20 | `d22b369fa9d269a2311a51ab26ef8e0069c3e55f8febfa0376340dd03e012b8a` |
+| to 1952-01-01 (`Hash1952`) | 1952-01-15, turn 44 (the game's end) | `21029217387d875c8723f0a99e46f199fa3181ba979352ac8200c6d5045e1322` |
+| to the game's end (`mvp-end`) | 1952-01-15, turn 44 | `21029217387d875c8723f0a99e46f199fa3181ba979352ac8200c6d5045e1322` |
`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
@@ -39,15 +39,15 @@ check `hash1950` and `hash1952`.
A further value is pinned for the browser smoke run (`?smoke=5`: the golden seed, five turns played through the UI's own
buttons, answering each event with its first option while the turn's Attention pays for it, the rest left to their
-ministers): `SMOKE OK 5 turns 1948-10-15 4104103f4e52fe4159f7b8d6acab9d2b651cd3c124952cfa74ebfd7333718ad5`.
+ministers): `SMOKE OK 5 turns 1948-10-15 3f7a0fe0d5f22e83edd00c8a913a8d216b4420c36907b11e2ec9406baecdad56`.
It depends on the UI path as well as the sim (which option is first, the turn grid), so re-record it when either changes.
Check every build with:
```
uv run tools/web_check.py unity/Builds/Web-<compression> --query "golden&smoke=5" \
- --expect "GOLDEN OK 1950 ea730229392c12e007cdf30aa8b19e4668bcd1dfdbda0735dd8d7612301d5144" \
- --expect "GOLDEN OK 1952 ca887e45cd413a41d4368c604caa37c3c0e19022195ac614001f7bfc507489ca" \
- --expect "SMOKE OK 5 turns 1948-10-15 4104103f4e52fe4159f7b8d6acab9d2b651cd3c124952cfa74ebfd7333718ad5"
+ --expect "GOLDEN OK 1950 d22b369fa9d269a2311a51ab26ef8e0069c3e55f8febfa0376340dd03e012b8a" \
+ --expect "GOLDEN OK 1952 21029217387d875c8723f0a99e46f199fa3181ba979352ac8200c6d5045e1322" \
+ --expect "SMOKE OK 5 turns 1948-10-15 3f7a0fe0d5f22e83edd00c8a913a8d216b4420c36907b11e2ec9406baecdad56"
```
**When a golden moves.** The test fails with the lines that changed, grouped by section (`[ind]`, `[pol]`, `[bud]`,
@@ -238,3 +238,10 @@ The hash reads the state keys, so it never sees a record outside its window. An
| GDD Phase 3 PR 1 | scenario-cautious | `5f162f0f` | the twelve cities and the new spending (was `5553c31a`) |
| GDD Phase 3 PR 1 | scenario-reckless | `a10877e2` | same (was `42041362`) |
| GDD Phase 3 PR 1 | scenario-mvp-absorb-first | `53852f2c` | same (was `e01bb37a`) |
+| GDD Phase 3 PR 2 | 1950 | `d22b369f` | GDD Phase 3 PR 2's arrivals over the cities (R-CITY-003, Q-ARRV-1, Q-ARRV-3): the cities take arrivals from the census day, 8 November 1948, not 15 May, so 78 fewer units arrive in them (269 refugees waiting on 1 January 1950, was 347), and they are spread over the twelve cities by census people instead of all landing in Tel Aviv (Tel Aviv 131, Haifa 52, Jerusalem 44). Only the `city{}` section and `coh` move (0.5418, was 0.5106); the national head count, the debt and the reference player's orders do not (was `ea730229`) |
+| GDD Phase 3 PR 2 | 1952 | `21029217` | same; 608 refugees waiting at the end (was 686), Tel Aviv 296 of them; `coh` 0.4364 (was 0.4213) (was `ca887e45`) |
+| GDD Phase 3 PR 2 | mvp-end | `21029217` | same; the same run as hash1952 (was `ca887e45`) |
+| GDD Phase 3 PR 2 | smoke5 | `3f7a0fe0` | the first five turns end before the census day, so the cities take no arrivals in them (was `4104103f`) |
+| GDD Phase 3 PR 2 | scenario-cautious | `a9afb0ad` | the arrivals over the cities; `city{}` and `coh` only (was `5f162f0f`) |
+| GDD Phase 3 PR 2 | scenario-reckless | `8f209d56` | same (was `a10877e2`) |
+| GDD Phase 3 PR 2 | scenario-mvp-absorb-first | `8601da93` | same (was `53852f2c`) |
diff --git a/docs/gdd/cities.md b/docs/gdd/cities.md
index c201ed87b..56057451c 100644
--- a/docs/gdd/cities.md
+++ b/docs/gdd/cities.md
@@ -10,7 +10,7 @@ As a player of the MVP, I want the twelve Jewish cities and towns to start at th
- Each city starts at its census population of 8 November 1948, every field recorded with a status: sourced, derived, wikipedia-only or design (the plan, proposed R-CITY-006 [S2]; the CBS census table [S4]). The owner chose the census values plus defaults for the gaps ("Census values + defaults", the owner on #569, recorded in the plan [S2]), and the census-day count is used as the 15 May 1948 start value.
- People become units at one thousand people per unit, rounding to nearest with a minimum of one unit for any city that has people, so Rosh Pinna starts with one (`Q-START-2`, decided 15 October 2026 [S3]).
- The five cities with a sourced working share start with derived employment [S4]; every other city starts from the national working share of 43.9 percent, its job slots equal its start employed count, and its housing capacity equals its start population (`Q-START-1`, decided 15 October 2026 [S3]).
-- Arrivals spread over the cities in proportion to census population, by cumulative largest-remainder apportionment with an ordinal tie-break (`Q-ARRV-1`, decided 15 October 2026 [S3]). The cities take arrivals only from the census day, while the national head count takes every arrival from 15 May 1948, so no immigrant is counted twice (`Q-ARRV-3`, decided 15 October 2026 [S3]).
+- Arrivals spread over the cities in proportion to census population, by cumulative largest-remainder apportionment with an ordinal tie-break (`Q-ARRV-1`, decided 15 October 2026 [S3]). The units are handed out one at a time, each to the city with the largest remainder, so a growing total never takes a unit back from a city (R-CITY-003). The cities take arrivals only from the census day, while the national head count takes every arrival from 15 May 1948, so no immigrant is counted twice (`Q-ARRV-3`, decided 15 October 2026 [S3]).
- `GameState.Population` stays the one record of the nation's people; the cities are the part placed in towns, and an invariant test checks they never exceed it (`Q-ARRV-2`, decided 15 October 2026 [S3]).
- Housing has per-city capacity and an average condition on a zero-to-one scale (`Q-START-3`). One capacity point houses one unit, and every refugee becomes a civilian on the next housing step (`Q-HOUSE-1`, decided 15 October 2026 [S3]). There is no hard cap: people above capacity are the city's overflow, and overflow lowers condition and Social cohesion (`Q-HOUSE-1` and `Q-HOUSE-2`, decided 15 October 2026 [S3]; D-D1, D-D2). The start condition and the size of the overflow effect are labelled design values taken from the plan's PR zero table (the plan's table merged by #604).
- Two housing types: permanent housing adds capacity and condition from the game's start; the transit camp is cheap, adds capacity and lowers condition, and keeps the ma'abarot policy gate in 1950 (`Q-HOUSE-3`, decided 15 October 2026 [S3]). Residents are assigned automatically, and people in training and recruits count against their city's housing while halutz units do not (`Q-HOUSE-4` and `Q-HOUSE-5`, decided 15 October 2026 [S3]).
diff --git a/docs/gdd/one-city.md b/docs/gdd/one-city.md
index 59437c836..26162a217 100644
--- a/docs/gdd/one-city.md
+++ b/docs/gdd/one-city.md
@@ -10,7 +10,7 @@ As a player of the MVP, I want to put Tel Aviv's people to work and house the im
- `AssignWorkers(city, job, n)` sets how many of the city's civilians work. It is refused, with the state unchanged, for a negative count, more than the city's jobs or civilians, an unknown city or role, or the legacy loop (R-CITY-001). It costs 0.5 Attention (a placeholder) (unitless).
- Each turn resolves in the order the owner approved for the plan's resolution phase (D-A6, #456 [S2][S3]): production, then housing and Social cohesion, then arrivals. A turn's arrivals are housed on the next turn.
- Production: each employed unit earns `income_per_job_per_year` IL millions a year, for the turn's share of a year (R-CITY-002).
-- Arrivals: the CBS series in `content/aliyah.yaml` arrives as refugees in `arrivals_city`, in whole units, counted from the game's start so that no unit is lost or counted twice (R-CITY-003, D-A5 [S2]).
+- Arrivals: the CBS series in `content/aliyah.yaml` arrives as refugees, in whole units, counted cumulatively so that no unit is lost or counted twice (R-CITY-003, D-A5 [S2]). With twelve cities they are spread over all of them: see `cities.md`.
- Housing: refugees become civilians, without a job, up to the city's housing capacity. The cap is a placeholder while D-D1 is open (R-CITY-004).
- Social cohesion: a share from 0% to 100%, the weighted housed share and employed share over all cities (R-CITY-005). No other system reads it; the top bar shows it as a resource meter, in the GDD loop only (the owner's ruling of 15 October 2026 [S4]).
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 1ce171f04..1790b4a2b 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -42,7 +42,9 @@ R-CITY-001: `AssignWorkers(city, role, n)` sets how many of the city's civilians
R-CITY-002: Each turn every city's employed units add `employed * income_per_job_per_year * the turn's share of a year` to the Treasury.
-R-CITY-003: Arrivals from the CBS series (`aliyah.yaml`) become refugees in the rules' `arrivals_city`. Let `P(t)` be the people the series brings from the first era's start to the date `t`, summed over the origin groups in ordinal order. A turn from date `d` to date `e` adds `floor(P(e) / people_per_unit) - floor(P(d) / people_per_unit)` refugees. `people_per_unit` is the same in every era (the loader refuses an era that changes it), so over any run of turns the refugees added are `floor(P(end) / people_per_unit) - floor(P(start) / people_per_unit)`: no unit is lost or counted twice. The legacy population (`GameState.Population`) also counts the same arrivals; the two are separate views of the same people until Phase 3 makes arrivals counts.
+R-CITY-003: Arrivals from the CBS series (`aliyah.yaml`) become refugees in the cities. Let `P(t)` be the people the series brings from `city_arrivals_from` to the date `t` (0 before it), summed over the origin groups in ordinal order. `city_arrivals_from` is 8 November 1948, the census day the cities' start values count: the census already holds the people who arrived from 15 May, so the cities take none before it (Q-ARRV-3, owner, 15 October 2026). The cities' arrived units by `t` are `U(t) = floor(P(t) / people_per_unit)`, and a turn from date `d` to date `e` adds `U(e) - U(d)` refugees over all cities. `people_per_unit` and `city_arrivals_from` are the same in every era (the loader refuses an era that changes either), so over any run of turns the refugees added are `U(end) - U(start)`: no unit is lost or counted twice. The units are split in proportion to the cities' census `people` (Q-ARRV-1): the first `U` units are handed out one at a time, unit `n` to the city with the largest remainder `n * people / total people - units it holds`, a tie to the lower city id (ordinal), and a turn gives each city its share of `U(e)` minus its share of `U(d)`. Building the split up one unit at a time keeps it cumulative: a fresh largest-remainder split of each total could take a unit back from a city as the total grows (the Alabama paradox; on the twelve cities it first happens at 7 units). The loader refuses a GDD game with no city.
+
+R-CITY-008: `GameState.Population` is the one record of the nation's people: it takes every arrival from 15 May 1948 and is the count the CBS anchors check. The cities are the part of it placed in towns, so their people (civilians, refugees, recruits and the groups in training, times `people_per_unit`) never exceed it (Q-ARRV-2, owner, 15 October 2026). No person is counted twice.
R-CITY-004: Each turn, `min(refugees, max(0, housing_capacity - civilians))` of a city's refugees become civilians without a job. The cap is a placeholder while overflow (D-D1) is open.
diff --git a/docs/superpowers/plans/2026-10-15-gdd-phase-3.md b/docs/superpowers/plans/2026-10-15-gdd-phase-3.md
index 3cef43bbe..94adc594f 100644
--- a/docs/superpowers/plans/2026-10-15-gdd-phase-3.md
+++ b/docs/superpowers/plans/2026-10-15-gdd-phase-3.md
@@ -257,7 +257,7 @@ Sources: CBS Statistical Abstract of Israel No. 14 (1963), Table 11, pp. 30-31,
**Goal:** the CBS arrivals (`aliyah.yaml`) land across the twelve cities by one stated rule, with no unit lost or counted twice; the national head count and the cities stop being two unrelated views of the same people (spec §6 Phase 3, `PopulationSystem.cs`: "arrivals become units or counts"); the CBS anchors still hold.
-**Files:** `Cities.cs` (`Arrive` splits; `ArrivedUnits` stays the national cumulative count), `PopulationSystem.cs`, `content/rules.yaml` (`mvp.arrivals_city` replaced by the split rule; labelled design values), `Content.cs`, `ContentLoader.cs`, `CitiesTests.cs`, `CalibrationTests.cs` (unchanged tolerance), new `ArrivalsTests.cs`, `ReferencePlayerTests.cs` if the split is a player order, `docs/rules/mvp.md`, `docs/gdd/arrivals-maabarot.md` (unless #532 has it).
+**Files:** `Cities.cs` (`Arrive` splits; `ArrivedUnits` is the units arriving between two dates, counted from the census day by `UnitsBy`), `PopulationSystem.cs`, `content/rules.yaml` (`mvp.arrivals_city` replaced by the split rule; labelled design values), `Content.cs`, `ContentLoader.cs`, `CitiesTests.cs`, `CalibrationTests.cs` (unchanged tolerance), new `ArrivalsTests.cs`, `ReferencePlayerTests.cs` if the split is a player order, `docs/rules/mvp.md`, `docs/gdd/arrivals-maabarot.md` (unless #532 has it).
**Rule IDs (proposed):** R-CITY-003 reworded (arrivals land across the cities, not in `arrivals_city`), or **R-ARRV-001** the split rule and **R-ARRV-002** the relation between `GameState.Population` and the cities (Q-ARRV-2). The maintainer picks R-CITY or R-ARRV (#532 proposed R-ARRV).
diff --git a/sim/Statecraft.Sim.Tests/ArrivalsTests.cs b/sim/Statecraft.Sim.Tests/ArrivalsTests.cs
new file mode 100644
index 000000000..2ef659dcf
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/ArrivalsTests.cs
@@ -0,0 +1,114 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Statecraft.Sim;
+
+/// <summary>GDD Phase 3 PR 2: the CBS arrivals spread over the cities (R-CITY-003, Q-ARRV-1 and Q-ARRV-3), and the one
+/// relation between the national head count and the cities (R-CITY-008, Q-ARRV-2). Owner, 15 October 2026, #375: "Take all
+/// recommendations".</summary>
+public class ArrivalsTests
+{
+ static StepResult Step(Content c, GameState s) => Simulation.Step(c, s, Array.Empty<Command>());
+
+ static readonly Content Mvp = ContentLoader.Load(RealContentTests.ContentRoot());
+
+ /// <summary>The fixture with three towns on their own hexes, of 10, 10 and 20 people (shares 1:1:2), housing for all the
+ /// fixture's arrivals. Fixture values, not history.</summary>
+ static Content Three() => ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>
+ {
+ ["map/settlement_hexes.yaml"] = "settlements:\n - { id: town_a, q: 1, r: 0 }\n - { id: town_b, q: 2, r: 1 }\n - { id: town_c, q: 3, r: 0 }\n",
+ ["map/settlements_1948.yaml"] = Fixture.Files["map/settlements_1948.yaml"]
+ + " - { id: town_b, name: Town B, lon: 34.42, lat: 33.28, type: town, founded: 1900, pre_modern: false }\n"
+ + " - { id: town_c, name: Town C, lon: 34.47, lat: 33.35, type: town, founded: 1900, pre_modern: false }\n",
+ ["cities.yaml"] = "cities:\n" + Fixture.City("town_a", 40, 1, 1, 0) + Fixture.City("town_b", 40, 1, 1, 0) + Fixture.City("town_c", 40, 2, 2, 0),
+ })));
+
+ /// <summary>The cities' people in units: civilians, refugees, recruits and the groups in training (Q-ARRV-2).</summary>
+ static int CityUnits(GameState s) =>
+ s.Cities.Values.Sum(x => x.Civilians + x.Refugees + x.Recruits) + s.Cohorts.Values.Sum(x => x.Count);
+
+ /// <summary>The cities' arrivals P(t): the series' people from the census day to <paramref name="t"/> (Q-ARRV-3).</summary>
+ static double CityPeople(Content c, DateTime t)
+ {
+ var from = c.Rules.Mvp!.CityArrivalsFrom;
+ return t <= from ? 0 : PopulationSystem.Arrivals(c, from, t).OrderBy(kv => kv.Key, StringComparer.Ordinal).Sum(kv => kv.Value);
+ }
+
+ // R-CITY-003 (review focus 1: no unit lost or doubled by the split)
+ [Fact]
+ public void TheSplitLosesNoUnit()
+ {
+ var s = Simulation.NewGame(Mvp, GoldenRun.Seed, Mode.Historical);
+ var start = s;
+ for (int i = 0; i < 44 && s.GameOver == null; i++)
+ {
+ var next = Step(Mvp, s).State; // no orders: only arrivals change the cities' people
+ Assert.Equal(Cities.ArrivedUnits(Mvp, s.Date, next.Date, 1000), CityUnits(next) - CityUnits(s));
+ s = next;
+ }
+ Assert.Equal((int)Math.Floor(CityPeople(Mvp, s.Date) / 1000) - (int)Math.Floor(CityPeople(Mvp, start.Date) / 1000), CityUnits(s) - CityUnits(start));
+ }
+
+ // R-CITY-003 (Q-ARRV-1): in proportion to the census people, one unit at a time to the largest remainder, ties to the
+ // lower id (ordinal).
+ [Fact]
+ public void EachCityGetsItsShare()
+ {
+ var c = Three();
+ Assert.Equal(new[] { 0, 0, 1 }, Cities.Apportion(c, 1).Values); // remainders 0.25, 0.25, 0.5
+ Assert.Equal(new[] { 1, 0, 1 }, Cities.Apportion(c, 2).Values); // remainders 0.5, 0.5, 0: the tie goes to town_a
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ var before = s.Cities.Values.Select(x => x.Civilians + x.Refugees).ToArray();
+ while (s.Date < new DateTime(1949, 1, 15)) s = Step(c, s).State;
+ var added = s.Cities.Values.Select((x, i) => x.Civilians + x.Refugees - before[i]).ToArray();
+ Assert.Equal(new[] { 6, 6, 11 }, added); // the fixture's 230 people are 23 units: quotas 5.75, 5.75, 11.5
+ }
+
+ // R-CITY-003: the split is a function of the cities' cumulative units alone, so a city never gives a unit back, as a fresh
+ // largest-remainder split of each total would (the Alabama paradox: at 7 units Petah Tikva would lose one).
+ [Fact]
+ public void TheSplitNeverTakesAUnitBack()
+ {
+ var prev = Cities.Apportion(Mvp, 0);
+ Assert.All(prev.Values, v => Assert.Equal(0, v));
+ for (int n = 1; n <= 1000; n++)
+ {
+ var cur = Cities.Apportion(Mvp, n);
+ Assert.Equal(n, cur.Values.Sum());
+ foreach (var kv in cur) Assert.True(kv.Value >= prev[kv.Key], $"{kv.Key} gives back a unit at {n}");
+ prev = cur;
+ }
+ }
+
+ // R-CITY-003 (Q-ARRV-3): the census of 8 November 1948 already counts the people who arrived from 15 May, so the cities
+ // take arrivals only from that day.
+ [Fact]
+ public void TheCitiesHoldTheirCensusCountsOnTheCensusDay()
+ {
+ var s = Simulation.NewGame(Mvp, GoldenRun.Seed, Mode.Historical);
+ Assert.Equal(511, CityUnits(s)); // the census start total (R-CITY-007)
+ while (s.Date < new DateTime(1948, 10, 15)) s = Step(Mvp, s).State;
+ Assert.Equal(new DateTime(1948, 10, 15), s.Date); // the last turn that starts before the census day
+ Assert.Equal(511, CityUnits(s));
+ var next = Step(Mvp, s).State;
+ Assert.Equal((int)Math.Floor(CityPeople(Mvp, next.Date) / 1000), CityUnits(next) - 511);
+ Assert.True(CityUnits(next) > 511);
+ }
+
+ // R-CITY-008 (Q-ARRV-2): GameState.Population is the one record of the nation's people; the cities are the part placed
+ // in towns, so they never hold more people than it. Replaces CitiesTests.BeforeCutoverArrivalsAreInTheLegacyHeadCountToo,
+ // which pinned the two as separate views of the same arrivals.
+ [Fact]
+ public void ThePopulationAndTheCitiesAgree()
+ {
+ var s = Simulation.NewGame(Mvp, GoldenRun.Seed, Mode.Historical);
+ var ppu = Mvp.Rules.Mvp!.PeoplePerUnit;
+ while (true)
+ {
+ Assert.True((double)CityUnits(s) * ppu <= s.Population.Values.Sum(), $"{s.Date:yyyy-MM-dd}: the cities hold more people than the nation");
+ if (s.Date >= Mvp.End || s.GameOver != null) break;
+ s = Simulation.Step(Mvp, s, GoldenRun.Orders(Mvp, s)).State;
+ }
+ Assert.Equal(Mvp.End, s.Date);
+ }
+}
diff --git a/sim/Statecraft.Sim.Tests/CitiesContentTests.cs b/sim/Statecraft.Sim.Tests/CitiesContentTests.cs
index 445c52650..32a787484 100644
--- a/sim/Statecraft.Sim.Tests/CitiesContentTests.cs
+++ b/sim/Statecraft.Sim.Tests/CitiesContentTests.cs
@@ -23,7 +23,7 @@ public class CitiesContentTests
Assert.Equal(("unit", "hakhshara", 3, 0.25), (halutz.Kind, halutz.Facility, halutz.TrainingTurns, halutz.TrainingCost));
Assert.Equal("", c.UnitTypes.Single(t => t.Id == "civilian").Facility);
var mvp = c.RulesAt(c.Eras[0].From).Mvp!;
- Assert.Equal((10, 1.2, 0.5, 0.5, "town_a"), (mvp.PeoplePerUnit, mvp.IncomePerJobPerYear, mvp.CohesionHousingWeight, mvp.CohesionJobsWeight, mvp.ArrivalsCity));
+ Assert.Equal((10, 1.2, 0.5, 0.5, new DateTime(1948, 5, 15)), (mvp.PeoplePerUnit, mvp.IncomePerJobPerYear, mvp.CohesionHousingWeight, mvp.CohesionJobsWeight, mvp.CityArrivalsFrom));
Assert.Equal("Town A", c.SettlementNames["town_a"]);
}
@@ -42,7 +42,7 @@ public class CitiesContentTests
public void TheRealGameStartsTheTrainingInTelAviv()
{
var c = ContentLoader.Load(RealContentTests.ContentRoot());
- Assert.Equal("tel_aviv", c.RulesAt(c.Eras[0].From).Mvp!.ArrivalsCity);
+ Assert.Equal(new DateTime(1948, 11, 8), c.RulesAt(c.Eras[0].From).Mvp!.CityArrivalsFrom); // the census day (Q-ARRV-3)
Assert.True(c.Rules.AttentionCost.ContainsKey("assign_workers"));
Assert.Equal(new[] { "tel_aviv" }, c.Cities.Where(x => x.Facilities.Count > 0).Select(x => x.Id));
Assert.Equal(new[] { "military_camp", "hakhshara" }, c.Cities.Single(x => x.Id == "tel_aviv").Facilities); // D-D5: one of each at the start
@@ -189,14 +189,14 @@ public class CitiesContentTests
new object[] { "cities.yaml", Cities(City.Replace("employed_share: { value: 0.6", "employed_share: { value: 1.2")), "cities[town_a].employed_share.value", "must be a number from 0 to 1" },
new object[] { "cities.yaml", Cities(City.Replace("employed_share: { value: 0.6", "employed_share: { value: 0.9")), "cities[town_a].job_slots.value", "fewer than the 9 employed units" },
new object[] { "cities.yaml", Cities(City.Replace("facilities: []", "facilities: [winery]")), "cities[town_a].facilities", "unknown facility 'winery'" },
- new object[] { "cities.yaml", "cities: []\n", "mvp.arrivals_city", "is not a city in cities.yaml" },
+ new object[] { "cities.yaml", "cities: []\n", "cities", "needs at least one city to take the arrivals" },
new object[] { "unit_types.yaml", "types:\n - { id: civilian, kind: population }\n - { id: civilian, kind: population }\n", "types[civilian].id", "duplicate id" },
new object[] { "unit_types.yaml", "types:\n - { id: civilian, kind: crowd }\n", "types[civilian].kind", "must be population or unit" },
new object[] { "rules.yaml", Rules(Fixture.GddRules.Replace("people_per_unit: 10", "people_per_unit: 0")), "mvp.people_per_unit", "must be >= 1" },
new object[] { "rules.yaml", Rules(Fixture.GddRules.Replace("income_per_job_per_year: 1.2", "income_per_job_per_year: -1")), "mvp.income_per_job_per_year", "must be a finite number >= 0" },
new object[] { "rules.yaml", Rules(Fixture.GddRules.Replace("cohesion_housing_weight: 0.5", "cohesion_housing_weight: 1.5")), "mvp.cohesion_housing_weight", "must be a number from 0 to 1" },
new object[] { "rules.yaml", Rules(Fixture.GddRules.Replace("cohesion_jobs_weight: 0.5", "cohesion_jobs_weight: 0.4")), "mvp.cohesion_jobs_weight", "the two cohesion weights must sum to 1" },
- new object[] { "rules.yaml", Rules(Fixture.GddRules.Replace("arrivals_city: town_a", "arrivals_city: nowhere")), "mvp.arrivals_city", "is not a city in cities.yaml" },
+ new object[] { "rules.yaml", Rules(Fixture.GddRules.Replace(" city_arrivals_from: 1948-05-15\n", "")), "mvp.city_arrivals_from", "required when eras.yaml systems.loop is gdd" },
new object[] { "rules.yaml", Rules(""), "mvp", "required when eras.yaml systems.loop is gdd" },
new object[] { "rules.yaml", Fixture.Files["rules.yaml"] + Fixture.GddRules, "attention_cost.assign_workers", "missing cost" },
new object[] { "rules.yaml", Rules(Fixture.GddRules).Replace(", train: 1", ""), "attention_cost.train", "missing cost" },
@@ -214,7 +214,7 @@ public class CitiesContentTests
public void ABadValueFailsNamingTheFileAndField(string file, string text, string field, string message)
{
var ex = Assert.Throws<ContentException>(() => Load(new Dictionary<string, string> { [file] = text }));
- Assert.Equal(field == "mvp.arrivals_city" ? "rules.yaml" : file, ex.File);
+ Assert.Equal(file, ex.File);
Assert.Equal(field, ex.Field);
Assert.Contains(message, ex.Message);
}
@@ -231,7 +231,7 @@ public class CitiesContentTests
Assert.Contains("missing file", ex.Message);
}
- /// <summary>Arrivals are counted from the game's start in units of one size (R-CITY-003), so an era may not change it.</summary>
+ /// <summary>The cities count arrivals from one day in units of one size (R-CITY-003), so an era may change neither.</summary>
[Fact]
public void PeoplePerUnitIsTheSameInEveryEra()
{
@@ -257,6 +257,10 @@ eras:
Assert.Equal("rules/later.yaml", ex.File);
Assert.Equal("mvp.people_per_unit", ex.Field);
Assert.Contains("must be the same in every era", ex.Message);
+ File.WriteAllText(Path.Combine(dir, "rules", "later.yaml"), "mvp: { city_arrivals_from: 1950-01-01 }\n");
+ ex = Assert.Throws<ContentException>(() => ContentLoader.Load(dir));
+ Assert.Equal(("rules/later.yaml", "mvp.city_arrivals_from"), (ex.File, ex.Field));
+ Assert.Contains("must be the same in every era", ex.Message);
}
[Fact]
diff --git a/sim/Statecraft.Sim.Tests/CitiesTests.cs b/sim/Statecraft.Sim.Tests/CitiesTests.cs
index e9935f410..46b33abcc 100644
--- a/sim/Statecraft.Sim.Tests/CitiesTests.cs
+++ b/sim/Statecraft.Sim.Tests/CitiesTests.cs
@@ -111,7 +111,10 @@ public class CitiesTests
public void ATurnsArrivalsAreHousedOnTheNextTurn()
{
// Tel Aviv starts full (Q-START-1: housing equals the start people), so 20 of its people are moved out to free room.
- var s = With(Simulation.NewGame(Mvp, GoldenRun.Seed, Mode.Historical), "tel_aviv", 228, 106, 0);
+ // The cities take arrivals from the census day, 8 November 1948 (Q-ARRV-3), so the turn from 15 November has some.
+ var s = Simulation.NewGame(Mvp, GoldenRun.Seed, Mode.Historical);
+ while (s.Date < new DateTime(1948, 11, 15)) s = Step(Mvp, s).State;
+ s = With(s, "tel_aviv", 228, 106, 0);
var one = Step(Mvp, s).State;
var arrived = one.Cities["tel_aviv"].Refugees;
Assert.True(arrived > 0);
@@ -120,39 +123,6 @@ public class CitiesTests
Assert.Equal(228 + Math.Min(arrived, 20), two.Civilians);
}
- // R-CITY-003
- [Fact]
- public void ArrivalsOverTheWholeRunEqualTheFloorOfTheTotal()
- {
- var s = Simulation.NewGame(Mvp, GoldenRun.Seed, Mode.Historical);
- var start = s.Date;
- int People(GameState x) => x.Cities["tel_aviv"].Civilians + x.Cities["tel_aviv"].Refugees;
- var before = People(s);
- for (int i = 0; i < 20; i++)
- {
- var next = Step(Mvp, s).State;
- Assert.Equal(Cities.ArrivedUnits(Mvp, s.Date, next.Date, 1000), People(next) - People(s));
- s = next;
- }
- var total = PopulationSystem.Arrivals(Mvp, start, s.Date).OrderBy(kv => kv.Key, StringComparer.Ordinal).Sum(kv => kv.Value);
- Assert.Equal((int)Math.Floor(total / 1000), People(s) - before);
- }
-
- /// <summary>Before cutover the same arrivals are in two views: the legacy head count by origin (GameState.Population, which
- /// the legacy economy reads) and the city's refugees. This pins that overlap so Phase 3, which makes arrivals counts, has
- /// to change it on purpose.</summary>
- // R-CITY-003
- [Fact]
- public void BeforeCutoverArrivalsAreInTheLegacyHeadCountToo()
- {
- var c = Town();
- var s = Simulation.NewGame(c, 1, Mode.Historical);
- for (int i = 0; i < 20; i++) s = Step(c, s).State;
- var people = PopulationSystem.Arrivals(c, c.Eras[0].From, s.Date).Values.Sum();
- Assert.Equal(Cities.ArrivedUnits(c, c.Eras[0].From, s.Date, 10), s.Cities["town_a"].Refugees + s.Cities["town_a"].Civilians - 10);
- Assert.True(s.Population["europe"] >= people, "the legacy head count also holds every arrival");
- }
-
// R-CITY-005
[Fact]
public void CohesionFallsWhenRefugeesWaitAndRisesWhenTheyAreHousedAndEmployed()
diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.cs
index 458dbe3e4..a7f17a8d0 100644
--- a/sim/Statecraft.Sim.Tests/Fixture.cs
+++ b/sim/Statecraft.Sim.Tests/Fixture.cs
@@ -221,7 +221,7 @@ mvp:
income_per_job_per_year: 1.2
cohesion_housing_weight: 0.5
cohesion_jobs_weight: 0.5
- arrivals_city: town_a
+ city_arrivals_from: 1948-05-15
build_yishuv_turns: 3
build_yishuv_cost: 1.5
objective_points: 100
diff --git a/sim/Statecraft.Sim.Tests/golden/hash1950.txt b/sim/Statecraft.Sim.Tests/golden/hash1950.txt
index 410632ec2..0c34618ed 100644
--- a/sim/Statecraft.Sim.Tests/golden/hash1950.txt
+++ b/sim/Statecraft.Sim.Tests/golden/hash1950.txt
@@ -100,19 +100,19 @@ map[
mapturn=0001-01-01:0;
over=
city{
- hadera=12,5,12,5,0
- haifa=99,42,99,42,0
- jerusalem=84,29,84,29,0
- netanya=12,5,12,5,0
- petah_tikva=22,10,22,10,0
- rehovot=13,5,13,5,0
- rishon_lezion=10,5,10,5,0
+ hadera=12,5,12,5,6
+ haifa=99,42,99,42,52
+ jerusalem=84,29,84,29,44
+ netanya=12,5,12,5,6
+ petah_tikva=22,10,22,10,12
+ rehovot=13,5,13,5,7
+ rishon_lezion=10,5,10,5,6
rosh_pinna=1,0,1,0,0
- safed=2,1,2,1,0
- tel_aviv=248,106,248,106,347
- tiberias=6,2,6,2,0
- zikhron_yaakov=2,1,2,1,0
-coh=0.5106245923026744 [3FE05709628F2570]
+ safed=2,1,2,1,1
+ tel_aviv=248,106,248,106,131
+ tiberias=6,2,6,2,3
+ zikhron_yaakov=2,1,2,1,1
+coh=0.541759762906349 [3FE1561891FF1663]
units[
1:halutz@-3,19
site{
diff --git a/sim/Statecraft.Sim.Tests/golden/hash1952.txt b/sim/Statecraft.Sim.Tests/golden/hash1952.txt
index 9300679e2..38620ddc5 100644
--- a/sim/Statecraft.Sim.Tests/golden/hash1952.txt
+++ b/sim/Statecraft.Sim.Tests/golden/hash1952.txt
@@ -121,19 +121,19 @@ map[
mapturn=0001-01-01:0;
over=mvp_ended
city{
- hadera=12,5,12,5,0
- haifa=99,42,99,42,0
- jerusalem=84,29,84,29,0
- netanya=12,5,12,5,0
- petah_tikva=22,10,22,10,0
- rehovot=13,5,13,5,0
- rishon_lezion=10,5,10,5,0
- rosh_pinna=1,0,1,0,0
- safed=2,1,2,1,0
- tel_aviv=248,106,248,106,686
- tiberias=6,2,6,2,0
- zikhron_yaakov=2,1,2,1,0
-coh=0.42134438484542747 [3FDAF74E7050EB18]
+ hadera=12,5,12,5,14
+ haifa=99,42,99,42,118
+ jerusalem=84,29,84,29,100
+ netanya=12,5,12,5,14
+ petah_tikva=22,10,22,10,26
+ rehovot=13,5,13,5,15
+ rishon_lezion=10,5,10,5,12
+ rosh_pinna=1,0,1,0,1
+ safed=2,1,2,1,3
+ tel_aviv=248,106,248,106,296
+ tiberias=6,2,6,2,7
+ zikhron_yaakov=2,1,2,1,2
+coh=0.4364309229357378 [3FDBEE7BF73E36BA]
units[
1:halutz@-3,19
site{
diff --git a/sim/Statecraft.Sim.Tests/golden/manifest.txt b/sim/Statecraft.Sim.Tests/golden/manifest.txt
index 58b892460..c6365a571 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 ea730229392c12e007cdf30aa8b19e4668bcd1dfdbda0735dd8d7612301d5144
-hash1952 ca887e45cd413a41d4368c604caa37c3c0e19022195ac614001f7bfc507489ca
-smoke5 4104103f4e52fe4159f7b8d6acab9d2b651cd3c124952cfa74ebfd7333718ad5
-scenario-reckless a10877e2060d7a3f6df59c0ce3df7a9be96367b1054ccc4aa9e55a8eb0f88579
-scenario-cautious 5f162f0fba0a2fa2406fc5c73ea333b7d1ceb6c0398215a882fc29b9deae4dbf
-scenario-mvp-absorb-first 53852f2c7d72e2b5bbc5977ecb0876c6f64ba6480a2ea1211d677e3c25415dd2
-mvp-end ca887e45cd413a41d4368c604caa37c3c0e19022195ac614001f7bfc507489ca
+hash1950 d22b369fa9d269a2311a51ab26ef8e0069c3e55f8febfa0376340dd03e012b8a
+hash1952 21029217387d875c8723f0a99e46f199fa3181ba979352ac8200c6d5045e1322
+smoke5 3f7a0fe0d5f22e83edd00c8a913a8d216b4420c36907b11e2ec9406baecdad56
+scenario-reckless 8f209d56a4e396750873fdfd37f35941f96d677d9a24e821793c6f016c8ad488
+scenario-cautious a9afb0ad22dd4cb14da6e94117ae538ad96e33d5af53ad64785e62fa85c6bc1f
+scenario-mvp-absorb-first 8601da9326339e51948c492f7b7ad662d261944c75f7d9a483c30cbb5f654f47
+mvp-end 21029217387d875c8723f0a99e46f199fa3181ba979352ac8200c6d5045e1322
diff --git a/sim/Statecraft.Sim.Tests/golden/mvp-end.txt b/sim/Statecraft.Sim.Tests/golden/mvp-end.txt
index 9300679e2..38620ddc5 100644
--- a/sim/Statecraft.Sim.Tests/golden/mvp-end.txt
+++ b/sim/Statecraft.Sim.Tests/golden/mvp-end.txt
@@ -121,19 +121,19 @@ map[
mapturn=0001-01-01:0;
over=mvp_ended
city{
- hadera=12,5,12,5,0
- haifa=99,42,99,42,0
- jerusalem=84,29,84,29,0
- netanya=12,5,12,5,0
- petah_tikva=22,10,22,10,0
- rehovot=13,5,13,5,0
- rishon_lezion=10,5,10,5,0
- rosh_pinna=1,0,1,0,0
- safed=2,1,2,1,0
- tel_aviv=248,106,248,106,686
- tiberias=6,2,6,2,0
- zikhron_yaakov=2,1,2,1,0
-coh=0.42134438484542747 [3FDAF74E7050EB18]
+ hadera=12,5,12,5,14
+ haifa=99,42,99,42,118
+ jerusalem=84,29,84,29,100
+ netanya=12,5,12,5,14
+ petah_tikva=22,10,22,10,26
+ rehovot=13,5,13,5,15
+ rishon_lezion=10,5,10,5,12
+ rosh_pinna=1,0,1,0,1
+ safed=2,1,2,1,3
+ tel_aviv=248,106,248,106,296
+ tiberias=6,2,6,2,7
+ zikhron_yaakov=2,1,2,1,2
+coh=0.4364309229357378 [3FDBEE7BF73E36BA]
units[
1:halutz@-3,19
site{
diff --git a/sim/Statecraft.Sim.Tests/golden/scenario-cautious.txt b/sim/Statecraft.Sim.Tests/golden/scenario-cautious.txt
index cf4aaf7d3..41f6790ed 100644
--- a/sim/Statecraft.Sim.Tests/golden/scenario-cautious.txt
+++ b/sim/Statecraft.Sim.Tests/golden/scenario-cautious.txt
@@ -86,17 +86,17 @@ map[
mapturn=0001-01-01:0;
over=
city{
- hadera=12,5,12,5,0
- haifa=99,42,99,42,0
- jerusalem=84,29,84,29,0
- netanya=12,5,12,5,0
- petah_tikva=22,10,22,10,0
- rehovot=13,5,13,5,0
- rishon_lezion=10,5,10,5,0
+ hadera=12,5,12,5,1
+ haifa=99,42,99,42,6
+ jerusalem=84,29,84,29,6
+ netanya=12,5,12,5,1
+ petah_tikva=22,10,22,10,1
+ rehovot=13,5,13,5,1
+ rishon_lezion=10,5,10,5,1
rosh_pinna=1,0,1,0,0
safed=2,1,2,1,0
- tel_aviv=248,106,248,106,111
+ tel_aviv=248,106,248,106,16
tiberias=6,2,6,2,0
zikhron_yaakov=2,1,2,1,0
-coh=0.6287719752227847 [3FE41EE667C72450]
+coh=0.6912776599813588 [3FE61EF253C26938]
food=2253,751,0
\ No newline at end of file
diff --git a/sim/Statecraft.Sim.Tests/golden/scenario-mvp-absorb-first.txt b/sim/Statecraft.Sim.Tests/golden/scenario-mvp-absorb-first.txt
index 7a2ff1ee9..0e91be5d4 100644
--- a/sim/Statecraft.Sim.Tests/golden/scenario-mvp-absorb-first.txt
+++ b/sim/Statecraft.Sim.Tests/golden/scenario-mvp-absorb-first.txt
@@ -94,17 +94,17 @@ map[
mapturn=0001-01-01:0;
over=
city{
- hadera=12,5,12,5,0
- haifa=99,42,99,42,0
- jerusalem=84,29,84,29,0
- netanya=12,5,12,5,0
- petah_tikva=22,10,22,10,0
- rehovot=13,5,13,5,0
- rishon_lezion=10,5,10,5,0
+ hadera=12,5,12,5,3
+ haifa=99,42,99,42,25
+ jerusalem=84,29,84,29,22
+ netanya=12,5,12,5,3
+ petah_tikva=22,10,22,10,6
+ rehovot=13,5,13,5,3
+ rishon_lezion=10,5,10,5,3
rosh_pinna=1,0,1,0,0
- safed=2,1,2,1,0
- tel_aviv=248,106,248,90,210
- tiberias=6,2,6,2,0
- zikhron_yaakov=2,1,2,1,0
-coh=0.5558023483365949 [3FE1C92201A4A95F]
+ safed=2,1,2,1,1
+ tel_aviv=248,106,248,90,64
+ tiberias=6,2,6,2,1
+ zikhron_yaakov=2,1,2,1,1
+coh=0.6015740525166592 [3FE340183A35CCB3]
food=2556,852,0
\ No newline at end of file
diff --git a/sim/Statecraft.Sim.Tests/golden/scenario-reckless.txt b/sim/Statecraft.Sim.Tests/golden/scenario-reckless.txt
index 3526c4e57..b5daf4b14 100644
--- a/sim/Statecraft.Sim.Tests/golden/scenario-reckless.txt
+++ b/sim/Statecraft.Sim.Tests/golden/scenario-reckless.txt
@@ -84,17 +84,17 @@ map[
mapturn=0001-01-01:0;
over=
city{
- hadera=12,5,12,5,0
- haifa=99,42,99,42,0
- jerusalem=84,29,84,29,0
- netanya=12,5,12,5,0
- petah_tikva=22,10,22,10,0
- rehovot=13,5,13,5,0
- rishon_lezion=10,5,10,5,0
+ hadera=12,5,12,5,1
+ haifa=99,42,99,42,6
+ jerusalem=84,29,84,29,6
+ netanya=12,5,12,5,1
+ petah_tikva=22,10,22,10,1
+ rehovot=13,5,13,5,1
+ rishon_lezion=10,5,10,5,1
rosh_pinna=1,0,1,0,0
safed=2,1,2,1,0
- tel_aviv=248,106,248,106,111
+ tel_aviv=248,106,248,106,16
tiberias=6,2,6,2,0
zikhron_yaakov=2,1,2,1,0
-coh=0.6287719752227847 [3FE41EE667C72450]
+coh=0.6912776599813588 [3FE61EF253C26938]
food=2253,751,0
\ No newline at end of file
diff --git a/sim/Statecraft.Sim/Cities.cs b/sim/Statecraft.Sim/Cities.cs
index 328105fc8..22a71155b 100644
--- a/sim/Statecraft.Sim/Cities.cs
+++ b/sim/Statecraft.Sim/Cities.cs
@@ -79,29 +79,65 @@ namespace Statecraft.Sim
s.Cohesion = Math.Max(0, Math.Min(1, r.CohesionHousingWeight * housed + r.CohesionJobsWeight * working));
}
- /// <summary>R-CITY-003 (D-A5): the turn's immigrants (the CBS series, aliyah.yaml) arrive as refugees in the mvp
- /// arrivals_city, in whole units. Before cutover PopulationSystem still adds the same people to GameState.Population,
- /// the head count the legacy economy reads: two views of one group until Phase 3 makes arrivals counts (spec section 6).</summary>
+ /// <summary>R-CITY-003 (D-A5, Q-ARRV-1): the turn's immigrants (the CBS series, aliyah.yaml) arrive as refugees, in whole
+ /// units, spread over the cities by <see cref="Apportion"/>. The cities count them from mvp.city_arrivals_from, the
+ /// census day their start values already include (Q-ARRV-3); PopulationSystem adds every arrival to the national head
+ /// count from the game's start, and the cities are the part of it placed in towns (R-CITY-008, Q-ARRV-2).</summary>
public static void Arrive(Content c, GameState s, MvpRules r, DateTime next, List<Cause> why)
{
var units = ArrivedUnits(c, s.Date, next, r.PeoplePerUnit);
if (units == 0) return;
- var x = s.Cities[r.ArrivalsCity];
- s.Cities[x.Id] = x.WithCounts(x.Civilians, x.Employed, x.Refugees + units);
- why.Add(new Cause("city", x.Id, units, FormattableString.Invariant($"{PlayerText.Settlement(c, x.Id)}: {units} groups of immigrants arrived and wait for homes")));
+ var before = UnitsBy(c, s.Date, r.PeoplePerUnit);
+ var had = Apportion(c, before);
+ foreach (var kv in Apportion(c, before + units))
+ {
+ var added = kv.Value - had[kv.Key];
+ if (added == 0) continue;
+ var x = s.Cities[kv.Key];
+ s.Cities[x.Id] = x.WithCounts(x.Civilians, x.Employed, x.Refugees + added);
+ why.Add(new Cause("city", x.Id, added, FormattableString.Invariant($"{PlayerText.Settlement(c, x.Id)}: {added} groups of immigrants arrived and wait for homes")));
+ }
}
- /// <summary>The whole units of <paramref name="peoplePerUnit"/> people that arrive in [from, to). Counted from the game's
- /// start, floor(people by to) minus floor(people by from), so over any run of turns no unit is lost or counted twice.</summary>
- public static int ArrivedUnits(Content c, DateTime from, DateTime to, int peoplePerUnit)
+ /// <summary>R-CITY-003 (Q-ARRV-1): the cities' shares of their first <paramref name="units"/> arrived units, by id. The
+ /// weights are the cities' census people. Units are handed out one at a time, each to the city whose share of the
+ /// units so far most exceeds what it holds (the largest remainder), a tie to the lower id (ordinal). A fresh
+ /// largest-remainder split of each total could take a unit back from a city when the total grows (the Alabama paradox;
+ /// on the real cities at 7 units), so the split is built up from the first unit. Decimal, so exact on every runtime.</summary>
+ public static SortedDictionary<string, int> Apportion(Content c, int units)
{
- int UnitsBy(DateTime t)
+ var held = new SortedDictionary<string, int>(StringComparer.Ordinal);
+ foreach (var x in c.Cities) held[x.Id] = 0;
+ var weight = c.Cities.ToDictionary(x => x.Id, x => x.People!.Value);
+ var total = weight.Values.Sum();
+ for (int n = 1; n <= units; n++)
{
- var people = 0.0;
- foreach (var kv in PopulationSystem.Arrivals(c, c.Eras[0].From, t).OrderBy(k => k.Key, StringComparer.Ordinal)) people += kv.Value;
- return (int)Math.Floor(people / peoplePerUnit);
+ string? best = null;
+ var most = 0m;
+ foreach (var kv in held) // ordinal order, and only a larger remainder replaces: a tie stays with the lower id
+ {
+ var remainder = n * weight[kv.Key] - kv.Value * total; // (the share minus what it holds) times the total
+ if (best == null || remainder > most) { best = kv.Key; most = remainder; }
+ }
+ held[best!]++;
}
- return UnitsBy(to) - UnitsBy(from);
+ return held;
+ }
+
+ /// <summary>The whole units of <paramref name="peoplePerUnit"/> people that arrive in the cities in [from, to). Counted
+ /// from mvp.city_arrivals_from, floor(people by to) minus floor(people by from), so over any run of turns no unit is lost
+ /// or counted twice.</summary>
+ public static int ArrivedUnits(Content c, DateTime from, DateTime to, int peoplePerUnit) =>
+ UnitsBy(c, to, peoplePerUnit) - UnitsBy(c, from, peoplePerUnit);
+
+ /// <summary>The cities' whole units of arrivals from mvp.city_arrivals_from to <paramref name="t"/> (0 before it).</summary>
+ static int UnitsBy(Content c, DateTime t, int peoplePerUnit)
+ {
+ var origin = c.RulesAt(c.Eras[0].From).Mvp!.CityArrivalsFrom; // the same in every era (the loader checks it)
+ if (t <= origin) return 0;
+ var people = 0.0;
+ foreach (var kv in PopulationSystem.Arrivals(c, origin, t).OrderBy(k => k.Key, StringComparer.Ordinal)) people += kv.Value;
+ return (int)Math.Floor(people / peoplePerUnit);
}
}
}
diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.cs
index 2f0ac58e2..08c2058de 100644
--- a/sim/Statecraft.Sim/Content.cs
+++ b/sim/Statecraft.Sim/Content.cs
@@ -464,8 +464,8 @@ namespace Statecraft.Sim
public double CohesionHousingWeight { get; set; }
/// <summary>Social cohesion's weight on the employed share (R-CITY-005). A placeholder while D-C1 is open.</summary>
public double CohesionJobsWeight { get; set; }
- /// <summary>The city every arrival lands in (Phase 1 has one city; R-CITY-003).</summary>
- public string ArrivalsCity { get; set; } = "";
+ /// <summary>The day the cities start taking arrivals: the census day their start values count (R-CITY-003, Q-ARRV-3).</summary>
+ public DateTime CityArrivalsFrom { get; set; }
/// <summary>The day the GDD game ends (R-LOOP-004; D-E5, 15 January 1952 in the real content), or null for the last
/// era's end. Read from rules.yaml through <see cref="Content.End"/>; the same in every era.</summary>
public DateTime? End { get; set; }
diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.cs
index 34be5090c..6700c3ccd 100644
--- a/sim/Statecraft.Sim/ContentLoader.cs
+++ b/sim/Statecraft.Sim/ContentLoader.cs
@@ -1025,7 +1025,8 @@ namespace Statecraft.Sim
// A trained count lands in City.Recruits (R-TRAIN-003); other trained counts wait for their decisions (D-D4).
if (x.Kind == "population" && x.Id != "recruit") throw new ContentException(uf, at + ".kind", "only recruit is a trained count until Phase 5");
}
- var cities = new HashSet<string>(c.Cities.Select(x => x.Id));
+ // R-CITY-003: the arrivals are spread over the cities, so there must be one to take them.
+ if (c.Cities.Count == 0) throw new ContentException(cf, "cities", "the GDD loop needs at least one city to take the arrivals");
foreach (var (file, r) in new[] { ("rules.yaml", c.Rules) }.Concat(c.EraRules.OrderBy(kv => kv.Key, StringComparer.Ordinal).Select(kv => ("rules/" + kv.Key + ".yaml", kv.Value))))
{
var m = r.Mvp ?? throw new ContentException(file, "mvp", "required when eras.yaml systems.loop is gdd");
@@ -1039,7 +1040,9 @@ namespace Statecraft.Sim
Unit(file, "mvp.cohesion_jobs_weight", m.CohesionJobsWeight);
if (Math.Abs(m.CohesionHousingWeight + m.CohesionJobsWeight - 1) > 1e-9)
throw new ContentException(file, "mvp.cohesion_jobs_weight", "the two cohesion weights must sum to 1");
- if (!cities.Contains(m.ArrivalsCity)) throw new ContentException(file, "mvp.arrivals_city", $"'{m.ArrivalsCity}' is not a city in cities.yaml");
+ // R-CITY-003: the cities count arrivals from one day; another day in a later era would lose or double-count units.
+ if (m.CityArrivalsFrom == default) throw new ContentException(file, "mvp.city_arrivals_from", "required when eras.yaml systems.loop is gdd");
+ if (m.CityArrivalsFrom != c.Rules.Mvp!.CityArrivalsFrom) throw new ContentException(file, "mvp.city_arrivals_from", "must be the same in every era (the cities count arrivals from one day)");
if (m.BuildYishuvTurns < 1) throw new ContentException(file, "mvp.build_yishuv_turns", "must be >= 1");
if (!(m.BuildYishuvCost >= 0 && IsFinite(m.BuildYishuvCost))) throw new ContentException(file, "mvp.build_yishuv_cost", "must be a finite number >= 0");
// R-FOOD-001 to R-FOOD-003: required, so a missing key is never read as 0 (a stock term of 0, or no stock).
diff --git a/sim/Statecraft.Sim/GoldenRun.cs b/sim/Statecraft.Sim/GoldenRun.cs
index fbd9577ce..120cb0df4 100644
--- a/sim/Statecraft.Sim/GoldenRun.cs
+++ b/sim/Statecraft.Sim/GoldenRun.cs
@@ -15,13 +15,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 = "ea730229392c12e007cdf30aa8b19e4668bcd1dfdbda0735dd8d7612301d5144";
+ public const string Hash1950 = "d22b369fa9d269a2311a51ab26ef8e0069c3e55f8febfa0376340dd03e012b8a";
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 = "ca887e45cd413a41d4368c604caa37c3c0e19022195ac614001f7bfc507489ca";
+ public const string Hash1952 = "21029217387d875c8723f0a99e46f199fa3181ba979352ac8200c6d5045e1322";
public static readonly DateTime Until1952 = new DateTime(1952, 1, 1);
diff --git a/tools/web_check.py b/tools/web_check.py
index 543ce4c95..20f555c3c 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 1950 ea730229392c12e007cdf30aa8b19e4668bcd1dfdbda0735dd8d7612301d5144" --expect "GOLDEN OK 1952 ca887e45cd413a41d4368c604caa37c3c0e19022195ac614001f7bfc507489ca"
+ uv run tools/web_check.py unity/Builds/Web-disabled --query "golden" --expect "GOLDEN OK 1950 d22b369fa9d269a2311a51ab26ef8e0069c3e55f8febfa0376340dd03e012b8a" --expect "GOLDEN OK 1952 21029217387d875c8723f0a99e46f199fa3181ba979352ac8200c6d5045e1322"
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