A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: a failing golden test shows which state changed (fixes #256) (#270)
agamrafaeli-instinctd310f9bc59ba
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c5d2ce7a1..2d9ae77de 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,10 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB## [Unreleased]### Added+- A golden-hash failure now shows what changed (#256): `GameState.Describe()` writes the state `Hash()` hashes as readable+ lines, each golden run's final state is committed under `sim/Statecraft.Sim.Tests/golden/`, and a failing golden test+ prints the changed lines by section. `STATECRAFT_UPDATE_GOLDEN=1 dotnet test` rewrites the snapshots. `Hash()` is+ unchanged, so the goldens do not move.- A start screen (#247): a painting of the 14 May 1948 ceremony in the Tel Aviv Museum hall (AI-generated concept artwith no identifiable person), two lines of the Declaration of Independence in the official Hebrew with the officialEnglish under each, and Continue (only with a save) and New Game (with the top bar's two-press confirmation). Automateddiff --git a/docs/determinism.md b/docs/determinism.mdindex 5725c1adc..ce2bda319 100644--- a/docs/determinism.md+++ b/docs/determinism.md@@ -37,6 +37,14 @@ uv run tools/web_check.py unity/Builds/Web-<compression> --query "golden&smoke=5--expect "SMOKE OK 5 turns 1948-06-19 d3fdd459ddb876bd8d775c20edd1202cf56ca7134a8ad06f873d4d92034aa5b6"```+**When a golden moves.** The test fails with the lines that changed, grouped by section (`[ind]`, `[pol]`, `[bud]`,+`[sit]` and so on), against a committed snapshot of the run's final state: `sim/Statecraft.Sim.Tests/golden/hash1950.txt`+and `hash1952.txt`, written by `GameState.Describe()`, which uses the same writer as `Hash()` (so the two cannot list+different fields) and shows every number as a plain value next to its IEEE bits. If the change is deliberate, run+`STATECRAFT_UPDATE_GOLDEN=1 dotnet test sim/Statecraft.sln`: it rewrites the snapshots, so the PR's diff of them shows+reviewers what moved. Then update the hash constants in the three places below by hand, and say why in the commit+message. The snapshot test also fails if a snapshot is stale while the hash is unchanged.+**Cause text is derived, not hashed.** The "Why did this happen?" lines (`Cause.Message`, `Cause.Delta`) are outputcomputed from the hashed state; replaying a save's commands regenerates them. Wording changes therefore do not move thegoldens (playtest 2 changed every line's casing with no hash change). They are still deterministic:diff --git a/sim/Statecraft.Sim.Tests/DeterminismTests.cs b/sim/Statecraft.Sim.Tests/DeterminismTests.csindex 3518464e7..dcc133f1c 100644--- a/sim/Statecraft.Sim.Tests/DeterminismTests.cs+++ b/sim/Statecraft.Sim.Tests/DeterminismTests.cs@@ -30,7 +30,7 @@ public class DeterminismTestsvar s = GoldenPlaythrough(ContentLoader.Load(RealContentTests.ContentRoot()));Assert.Null(s.GameOver);Assert.True(s.Date >= GoldenRun.Until1950);- Assert.Equal(GoldenHash, s.Hash());+ GoldenSnapshot.Check("hash1950", s, GoldenHash);}/// <summary>Same rule for the second golden run, which covers the M3 content range (to 1952-01-01).</summary>@@ -42,7 +42,7 @@ public class DeterminismTestsvar s = GoldenRun.Play(ContentLoader.Load(RealContentTests.ContentRoot()), GoldenRun.Until1952);Assert.Null(s.GameOver);Assert.Equal(new DateTime(1952, 2, 27), s.Date);- Assert.Equal(GoldenHash1952, s.Hash());+ GoldenSnapshot.Check("hash1952", s, GoldenHash1952);}/// <summary>The library constants Unity players compare against are the values these tests pin.</summary>diff --git a/sim/Statecraft.Sim.Tests/GoldenSnapshot.cs b/sim/Statecraft.Sim.Tests/GoldenSnapshot.csnew file mode 100644index 000000000..fefc822c6--- /dev/null+++ b/sim/Statecraft.Sim.Tests/GoldenSnapshot.cs@@ -0,0 +1,72 @@+using System;+using System.Collections.Generic;+using System.IO;+using System.Linq;+using System.Text;+using Statecraft.Sim;++/// <summary>Makes a golden-hash failure readable (#256). Each golden run's final state is committed as text+/// (sim/Statecraft.Sim.Tests/golden/<name>.txt, written by <see cref="GameState.Describe"/>). When the hash differs,+/// the test fails with the lines that changed against that snapshot, grouped by section, instead of two hashes.+/// To accept a deliberate change, run <c>STATECRAFT_UPDATE_GOLDEN=1 dotnet test</c>: it rewrites the snapshot, so the+/// snapshot's diff in the PR shows reviewers what moved. The hash constants are still updated by hand (docs/determinism.md).</summary>+public static class GoldenSnapshot+{+ static string Path_(string name) =>+ Path.Combine(Directory.GetParent(RealContentTests.ContentRoot())!.FullName, "sim", "Statecraft.Sim.Tests", "golden", name + ".txt");++ /// <summary>Asserts the state's hash equals <paramref name="expectedHash"/>; on a mismatch fails with the diff.+ /// Also asserts the committed snapshot is the state's current description, so it cannot go stale.</summary>+ public static void Check(string name, GameState state, string expectedHash)+ {+ var now = state.Describe();+ var path = Path_(name);+ var update = Environment.GetEnvironmentVariable("STATECRAFT_UPDATE_GOLDEN") == "1";+ if (update) File.WriteAllText(path, now);+ var hashOk = state.Hash() == expectedHash;+ var saved = File.Exists(path) ? File.ReadAllText(path).Replace("\r\n", "\n") : null; // a CRLF checkout is not a change+ if (hashOk && saved == now) return;+ var sb = new StringBuilder();+ if (!hashOk) sb.AppendLine($"Golden '{name}' moved: expected {expectedHash}, got {state.Hash()}.");+ else sb.AppendLine($"Golden '{name}' hash is unchanged but its snapshot is out of date.");+ if (saved == null) sb.AppendLine($"No snapshot at {path}; run STATECRAFT_UPDATE_GOLDEN=1 dotnet test to create it.");+ else sb.Append(Diff(saved, now));+ if (update) sb.AppendLine("Snapshot rewritten (STATECRAFT_UPDATE_GOLDEN=1). Update the hash constants in GoldenRun.cs, DeterminismTests.cs and docs/determinism.md, and say why in the commit message.");+ else sb.AppendLine("If this is deliberate: STATECRAFT_UPDATE_GOLDEN=1 dotnet test, then update the three hash constants (docs/determinism.md).");+ Assert.Fail(sb.ToString());+ }++ /// <summary>Changed lines between two descriptions, grouped by section (the label before '{' or '[' or '=').</summary>+ public static string Diff(string before, string after)+ {+ List<(string section, string line)> Parse(string text)+ {+ var res = new List<(string, string)>();+ string section = "header";+ foreach (var raw in text.Split('\n'))+ {+ if (raw.Length == 0) continue;+ if (!raw.StartsWith(" "))+ {+ var end = raw.IndexOfAny(new[] { '{', '[', '=' });+ section = end > 0 && raw.IndexOf(';') is var semi && (semi < 0 || end < semi) ? raw.Substring(0, end) : "header";+ }+ res.Add((section, raw));+ }+ return res;+ }+ var a = Parse(before); var b = Parse(after);+ var aSet = new HashSet<(string, string)>(a); var bSet = new HashSet<(string, string)>(b);+ var sb = new StringBuilder();+ foreach (var g in a.Concat(b).Select(x => x.section).Distinct())+ {+ var removed = a.Where(x => x.section == g && !bSet.Contains(x)).Select(x => " - " + x.line.TrimStart()).ToList();+ var added = b.Where(x => x.section == g && !aSet.Contains(x)).Select(x => " + " + x.line.TrimStart()).ToList();+ if (removed.Count + added.Count == 0) continue;+ sb.AppendLine($"[{g}]");+ foreach (var l in removed.Take(40)) sb.AppendLine(l);+ foreach (var l in added.Take(40)) sb.AppendLine(l);+ }+ return sb.Length == 0 ? "(the descriptions are identical)\n" : sb.ToString();+ }+}diff --git a/sim/Statecraft.Sim.Tests/GoldenSnapshotTests.cs b/sim/Statecraft.Sim.Tests/GoldenSnapshotTests.csnew file mode 100644index 000000000..5feb316fe--- /dev/null+++ b/sim/Statecraft.Sim.Tests/GoldenSnapshotTests.cs@@ -0,0 +1,72 @@+using System;+using Statecraft.Sim;++/// <summary>The readable golden failure (#256): Describe() lists what Hash() hashes, and Diff names what moved.</summary>+public class GoldenSnapshotTests+{+ static GameState Fresh() => Simulation.NewGame(ContentLoader.Load(RealContentTests.ContentRoot()), GoldenRun.Seed, Mode.Historical);++ [Fact]+ public void ChangingOneIndicatorShowsThatIndicatorInTheDiff()+ {+ var a = Fresh(); var b = a.Clone();+ var key = a.Indicators.Keys.OrderBy(k => k, StringComparer.Ordinal).First();+ b.Indicators[key] += 0.125;+ Assert.NotEqual(a.Hash(), b.Hash());+ var diff = GoldenSnapshot.Diff(a.Describe(), b.Describe());+ Assert.Contains("[ind]", diff);+ Assert.Contains(key + "=", diff);+ Assert.DoesNotContain("[pol]", diff);+ Assert.DoesNotContain("[bud]", diff);+ }++ [Fact]+ public void ChangingTheTreasuryAndAFiredEventShowsEachOnItsOwnLine()+ {+ var a = Fresh(); var b = a.Clone();+ b.Treasury += 1;+ b.FiredEvents.Add("zzz_probe_event");+ var diff = GoldenSnapshot.Diff(a.Describe(), b.Describe());+ Assert.Contains("[treasury]", diff);+ Assert.Contains("[fired]\n + zzz_probe_event\n", diff.Replace("\r\n", "\n"));+ Assert.DoesNotContain("[sit]", diff);+ }++ [Fact]+ public void ChangingOneChosenOptionOrAppointmentShowsOnlyThatEntry()+ {+ var a = Fresh();+ a.ChosenOptions["aaa_event"] = "first"; a.ChosenOptions["zzz_event"] = "first";+ a.Appointments["finance_minister"] = new Appointment("someone", new DateTime(1949, 3, 10));+ var b = a.Clone();+ b.ChosenOptions["aaa_event"] = "second";+ b.Appointments["finance_minister"] = new Appointment("other", new DateTime(1949, 3, 10));+ var diff = GoldenSnapshot.Diff(a.Describe(), b.Describe()).Replace("\r\n", "\n");+ Assert.Contains("[chosen]\n - aaa_event=first\n + aaa_event=second\n", diff);+ Assert.Contains("[appt]\n - finance_minister=someone@1949-03-10\n + finance_minister=other@1949-03-10\n", diff);+ Assert.DoesNotContain("zzz_event", diff);+ }++ [Fact]+ public void IdenticalStatesHaveNoDiffAndTheSameHash()+ {+ var a = Fresh(); var b = a.Clone();+ Assert.Equal(a.Hash(), b.Hash());+ Assert.Equal(a.Describe(), b.Describe());+ Assert.Contains("identical", GoldenSnapshot.Diff(a.Describe(), b.Describe()));+ }++ [Fact]+ public void DescribeIsTheSameInEveryCulture()+ {+ var a = Fresh();+ var before = System.Globalization.CultureInfo.CurrentCulture;+ try+ {+ var invariant = a.Describe();+ System.Globalization.CultureInfo.CurrentCulture = new System.Globalization.CultureInfo("de-DE");+ Assert.Equal(invariant, a.Describe());+ }+ finally { System.Globalization.CultureInfo.CurrentCulture = before; }+ }+}diff --git a/sim/Statecraft.Sim.Tests/golden/hash1950.txt b/sim/Statecraft.Sim.Tests/golden/hash1950.txtnew file mode 100644index 000000000..3d2c15b42--- /dev/null+++ b/sim/Statecraft.Sim.Tests/golden/hash1950.txt@@ -0,0 +1,99 @@+1950-02-27;1948;Historical;35;+ind{+ food_supply=0.8475 [3FEB1EB851EB851F]+ housing=0.4330532365826626 [3FDBB724EC232ACA]+ intl_standing=0.8400000000000003 [3FEAE147AE147AE4]+ morale=0.44505666965923585 [3FDC7BCEF84365E2]+ security=0.5037912258539358 [3FE01F0EC6E1BDAD]+pol{+ border_settlement=0.2 [3FC999999999999A]+ housing_construction=0.3 [3FD3333333333333]+ maabarot=0 [0000000000000000]+ rationing=1 [3FF0000000000000]+eff{+ border_villages_secure=0.03879122585393575 [3FA3DC718CD42CB9]+ building_houses=0.08305323658266262 [3FB542FA16F31190]+ homes_lift_morale=0.06474706472362149 [3FB093437D7FFCB2]+ rationing_feeds=0.2975 [3FD30A3D70A3D70A]+ rationing_grates=-0.15 [BFC3333333333333]+ safety_lifts_morale=0.05030960493561433 [3FA9C22E37BF0CB2]+shift{+ food_supply=0.15000000000000002 [3FC3333333333334]+ housing=0 [0000000000000000]+ intl_standing=0.3400000000000003 [3FD5C28F5C28F5C8]+ morale=-0.07000000000000006 [BFB1EB851EB851F0]+ security=0.16500000000000004 [3FC51EB851EB8520]+bud{+ agriculture_minister=0.07 [3FB1EB851EB851EC]+ defense_minister=0.45 [3FDCCCCCCCCCCCCD]+ education_minister=0.06 [3FAEB851EB851EB8]+ finance_minister=0.05 [3FA999999999999A]+ health_minister=0.07 [3FB1EB851EB851EC]+ interior_minister=0.05 [3FA999999999999A]+ labour_minister=0.1 [3FB999999999999A]+ prime_minister=0.15 [3FC3333333333333]+pop{+ africa=52054.01585594315 [40E96AC081E452A9]+ america_oceania=2229.985467792672 [40A16BF88F3C0993]+ asia=86153.10721742504 [40F50891B7299E62]+ europe=214207.90382761517 [410A25FF3B09F903]+ unknown=18488.77061889312 [40D20E3151D1E7E8]+ veterans=669284.2678813029 [41246CC88927BCF6]+sit[+treasury=0 [0000000000000000]+debt=97.88494849189715 [405878A2FEFFD5F0]+fx=88.29485501614538 [405612DEE792D9FB]+rung=2;cf=0;+mob=0.05 [3FA999999999999A]+stab=0.507928756679837 [3FE040F3CED46932]+att=4 [4010000000000000]+fired[+ altalena+ armistice_egypt+ armistice_jordan+ armistice_lebanon+ armistice_syria+ austerity_1949+ bernadotte_assassination+ elections_1949+ first_truce+ frumkin_commission+ idf_founding+ jerusalem_ceasefire+ jerusalem_military_government+ latrun_proposal+ operation_hiram+ operation_horev+ operation_yoav+ rhodes_talks+ second_truce+ sinai_withdrawal+ ten_days+pending[+ frumkin_commission+chosen{+ altalena=enforce+ armistice_egypt=sign+ armistice_jordan=sign+ armistice_lebanon=sign+ armistice_syria=sign+ austerity_1949=impose+ bernadotte_assassination=outlaw+ elections_1949=hold+ first_truce=accept+ idf_founding=one_army+ jerusalem_ceasefire=sign+ jerusalem_military_government=military_government+ latrun_proposal=accept_vote+ operation_hiram=launch+ operation_horev=launch+ operation_yoav=stop_at_ceasefire+ rhodes_talks=send_delegation+ second_truce=comply+ sinai_withdrawal=withdraw+ ten_days=central_front+appt{+under=;+map[+mapturn=0001-01-01:0;+over=\ No newline at end of filediff --git a/sim/Statecraft.Sim.Tests/golden/hash1952.txt b/sim/Statecraft.Sim.Tests/golden/hash1952.txtnew file mode 100644index 000000000..f04557e01--- /dev/null+++ b/sim/Statecraft.Sim.Tests/golden/hash1952.txt@@ -0,0 +1,120 @@+1952-02-27;1948;Historical;43;+ind{+ food_supply=0.839833984375 [3FEADFEB851EB852]+ housing=0.43485009819364695 [3FDBD4958199DCD0]+ intl_standing=0.8300000000000003 [3FEA8F5C28F5C292]+ morale=0.4597343174015912 [3FDD6C497C85AD8E]+ security=0.5352660109379224 [3FE120E62F7470AE]+pol{+ border_settlement=0.2 [3FC999999999999A]+ housing_construction=0.3 [3FD3333333333333]+ maabarot=1 [3FF0000000000000]+ rationing=1 [3FF0000000000000]+eff{+ border_villages_secure=0.04026601093792225 [3FA49DBF203CCD5F]+ building_houses=0.084850098193647 [3FB5B8BC6CCDD9AA]+ homes_lift_morale=0.06665100052742542 [3FB1100A3B82CEFE]+ rationing_feeds=0.339833984375 [3FD5BFD70A3D70A4]+ rationing_grates=-0.15 [BFC3333333333333]+ safety_lifts_morale=0.053083316874165815 [3FAB2DBC8BE02064]+shift{+ food_supply=0.09999999999999998 [3FB9999999999998]+ housing=0 [0000000000000000]+ intl_standing=0.3300000000000003 [3FD51EB851EB8524]+ morale=-0.06000000000000005 [BFAEB851EB851EC0]+ security=0.19500000000000012 [3FC8F5C28F5C28FA]+bud{+ agriculture_minister=0.07 [3FB1EB851EB851EC]+ defense_minister=0.45 [3FDCCCCCCCCCCCCD]+ education_minister=0.06 [3FAEB851EB851EB8]+ finance_minister=0.05 [3FA999999999999A]+ health_minister=0.07 [3FB1EB851EB851EC]+ interior_minister=0.05 [3FA999999999999A]+ labour_minister=0.1 [3FB999999999999A]+ prime_minister=0.15 [3FC3333333333333]+pop{+ africa=97023.87456738956 [40F7AFFDFE3A6005]+ america_oceania=5293.427260779819 [40B4AD6D60F66430]+ asia=243201.36816545296 [410DB00AF200BAA0]+ europe=339252.8124862721 [4114B4D33FFC66BC]+ unknown=25479.920679861305 [40D8E1FAEC6B3999]+ veterans=692243.4377982062 [41252026E0271624]+sit[+ fx_crisis+treasury=0 [0000000000000000]+debt=198.45839469313046 [4068CEAB2B58F4F8]+fx=-36.80544499186334 [C0426718D24D63D8]+rung=2;cf=0;+mob=0.05 [3FA999999999999A]+stab=0.5164021806898154 [3FE0865DDDB4AAB8]+att=4 [4010000000000000]+fired[+ altalena+ armistice_egypt+ armistice_jordan+ armistice_lebanon+ armistice_syria+ austerity_1949+ bernadotte_assassination+ clothing_rationing_1950+ education_registration_1951+ elections_1949+ first_truce+ forex_crisis_1951+ frumkin_commission+ hula_drainage+ idf_founding+ iraqi_exodus+ israel_bonds+ jerusalem_ceasefire+ jerusalem_military_government+ latrun_proposal+ law_of_return+ maabarot_policy+ ministry_supply_crisis+ operation_hiram+ operation_horev+ operation_yoav+ reparations_claim+ rhodes_talks+ second_truce+ sinai_withdrawal+ ten_days+pending[+chosen{+ altalena=enforce+ armistice_egypt=sign+ armistice_jordan=sign+ armistice_lebanon=sign+ armistice_syria=sign+ austerity_1949=impose+ bernadotte_assassination=outlaw+ clothing_rationing_1950=extend+ education_registration_1951=press_plan+ elections_1949=hold+ first_truce=accept+ forex_crisis_1951=request_aid+ frumkin_commission=inquiry+ hula_drainage=continue_works+ idf_founding=one_army+ iraqi_exodus=airlift+ israel_bonds=launch+ jerusalem_ceasefire=sign+ jerusalem_military_government=military_government+ latrun_proposal=accept_vote+ law_of_return=enact+ maabarot_policy=maabarot+ ministry_supply_crisis=restructure+ operation_hiram=launch+ operation_horev=launch+ operation_yoav=stop_at_ceasefire+ reparations_claim=claim+ rhodes_talks=send_delegation+ second_truce=comply+ sinai_withdrawal=withdraw+ ten_days=central_front+appt{+under=;+map[+mapturn=0001-01-01:0;+over=\ No newline at end of filediff --git a/sim/Statecraft.Sim/GameState.cs b/sim/Statecraft.Sim/GameState.csindex 4cdf4ac9e..fac730ff2 100644--- a/sim/Statecraft.Sim/GameState.cs+++ b/sim/Statecraft.Sim/GameState.cs@@ -80,40 +80,73 @@ namespace Statecraft.Sim/// written as 0.0), so hashes match across .NET, Mono and IL2CPP.</summary>public string Hash(){+ using var sha = SHA256.Create();+ var bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(CanonicalText(false)));+ return string.Concat(bytes.Select(b => b.ToString("x2")));+ }++ /// <summary>The state in the order and form <see cref="Hash"/> hashes it, one line per section, with each number+ /// also written as a plain value (`name=1.5 [3FF8000000000000]`). For humans: a golden-hash failure diffs this+ /// (issue #256). It shares one writer with <see cref="Hash"/>, so the two cannot list different fields.</summary>+ public string Describe() => CanonicalText(true);++ string CanonicalText(bool readable)+ {+ // Hash text: one line, ';'-separated, closing brackets. Readable text: a section label per line, each entry+ // on its own indented line, no closing brackets. Both are written by the calls below, in the same order.var sb = new StringBuilder();- void Num(string k, double v) => sb.Append(k).Append('=').Append(BitConverter.DoubleToInt64Bits(v == 0.0 ? 0.0 : v).ToString("X16", CultureInfo.InvariantCulture)).Append(';');+ void Nl() { if (readable) sb.Append('\n'); }+ void Entry() { if (readable) sb.Append("\n "); }+ void Close(char c) { if (!readable) sb.Append(c); }+ void Num(string k, double v, bool inMap = false)+ {+ var bits = BitConverter.DoubleToInt64Bits(v == 0.0 ? 0.0 : v).ToString("X16", CultureInfo.InvariantCulture);+ if (readable) sb.Append(inMap ? "\n " : "\n").Append(k).Append('=').Append((v == 0.0 ? 0.0 : v).ToString("R", CultureInfo.InvariantCulture)).Append(" [").Append(bits).Append(']');+ else sb.Append(k).Append('=').Append(bits).Append(';');+ }void Map(string name, Dictionary<string, double> m){- sb.Append(name).Append('{');- foreach (var kv in m.OrderBy(k => k.Key, StringComparer.Ordinal)) Num(kv.Key, kv.Value);- sb.Append('}');+ Nl(); sb.Append(name).Append('{');+ foreach (var kv in m.OrderBy(k => k.Key, StringComparer.Ordinal)) Num(kv.Key, kv.Value, true);+ Close('}');}+ void List(string name, IEnumerable<string> items)+ {+ Nl(); sb.Append(name).Append('[');+ if (readable) foreach (var i in items) { Entry(); sb.Append(i); }+ else sb.Append(string.Join(",", items));+ Close(']');+ }+ void Sep() { if (!readable) sb.Append(';'); }sb.Append(Date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).Append(';').Append(RngState).Append(';').Append(Mode).Append(';').Append(Turn).Append(';');Map("ind", Indicators); Map("pol", Policies); Map("eff", EffectContributions); Map("shift", IndicatorShifts);Map("bud", Budget); Map("pop", Population);- sb.Append("sit[").Append(string.Join(",", ActiveSituations)).Append(']');+ List("sit", ActiveSituations);Num("treasury", Treasury); Num("debt", Debt); Num("fx", FxReserves);- sb.Append("rung=").Append(Rung).Append(";cf=").Append(CeasefireWeeksLeft).Append(';');+ Nl(); sb.Append("rung=").Append(Rung).Append(";cf=").Append(CeasefireWeeksLeft).Append(';');Num("mob", Mobilization); Num("stab", CoalitionStability); Num("att", Attention);- sb.Append("fired[").Append(string.Join(",", FiredEvents)).Append(']');- sb.Append("pending[").Append(string.Join(",", PendingEvents)).Append(']');- sb.Append("chosen{");- foreach (var kv in ChosenOptions.OrderBy(k => k.Key, StringComparer.Ordinal)) sb.Append(kv.Key).Append('=').Append(kv.Value).Append(';');- sb.Append('}');- sb.Append("appt{");+ List("fired", FiredEvents);+ List("pending", PendingEvents);+ Nl(); sb.Append("chosen{");+ foreach (var kv in ChosenOptions.OrderBy(k => k.Key, StringComparer.Ordinal)) { Entry(); sb.Append(kv.Key).Append('=').Append(kv.Value); Sep(); }+ Close('}');+ Nl(); sb.Append("appt{");foreach (var kv in Appointments.OrderBy(k => k.Key, StringComparer.Ordinal))- sb.Append(kv.Key).Append('=').Append(kv.Value.Person).Append('@').Append(kv.Value.From.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).Append(';');- sb.Append("}under=").Append(AppointedUnder).Append(';');- sb.Append("map[");+ {+ Entry(); sb.Append(kv.Key).Append('=').Append(kv.Value.Person).Append('@').Append(kv.Value.From.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)); Sep();+ }+ Close('}');+ Nl(); sb.Append("under=").Append(AppointedUnder).Append(';');+ Nl(); sb.Append("map[");foreach (var p in Placements)- sb.Append(p.Action).Append('@').Append(p.Q).Append(',').Append(p.R).Append('@').Append(p.Date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).Append(';');- sb.Append(']');- sb.Append("mapturn=").Append(MapActionsTurnDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).Append(':').Append(MapActionsThisTurn).Append(';');- sb.Append("over=").Append(GameOver ?? "");- using var sha = SHA256.Create();- var bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(sb.ToString()));- return string.Concat(bytes.Select(b => b.ToString("x2")));+ {+ Entry(); sb.Append(p.Action).Append('@').Append(p.Q).Append(',').Append(p.R).Append('@').Append(p.Date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)); Sep();+ }+ Close(']');+ Nl(); sb.Append("mapturn=").Append(MapActionsTurnDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).Append(':').Append(MapActionsThisTurn).Append(';');+ Nl(); sb.Append("over=").Append(GameOver ?? "");+ return sb.ToString();}}}