A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
CLI: the Briefing prints the title and text the game shows (Refs #3022) (#3030)
Eyal Golan385e834ae5e2
diff --git a/changelog.d/3022-cli-briefing-variants.md b/changelog.d/3022-cli-briefing-variants.mdnew file mode 100644index 000000000..c87b887f1--- /dev/null+++ b/changelog.d/3022-cli-briefing-variants.md@@ -0,0 +1,4 @@+### Fixed++- Developer CLI (#3022): the Briefing prints each card's title and text as the game shows them, a road variant's, else+ the early or late text, with names following the player's appointments. It printed the ordinary title and text.diff --git a/sim/Statecraft.Cli/Briefing.cs b/sim/Statecraft.Cli/Briefing.csnew file mode 100644index 000000000..5bf77a5a9--- /dev/null+++ b/sim/Statecraft.Cli/Briefing.cs@@ -0,0 +1,24 @@+using Statecraft.Sim;++namespace Statecraft.Cli+{+ /// <summary>The turn's briefing in the text front end: the date, government and security level, then each pending+ /// card with its options. A card's title and text are the game's (#3022): EventSystem.Title and EventSystem.Render with+ /// the state, so a road variant's, else the early or late text, with names following the player's appointments.</summary>+ public static class Briefing+ {+ public static void Write(Content c, GameState s, TextWriter output)+ {+ var gov = Offices.Government(c, s.Date);+ var attention = c.UsesAttention ? $" | attention {s.Attention:0.0}" : "";+ output.WriteLine($"== {s.Date:yyyy-MM-dd} | turn {s.Turn} | {gov?.Name} | security level {s.Rung}{attention}");+ foreach (var id in s.PendingEvents)+ {+ var e = c.Events.First(x => x.Id == id);+ var fillDate = EventSystem.FillDate(e, s.Date); // after the window ends, name the last in-window holder+ output.WriteLine($" EVENT {e.Id}: {EventSystem.Title(c, s, e)} - {EventSystem.Render(c, s, e)}");+ foreach (var o in e.Options) output.WriteLine($" {o.Id}: {Offices.Fill(c, o.Text, fillDate)}");+ }+ }+ }+}diff --git a/sim/Statecraft.Cli/Program.cs b/sim/Statecraft.Cli/Program.csindex c30a3d380..3c83c962e 100644--- a/sim/Statecraft.Cli/Program.cs+++ b/sim/Statecraft.Cli/Program.cs@@ -144,7 +144,7 @@ bool auto = autoMode == "historical";for (int t = 0; t < turns && state.GameOver == null; t++){- Briefing(content, state);+ Briefing.Write(content, state, Console.Out);var commands = auto ? HistoricalAI.Commands(content, state).ToList() : ReadCommands();if (commands == null) break;var result = Simulation.Step(content, state, commands);@@ -156,20 +156,6 @@ Console.WriteLine($"End {state.Date:yyyy-MM-dd}: population {state.TotalPopulatiConsole.WriteLine($"State hash {state.Hash()}");return 0;-static void Briefing(Content c, GameState s)-{- var gov = Offices.Government(c, s.Date);- var attention = c.UsesAttention ? $" | attention {s.Attention:0.0}" : "";- Console.WriteLine($"== {s.Date:yyyy-MM-dd} | turn {s.Turn} | {gov?.Name} | security level {s.Rung}{attention}");- foreach (var id in s.PendingEvents)- {- var e = c.Events.First(x => x.Id == id);- var fillDate = EventSystem.FillDate(e, s.Date); // after the window ends, name the last in-window holder- Console.WriteLine($" EVENT {e.Id}: {Offices.Fill(c, e.Title, fillDate)} - {EventSystem.Render(c, e, s.Date)}");- foreach (var o in e.Options) Console.WriteLine($" {o.Id}: {Offices.Fill(c, o.Text, fillDate)}");- }-}-static List<Command>? ReadCommands(){var list = new List<Command>();diff --git a/sim/Statecraft.Sim.Tests/BriefingCliTests.cs b/sim/Statecraft.Sim.Tests/BriefingCliTests.csnew file mode 100644index 000000000..4f508028f--- /dev/null+++ b/sim/Statecraft.Sim.Tests/BriefingCliTests.cs@@ -0,0 +1,52 @@+using System;+using System.IO;+using System.Linq;+using Statecraft.Cli;+using Statecraft.Sim;++/// <summary>#3022: the CLI's Briefing prints a card's title and text as the game shows them (EventSystem.Title and+/// EventSystem.Render with the state: a road variant's, else the early or late text, names from the player's+/// appointments), not the card's ordinary title and text.</summary>+public class BriefingCliTests+{+ static string EventLine(Content c, GameState s, string id)+ {+ var output = new StringWriter();+ Briefing.Write(c, s, output);+ return output.ToString().Replace("\r\n", "\n").Split('\n').Single(x => x.StartsWith($" EVENT {id}: ", StringComparison.Ordinal));+ }++ // R-ENEMY-007: a card shown after its window prints its late text. Real content, rhodes_talks on its `to`.+ // Red without it: the Briefing printed the ordinary text.+ [Fact]+ public void ACardShownLatePrintsItsLateText()+ {+ var c = ContentLoader.Load(RealContentTests.ContentRoot());+ var e = c.Events.Single(x => x.Id == "rhodes_talks");+ var s = Simulation.NewGame(c, GoldenRun.Seed, Mode.Historical);+ s.Date = e.To!.Value;+ s.PendingEvents.Add(e.Id);+ Assert.True(EventSystem.ShowsLate(e, s.Date));+ var line = EventLine(c, s, e.Id);+ Assert.Equal($" EVENT {e.Id}: {EventSystem.Title(c, s, e)} - {EventSystem.Render(c, s, e)}", line);+ Assert.Contains(Cabinet.Fill(c, s, e.LateText, EventSystem.FillDate(e, s.Date)), line);+ Assert.DoesNotContain(Cabinet.Fill(c, s, e.Text, EventSystem.FillDate(e, s.Date)), line);+ }++ // R-WAR-008: a card shown before its `from` prints its early text. Gdd03ArmisticeOfferTests' fixture early text.+ // Red without it: the Briefing printed the ordinary text.+ [Fact]+ public void ACardShownEarlyPrintsItsEarlyText()+ {+ var c = Gdd03ArmisticeOfferTests.LoadEarly();+ var e = c.Events.Single(x => x.Id == "armistice_egypt");+ var s = CombatTests.With(c);+ s.Date = new DateTime(1948, 12, 15);+ s.PendingEvents.Add(e.Id);+ Assert.True(EventSystem.ShowsEarly(e, s.Date));+ var line = EventLine(c, s, e.Id);+ Assert.Equal($" EVENT {e.Id}: {EventSystem.Title(c, s, e)} - {EventSystem.Render(c, s, e)}", line);+ Assert.Contains(Cabinet.Fill(c, s, Gdd03ArmisticeOfferTests.Early, s.Date), line);+ Assert.DoesNotContain("Israel decides whether to sign.", line);+ }+}diff --git a/sim/Statecraft.Sim.Tests/Gdd03ArmisticeOfferTests.cs b/sim/Statecraft.Sim.Tests/Gdd03ArmisticeOfferTests.csindex fc5775f01..444efae9e 100644--- a/sim/Statecraft.Sim.Tests/Gdd03ArmisticeOfferTests.cs+++ b/sim/Statecraft.Sim.Tests/Gdd03ArmisticeOfferTests.cs@@ -321,12 +321,12 @@ options:// (Recommended)": no new saved state). A fixture text, never a real card's: the four real texts wait for the owner's// approval of the words and their sign-off ("You approve the words (Recommended)", "You, before they land (Recommended)").- const string Early = "The talks came sooner. {prime_minister} must decide.";+ internal const string Early = "The talks came sooner. {prime_minister} must decide.";const string EarlyHe = "השיחות הגיעו מוקדם יותר. על {prime_minister} להחליט.";static string WithEarly(string card, string text = Early) => card.Replace("office: prime_minister", $"early_text: '{text}'\noffice: prime_minister");- static Content LoadEarly(string ruleset = SaveGame.Gdd03Ruleset)+ internal static Content LoadEarly(string ruleset = SaveGame.Gdd03Ruleset){var f = Gdd03MovementFortTests.Files(ruleset);f["events/armistice_egypt.yaml"] = WithEarly(Card("egypt", "1949-12-01"));