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: the end report reads a finished game (refs #810) (#1149)

Beri7e8ff05e2165
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c1639abce..93d18ac07 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,9 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
fit; Security's level wraps with its caption, and the 12 px text floor is preserved.
### Added
+- The sim's end report, `EndReport.For`, reads a finished game for the end screen: the outcome, the score, each
+ objective's date beside its historical date, Social cohesion and International Support, and the population beside
+ its latest CBS anchor (R-END-005, R-END-006; refs #810). It changes no state and no golden; the score's parts wait for #809.
- An opt-in Civilization-style hex-tile map (`?hex-tiles`, desktop `-hex-tiles`; `?hex-tiles=tel_aviv_crop` for the
Tel Aviv crop): one-file hex prototypes (towns, orchards, fields, forests, hills), units as their own layer, painted
ground, a landscape ring round the play hexes and a warmer light while it is on. Presentation only; off by default,
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 250e778e6..7852527d6 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -190,6 +190,14 @@ R-END-001: Money is exhausted when the debt is at or above `debt_ceiling` (Q-DEF
R-END-002: In the resolver's last step, after the objectives and the score (spec §2.3, step 11), a turn end with Money and Food both exhausted adds 1 to `ExhaustedTurns`, and any other turn end sets it back to 0. When it reaches `defeat_turns`, the game ends with `defeat_economy` and a cause in the turn's causes, under the game's end (`era`) like the MVP end. `defeat_turns` is 3, a labelled design value (Q-DEF-2, owner, 18 October 2026, #784: "3 turns"), required in the GDD loop, at least 1. The step reads the debt as it finds it: the turn's deficit is borrowed after the resolution, so it counts from the next turn's end. A defeat on the game's last turn ends it as a defeat. `ExhaustedTurns` is in the state hash only when above 0, so a run that never has both exhausted hashes as before; the legacy loop never counts.
+## The end report
+
+D-H4 as decided (owner, 17 October 2026, #784: Q-END-1 and Q-END-2 as recommended): #19's legacy report folds into the end screen, which reads one sim helper, `EndReport.For` (Phase 7 PR 7, #810). This first slice reads only what the state already holds; the score's parts wait for #809, and the war loss for #8.
+
+R-END-005: Once the game has ended, the end report lists the outcome (the `GameOver` code), the end date, the state's score as it stands, every objective in `objectives.yaml` order with its historical date and, when completed, the player's date and the months from history (`Objectives.MonthsFromHistory`), and the two national parameters, Social cohesion and International Support, with no historical value. It is pure: it computes no rule, writes nothing, and two calls give the same report with the state hash unchanged. A game still on has no report.
+
+R-END-006: The report compares one measure with history (Q-END-2): the Jewish population at the end against the latest CBS anchor in `population.yaml` dated on or before the end, given with that anchor's date and sources. A game that ends before the first anchor has no comparison. No other value is compared, and none is invented.
+
## Government
D-C5 as decided (12 October 2026): the cabinet and Attention stay, the coalition is optional with no collapse. The coalition votes, the budget shares and the policies keep running and visible as before (Q-GOV-1, decided 15 October 2026, "Take all recommendations", #375). The defeat (D-B5) is built in Phase 7 (Q-GOV-2, decided the same day).
diff --git a/sim/Statecraft.Sim.Tests/EndReportTests.cs b/sim/Statecraft.Sim.Tests/EndReportTests.cs
new file mode 100644
index 000000000..a77ada6cd
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/EndReportTests.cs
@@ -0,0 +1,109 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Statecraft.Sim;
+
+/// <summary>The end report (GDD Phase 7 PR 7, D-H4; #810): a pure reading of the final state. It carries the outcome code, the
+/// state's score, each objective with the player's date beside the historical date, the national parameters and the one
+/// comparison with history Q-END-2 allows, the population against its CBS anchor. The score's parts wait for #809.</summary>
+public class EndReportTests
+{
+ static readonly Content Real = ContentLoader.Load(RealContentTests.ContentRoot());
+
+ /// <summary>A real GDD game on its last day, ended as the MVP ends, with the first objective completed a month early.</summary>
+ static GameState Ended()
+ {
+ var s = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
+ var first = Real.Objectives[0];
+ Assert.True(Objectives.Record(Real, s, Real.RulesAt(s.Date).Mvp!, first.Id, first.ReferenceDate.AddMonths(-1), new List<Cause>()));
+ s.Date = Real.End;
+ s.GameOver = GameOverCodes.MvpEnded;
+ return s;
+ }
+
+ // R-END-005
+ [Fact]
+ public void TheReportCarriesTheOutcomeTheScoreAndEveryObjectivesDates()
+ {
+ var s = Ended();
+ var r = EndReport.For(Real, s);
+ Assert.Equal(GameOverCodes.MvpEnded, r.Outcome);
+ Assert.Equal(s.Date, r.Date);
+ Assert.True(s.Score > 0);
+ Assert.Equal(s.Score, r.Score); // the state's own total: no part is recomputed here (#809)
+ // Every objective in content order, done or not, with its historical date; the player's date only when completed.
+ Assert.Equal(Real.Objectives.Select(o => o.Id), r.Objectives.Select(o => o.Id));
+ var first = Real.Objectives[0];
+ var done = r.Objectives[0];
+ Assert.Equal(first.ReferenceDate, done.Historical);
+ Assert.Equal(s.Objectives[first.Id], done.Completed);
+ Assert.Equal(1, done.MonthsFromHistory); // Objectives.MonthsFromHistory: a month early
+ Assert.Equal(first.Card, done.Card);
+ Assert.All(r.Objectives.Skip(1), o => { Assert.Null(o.Completed); Assert.Null(o.MonthsFromHistory); });
+ // The GDD's two national parameters, as the state holds them, with no historical value (Q-END-2).
+ Assert.Equal(s.Indicators["morale"], r.SocialCohesion);
+ Assert.Equal(s.Indicators["intl_standing"], r.InternationalSupport);
+ }
+
+ // R-END-005
+ [Fact]
+ public void ADefeatReportsItsCause()
+ {
+ var s = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
+ s.GameOver = GameOverCodes.DefeatEconomy;
+ var r = EndReport.For(Real, s);
+ Assert.Equal(GameOverCodes.DefeatEconomy, r.Outcome);
+ Assert.Equal(s.Date, r.Date);
+ Assert.Equal(0, r.Score);
+ Assert.All(r.Objectives, o => Assert.Null(o.Completed));
+ }
+
+ /// <summary>Review focus 5: the report writes nothing, and two calls read the same.</summary>
+ // R-END-005
+ [Fact]
+ public void TheReportIsPure()
+ {
+ var s = Ended();
+ var hash = s.Hash();
+ var a = EndReport.For(Real, s);
+ var b = EndReport.For(Real, s);
+ Assert.Equal(hash, s.Hash());
+ Assert.Equal(a.Outcome, b.Outcome);
+ Assert.Equal(a.Date, b.Date);
+ Assert.Equal(a.Score, b.Score);
+ Assert.Equal(a.SocialCohesion, b.SocialCohesion);
+ Assert.Equal(a.InternationalSupport, b.InternationalSupport);
+ Assert.Equal(a.Population, b.Population);
+ Assert.Same(a.PopulationHistory, b.PopulationHistory);
+ Assert.Equal(a.Objectives.Select(o => (o.Id, o.Card, o.Historical, o.Completed, o.MonthsFromHistory)),
+ b.Objectives.Select(o => (o.Id, o.Card, o.Historical, o.Completed, o.MonthsFromHistory)));
+ }
+
+ /// <summary>Q-END-2: the population is the one measure compared with history, against the latest CBS anchor on or before
+ /// the end, and that anchor carries its source.</summary>
+ // R-END-006
+ [Fact]
+ public void EveryHistoryLineHasASource()
+ {
+ var s = Ended();
+ var r = EndReport.For(Real, s);
+ Assert.Equal(s.TotalPopulation, r.Population);
+ var anchor = r.PopulationHistory!;
+ Assert.Equal(Real.PopulationAnchors.Where(a => a.Date <= s.Date).Max(a => a.Date), anchor.Date);
+ Assert.NotEmpty(anchor.Sources);
+ Assert.All(anchor.Sources, x => Assert.StartsWith("https://", x.Url));
+
+ // Before the first anchor there is nothing to compare with, so no line.
+ var early = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
+ Assert.True(early.Date < Real.PopulationAnchors.Min(a => a.Date));
+ early.GameOver = GameOverCodes.DefeatEconomy;
+ Assert.Null(EndReport.For(Real, early).PopulationHistory);
+ }
+
+ [Fact]
+ public void AGameStillOnHasNoReport()
+ {
+ var s = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
+ Assert.Throws<InvalidOperationException>(() => EndReport.For(Real, s));
+ }
+}
diff --git a/sim/Statecraft.Sim/EndReport.cs b/sim/Statecraft.Sim/EndReport.cs
new file mode 100644
index 000000000..8a3a13889
--- /dev/null
+++ b/sim/Statecraft.Sim/EndReport.cs
@@ -0,0 +1,71 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Statecraft.Sim
+{
+ /// <summary>The end report (D-H4; GDD Phase 7 PR 7, #810), folding in #19's legacy report: what the end screen reads once
+ /// <see cref="GameState.GameOver"/> is set. A pure reading of the final state and content (R-END-005): it computes no
+ /// rule and writes nothing, so calling it twice gives the same report and leaves the hash as it was. The score is the
+ /// state's own total; its parts wait for #809, because <see cref="Objectives.Record"/> scores with the turn-start rules,
+ /// which a later reading cannot always recover across an era boundary.</summary>
+ public sealed class EndReport
+ {
+ /// <summary>Why the game ended, one of the <see cref="GameOverCodes"/> (PlayerText.GameOver words it).</summary>
+ public string Outcome { get; }
+ /// <summary>The date the game ended on (the state's date).</summary>
+ public DateTime Date { get; }
+ /// <summary><see cref="GameState.Score"/> as the game left it.</summary>
+ public int Score { get; }
+ /// <summary>Every objective, in objectives.yaml's order (Q-CARD-2), completed or not.</summary>
+ public IReadOnlyList<EndObjective> Objectives { get; }
+ /// <summary>The GDD's two national parameters (0 to 1: morale shown as Social cohesion, intl_standing as International
+ /// Support), shown without a historical value (Q-END-2).</summary>
+ public double SocialCohesion { get; }
+ public double InternationalSupport { get; }
+ /// <summary>The Jewish population at the end (<see cref="GameState.TotalPopulation"/>).</summary>
+ public double Population { get; }
+ /// <summary>The one comparison with history (Q-END-2, R-END-006): the latest CBS anchor (population.yaml) dated on or
+ /// before <see cref="Date"/>, with its sources; null when the game ended before the first anchor.</summary>
+ public PopulationAnchor? PopulationHistory { get; }
+
+ EndReport(string outcome, DateTime date, int score, IReadOnlyList<EndObjective> objectives, double cohesion, double support,
+ double population, PopulationAnchor? history)
+ {
+ Outcome = outcome; Date = date; Score = score; Objectives = objectives; SocialCohesion = cohesion;
+ InternationalSupport = support; Population = population; PopulationHistory = history;
+ }
+
+ /// <summary>The report of a game that has ended; a game still on has none.</summary>
+ public static EndReport For(Content c, GameState s)
+ {
+ if (c == null) throw new ArgumentNullException(nameof(c));
+ if (s == null) throw new ArgumentNullException(nameof(s));
+ if (s.GameOver == null) throw new InvalidOperationException("the game has not ended, so it has no end report");
+ var objectives = c.Objectives.Select(o => s.Objectives.TryGetValue(o.Id, out var done)
+ ? new EndObjective(o.Id, o.Card, o.ReferenceDate, done, Sim.Objectives.MonthsFromHistory(done, o.ReferenceDate))
+ : new EndObjective(o.Id, o.Card, o.ReferenceDate, null, null)).ToList();
+ // The anchors are few and dated; the latest one not after the end is the comparison (ties cannot happen: dates are unique).
+ var history = c.PopulationAnchors.Where(a => a.Date <= s.Date).OrderBy(a => a.Date).LastOrDefault();
+ return new EndReport(s.GameOver, s.Date, s.Score, objectives, s.Indicators["morale"], s.Indicators["intl_standing"],
+ s.TotalPopulation, history);
+ }
+ }
+
+ /// <summary>One objective in the end report: its card, the historical date, and the player's date with the months from
+ /// history (<see cref="Objectives.MonthsFromHistory"/>: positive when early) when it was completed.</summary>
+ public sealed class EndObjective
+ {
+ public string Id { get; }
+ /// <summary>The card event's id (content/events/), whose title the screen shows.</summary>
+ public string Card { get; }
+ public DateTime Historical { get; }
+ public DateTime? Completed { get; }
+ public int? MonthsFromHistory { get; }
+
+ public EndObjective(string id, string card, DateTime historical, DateTime? completed, int? monthsFromHistory)
+ {
+ Id = id; Card = card; Historical = historical; Completed = completed; MonthsFromHistory = monthsFromHistory;
+ }
+ }
+}
diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.cs
index 3c97bab0a..8624944e2 100644
--- a/sim/Statecraft.Sim/Simulation.cs
+++ b/sim/Statecraft.Sim/Simulation.cs
@@ -69,7 +69,7 @@ namespace Statecraft.Sim
s.Turn++;
if (s.GameOver == null && s.Date >= end)
{
- // the legacy report (#19) will come before this once it exists
+ // #19's legacy report is EndReport.For, which the end screen reads once GameOver is set (D-H4)
s.GameOver = end == c.Eras[c.Eras.Count - 1].To ? GameOverCodes.EraEnded : GameOverCodes.MvpEnded;
why.Add(new Cause("era", s.GameOver, 0, PlayerText.GameOver(s.GameOver)));
}