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.

Advisors: plumbing for the new-player course, no rows yet (Refs #2933) (#2942)

Eyal Golanda45d9c72b1c
diff --git a/changelog.d/2933-advisor-plumbing.md b/changelog.d/2933-advisor-plumbing.md
new file mode 100644
index 000000000..b60a3b56e
--- /dev/null
+++ b/changelog.d/2933-advisor-plumbing.md
@@ -0,0 +1,5 @@
+- Advisors: groundwork for the new-player course (#2933): a `turn_at_least` condition, `lapse_after` and `fallback` fields on
+ a message, and a `course_open` signal set when the opening chain opens by itself. No message uses them yet, so nothing
+ changes on screen.
+- Advisors: at help level off, experienced or warnings the opening chain no longer opens by itself on a first game. It
+ counts as seen, so it does not come later, and the new-player course does not open. The encyclopedia still reopens it.
diff --git a/unity/Assets/Scripts/UI/AdvisorCatalog.cs b/unity/Assets/Scripts/UI/AdvisorCatalog.cs
index 1036ba3f0..02d50bc6f 100644
--- a/unity/Assets/Scripts/UI/AdvisorCatalog.cs
+++ b/unity/Assets/Scripts/UI/AdvisorCatalog.cs
@@ -62,12 +62,19 @@ namespace Statecraft.Game.UI
public string DisagreesWith { get; set; } = "";
public string HeReview { get; set; } = Pending;
public Media? Media { get; set; }
+ /// <summary>A second signal that also queues it, for a chain step that must survive a closed chain; its requires
+ /// then only orders the chain (AdvisorQueue.Eligible).</summary>
+ public string Fallback { get; set; } = "";
+ /// <summary>A teaching message's last game turn, the first being 1, as turn_at_least; 0 never lapses.</summary>
+ public int LapseAfter { get; set; }
/// <summary>Teaching (help levels new and experienced) as against advice and warnings (spec 7.1's button sets).</summary>
public bool Teaching => Level == "new" || Level == "experienced";
public bool Critical => Level == "critical";
/// <summary>Its text may show in this language: English always, Hebrew once approved (OQ-4).</summary>
public bool ApprovedIn(bool hebrew) => !hebrew || HeReview == Approved;
+ /// <summary>Its signal or its fallback holds.</summary>
+ public bool Holds(IReadOnlyCollection<string> holding) => holding.Contains(Signal) || holding.Contains(Fallback);
}
public sealed class Page
@@ -162,6 +169,8 @@ namespace Statecraft.Game.UI
if (!IdPattern.IsMatch(m.Id)) p.Add($"{at}: an id is lower-case letters, digits, '_' and '.'");
if (!AdvisorIds.Contains(m.Advisor)) p.Add($"{at}: unknown advisor '{m.Advisor}'");
if (!known.Signals.Contains(m.Signal)) p.Add($"{at}: unknown signal '{m.Signal}'");
+ if (m.Fallback != "" && !known.Signals.Contains(m.Fallback)) p.Add($"{at}: unknown fallback signal '{m.Fallback}'");
+ if (m.LapseAfter != 0 && (m.LapseAfter < 1 || !m.Teaching)) p.Add($"{at}: lapse_after is a game turn, on teaching messages only");
foreach (var k in m.When.Keys) if (!known.Conditions.Contains(k)) p.Add($"{at}: unknown condition '{k}'");
foreach (var r in m.Requires) if (!byId.ContainsKey(r)) p.Add($"{at}: requires unknown message '{r}'");
if (!Levels.Contains(m.Level)) p.Add($"{at}: level must be one of {string.Join(", ", Levels)}");
diff --git a/unity/Assets/Scripts/UI/AdvisorPresenter.cs b/unity/Assets/Scripts/UI/AdvisorPresenter.cs
index 543b57a65..2a2ba9ad9 100644
--- a/unity/Assets/Scripts/UI/AdvisorPresenter.cs
+++ b/unity/Assets/Scripts/UI/AdvisorPresenter.cs
@@ -228,6 +228,11 @@ namespace Statecraft.Game.UI
&& !hudRoot.ClassListContains(StartScreenPresenter.OpenClass) && chain.Any(InTour))
{
session.Settings.MarkOpeningSeen();
+ // Owner ruling on #2942, "Off silences it": above the new level the chain does not open by itself and
+ // still counts as seen, so it never comes later; no course opens either. The encyclopedia can reopen it.
+ if (session.Settings.LevelRank > 0) return;
+ session.Settings.MarkCourseOpen();
+ Evaluate(); // course_open holds from here: its rows wait behind the chain
OpenChain();
}
}
@@ -392,7 +397,7 @@ namespace Statecraft.Game.UI
var ctx = Context();
var holding = AdvisorSignals.Holding(ctx, session);
if (budgetUnsubmitted) holding.Add(AdvisorSignals.BudgetUnsubmitted); // as in Evaluate's Prune
- if (!(holding.Contains(m.Signal) && AdvisorSignals.When(ctx, m.When)))
+ if (!(m.Holds(holding) && AdvisorSignals.When(ctx, m.When)))
session.Queue.Drop(m, Turn, bridge.State.Date);
}
Render();
diff --git a/unity/Assets/Scripts/UI/AdvisorQueue.cs b/unity/Assets/Scripts/UI/AdvisorQueue.cs
index d16831c96..669731f58 100644
--- a/unity/Assets/Scripts/UI/AdvisorQueue.cs
+++ b/unity/Assets/Scripts/UI/AdvisorQueue.cs
@@ -43,18 +43,19 @@ namespace Statecraft.Game.UI
{
foreach (var m in catalog.Messages)
{
- if (!holding.Contains(m.Signal) || waiting.Any(w => w.M == m)) continue;
- if (!Eligible(m, turn) || !when(m.When)) continue;
+ if (!m.Holds(holding) || waiting.Any(w => w.M == m)) continue;
+ if (!Eligible(m, turn) || Lapsed(m, turn) || !when(m.When)) continue;
waiting.Add(new Waiting { M = m, Seq = seq++, NotBefore = turn });
}
}
/// <summary>Each turn, a waiting or put-off warning whose signal or condition no longer holds goes to the history as
/// missed, not seen, so its signal can bring it back (owner, #2024). Critical messages are never pruned, and teaching
- /// ones are not warnings. The one on screen (<paramref name="shown"/>) stays until the player closes it (owner, 1 Nov).</summary>
+ /// ones are not warnings: they go only past their lapse_after. The one on screen (<paramref name="shown"/>) stays until
+ /// the player closes it (owner, 1 Nov).</summary>
public void Prune(IReadOnlyCollection<string> holding, Func<IReadOnlyDictionary<string, double>, bool> when, int turn, DateTime date, AdvisorCatalog.Message? shown = null)
{
- foreach (var w in waiting.Where(w => w.M != shown && !w.M.Critical && !w.M.Teaching && !(holding.Contains(w.M.Signal) && when(w.M.When))).ToList())
+ foreach (var w in waiting.Where(w => w.M != shown && !w.M.Critical && (w.M.Teaching ? Lapsed(w.M, turn) : !(w.M.Holds(holding) && when(w.M.When)))).ToList())
{
waiting.Remove(w);
history.Add(new Entry(w.M.Id, turn, date, Outcome.Missed));
@@ -64,7 +65,11 @@ namespace Statecraft.Game.UI
bool Eligible(AdvisorCatalog.Message m, int turn) =>
Array.IndexOf(AdvisorCatalog.Levels, m.Level) >= settings.LevelRank
&& (m.Repeat == AdvisorCatalog.Once ? !settings.Seen(m.Id) : !(lastShown.TryGetValue(m.Id, out var t) && turn < t + m.CooldownTurns))
- && m.Requires.All(settings.Seen);
+ && (m.Fallback != "" || m.Requires.All(settings.Seen));
+
+ /// <summary>Past a teaching message's last game turn; <paramref name="turn"/> is State.Turn, which starts at 0. Offer checks it
+ /// too, or a lapsed message whose signal still holds would queue and go to the history again on every change.</summary>
+ static bool Lapsed(AdvisorCatalog.Message m, int turn) => m.Teaching && m.LapseAfter > 0 && turn >= m.LapseAfter;
void Caps(int turn)
{
diff --git a/unity/Assets/Scripts/UI/AdvisorSettings.cs b/unity/Assets/Scripts/UI/AdvisorSettings.cs
index 08fec2c1a..cafdae812 100644
--- a/unity/Assets/Scripts/UI/AdvisorSettings.cs
+++ b/unity/Assets/Scripts/UI/AdvisorSettings.cs
@@ -7,11 +7,11 @@ using UnityEngine;
namespace Statecraft.Game.UI
{
/// <summary>The advisors' lines in the settings file (spec 15; SettingsStore: presentation only, never the sim or the
- /// save): the help level, the messages seen (one line, advisor_seen=a,b,c) and the opening chain's mark. The marks
+ /// save): the help level, the messages seen (one line, advisor_seen=a,b,c), the opening chain's mark and the new-player course's. The marks
/// are also kept in memory, so a failed write (logged) or no file at all (automated runs) only costs persistence.</summary>
public sealed class AdvisorSettings
{
- public const string LevelKey = "advisor_level", SeenKey = "advisor_seen", OpeningKey = "advisor_opening";
+ public const string LevelKey = "advisor_level", SeenKey = "advisor_seen", OpeningKey = "advisor_opening", CourseKey = "advisor_course";
/// <summary>The legacy first-turn guide's saved line (spec 9.3: honoured, so a player who saw the guide gets no chain by itself).</summary>
public const string GuideSeenKey = "first_turn_guide";
/// <summary>Spec 6, from the chattiest; a message shows when its level's index (AdvisorCatalog.Levels) is at least this one's.</summary>
@@ -19,7 +19,7 @@ namespace Statecraft.Game.UI
readonly SettingsStore? store;
readonly SortedSet<string> seen = new SortedSet<string>(StringComparer.Ordinal);
- bool openingSeen;
+ bool openingSeen, courseOpen;
public AdvisorSettings(SettingsStore? store)
{
@@ -28,6 +28,7 @@ namespace Statecraft.Game.UI
Level = Array.IndexOf(Levels, stored) >= 0 ? stored! : Levels[0];
foreach (var id in (store?.Read(SeenKey) ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) seen.Add(id);
openingSeen = store?.Read(OpeningKey) == "seen" || store?.Read(GuideSeenKey) == "seen";
+ courseOpen = store?.Read(CourseKey) == "open";
}
/// <summary>A settings file exists to remember the marks in (none in automated runs and EditMode tests).</summary>
@@ -62,6 +63,16 @@ namespace Statecraft.Game.UI
Write(OpeningKey, "seen");
}
+ /// <summary>The chain opened by itself on this player's first game (#2933), so the course's rows may show; a returning
+ /// player, whose chain mark predates this line, has none.</summary>
+ public bool CourseOpen => courseOpen;
+
+ public void MarkCourseOpen()
+ {
+ courseOpen = true;
+ Write(CourseKey, "open");
+ }
+
void Write(string key, string value)
{
if (store == null) return;
diff --git a/unity/Assets/Scripts/UI/AdvisorSignals.cs b/unity/Assets/Scripts/UI/AdvisorSignals.cs
index b429dece6..c7e9187f6 100644
--- a/unity/Assets/Scripts/UI/AdvisorSignals.cs
+++ b/unity/Assets/Scripts/UI/AdvisorSignals.cs
@@ -12,7 +12,7 @@ namespace Statecraft.Game.UI
public static class AdvisorSignals
{
public const string NewGame = "new_game", TurnEnded = "turn_ended", Opening = "opening",
- AttentionRefused = "attention_refused", BudgetUnsubmitted = "budget_unsubmitted", CityShown = "city_shown", UnitShown = "unit_shown";
+ AttentionRefused = "attention_refused", BudgetUnsubmitted = "budget_unsubmitted", CityShown = "city_shown", UnitShown = "unit_shown", CourseOpen = "course_open";
public static readonly IReadOnlyCollection<string> Events = new[] { NewGame, TurnEnded, Opening, AttentionRefused, BudgetUnsubmitted, CityShown, UnitShown };
public static readonly IReadOnlyDictionary<string, Func<AdvisorContext, bool>> States = new Dictionary<string, Func<AdvisorContext, bool>>
{
@@ -45,8 +45,10 @@ namespace Statecraft.Game.UI
["debt_ratio_at_least"] = ctx => ctx.Content.RulesAt(ctx.State.Date).Mvp?.DebtCeiling is double ceiling && ceiling > 0 ? ctx.State.Debt / ceiling : 0,
["refugees_at_least"] = ctx => ctx.State.Cities.Values.Sum(x => x.Refugees),
["cards_waiting_at_least"] = ctx => ctx.Card?.Shown != null ? 1 : 0,
+ // The game's turn, the first being 1 (State.Turn starts at 0).
+ ["turn_at_least"] = ctx => ctx.State.Turn + 1,
};
- public static IEnumerable<string> Names => Events.Concat(States.Keys);
+ public static IEnumerable<string> Names => Events.Concat(States.Keys).Append(CourseOpen);
/// <summary>The Arms the costliest single Arms action takes under the rules in force: a recruit group
/// (mvp.arms_per_recruit_group, R-ARMS-003), an attack (mvp.arms_per_attack, R-COMBAT-004), or one of our unit types'
@@ -73,6 +75,7 @@ namespace Statecraft.Game.UI
{
var holding = new HashSet<string>(session.FiredTurn == ctx.State.Turn ? session.Fired : Enumerable.Empty<string>(), StringComparer.Ordinal);
foreach (var kv in States) if (kv.Value(ctx)) holding.Add(kv.Key);
+ if (session.Settings.CourseOpen) holding.Add(CourseOpen); // a settings line, not the state: it needs the session
return holding;
}
}
diff --git a/unity/Assets/Tests/EditMode/AdvisorCatalogTests.cs b/unity/Assets/Tests/EditMode/AdvisorCatalogTests.cs
index a0d9c2d2a..832f1533a 100644
--- a/unity/Assets/Tests/EditMode/AdvisorCatalogTests.cs
+++ b/unity/Assets/Tests/EditMode/AdvisorCatalogTests.cs
@@ -111,6 +111,9 @@ public class AdvisorCatalogTests
[TestCase("{ id: x, advisor: dayan, signal: new_game, level: new, quote: q9 }", "not on the verified list")]
[TestCase("{ id: x, advisor: dayan, signal: new_game, level: new, he_review: maybe }", "he_review must be")]
[TestCase("{ id: x, advisor: dayan, signal: new_game, level: warnings, actions: [{ encyclopedia: moon }] }", "encyclopedia actions are for teaching messages")]
+ [TestCase("{ id: x, advisor: dayan, signal: new_game, fallback: moon, level: new }", "unknown fallback signal 'moon'")]
+ [TestCase("{ id: x, advisor: dayan, signal: new_game, level: warnings, lapse_after: 3 }", "lapse_after is a game turn, on teaching messages only")]
+ [TestCase("{ id: x, advisor: dayan, signal: new_game, level: new, lapse_after: -1 }", "lapse_after is a game turn, on teaching messages only")]
public void EachBrokenRowIsNamed(string row, string expected)
{
var problems = ProblemsOf("messages:\n - " + row + "\n", "advisor.x.text", "advisor.Bad Id.text");
diff --git a/unity/Assets/Tests/EditMode/AdvisorOpeningTests.cs b/unity/Assets/Tests/EditMode/AdvisorOpeningTests.cs
index 9e9d876fd..39cee320b 100644
--- a/unity/Assets/Tests/EditMode/AdvisorOpeningTests.cs
+++ b/unity/Assets/Tests/EditMode/AdvisorOpeningTests.cs
@@ -108,15 +108,104 @@ public class AdvisorOpeningTests
using var automated = new Rig(En, null); automated.Advisor.NewGame(); Assert.IsFalse(automated.Advisor.InChain);
}
- /// <summary>The plan's assumption (c): the opening chain is the first game's onboarding, as the guide was, so it ignores
- /// the help level (review of the S2 head).</summary>
+ /// <summary>Owner ruling on #2942, replacing the plan's assumption (c): "Off silences it". At help off, experienced or
+ /// warnings the chain does not open by itself and counts as seen, so it never appears later, even at the new level; the
+ /// course does not open either. A chain reopened by hand from the encyclopedia still shows.</summary>
[TestCase("off")] [TestCase("experienced")] [TestCase("warnings")]
- public void AnyHelpLevelGetsTheOpeningChainOnItsFirstGame(string level)
+ public void AHelpLevelAboveNewSilencesTheOpeningChainForGood(string level)
{
var store = Store(); store.Write(AdvisorSettings.LevelKey, level);
+ using (var rig = new Rig(En, store))
+ {
+ rig.Advisor.NewGame();
+ Assert.IsFalse(rig.Advisor.InChain, "no chain by itself at " + level);
+ Assert.IsTrue(rig.Session.Settings.OpeningSeen, "it counts as seen");
+ Assert.AreEqual("seen", store.Read(AdvisorSettings.OpeningKey));
+ Assert.IsFalse(rig.Session.Settings.CourseOpen, "and opens no course");
+ Assert.IsNull(store.Read(AdvisorSettings.CourseKey));
+ rig.Session.Settings.SetLevel("new");
+ rig.Advisor.NewGame();
+ Assert.IsFalse(rig.Advisor.InChain, "nor on a later game at the new level");
+ rig.Advisor.OpenChain();
+ Assert.IsTrue(rig.Advisor.InChain, "reopened by hand it shows");
+ Assert.IsFalse(rig.Session.Settings.CourseOpen);
+ }
+ using var later = new Rig(En, store); later.Advisor.NewGame();
+ Assert.IsFalse(later.Advisor.InChain, "nor after a restart");
+ Assert.IsFalse(later.Session.Settings.CourseOpen); Assert.IsNull(store.Read(AdvisorSettings.CourseKey));
+ }
+
+ /// <summary>At the new level, stored or the default, the first game still gets the chain and the course.</summary>
+ [TestCase("new")] [TestCase("")]
+ public void TheNewHelpLevelGetsTheOpeningChainOnItsFirstGame(string level)
+ {
+ var store = Store(); if (level != "") store.Write(AdvisorSettings.LevelKey, level); // "": no line, the default
+ using var rig = new Rig(En, store); rig.Advisor.NewGame();
+ Assert.IsTrue(rig.Advisor.InChain, "the first new game shows the chain at " + (level == "" ? "the default" : level));
+ Assert.IsTrue(rig.Session.Settings.OpeningSeen); Assert.IsTrue(rig.Session.Settings.CourseOpen);
+ }
+
+ /// <summary>#2933: the course opens with the chain's automatic opening, so only on a first game.</summary>
+ [Test]
+ public void TheAutomaticChainOpensTheCourse()
+ {
+ var store = Store();
+ using var rig = new Rig(En, store); rig.Advisor.NewGame();
+ Assert.IsTrue(rig.Advisor.InChain); Assert.IsTrue(rig.Session.Settings.CourseOpen);
+ Assert.AreEqual("open", store.Read(AdvisorSettings.CourseKey));
+ }
+
+ [Test]
+ public void ReturningPlayersAndAReopenedChainOpenNoCourse()
+ {
+ var store = Store(); store.Write(AdvisorSettings.OpeningKey, "seen");
using var rig = new Rig(En, store); rig.Advisor.NewGame();
- Assert.IsTrue(rig.Advisor.InChain, "the first new game shows the chain at " + level);
- Assert.IsTrue(rig.Session.Settings.OpeningSeen);
+ Assert.IsFalse(rig.Advisor.InChain);
+ rig.Advisor.OpenChain();
+ Assert.IsTrue(rig.Advisor.InChain, "reopened by hand");
+ Assert.IsFalse(rig.Session.Settings.CourseOpen); Assert.IsNull(store.Read(AdvisorSettings.CourseKey));
+ }
+
+ [Test]
+ public void NoAutomaticChainNoCourse()
+ {
+ using var automated = new Rig(En, null); automated.Advisor.NewGame();
+ Assert.IsFalse(automated.Session.Settings.CourseOpen, "an automated run");
+ using var pending = new Rig(He, Store()); pending.Advisor.NewGame();
+ Assert.IsFalse(pending.Session.Settings.CourseOpen, "Hebrew with every step pending shows no chain");
+ }
+
+ /// <summary>#2933, the plan's quit and X case, on an in-memory row only: objectives gets a course_open fallback. After X on
+ /// the first step it shows as a queue row, comes back from under a layer (its own signal, opening, never holds), and on
+ /// a Continue it is offered from the settings line alone, with no chain.</summary>
+ [Test]
+ public void AFallbackStepSurvivesXALayerAndAContinue()
+ {
+ var yaml = File.ReadAllText(AdvisorCatalog.Path);
+ const string Row = "id: opening.objectives, advisor: ben_gurion, signal: opening,";
+ StringAssert.Contains(Row, yaml);
+ var catalog = AdvisorCatalog.Parse(yaml.Replace(Row, Row + " fallback: course_open,"));
+ var store = Store();
+ using (var rig = new Rig(En, store, session: new AdvisorSession(catalog, new AdvisorSettings(store), true)))
+ {
+ rig.Advisor.NewGame();
+ Assert.AreEqual("opening.greeting", rig.Advisor.Shown?.Id);
+ rig.Advisor.CloseChain();
+ rig.Card.Collapse(takeFocus: false);
+ Assert.AreEqual("opening.objectives", rig.Advisor.Shown?.Id, "X on the first step");
+ Assert.IsTrue(rig.Advisor.IsOpen);
+ rig.Card.Reopen();
+ Assert.IsFalse(rig.Advisor.IsOpen, "under the card");
+ rig.Card.Collapse(takeFocus: false);
+ Assert.AreEqual("opening.objectives", rig.Advisor.Shown?.Id, "back from under the card");
+ Assert.IsTrue(rig.Advisor.IsOpen);
+ Assert.IsFalse(rig.Session.Queue.History.Any(e => e.Outcome == AdvisorQueue.Outcome.Missed));
+ }
+ using var continued = new Rig(En, store, session: new AdvisorSession(catalog, new AdvisorSettings(store), true));
+ continued.Card.Collapse(takeFocus: false);
+ continued.Advisor.Resume();
+ Assert.IsFalse(continued.Advisor.InChain);
+ Assert.AreEqual("opening.objectives", continued.Advisor.Shown?.Id, "a Continue, not seen yet");
}
[Test]
diff --git a/unity/Assets/Tests/EditMode/AdvisorQueueTests.cs b/unity/Assets/Tests/EditMode/AdvisorQueueTests.cs
index a10437a26..500bf3603 100644
--- a/unity/Assets/Tests/EditMode/AdvisorQueueTests.cs
+++ b/unity/Assets/Tests/EditMode/AdvisorQueueTests.cs
@@ -164,6 +164,78 @@ public class AdvisorQueueTests
Assert.AreEqual(1, q.History.Count, "Counsel lists it once");
}
+ /// <summary>#2933: lapse_after is the game's turn, the first being 1, so State.Turn 2 is turn 3, the row's last. Past it the
+ /// row goes to the history as missed, not seen; its signal still holds, and it does not come back a second time.</summary>
+ [Test]
+ public void ATeachingRowLapsesUnseenAfterItsGameTurnAndOnlyOnce()
+ {
+ var settings = new AdvisorSettings(null);
+ var q = new AdvisorQueue(Catalog(Row("t", "new", extra: ", lapse_after: 3")), settings);
+ q.Offer(Fired, Always, 2); q.Prune(Fired, Always, 2, Day);
+ Assert.AreEqual("t", q.Head(2, false)?.Id, "turn 3 is still in time");
+ for (int turn = 3; turn <= 5; turn++) { q.Offer(Fired, Always, turn); q.Prune(Fired, Always, turn, Day); }
+ Assert.IsNull(q.Head(5, false));
+ Assert.AreEqual(1, q.History.Count(e => e.Id == "t" && e.Outcome == AdvisorQueue.Outcome.Missed), "missed once, not once per Changed");
+ Assert.IsFalse(settings.Seen("t"));
+ }
+
+ [Test]
+ public void ARowFirstHoldingAfterItsLapseNeverQueues()
+ {
+ var q = new AdvisorQueue(Catalog(Row("t", "new", extra: ", lapse_after: 3")), new AdvisorSettings(null));
+ q.Offer(Fired, Always, 3); q.Prune(Fired, Always, 3, Day);
+ Assert.IsNull(q.Head(3, false));
+ Assert.IsEmpty(q.History, "it never waited");
+ }
+
+ /// <summary>As with warnings (owner, 1 Nov): the one on screen stays until the player closes it.</summary>
+ [Test]
+ public void TheLapsingRowOnScreenStaysUntilItIsClosed()
+ {
+ var q = new AdvisorQueue(Catalog(Row("t", "new", extra: ", lapse_after: 3")), new AdvisorSettings(null));
+ q.Offer(Fired, Always, 2);
+ var shown = q.Head(2, false)!;
+ q.Offer(Fired, Always, 3); q.Prune(Fired, Always, 3, Day, shown);
+ Assert.AreEqual("t", q.Head(3, false)?.Id);
+ Assert.IsEmpty(q.History);
+ }
+
+ [Test]
+ public void ATeachingRowWithNoLapseAfterKeepsWaiting()
+ {
+ var q = new AdvisorQueue(Catalog(Row("t", "new")), new AdvisorSettings(null));
+ q.Offer(Fired, Always, 0);
+ q.Prune(Array.Empty<string>(), Always, 99, Day);
+ Assert.AreEqual("t", q.Head(99, false)?.Id);
+ }
+
+ /// <summary>#2933: a chain row's requires only orders the chain, so on its fallback signal it does not wait for the earlier
+ /// steps. Any other row still does.</summary>
+ [Test]
+ public void AFallbackRowQueuesOnItsFallbackSignalWhateverItRequires()
+ {
+ var settings = new AdvisorSettings(null);
+ var q = new AdvisorQueue(Catalog("{ id: first, advisor: dayan, signal: other, level: new }",
+ "{ id: fb, advisor: dayan, signal: other, fallback: s, requires: [first], level: new }",
+ "{ id: plain, advisor: dayan, signal: s, requires: [first], level: new }"), settings);
+ q.Offer(Fired, Always, 1);
+ Assert.AreEqual("fb", q.Head(1, false)?.Id);
+ q.Done(q.Head(1, false)!, 1, Day);
+ q.Offer(Fired, Always, 2);
+ Assert.IsNull(q.Head(2, false), "plain still waits on first, and fb is seen");
+ }
+
+ /// <summary>The warning check reads the row's signal or its fallback, as Offer does.</summary>
+ [Test]
+ public void AWarningHeldByItsFallbackIsPrunedOnlyWhenThatStops()
+ {
+ var q = new AdvisorQueue(Catalog("{ id: w, advisor: dayan, signal: other, fallback: s, level: warnings }"), new AdvisorSettings(null));
+ q.Offer(Fired, Always, 1); q.Prune(Fired, Always, 1, Day);
+ Assert.AreEqual("w", q.Head(1, false)?.Id);
+ q.Prune(Array.Empty<string>(), Always, 2, Day);
+ Assert.IsNull(q.Head(2, false));
+ }
+
[Test]
public void ResetForgetsTheGameButNotTheSeenMarks()
{
diff --git a/unity/Assets/Tests/EditMode/AdvisorSettingsTests.cs b/unity/Assets/Tests/EditMode/AdvisorSettingsTests.cs
index fea41dfc0..fcd465932 100644
--- a/unity/Assets/Tests/EditMode/AdvisorSettingsTests.cs
+++ b/unity/Assets/Tests/EditMode/AdvisorSettingsTests.cs
@@ -35,6 +35,20 @@ public class AdvisorSettingsTests
Assert.Throws<ArgumentException>(() => new AdvisorSettings(store).SetLevel("chatty"));
}
+ /// <summary>#2933: the new-player course's line, apart from the opening's, so a returning player's chain mark does not open it.</summary>
+ [Test]
+ public void TheCourseLineRoundTrips()
+ {
+ var store = new SettingsStore(dir);
+ store.Write(AdvisorSettings.OpeningKey, "seen");
+ var a = new AdvisorSettings(store);
+ Assert.IsFalse(a.CourseOpen);
+ a.MarkCourseOpen();
+ Assert.IsTrue(a.CourseOpen);
+ Assert.AreEqual("open", store.Read("advisor_course"));
+ Assert.IsTrue(new AdvisorSettings(store).CourseOpen);
+ }
+
/// <summary>Spec 9.3: a player who saw the first-turn guide does not get the opening chain by itself.</summary>
[Test]
public void TheGuidesSeenLineCountsAsTheOpeningSeen()
diff --git a/unity/Assets/Tests/EditMode/AdvisorSignalsTests.cs b/unity/Assets/Tests/EditMode/AdvisorSignalsTests.cs
index 1a086cc11..d8249fb22 100644
--- a/unity/Assets/Tests/EditMode/AdvisorSignalsTests.cs
+++ b/unity/Assets/Tests/EditMode/AdvisorSignalsTests.cs
@@ -51,6 +51,31 @@ public class AdvisorSignalsTests
return ids;
}
+ /// <summary>#2933: turn_at_least reads the game's turn, the first being 1; State.Turn starts at 0.</summary>
+ [Test]
+ public void TurnAtLeastReadsTheGamesTurn()
+ {
+ var b = Bridge(); var ctx = new AdvisorContext(b, null);
+ Assert.AreEqual(0, b.State.Turn, "precondition: a new game");
+ Assert.IsTrue(AdvisorSignals.When(ctx, new Dictionary<string, double> { ["turn_at_least"] = 1 }));
+ Assert.IsFalse(AdvisorSignals.When(ctx, new Dictionary<string, double> { ["turn_at_least"] = 2 }));
+ b.State.Turn = 1;
+ Assert.IsTrue(AdvisorSignals.When(ctx, new Dictionary<string, double> { ["turn_at_least"] = 2 }));
+ }
+
+ /// <summary>#2933: course_open comes from the settings line, so it holds on a loaded game as well.</summary>
+ [Test]
+ public void CourseOpenHoldsOnceTheSettingIsSet()
+ {
+ var settings = new AdvisorSettings(null);
+ var session = new AdvisorSession(AdvisorCatalog.Load(), settings, true);
+ var ctx = new AdvisorContext(Bridge(), null);
+ CollectionAssert.Contains(AdvisorSignals.Names, "course_open", "a row may name it");
+ Assert.IsFalse(AdvisorSignals.Holding(ctx, session).Contains("course_open"));
+ settings.MarkCourseOpen();
+ Assert.IsTrue(AdvisorSignals.Holding(ctx, session).Contains("course_open"));
+ }
+
/// <summary>Review (must-fix 2): a game loaded with Continue already at the debt ceiling has its critical warning as the
/// start screen closes, not only after the next change.</summary>
[Test]