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.

The end screen shows the score's reference line (Refs #812) (#1967)

Berib872818fa086
diff --git a/changelog.d/laneMI-812.md b/changelog.d/laneMI-812.md
new file mode 100644
index 000000000..3be56280f
--- /dev/null
+++ b/changelog.d/laneMI-812.md
@@ -0,0 +1 @@
+- The end screen shows what completing every objective on its historical date scores, beside the score; the sim computes it (Refs #812).
diff --git a/sim/Statecraft.Sim.Tests/EndReportTests.cs b/sim/Statecraft.Sim.Tests/EndReportTests.cs
index 12a2a8585..237e09d35 100644
--- a/sim/Statecraft.Sim.Tests/EndReportTests.cs
+++ b/sim/Statecraft.Sim.Tests/EndReportTests.cs
@@ -50,6 +50,60 @@ public class EndReportTests
Assert.Equal(s.Indicators["intl_standing"], r.InternationalSupport);
}
+ // Q-SCORE-2, R-OBJ-006: the score of a run that completes every objective on its historical date, read from content.
+ [Fact]
+ public void TheReferenceScoreIsWhatCompletingEveryObjectiveOnItsHistoricalDateScores()
+ {
+ var s = Ended();
+ Assert.Equal(200, EndReport.For(Real, s).ReferenceScore); // 100 each: the three infrastructure parts count once, plus absorption
+
+ // The same number by playing it: every objective recorded on its reference date, no timing bonus on time.
+ var perfect = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
+ foreach (var o in Real.Objectives)
+ Assert.True(Objectives.Record(Real, perfect, Real.RulesAt(perfect.Date).Mvp!, o.Id, o.ReferenceDate, new List<Cause>()));
+ perfect.GameOver = GameOverCodes.MvpEnded;
+ Assert.Equal(perfect.Score, EndReport.For(Real, perfect).ReferenceScore);
+ }
+
+ // Q-SCORE-2 across an era override: each paying objective takes objective_points from the rules of the turn that ends on its own
+ // reference date, as scoring would. The real content split at 1950 with a later era whose rules pay 1: absorption (20 December
+ // 1949) pays in the founding era's 100, the infrastructure group with its latest part (yishuvim, 15 December 1950) in the later
+ // era. The game ends in the later era. The split is set on the loaded content: the real rules.yaml dates a line past 1950, which
+ // the loader would refuse in a founding era that short, and only RulesAt matters here.
+ [Fact]
+ public void TheReferenceScoreReadsEachObjectivesOwnEra()
+ {
+ var c = ContentLoader.Load(RealContentTests.ContentRoot());
+ var cut = new DateTime(1950, 1, 1);
+ c.Eras.Add(new Era { Id = "later", Name = "A Later Chapter", From = cut, To = c.Eras[0].To, Systems = c.Eras[0].Systems });
+ c.Eras[0].To = cut;
+ c.EraRules["later"] = new Rules { Mvp = new MvpRules { ObjectivePoints = 1, ObjectiveBonusPerMonth = 0, ObjectiveBonusCap = 0 } };
+ Assert.Equal(1, c.RulesAt(c.End.AddDays(-1)).Mvp!.ObjectivePoints); // the game ends after the override
+
+ // A perfect run: every objective on its reference date, in date order, scored with the rules of the turn that ends there.
+ var s = Simulation.NewGame(c, GoldenRun.Seed, Mode.Historical);
+ foreach (var o in c.Objectives.OrderBy(o => o.ReferenceDate))
+ Assert.True(Objectives.Record(c, s, c.RulesAt(o.ReferenceDate.AddDays(-1)).Mvp!, o.Id, o.ReferenceDate, new List<Cause>()));
+ s.Date = c.End;
+ s.GameOver = GameOverCodes.MvpEnded;
+ Assert.Equal(101, s.Score);
+ Assert.Equal(s.Score, EndReport.For(c, s).ReferenceScore);
+ }
+
+ // A group id and a standalone objective id are separate namespaces: a part_of equal to a standalone objective's id still pays both.
+ [Fact]
+ public void AGroupIdEqualToAStandaloneObjectiveIdStillCountsBoth()
+ {
+ var c = ContentLoader.Load(RealContentTests.ContentRoot());
+ foreach (var o in c.Objectives.Where(o => o.PartOf != "")) o.PartOf = "absorb_immigrants";
+ var s = Simulation.NewGame(c, GoldenRun.Seed, Mode.Historical);
+ foreach (var o in c.Objectives)
+ Assert.True(Objectives.Record(c, s, c.RulesAt(s.Date).Mvp!, o.Id, o.ReferenceDate, new List<Cause>()));
+ s.GameOver = GameOverCodes.MvpEnded;
+ Assert.Equal(200, s.Score);
+ Assert.Equal(s.Score, EndReport.For(c, s).ReferenceScore);
+ }
+
/// <summary>The fixture above has no prisoner points; here a real exchange (Prisoners.Return, the producer) scores some and the
/// report carries that part.</summary>
// R-END-005
diff --git a/sim/Statecraft.Sim.Tests/ObjectivesTests.cs b/sim/Statecraft.Sim.Tests/ObjectivesTests.cs
index b5ec271aa..bf67cb56e 100644
--- a/sim/Statecraft.Sim.Tests/ObjectivesTests.cs
+++ b/sim/Statecraft.Sim.Tests/ObjectivesTests.cs
@@ -234,6 +234,42 @@ eras:
Assert.Equal(160, r.State.Score); // 100 and the capped bonus; the later era would give 1 + 60
}
+ // R-END-005: the end report's reference score reads objective_points from the rules of the turn that ends on the objective's
+ // reference date (12 June 1949, in the later era, whose override says 1), not from the turn that scored it. Here the objective
+ // completes early, on 12 June 1948, the later era's first day, in a turn that started on 29 May in the founding era.
+ [Fact]
+ public void TheReferenceScoreReadsTheRulesOfTheReferenceDateNotOfTheTurnThatScored()
+ {
+ const string eras = @"
+eras:
+ - id: founding
+ name: The Founding
+ from: 1948-05-15
+ to: 1948-06-12
+ systems: { loop: gdd }
+ - id: later
+ name: A Later Chapter
+ from: 1948-06-12
+ to: 1957-01-01
+ systems: { loop: gdd }
+";
+ var o = Fixture.Gdd(new Dictionary<string, string> { ["eras.yaml"] = eras, ["objectives.yaml"] = ObjectivesYaml });
+ var card = Card.Replace("from: 1948-05-15", "from: 1948-06-12");
+ var dir = Fixture.Write(o, new Dictionary<string, string> { ["first_card.yaml"] = card });
+ System.IO.Directory.CreateDirectory(System.IO.Path.Combine(dir, "rules"));
+ System.IO.File.WriteAllText(System.IO.Path.Combine(dir, "rules", "later.yaml"), "mvp: { objective_points: 1 }\n");
+ var c = ContentLoader.Load(dir);
+
+ var r = StartBuilding(c);
+ while (r.State.Sites["site_a"].BuiltOn == null) r = Step(c, r.State);
+ Assert.Equal(D("1948-06-12"), r.State.Date);
+ r.State.GameOver = GameOverCodes.MvpEnded;
+ foreach (var k in new[] { "morale", "intl_standing" }) r.State.Indicators.TryAdd(k, 0); // the report reads both; the fixture defines neither
+ var report = EndReport.For(c, r.State);
+ Assert.Equal(100, report.ScoreParts.ObjectivePoints); // scoring used the founding era's 100
+ Assert.Equal(1, report.ReferenceScore); // on its reference date it would have paid the later era's 1
+ }
+
// R-OBJ-001: a build that is stopped completes nothing.
[Fact]
public void AStoppedBuildCompletesNothing()
diff --git a/sim/Statecraft.Sim/EndReport.cs b/sim/Statecraft.Sim/EndReport.cs
index 17bbcd79b..c184cd80b 100644
--- a/sim/Statecraft.Sim/EndReport.cs
+++ b/sim/Statecraft.Sim/EndReport.cs
@@ -20,6 +20,11 @@ namespace Statecraft.Sim
public int Score { get; }
/// <summary>The parts of <see cref="Score"/> (R-SCORE-001); they sum to it.</summary>
public ScoreParts ScoreParts { get; }
+ /// <summary>What completing every objective on its historical date scores (Q-SCORE-2, owner, 17 October 2026): objective_points
+ /// for each objective, the parts of one part_of group counted once (R-OBJ-006), and no timing bonus on the day. Each pays with
+ /// the rules of the turn that ends on its reference date (a group's: its latest part's), as scoring would. The end screen
+ /// shows it beside the score; 0 when the content has no GDD objectives.</summary>
+ public int ReferenceScore { 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
@@ -35,10 +40,10 @@ namespace Statecraft.Sim
/// (<see cref="GameState.PrisonersReturned"/> units times the people per unit); 0 when none went home.</summary>
public int PrisonersReturned { get; }
- EndReport(string outcome, DateTime date, int score, ScoreParts scoreParts, IReadOnlyList<EndObjective> objectives, double cohesion, double support,
+ EndReport(string outcome, DateTime date, int score, ScoreParts scoreParts, int referenceScore, IReadOnlyList<EndObjective> objectives, double cohesion, double support,
double population, PopulationAnchor? history, int prisonersReturned)
{
- Outcome = outcome; Date = date; Score = score; ScoreParts = scoreParts; Objectives = objectives; SocialCohesion = cohesion;
+ Outcome = outcome; Date = date; Score = score; ScoreParts = scoreParts; ReferenceScore = referenceScore; Objectives = objectives; SocialCohesion = cohesion;
InternationalSupport = support; Population = population; PopulationHistory = history;
PrisonersReturned = prisonersReturned;
}
@@ -54,7 +59,15 @@ namespace Statecraft.Sim
: 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, Sim.ScoreParts.For(s), objectives, s.Indicators["morale"], s.Indicators["intl_standing"],
+ // The base pays once per objective with no part_of and once per part_of group, as Objectives.Record awards it: a group
+ // with its last part, so on the latest part's reference date. The two are separate namespaces: a group id may equal a
+ // standalone objective's id and both still pay.
+ var paysOn = c.Objectives.Where(o => o.PartOf == "").Select(o => o.ReferenceDate)
+ .Concat(c.Objectives.Where(o => o.PartOf != "").GroupBy(o => o.PartOf, StringComparer.Ordinal).Select(g => g.Max(o => o.ReferenceDate)));
+ // Scoring reads the rules of the date the turn started from. A turn that ends on a reference date never crosses an era's
+ // start (Simulation.TurnEnd cuts it there), so the day before that date is in the era the turn started in.
+ var reference = paysOn.Sum(d => c.RulesAt(d.AddDays(-1)).Mvp?.ObjectivePoints ?? 0);
+ return new EndReport(s.GameOver, s.Date, s.Score, Sim.ScoreParts.For(s), reference, objectives, s.Indicators["morale"], s.Indicators["intl_standing"],
s.TotalPopulation, history, s.PrisonersReturned.Values.Sum() * (c.RulesAt(s.Date).Mvp?.PeoplePerUnit ?? 0)); // no prisoners without the GDD rules
}
}
diff --git a/unity/Assets/Scripts/UI/EndScreenPresenter.cs b/unity/Assets/Scripts/UI/EndScreenPresenter.cs
index 671f217cd..26f3dce2d 100644
--- a/unity/Assets/Scripts/UI/EndScreenPresenter.cs
+++ b/unity/Assets/Scripts/UI/EndScreenPresenter.cs
@@ -69,8 +69,8 @@ namespace Statecraft.Game.UI
public bool ClosedThisFrame => closedAt == UnityEngine.Time.frameCount;
/// <summary>The screen's lines for an ended game, in order: the outcome, its history note when it has one, the score,
- /// one per objective, Social cohesion, International Support, the population with its CBS anchor and, when some went
- /// home, the prisoners returned. Every value is the report's.</summary>
+ /// the reference score, one per objective, Social cohesion, International Support, the population with its CBS anchor
+ /// and, when some went home, the prisoners returned. Every value is the report's.</summary>
public static IReadOnlyList<(string Name, string Text)> Lines(Content c, GameState s, UiText t)
{
var r = EndReport.For(c, s);
@@ -86,6 +86,8 @@ namespace Statecraft.Game.UI
var note = "end.note." + r.Outcome;
if (t.Has(outcome) && t.Has(note)) lines.Add(("note", t[note]));
lines.Add(("score", t.Format("hud.score", r.Score)));
+ // Q-SCORE-2: beside the score, what a run on the historical dates scores (the sim's number; nothing computed here).
+ if (r.ReferenceScore > 0) lines.Add(("score-reference", t.Format("end.reference_score", r.ReferenceScore)));
foreach (var o in r.Objectives)
{
var title = EventSystem.Title(c, s, c.Events.First(e => e.Id == o.Card)); // as the objective's card shows it
diff --git a/unity/Assets/Tests/EditMode/EndScreenTests.cs b/unity/Assets/Tests/EditMode/EndScreenTests.cs
index f89b8fbbb..60f64be89 100644
--- a/unity/Assets/Tests/EditMode/EndScreenTests.cs
+++ b/unity/Assets/Tests/EditMode/EndScreenTests.cs
@@ -111,12 +111,15 @@ public class EndScreenTests
Assert.IsTrue(k.End.IsOpen, "a loaded ended game opens on its end screen");
var s = k.Bridge.State; var r = EndReport.For(C, s);
var names = k.Ui.Q<ScrollView>("end-screen-rows").Children().Select(x => x.name).ToList();
- var expected = new[] { "outcome", "score" }.Concat(r.Objectives.Select(o => "objective-" + o.Id))
+ var expected = new[] { "outcome", "score", "score-reference" }.Concat(r.Objectives.Select(o => "objective-" + o.Id))
.Concat(new[] { "cohesion", "standing", "population" }).Select(n => "end-screen-" + n);
CollectionAssert.AreEqual(expected, names, "the report's parts, in order");
Assert.AreEqual(En["end.outcome.mvp_ended"], k.Line("outcome"));
Assert.AreEqual(En.Format("hud.score", s.Score), k.Line("score"));
Assert.Greater(s.Score, 0);
+ Assert.AreEqual(200, r.ReferenceScore, "the reference is the sim's number (Q-SCORE-2)");
+ Assert.AreEqual(En.Format("end.reference_score", r.ReferenceScore), k.Line("score-reference"));
+ StringAssert.Contains("200", k.Line("score-reference"));
// The first objective: the card's title, the player's date and the historical date (Q-END-1).
var first = C.Objectives.Single(o => o.Id == "absorb_immigrants"); // by id: the first in id order, as before R-OBJ-007
string Date(System.DateTime d) => En.Format("date.day_month_year", d.Day, En["date.month_" + d.Month], d.Year);
diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yaml
index 3478a21e3..f082e1727 100644
--- a/unity/Assets/UI/strings.en.yaml
+++ b/unity/Assets/UI/strings.en.yaml
@@ -422,6 +422,7 @@ report.unit: "Force {0}"
end.title: "The game has ended"
end.outcome.mvp_ended: "The game has reached its last turn."
end.outcome.defeat_economy: "Money and Food ran out."
+end.reference_score: "Completing every objective on its historical date scores {0:N0}."
end.objective_done: "{0}: completed on {1}; historically {2}"
end.objective_open: "{0}: not completed; historically {1}"
end.parameter: "{0}: {1}"
diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yaml
index 25cbbda8f..1f63fba45 100644
--- a/unity/Assets/UI/strings.he.yaml
+++ b/unity/Assets/UI/strings.he.yaml
@@ -454,6 +454,7 @@ report.unit: "כוח {0}"
end.title: "המשחק הסתיים"
end.outcome.mvp_ended: "המשחק הגיע לתורו האחרון."
end.outcome.defeat_economy: "הכסף והמזון אזלו."
+end.reference_score: "השלמת כל יעד בתאריך ההיסטורי שלו מניבה ניקוד של {0:N0}."
end.objective_done: "יעד {0}: הושלם ב־{1}; בהיסטוריה ב־{2}"
end.objective_open: "יעד {0}: לא הושלם; בהיסטוריה ב־{1}"
end.parameter: "{0}: {1}"