A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
#nullable enable
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Statecraft.Game;
using Statecraft.Game.Map;
using Statecraft.Game.Map.Units;
using Statecraft.Game.UI;
using Statecraft.Sim;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.UIElements;
/// <summary>GDD Phase 5 PR 15 (#754): the unit card's orders. Slice 1, Move: the card offers Move only when the sim's
/// Movement.Reachable has a hex for the unit; pressing it lights exactly those hexes on the map, a click on one queues the
/// sim's Move through SimBridge, and a click anywhere else ends the pick and selects as before. Slice 2, Fortify and Hold:
/// each shows only where the sim's Orders.Check takes it, else the sim's reason, and a press queues the sim's UnitOrder.
/// Slice 3, Attack: shown only where the sim's Combat.Check takes some hex; pressing it lights those hexes with
/// Combat.Preview's strength ratio and Combat.Outcomes' bands for each (Q-UI-1), and a click on one commits the attack.</summary>
public class UnitOrdersTests
{
static readonly Content C = ContentLoader.Load(Paths.Content);
static List<UnitEntry> Units => UnitData.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", UnitData.DefaultFileName)));
static UiText Text => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);
static MapScene BuildMap()
{
EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);
var map = new GameObject("MapScene").AddComponent<MapScene>();
map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("MapFrame"));
map.Build();
return map;
}
static bool Shown(VisualElement e) => e.style.display.value != DisplayStyle.None;
static Material Load(string name) => AssetDatabase.LoadAssetAtPath<Material>($"Assets/Materials/{name}.mat");
/// <summary>The sim unit a row stands for is the starting force of that row (R-UNIT-006: unit i of a new game is
/// StartingForces[i]); none for a row with no starting force, or once the unit has left the state.</summary>
[Test]
public void ARowsSimUnitIsItsStartingForce()
{
var s = GameSession.New(C, GoldenRun.Seed, Mode.Historical).State;
var golani = Units.Single(u => u.Id == "golani");
var id = C.StartingForces.ToList().FindIndex(f => f.Row == "golani");
Assert.GreaterOrEqual(id, 0, "precondition: Golani is a starting force");
Assert.AreEqual(id, UnitCard.SimUnit(C, s, golani));
Assert.IsNull(UnitCard.SimUnit(C, s, Units.Single(u => u.Id == "yiftach")), "Yiftach has no starting force (its window does not cover the start, #1241)");
s.Units.Remove(id);
Assert.IsNull(UnitCard.SimUnit(C, s, golani), "a unit no longer in the state");
Assert.IsNull(UnitCard.SimUnit(SimBridgeGddTests.Legacy, s, golani), "the legacy loop has no starting forces");
}
/// <summary>The card shows Move only where Movement.Reachable has a hex: Golani's at the start; not an enemy force's
/// (Reachable is empty for it), and not once the game is over.</summary>
[Test]
public void TheCardOffersMoveOnlyWhereTheSimHasAHex()
{
using var ui = new UiTestKit();
var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
var bridge = new SimBridge(g, Text);
var tokens = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a);
PlacedToken? shown = null;
var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(), selectedUnit: () => shown);
var move = ui.Q<Button>("info-move");
var golani = tokens.Single(t => t.Unit.Id == "golani");
Assert.IsNotEmpty(Movement.Reachable(C, g.State, UnitCard.SimUnit(C, g.State, golani.Unit)!.Value), "precondition");
shown = new PlacedToken(golani, new AnchorSpot(0, 0, 0, 0, false));
info.ShowUnit();
Assert.AreEqual(DisplayStyle.Flex, move.style.display.value, "Golani can move");
Assert.AreEqual("Move", move.text, "Q-UI-2's approved name");
var enemy = tokens.First(t => t.Unit.Side != UnitData.Israel && UnitCard.SimUnit(C, g.State, t.Unit) != null);
Assert.IsEmpty(Movement.Reachable(C, g.State, UnitCard.SimUnit(C, g.State, enemy.Unit)!.Value), "precondition");
shown = new PlacedToken(enemy, new AnchorSpot(0, 0, 0, 0, false));
info.ShowUnit();
Assert.AreEqual(DisplayStyle.None, move.style.display.value, "an enemy force has no Move");
shown = new PlacedToken(golani, new AnchorSpot(0, 0, 0, 0, false));
g.State.GameOver = GameOverCodes.MvpEnded;
info.ShowUnit();
Assert.AreEqual(DisplayStyle.None, move.style.display.value, "no orders once the game is over");
info.Dispose();
}
/// <summary>Move lights exactly Movement.Reachable's hexes. A click on one commits Move(unit, q, r) through SimBridge and
/// keeps the card; a click on an unreachable water hex commits nothing and shows that hex;
/// a second press of Move keeps the pick (a unit that can move always has it open, owner 25 Oct 2026). Each end of the
/// pick clears the overlay.</summary>
[Test]
public void AClickOnALitHexCommitsTheMoveAndAnUnreachableClickEndsThePick()
{
var map = BuildMap();
using var ui = new UiTestKit();
try
{
var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);
var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
layer.Show(bridge.Content, bridge.State);
var lit = new List<IReadOnlyCollection<(int q, int r)>>();
var towns = SettlementPlacer.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", SettlementPlacer.DefaultFileName))).ToDictionary(t => t.Id, t => t.Name);
var info = new InfoPanelPresenter(ui.Root, bridge, Text, towns,
selectedUnit: () => layer.Selected is string sel ? layer.Tokens.First(p => p.Token.Unit.Id == sel) : (PlacedToken?)null,
showReachable: hexes => { lit.Add(hexes.ToList()); map.ShowReachable(hexes); });
var golani = layer.Tokens.Single(p => p.Token.Unit.Id == "golani");
var id = UnitCard.SimUnit(C, bridge.State, golani.Token.Unit)!.Value;
var reach = Movement.Reachable(C, bridge.State, id).Keys.ToList();
var move = ui.Q<Button>("info-move");
GameRoot.OnHexClicked(map, layer, info, golani.Q, golani.R);
Assert.IsTrue(info.ShowsUnit);
UiTestKit.Press(move);
CollectionAssert.AreEqual(reach, lit.Last(), "the overlay is Reachable's hexes, in its order");
Assert.IsTrue(map.Terrain.transform.Find(MapScene.ReachableName).GetComponent<MeshRenderer>().enabled);
Assert.IsTrue(ui.Q<Label>("info-settlements").text.Contains(Text["unit.move_pick"]), ui.Q<Label>("info-settlements").text);
UiTestKit.Press(move); // a second press keeps the pick: a unit that can move always has its reach lit
CollectionAssert.AreEqual(reach, lit.Last(), "a second press of Move keeps the reach lit");
Assert.IsTrue(map.Terrain.transform.Find(MapScene.ReachableName).GetComponent<MeshRenderer>().enabled);
// Task12/spec8.1:248: unlit land with a route now gives go-to (tested below); water ends the pick.
var water = C.Hexes.First(h => !h.Land);
Assert.IsFalse(reach.Contains((water.Q, water.R)), "precondition: water has no move or go-to route");
UiTestKit.Press(move);
GameRoot.OnHexClicked(map, layer, info, water.Q, water.R);
Assert.IsEmpty(lit.Last());
Assert.IsEmpty(bridge.Queued);
Assert.IsEmpty(bridge.Session.Committed);
Assert.IsFalse(info.ShowsUnit);
Assert.AreEqual((water.Q, water.R), info.Selected);
// A lit hex: the sim's Move is committed, the unit stays selected and the card has no queued-move line.
GameRoot.OnHexClicked(map, layer, info, golani.Q, golani.R);
UiTestKit.Press(move);
var (q, r) = reach.Last();
map.Select(q, r); // MapPointer outlines the hex before it raises HexClicked
GameRoot.OnHexClicked(map, layer, info, q, r);
var committed = bridge.Session.Committed.OfType<Move>().Single();
Assert.AreEqual((id, q, r), (committed.Unit, committed.Q, committed.R));
CollectionAssert.AreEquivalent(Movement.Reachable(C, bridge.State, id, bridge.Spent).Keys.Select(h => (h.Q, h.R)).ToList(), lit.Last(), "movement reopens only the remaining reach");
Assert.AreEqual("golani", layer.Selected);
Assert.IsTrue(info.ShowsUnit);
Assert.IsFalse(map.Terrain.transform.Find(MapScene.SelectionName).GetComponent<MeshRenderer>().enabled, "one highlight: the ring");
Assert.IsFalse(ui.Q<Label>("info-settlements").text.Contains("Move ordered"), ui.Q<Label>("info-settlements").text);
// Another selection ends any pick reopened by movement points left.
info.Clear();
Assert.IsEmpty(lit.Last(), "another selection ends the pick");
info.Dispose();
}
finally { Object.DestroyImmediate(map.gameObject); }
}
/// <summary>R-MOVE-001 on screen: a click on a lit hex moves the unit at once, the Move pick opens again on what the
/// points left reach, and the card shows the points.</summary>
[Test]
public void TheLitReachShrinksAfterAMove()
{
var map = BuildMap();
using var ui = new UiTestKit();
var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);
var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
layer.Show(bridge.Content, bridge.State);
var lit = new List<IReadOnlyCollection<(int q, int r)>>();
var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(),
selectedUnit: () => layer.Selected is string sel ? layer.Tokens.First(p => p.Token.Unit.Id == sel) : (PlacedToken?)null,
showReachable: hexes => lit.Add(hexes.ToList()));
var golani = layer.Tokens.Single(p => p.Token.Unit.Id == "golani");
var id = UnitCard.SimUnit(C, bridge.State, golani.Token.Unit)!.Value;
var cheap = Movement.Reachable(C, bridge.State, id).Where(kv => kv.Value == 1).Select(kv => kv.Key).ToList();
Assert.IsNotEmpty(cheap, "precondition: Golani has a one-point step");
GameRoot.OnHexClicked(map, layer, info, golani.Q, golani.R);
UiTestKit.Press(ui.Q<Button>("info-move"));
var before = lit.Last().Count;
GameRoot.OnHexClicked(map, layer, info, cheap[0].Q, cheap[0].R);
Assert.AreEqual((cheap[0].Q, cheap[0].R), (bridge.State.Units[id].Q, bridge.State.Units[id].R), "the unit moved at once");
CollectionAssert.AreEquivalent(Movement.Reachable(C, bridge.State, id, bridge.Spent).Keys.Select(h => (h.Q, h.R)).ToList(), lit.Last());
Assert.Less(lit.Last().Count, before);
var full = C.UnitTypes.Single(t => t.Id == bridge.State.Units[id].Type).MovementPoints;
StringAssert.Contains(Text.Format("unit.points", full - 1, full), ui.Q<Label>("info-settlements").text);
info.Dispose();
}
/// <summary>#1617: while a Move pick is open, a click on the unit card is the map's only where it falls on the card's
/// text (not a button, not another panel) over a hex PickTarget takes: a lit hex, or an unlit hex with a go-to route
/// (#1398); an unlit hex with no route stays blocked. The hex is asked only then. With no pick open, never. Selecting
/// the unit opens its pick, with no press of Move (owner, 25 Oct 2026).</summary>
[Test]
public void OnlyAHexTheMovePickTakesUnderTheCardsTextTakesAClickThroughTheCard()
{
using var ui = new UiTestKit();
var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
var bridge = new SimBridge(g, Text);
var golani = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a).Single(t => t.Unit.Id == "golani");
PlacedToken? shown = new PlacedToken(golani, new AnchorSpot(0, 0, 0, 0, false));
var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(), selectedUnit: () => shown);
info.ShowUnit();
var reach = Movement.Reachable(C, g.State, UnitCard.SimUnit(C, g.State, golani.Unit)!.Value).Keys.ToList();
(int q, int r)? lit = (reach[0].Q, reach[0].R);
var id = UnitCard.SimUnit(C, g.State, golani.Unit)!.Value;
var tlv = C.SettlementHexes.Single(t => t.Id == "tel_aviv");
(int q, int r)? routable = (tlv.Q, tlv.R);
Assert.IsFalse(reach.Contains((tlv.Q, tlv.R)), "precondition: Tel Aviv is out of Golani's reach this turn");
Assert.IsNotEmpty(Movement.Route(C, g.State, id, tlv.Q, tlv.R, bridge.Spent), "precondition: a go-to route reaches Tel Aviv");
var none = C.Hexes.First(h => !h.Land); // the sea: no route goes there
Assert.IsEmpty(Movement.Route(C, g.State, id, none.Q, none.R, bridge.Spent), "precondition: no go-to route reaches the sea");
(int q, int r)? unroutable = (none.Q, none.R);
var title = ui.Q<Label>("info-title"); var move = ui.Q<Button>("info-move");
var asked = 0;
System.Func<(int q, int r)?> At((int q, int r)? hex) => () => { asked++; return hex; };
Assert.IsTrue(info.TakesClickThrough(title, At(lit)), "selecting the unit opened its pick");
UiTestKit.Press(move);
Assert.IsTrue(info.TakesClickThrough(title, At(lit)), "the card's text over a lit hex");
Assert.IsTrue(info.TakesClickThrough(ui.Q<VisualElement>("info-panel"), At(lit)), "the card's own background over a lit hex");
Assert.IsTrue(info.TakesClickThrough(title, At(routable)), "the card's text over an unlit hex with a go-to route");
Assert.IsFalse(info.TakesClickThrough(title, At(unroutable)), "the card's text over an unlit hex with no route");
Assert.IsFalse(info.TakesClickThrough(title, At(null)), "the card's text off the map");
asked = 0;
Assert.IsFalse(info.TakesClickThrough(move, At(lit)), "a button keeps its click over a lit hex");
Assert.IsFalse(info.TakesClickThrough(move, At(routable)), "and over a hex with a go-to route");
Assert.IsFalse(info.TakesClickThrough(ui.Q<VisualElement>("info-orders"), At(routable)), "the orders row beside its buttons keeps its click (#1728)");
Assert.IsFalse(info.TakesClickThrough(ui.Q<VisualElement>("info-primary-orders"), At(lit)), "and so does its inner group");
Assert.IsFalse(info.TakesClickThrough(ui.Q<VisualElement>("top-bar"), At(lit)), "another panel keeps its click");
Assert.IsFalse(info.TakesClickThrough(null, At(lit)), "no UI: the map has the click anyway");
Assert.AreEqual(0, asked, "the hex is asked only for the card's text");
UiTestKit.Press(move); // a second press keeps the pick
Assert.IsTrue(info.TakesClickThrough(title, At(lit)), "a second press of Move keeps the pick");
info.Clear();
asked = 0;
Assert.IsFalse(info.TakesClickThrough(title, At(lit)), "no pick open");
Assert.AreEqual(0, asked, "the hex is not asked with no pick open");
info.Dispose();
}
/// <summary>Slice 2 (#754): for every unit with a sim unit, Israel's and the enemy's, the card shows Fortify and Hold each
/// only where the sim's Orders.Check takes it, and where it does not, on Israel's units the sim's reason, whatever it is
/// (so a refusal the sim adds later, such as artillery's hold, shows with no change here); an enemy's card gives no reason
/// (the sim's "not yours" is in English and says nothing the card does not). A unit already holding has no Hold, with the
/// sim's reason; once the game is over neither shows.</summary>
[Test]
public void TheCardOffersFortifyAndHoldOnlyWhereTheSimTakesThem()
{
using var ui = new UiTestKit();
var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
var bridge = new SimBridge(g, Text);
PlacedToken? shown = null;
var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(), selectedUnit: () => shown);
var buttons = new[] { (Orders.Fortify, ui.Q<Button>("info-fortify")), (Orders.Hold, ui.Q<Button>("info-hold")) };
var tokens = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a).Where(t => UnitCard.SimUnit(C, g.State, t.Unit) != null).ToList();
Assert.IsTrue(tokens.Any(t => t.Unit.Side == UnitData.Israel) && tokens.Any(t => t.Unit.Side != UnitData.Israel), "precondition: both sides");
void Expect(UnitToken token, string at)
{
shown = new PlacedToken(token, new AnchorSpot(0, 0, 0, 0, false));
info.ShowUnit();
var id = UnitCard.SimUnit(C, bridge.State, token.Unit)!.Value;
foreach (var (order, button) in buttons)
{
var why = Orders.Check(C, bridge.State, id, order);
Assert.AreEqual(why == null ? DisplayStyle.Flex : DisplayStyle.None, button.style.display.value, $"{at} {token.Unit.Id}: {order} ({why})");
if (why == null) continue;
if (token.Unit.Side == UnitData.Israel) StringAssert.Contains(why, ui.Q<Label>("info-reason").text, $"{at} {token.Unit.Id}: the sim's reason");
else StringAssert.DoesNotContain(why, ui.Q<Label>("info-reason").text, $"{at} {token.Unit.Id}: no reason on an enemy's card");
}
}
foreach (var token in tokens) Expect(token, "start");
Assert.AreEqual(("Fortify", "Hold"), (buttons[0].Item2.text, buttons[1].Item2.text), "Q-UI-2's approved names");
var golani = tokens.Single(t => t.Unit.Id == "golani");
var id0 = UnitCard.SimUnit(C, g.State, golani.Unit)!.Value;
Assert.IsNull(bridge.Queue(new UnitOrder(id0, Orders.Hold)));
bridge.EndTurn();
Assert.IsNotNull(Orders.Check(C, bridge.State, id0, Orders.Hold), "precondition: Golani holds");
Expect(golani, "holding");
Assert.IsTrue(Shown(buttons[0].Item2), "a holding unit can still fortify");
bridge.State.GameOver = GameOverCodes.MvpEnded;
info.ShowUnit();
Assert.IsFalse(buttons.Any(b => Shown(b.Item2)), "no orders once the game is over");
info.Dispose();
}
/// <summary>Fortify queues the sim's UnitOrder(unit, fortify) through SimBridge and the card says when it is set; Hold
/// then replaces it (one standing order per unit) and the card says so instead.</summary>
[Test]
public void FortifyAndHoldQueueTheSimsOrder()
{
using var ui = new UiTestKit();
var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
var bridge = new SimBridge(g, Text);
var golani = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a).Single(t => t.Unit.Id == "golani");
PlacedToken? shown = new PlacedToken(golani, new AnchorSpot(0, 0, 0, 0, false));
var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(), selectedUnit: () => shown);
var id = UnitCard.SimUnit(C, g.State, golani.Unit)!.Value;
info.ShowUnit();
string Lines() => ui.Q<Label>("info-settlements").text;
Assert.IsFalse(Lines().Contains(Text["unit.fortify_queued"]) || Lines().Contains(Text["unit.hold_queued"]), Lines());
UiTestKit.Press(ui.Q<Button>("info-fortify"));
var queued = bridge.Session.Committed.OfType<UnitOrder>().Last();
Assert.AreEqual((id, Orders.Fortify, (int?)null, (int?)null), (queued.Unit, queued.Order, queued.Q, queued.R));
StringAssert.Contains(Text["unit.fortify_queued"], Lines());
UiTestKit.Press(ui.Q<Button>("info-hold"));
queued = bridge.Session.Committed.OfType<UnitOrder>().Last();
Assert.AreEqual((id, Orders.Hold), (queued.Unit, queued.Order));
StringAssert.Contains(Text["unit.hold_queued"], Lines());
Assert.IsFalse(Lines().Contains(Text["unit.fortify_queued"]), Lines());
Assert.IsEmpty(bridge.Queued, "standing orders commit immediately");
Assert.AreEqual(2, bridge.Session.Committed.Count, "both clicks remain in the committed history");
Assert.IsEmpty(bridge.EndTurn().Rejected, "the sim replays the committed orders once");
Assert.AreEqual(Orders.Hold, bridge.State.Units[id].Order);
info.Dispose();
}
/// <summary>Spec 7.3: an order that finishes the unit for the turn asks for the next unit.</summary>
[Test]
public void AFinishingOrderAsksForTheNextUnit()
{
using var ui = new UiTestKit();
var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);
var tokens = UnitRoster.FromState(Units, C, bridge.State, _ => true, (row, a, q, r) => a);
PlacedToken? shown = new PlacedToken(tokens.Single(t => t.Unit.Id == "golani"), new AnchorSpot(0, 0, 0, 0, false));
var asked = 0;
var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(), selectedUnit: () => shown, unitDone: () => asked++);
info.ShowUnit();
UiTestKit.Press(ui.Q<Button>("info-fortify"));
Assert.AreEqual(1, asked);
info.Dispose();
}
[Test]
public void ATokenWithNoPointsLeftIsDimmed()
{
var map = BuildMap();
try
{
var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);
layer.Show(bridge.Content, bridge.State);
layer.Dim(new[] { "golani" });
var block = new MaterialPropertyBlock();
var badge = layer.transform.Find("Tokens/golani/Badge").GetComponentsInChildren<Renderer>();
Assert.Greater(badge.Length, 1, "precondition: the badge has a plate and a glyph");
foreach (var part in badge)
{
part.GetPropertyBlock(block);
var own = part.sharedMaterial.color;
var want = new Vector4(own.r * UnitLayer.DimShade, own.g * UnitLayer.DimShade, own.b * UnitLayer.DimShade, own.a);
Assert.Less(Vector4.Distance(want, (Vector4)block.GetColor("_BaseColor")), 1e-3f,
part.name + ": dimmed from its own colour, so the glyph keeps its contrast");
}
layer.Dim(new string[0]);
foreach (var part in badge) { part.GetPropertyBlock(block); Assert.IsTrue(block.isEmpty, part.name + ": undimmed when it has points again"); }
}
finally { Object.DestroyImmediate(map.gameObject); }
}
/// <summary>R-UNIT-005 (#1309): Send home is absent until the shown Israeli unit's own front has signed its armistice,
/// then carries the localized label, queues the sim's UnitOrder through the same bridge as the standing orders and shows
/// its queued line under the card's lines.</summary>
[Test]
public void SendHomeAppearsAfterTheFrontsArmisticeAndQueuesTheSimsOrder()
{
var he = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");
foreach (var (t, label) in new[] { (Text, "Send home"), (he, "שליחה הביתה") })
{
using var ui = new UiTestKit();
var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
var bridge = new SimBridge(g, t);
var tokens = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a);
var token = tokens.Single(x => x.Unit.Id == "golani");
var id = UnitCard.SimUnit(C, g.State, token.Unit)!.Value;
var u = g.State.Units[id];
var next = new[] { (1, 0), (1, -1), (0, -1), (-1, 0), (-1, 1), (0, 1) }.Select(d => (q: u.Q + d.Item1, r: u.R + d.Item2))
.First(h => C.HexAt(h.q, h.r)?.Land == true && !g.State.Units.Values.Any(x => (x.Q, x.R) == h));
var egypt = g.State.Units.Values.First(x => x.Side == "egypt");
g.State.Units[egypt.Id] = new Unit(egypt.Id, egypt.Type, next.q, next.r, egypt.Service, egypt.Side, egypt.Strength,
egypt.Order, egypt.OrderTarget, egypt.HomeCity);
PlacedToken? selected = new PlacedToken(token, new AnchorSpot(0, 0, 0, 0, false));
var info = new InfoPanelPresenter(ui.Root, bridge, t, new Dictionary<string, string>(), selectedUnit: () => selected);
var button = ui.Q<Button>("info-send-home");
Assert.AreEqual("The armistice with Egypt is not signed", Demobilization.Check(C, g.State, id), "precondition");
info.ShowUnit();
Assert.AreEqual(DisplayStyle.None, button.style.display.value, "hidden before the relevant armistice");
g.State.ChosenOptions["armistice_egypt"] = "sign";
Assert.IsNull(Demobilization.Check(C, g.State, id), "precondition: the relevant armistice opens the order");
info.ShowUnit();
Assert.AreEqual(DisplayStyle.Flex, button.style.display.value, "shown after the relevant armistice");
Assert.AreEqual(label, button.text);
UiTestKit.Press(button);
var queued = bridge.Queued.OfType<UnitOrder>().Single();
Assert.AreEqual((id, Demobilization.SendHome, (int?)null, (int?)null), (queued.Unit, queued.Order, queued.Q, queued.R));
StringAssert.Contains(t["unit.send_home_queued"], ui.Q<Label>("info-settlements").text, "the card says the order waits for End turn");
info.Dispose();
}
}
/// <summary>#1510 (R-TRAIN-004): a damaged unit of Israel's on a city's hex gets Reinforce for its missing strength, in
/// English and Hebrew; a press queues the sim's Reinforce and the card says it waits for End turn. With no Arms the button
/// hides and the sim's reason shows; an undamaged unit, or one off a city, gets neither.</summary>
[Test]
public void ReinforceQueuesTheMissingStrengthFromTheCityTheUnitStandsIn()
{
var he = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");
foreach (var (t, label, arms) in new[] { (Text, "Reinforce +", "not enough Arms"), (he, "תגבור +", "אין די כלי נשק") })
{
using var ui = new UiTestKit();
var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
var bridge = new SimBridge(g, t);
var token = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a).Single(x => x.Unit.Id == "golani");
var id = UnitCard.SimUnit(C, g.State, token.Unit)!.Value;
var u = g.State.Units[id];
var city = C.SettlementHexes.Single(h => h.Id == "tel_aviv");
PlacedToken? selected = new PlacedToken(token, new AnchorSpot(0, 0, 0, 0, false));
var info = new InfoPanelPresenter(ui.Root, bridge, t, new Dictionary<string, string>(), selectedUnit: () => selected);
var button = ui.Q<Button>("info-reinforce");
info.ShowUnit();
Assert.AreEqual(DisplayStyle.None, button.style.display.value, "Golani at the start has lost nobody");
g.State.Units[id] = new Unit(u.Id, u.Type, city.Q, city.R, u.Service, u.Side, u.Strength - 2, u.Order, u.OrderTarget, u.HomeCity, u.Strength);
g.State.Arms = 0;
info.ShowUnit();
Assert.AreEqual(DisplayStyle.None, button.style.display.value, "no Arms, no Reinforce");
StringAssert.Contains(arms, ui.Q<Label>("info-reason").text, "the sim's reason shows, in the UI's language (#2072)");
g.State.Arms = 100;
info.ShowUnit();
Assert.AreEqual(DisplayStyle.Flex, button.style.display.value, "damaged, in Tel Aviv, with Arms");
Assert.AreEqual(t.Format("unit.order.reinforce", 2), button.text);
StringAssert.StartsWith(label, button.text);
UiTestKit.Press(button);
var queued = bridge.Queued.OfType<Reinforce>().Single();
Assert.AreEqual((id, "tel_aviv", 2), (queued.Unit, queued.City, queued.Count));
StringAssert.Contains(t["unit.reinforce_queued"], ui.Q<Label>("info-settlements").text, "the card says the order waits for End turn");
Assert.AreEqual(DisplayStyle.None, button.style.display.value, "one order a unit");
info.Dispose();
}
}
// Red-first prediction at ae4bfdaab: the card runs the sim's Reinforce on a copy of the displayed state, without the queue,
// so it offers Reinforce even though the earlier craftsman reassignment leaves End turn no idle civilian for it.
[Test]
public void AQueuedCraftsmanReassignmentHidesReinforceThatEndTurnWouldRefuse()
{
using var ui = new UiTestKit();
var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
var bridge = new SimBridge(g, Text);
var token = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a).Single(x => x.Unit.Id == "golani");
var id = UnitCard.SimUnit(C, g.State, token.Unit)!.Value;
var u = g.State.Units[id];
var city = C.SettlementHexes.Single(h => h.Id == "tel_aviv");
g.State.Units[id] = new Unit(u.Id, u.Type, city.Q, city.R, u.Service, u.Side, u.Strength - 1, u.Order, u.OrderTarget, u.HomeCity, u.Strength);
var telAviv = g.State.Cities[city.Id];
g.State.Cities[city.Id] = telAviv.WithCounts(1, 0, 0).WithCraftsmen(0).WithQualified(new Qualified(1, 0, System.Array.Empty<int>()));
g.State.Arms = 100;
Assert.IsNull(bridge.Queue(new ReassignCraftsmen(city.Id, 1)));
Assert.AreEqual(0, Training.Available(g.State, city.Id, bridge.Queued), "the queued reassignment reserves the only idle civilian");
var candidate = new Reinforce(id, city.Id, 1);
var preview = Simulation.Preview(C, bridge.TurnStart, bridge.Session.Committed.Concat(bridge.Queued).Append(candidate).ToList());
var rejected = preview.Rejected.Single(x => ReferenceEquals(x.Command, candidate));
StringAssert.Contains("0 civilians without work", rejected.Reason, "precondition: the exact End-turn preview refuses Reinforce");
PlacedToken? selected = new PlacedToken(token, new AnchorSpot(0, 0, 0, 0, false));
using var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(), selectedUnit: () => selected);
info.ShowUnit();
Assert.AreEqual(DisplayStyle.None, ui.Q<Button>("info-reinforce").style.display.value);
}
// #2714 (a): the Arms half of ReinforceQueuesTheMissingStrengthFromTheCityTheUnitStandsIn. Golani has lost one group in
// Tel Aviv, with civilians without work to spare and Arms for exactly one recruit group. A queued recruit Train takes those
// Arms when End turn runs it, so End turn would refuse the reinforcement (R-ARMS-003): the card offers no Reinforce and
// shows the sim's Arms reason, in English and Hebrew. Red-first prediction at 54d62e801^ (reasoned, not run): the card
// ran the sim's Reinforce on a copy of the displayed state, which the deferred Train has not touched, so it was offered.
[Test]
public void AQueuedTrainThatLeavesTooFewArmsHidesReinforceAndShowsWhy()
{
var he = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");
foreach (var (t, arms) in new[] { (Text, "not enough Arms"), (he, "אין די כלי נשק") })
{
using var ui = new UiTestKit();
var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
var bridge = new SimBridge(g, t);
var token = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a).Single(x => x.Unit.Id == "golani");
var id = UnitCard.SimUnit(C, g.State, token.Unit)!.Value;
var u = g.State.Units[id];
var city = C.SettlementHexes.Single(h => h.Id == "tel_aviv");
g.State.Units[id] = new Unit(u.Id, u.Type, city.Q, city.R, u.Service, u.Side, u.Strength - 1, u.Order, u.OrderTarget, u.HomeCity, u.Strength);
var telAviv = g.State.Cities[city.Id];
g.State.Cities[city.Id] = telAviv.WithCounts(50, 47, telAviv.Refugees);
var group = C.RulesAt(g.State.Date).Mvp!.ArmsPerRecruitGroup!.Value;
Assert.Greater(group, 0, "precondition: a recruit group takes Arms");
g.State.Arms = group;
Assert.IsNull(Training.Reinforce(C, g.State.Clone(), id, city.Id, 1, new List<Cause>()),
"precondition: on the displayed state alone, the one-group Reinforce is accepted");
var train = new Train(city.Id, "recruit", 1);
Assert.IsNull(bridge.Queue(train), "precondition: the recruit Train is queued");
Assert.GreaterOrEqual(Training.Available(g.State, city.Id, bridge.Queued), 1, "precondition: a civilian without work is left after the Train");
Assert.AreEqual(group, bridge.State.Arms, "precondition: the deferred Train has not taken its Arms yet");
var candidate = new Reinforce(id, city.Id, 1);
var preview = Simulation.Preview(C, bridge.TurnStart, bridge.Session.Committed.Concat(bridge.Queued).Append(candidate).ToList());
Assert.IsFalse(preview.Rejected.Any(x => ReferenceEquals(x.Command, train)), "precondition: End turn accepts the Train");
StringAssert.Contains("not enough Arms", preview.Rejected.Single(x => ReferenceEquals(x.Command, candidate)).Reason,
"precondition: after the Train, the exact End-turn preview refuses Reinforce for its Arms");
PlacedToken? selected = new PlacedToken(token, new AnchorSpot(0, 0, 0, 0, false));
using var info = new InfoPanelPresenter(ui.Root, bridge, t, new Dictionary<string, string>(), selectedUnit: () => selected);
info.ShowUnit();
Assert.AreEqual(DisplayStyle.None, ui.Q<Button>("info-reinforce").style.display.value, "the queued Train leaves too few Arms");
StringAssert.Contains(arms, ui.Q<Label>("info-reason").text, "the sim's Arms reason shows, in the UI's language");
}
}
// #2978 (owner, 9 November 2026: "Enabled + toast (Recommended)"): a Reinforce the Attention left cannot pay for keeps its
// button, and the press is refused with the bridge's order.no_attention toast, in English and Hebrew; it queues nothing.
// With the Attention short, a Reinforce the sim refuses anyway (no Arms) still hides and shows the sim's reason. Red-first
// prediction at e29447748: the card asks End turn's preview, which charges Attention first (AttentionSystem.TrySpend), so the
// button hides behind the Attention refusal.
[Test]
public void AReinforceTheAttentionCannotPayStaysOfferedAndTheBridgeSaysWhy()
{
var he = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");
foreach (var (t, arms) in new[] { (Text, "not enough Arms"), (he, "אין די כלי נשק") })
{
using var ui = new UiTestKit();
var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
var bridge = new SimBridge(g, t);
var refusals = new List<string>();
bridge.Refused += refusals.Add;
var token = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a).Single(x => x.Unit.Id == "golani");
var id = UnitCard.SimUnit(C, g.State, token.Unit)!.Value;
var u = g.State.Units[id];
var city = C.SettlementHexes.Single(h => h.Id == "tel_aviv");
g.State.Units[id] = new Unit(u.Id, u.Type, city.Q, city.R, u.Service, u.Side, u.Strength - 2, u.Order, u.OrderTarget, u.HomeCity, u.Strength);
g.State.Arms = 100;
// A queued order in another city leaves half a Reinforce's price.
var filler = new AssignWorkers("jerusalem", "job", 0);
var candidate = new Reinforce(id, city.Id, 2);
var price = bridge.Price(candidate)!.Value;
g.State.Attention = bridge.Price(filler)!.Value + price / 2;
Assert.IsNull(bridge.Queue(filler), "precondition: the filler is queued");
Assert.IsFalse(bridge.CanPay(candidate), "precondition: the Attention left cannot pay for Reinforce");
Assert.That(bridge.AttentionLeft!.Value, Is.GreaterThan(0).And.LessThan(price), "precondition: some Attention is left");
var left = Simulation.Preview(C, bridge.TurnStart, bridge.Session.Committed.Concat(bridge.Queued).ToList());
Assert.IsEmpty(left.Rejected, "precondition: End turn takes the filler, so its Attention is spent");
Assert.IsNull(Training.Reinforce(C, left.State, id, city.Id, 2, new List<Cause>()), "precondition: the sim's Reinforce rule takes it");
PlacedToken? selected = new PlacedToken(token, new AnchorSpot(0, 0, 0, 0, false));
using var info = new InfoPanelPresenter(ui.Root, bridge, t, new Dictionary<string, string>(), selectedUnit: () => selected);
var button = ui.Q<Button>("info-reinforce");
info.ShowUnit();
Assert.AreEqual(DisplayStyle.Flex, button.style.display.value, "only the Attention is short, so Reinforce stays offered");
Assert.IsTrue(button.enabledSelf, "and enabled");
Assert.AreEqual(t.Format("unit.order.reinforce", 2), button.text);
var before = bridge.AttentionLeft!.Value;
UiTestKit.Press(button);
Assert.AreSame(filler, bridge.Queued.Single(), "the bridge refuses the press: the queue is unchanged");
Assert.AreEqual(before, bridge.AttentionLeft!.Value, 1e-9, "the refused press spends nothing");
Assert.AreEqual(new[] { t.Format("order.no_attention", price, before) }, refusals);
g.State.Arms = 0;
info.ShowUnit();
Assert.AreEqual(DisplayStyle.None, button.style.display.value, "no Arms, no Reinforce, whatever the Attention");
StringAssert.Contains(arms, ui.Q<Label>("info-reason").text, "the sim's reason shows, not the Attention's");
}
}
/// <summary>#2072, owner review item 1: a Reinforce the sim refuses for Arms ("Tel Aviv: not enough Arms for basic training
/// (need ..)") reaches the player through SimBridge, in Hebrew whole: the town and the course in Hebrew too, no Latin
/// letter. The bridge queues it (a Reinforce waits for End turn) and End turn raises the sim's refusal, which the toast
/// reads. SimBridge.Refuse never sees it: a queue-time refusal (Orders, Combat, Movement) carries no town or course.</summary>
[Test]
public void AReinforceRefusedThroughTheBridgeReadsInHebrewWhole()
{
var he = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");
var namesHe = SettlementPlacer.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", SettlementPlacer.DefaultFileName))).ToDictionary(t => t.Id, t => t.NameHe);
using var ui = new UiTestKit();
var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
var bridge = new SimBridge(g, he) { TownNamesHe = namesHe };
using var toast = new ToastPresenter(ui.Root, bridge, he) { TownNamesHe = namesHe };
var token = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a).Single(x => x.Unit.Id == "golani");
var id = UnitCard.SimUnit(C, g.State, token.Unit)!.Value;
var u = g.State.Units[id];
var city = C.SettlementHexes.Single(h => h.Id == "tel_aviv");
g.State.Units[id] = new Unit(u.Id, u.Type, city.Q, city.R, u.Service, u.Side, u.Strength - 2, u.Order, u.OrderTarget, u.HomeCity, u.Strength);
g.State.Arms = 0;
Assert.IsNull(bridge.Queue(new Reinforce(id, "tel_aviv", 2)), "the bridge queues it");
var rejected = bridge.EndTurn().Rejected.Single(x => x.Command is Reinforce).Reason;
StringAssert.StartsWith("Tel Aviv: not enough Arms for basic training", rejected, "the sim's English, with a town and a course");
var line = ui.Q<Label>("toast").text;
StringAssert.Contains(namesHe["tel_aviv"], line, "the town in Hebrew");
StringAssert.Contains(he["why.cause.course.basic"], line, "the course in Hebrew");
StringAssert.DoesNotMatch("[A-Za-z]", line, "no English left in the refusal");
}
/// <summary>Codex's review of #1527, finding 3, on the card: once Send home is queued for a unit, the card offers it no
/// other order (Move, Fortify, Hold, Attack, Reinforce, Skip, nor Send home again) and says the unit goes home.</summary>
[Test]
public void AUnitGoingHomeIsOfferedNoOtherOrder()
{
using var ui = new UiTestKit();
var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
var bridge = new SimBridge(g, Text);
var token = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a).Single(x => x.Unit.Id == "golani");
var id = UnitCard.SimUnit(C, g.State, token.Unit)!.Value;
var u = g.State.Units[id];
var city = C.SettlementHexes.Single(h => h.Id == "tel_aviv");
g.State.Units[id] = new Unit(u.Id, u.Type, city.Q, city.R, u.Service, u.Side, u.Strength - 2, u.Order, u.OrderTarget, u.HomeCity, u.Strength);
g.State.Arms = 100;
PlacedToken? selected = new PlacedToken(token, new AnchorSpot(0, 0, 0, 0, false));
var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(), selectedUnit: () => selected);
var orders = new[] { "info-move", "info-fortify", "info-hold", "info-reinforce", "info-skip" }.Select(n => ui.Q<Button>(n)).ToList();
info.ShowUnit();
foreach (var b in orders) Assert.IsTrue(Shown(b), $"precondition: {b.name} is offered");
Assert.IsNull(bridge.Queue(new UnitOrder(id, Demobilization.SendHome)));
info.ShowUnit();
foreach (var b in orders.Append(ui.Q<Button>("info-attack")).Append(ui.Q<Button>("info-send-home")))
Assert.IsFalse(Shown(b), $"{b.name} is not offered to a unit going home");
StringAssert.Contains(Text["unit.send_home_queued"], ui.Q<Label>("info-settlements").text, "the card says it goes home");
info.Dispose();
}
/// <summary>Gives the state the Arms for an attack and, when Golani has no enemy in reach (the sim's Combat.Check takes no
/// hex), puts the first enemy sim unit on the first free land hex next to it; returns Golani's sim id.</summary>
internal static int EnemyInGolanisReach(GameState s)
{
var id = C.StartingForces.ToList().FindIndex(f => f.Row == "golani");
s.Arms = 1000;
if (Targets(s, id).Count > 0) return id;
var g = s.Units[id];
var enemy = s.Units.Values.First(u => u.Side != "" && u.Side != Movement.PlayerSide);
var at = new[] { (1, 0), (1, -1), (0, -1), (-1, 0), (-1, 1), (0, 1) }.Select(d => (q: g.Q + d.Item1, r: g.R + d.Item2))
.First(h => C.HexAt(h.q, h.r)?.Land == true && !s.Units.Values.Any(u => (u.Q, u.R) == h));
s.Units[enemy.Id] = new Unit(enemy.Id, enemy.Type, at.q, at.r, enemy.Service, enemy.Side, enemy.Strength);
return id;
}
/// <summary>The hexes the card offers for an attack: every unit's hex the sim's Combat.Check takes.</summary>
static List<(int q, int r)> Targets(GameState s, int unit) =>
s.Units.Values.Select(u => (u.Q, u.R)).Distinct().Where(h => Combat.Check(C, s, unit, h.Item1, h.Item2) == null).ToList();
/// <summary>Slice 3 (#754): for every unit with a sim unit, Israel's and the enemy's, the card shows Attack only where
/// the sim's Combat.Check takes some hex, and on Israel's units the sim's reason for each hex in reach it refuses (an
/// enemy's card gives none, as for Fortify and Hold). With no Arms, Golani
/// (an enemy in its reach) has no Attack and shows the sim's reason; once the game is over no card has one.</summary>
[Test]
public void TheCardOffersAttackOnlyWhereTheSimTakesAHex()
{
using var ui = new UiTestKit();
var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
var bridge = new SimBridge(g, Text);
var id = EnemyInGolanisReach(g.State);
var tokens = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a).Where(t => UnitCard.SimUnit(C, g.State, t.Unit) != null).ToList();
// An enemy with a card next to Golani, so an enemy's card has a hex in reach the sim refuses ("not yours").
var foe = UnitCard.SimUnit(C, g.State, tokens.First(t => t.Unit.Side != UnitData.Israel).Unit)!.Value;
var gq = g.State.Units[id].Q; var gr = g.State.Units[id].R;
var next = new[] { (1, 0), (1, -1), (0, -1), (-1, 0), (-1, 1), (0, 1) }.Select(d => (q: gq + d.Item1, r: gr + d.Item2))
.First(h => C.HexAt(h.q, h.r)?.Land == true && !g.State.Units.Values.Any(u => (u.Q, u.R) == h));
var f = g.State.Units[foe];
g.State.Units[foe] = new Unit(f.Id, f.Type, next.q, next.r, f.Service, f.Side, f.Strength);
Assert.IsNotNull(Combat.Preview(C, g.State, foe, gq, gr), "precondition: Golani is in an enemy card's reach");
PlacedToken? shown = null;
var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(), selectedUnit: () => shown);
var attack = ui.Q<Button>("info-attack");
var offered = new HashSet<bool>();
foreach (var token in tokens)
{
shown = new PlacedToken(token, new AnchorSpot(0, 0, 0, 0, false));
info.ShowUnit();
var u = UnitCard.SimUnit(C, g.State, token.Unit)!.Value;
var has = Targets(g.State, u).Count > 0;
offered.Add(has);
Assert.AreEqual(has ? DisplayStyle.Flex : DisplayStyle.None, attack.style.display.value, token.Unit.Id);
foreach (var h in g.State.Units.Values.Select(x => (x.Q, x.R)).Distinct().Where(h => Combat.Preview(C, g.State, u, h.Item1, h.Item2) != null))
if (Combat.Check(C, g.State, u, h.Item1, h.Item2) is string why)
if (token.Unit.Side == UnitData.Israel) StringAssert.Contains(why, ui.Q<Label>("info-reason").text, $"{token.Unit.Id}: the sim's reason");
else StringAssert.DoesNotContain(why, ui.Q<Label>("info-reason").text, $"{token.Unit.Id}: no reason on an enemy's card");
}
CollectionAssert.AreEquivalent(new[] { true, false }, offered, "precondition: some cards offer Attack and some do not");
shown = new PlacedToken(tokens.Single(t => t.Unit.Id == "golani"), new AnchorSpot(0, 0, 0, 0, false));
info.ShowUnit();
Assert.AreEqual("Attack", attack.text, "Q-UI-2's approved name");
var at = Targets(g.State, id)[0];
g.State.Arms = 0;
info.ShowUnit();
var short_ = Combat.Check(C, g.State, id, at.q, at.r);
Assert.IsNotNull(short_, "precondition: no Arms");
Assert.AreEqual(DisplayStyle.None, attack.style.display.value, "no Arms for an attack");
StringAssert.Contains(short_, ui.Q<Label>("info-reason").text, "the sim's reason");
g.State.Arms = 1000;
g.State.GameOver = GameOverCodes.MvpEnded;
info.ShowUnit();
Assert.AreEqual(DisplayStyle.None, attack.style.display.value, "no orders once the game is over");
info.Dispose();
}
/// <summary>Attack lights exactly the hexes Combat.Check takes, and the card gives each its units' names with
/// Combat.Preview's strength ratio and Combat.Outcomes' bands for its row (Q-UI-1). A click on an unlit hex commits
/// nothing; a click on a lit one commits UnitOrder(unit, attack, q, r) through SimBridge and fights it at once.</summary>
[Test]
public void AttackShowsEachTargetsOddsAndAClickOnOneCommitsTheAttack()
{
var map = BuildMap();
using var ui = new UiTestKit();
try
{
var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);
var id = EnemyInGolanisReach(bridge.State);
var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
layer.Show(bridge.Content, bridge.State);
var lit = new List<IReadOnlyCollection<(int q, int r)>>();
var towns = SettlementPlacer.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", SettlementPlacer.DefaultFileName))).ToDictionary(t => t.Id, t => t.Name);
var info = new InfoPanelPresenter(ui.Root, bridge, Text, towns,
selectedUnit: () => layer.Selected is string sel ? layer.Tokens.First(p => p.Token.Unit.Id == sel) : (PlacedToken?)null,
showReachable: hexes => { lit.Add(hexes.ToList()); map.ShowReachable(hexes); },
unitName: u => "Unit-" + u);
var golani = layer.Tokens.Single(p => p.Token.Unit.Id == "golani");
var attack = ui.Q<Button>("info-attack");
string Lines() => ui.Q<Label>("info-settlements").text;
string Odds(int q, int r)
{
var p = Combat.Preview(C, bridge.State, id, q, r)!.Value;
var bands = Combat.Outcomes(C, bridge.State, p.Row, id, q, r).Select(b => Text.Format(b.Retreat ? "unit.attack_band_retreat" : "unit.attack_band",
b.Faces, b.Of, b.AttackersLose, b.DefendersLose));
var names = string.Join(", ", bridge.State.Units.Values.Where(u => (u.Q, u.R) == (q, r)).Where(u => u.Side != "" && u.Side != Movement.PlayerSide).Select(u => "Unit-" + u.Id));
return Text.Format("unit.attack_odds", names, p.RatioPercent) + "\n" + string.Join("\n", bands); // one band a line
}
GameRoot.OnHexClicked(map, layer, info, golani.Q, golani.R);
UiTestKit.Press(attack);
var targets = Targets(bridge.State, id);
Assert.IsNotEmpty(targets, "precondition");
CollectionAssert.AreEquivalent(targets, lit.Last(), "the lit hexes are the ones Combat.Check takes");
StringAssert.Contains(Text["unit.attack_pick"], Lines());
foreach (var (q, r) in targets) StringAssert.Contains(Odds(q, r), Lines());
StringAssert.Contains("strength ratio", Lines());
// An unlit hex: nothing committed, the pick ends.
var tlv = C.SettlementHexes.Single(t => t.Id == "tel_aviv");
Assert.IsFalse(targets.Contains((tlv.Q, tlv.R)), "precondition");
GameRoot.OnHexClicked(map, layer, info, tlv.Q, tlv.R);
Assert.IsEmpty(lit.Last());
Assert.IsEmpty(bridge.Queued);
Assert.IsEmpty(bridge.Session.Committed);
// A lit hex: the sim's attack is committed and fought at once.
GameRoot.OnHexClicked(map, layer, info, golani.Q, golani.R);
UiTestKit.Press(attack);
var at = targets[0];
GameRoot.OnHexClicked(map, layer, info, at.q, at.r);
var committed = bridge.Session.Committed.OfType<UnitOrder>().Single();
Assert.AreEqual((id, Combat.Attack, (int?)at.q, (int?)at.r), (committed.Unit, committed.Order, committed.Q, committed.R));
Assert.IsEmpty(bridge.Queued);
Assert.IsEmpty(lit.Last());
Assert.IsFalse(Lines().Contains(Text["unit.attack_pick"]), Lines());
Assert.IsEmpty(bridge.EndTurn().Rejected, "End turn keeps the committed attack result");
info.Dispose();
}
finally { Object.DestroyImmediate(map.gameObject); }
}
/// <summary>R-COMBAT-001 on screen: the attack is fought at the click; the toast names the units, and the card shows
/// the unit spent, or no unit if its own attack destroyed it (Review Focus 4). The seed fixes the draw, so one branch runs.</summary>
[Test]
public void AnAttackShowsItsResultAtOnce()
{
using var ui = new UiTestKit();
var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);
var tokens = UnitRoster.FromState(Units, C, bridge.State, _ => true, (row, a, q, r) => a);
var golani = tokens.Single(t => t.Unit.Id == "golani");
PlacedToken? shown = new PlacedToken(golani, new AnchorSpot(0, 0, 0, 0, false));
var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(), selectedUnit: () => shown);
using var toast = new ToastPresenter(ui.Root, bridge, Text) { Units = Units };
var iraqi = bridge.State.Units.Values.First(u => u.Side == "iraq" && MapActions.Distance(u.Q, u.R, bridge.State.Units[0].Q, bridge.State.Units[0].R) == 1);
var arms = bridge.State.Arms;
Assert.IsNull(bridge.Queue(new UnitOrder(0, Combat.Attack, iraqi.Q, iraqi.R)));
Assert.AreEqual(arms - 1, bridge.State.Arms, "paid at once (arms_per_attack 1)");
var line = ui.Q<Label>("toast").text;
StringAssert.StartsWith("The attack on a hex 10 km south-west of Degania Alef (", line); // the place, not the hex's coordinates
StringAssert.DoesNotContain("unit 0", line);
StringAssert.Contains(golani.Unit.Name, line);
info.ShowUnit();
if (bridge.State.Units.ContainsKey(0))
{
var full = C.UnitTypes.Single(t => t.Id == bridge.State.Units[0].Type).MovementPoints;
StringAssert.Contains(Text.Format("unit.points", 0, full), ui.Q<Label>("info-settlements").text);
}
else
Assert.IsFalse(info.ShowsUnit, "a unit its own attack destroyed has no card");
info.Dispose();
}
/// <summary>The overlay draws one band per hex given (two rings of MapBuilder.RingVertices each) and hides when given
/// none, or only hexes off the map.</summary>
[Test]
public void TheReachableOverlayHasOneBandPerHex()
{
var map = BuildMap();
try
{
var hexes = C.Hexes.Where(h => h.Land).Take(3).Select(h => (h.Q, h.R)).ToList();
map.ShowReachable(hexes);
var go = map.Terrain.transform.Find(MapScene.ReachableName);
Assert.IsTrue(go.GetComponent<MeshRenderer>().enabled);
Assert.AreEqual(3 * 2 * MapBuilder.RingVertices, go.GetComponent<MeshFilter>().sharedMesh.vertexCount);
map.ShowReachable(new[] { (9999, 9999) });
Assert.IsFalse(go.GetComponent<MeshRenderer>().enabled, "off the map: nothing to light");
map.ShowReachable(hexes);
map.ShowReachable(new (int, int)[0]);
Assert.IsFalse(go.GetComponent<MeshRenderer>().enabled);
}
finally { Object.DestroyImmediate(map.gameObject); }
}
/// <summary>Spec 8.1: every route hex has one band, and the last hex of each turn carries that turn's number.</summary>
[Test]
public void TheRouteOverlayShowsTurnNumbers()
{
var map = BuildMap();
using var ui = new UiTestKit();
try
{
using var labels = new MapLabelsPresenter(ui.Root, map, Camera.main);
var hexes = C.Hexes.Where(h => h.Land).Take(3).ToList();
var route = new[] { (hexes[0].Q, hexes[0].R, 1), (hexes[1].Q, hexes[1].R, 1), (hexes[2].Q, hexes[2].R, 2) };
map.ShowRoute(route);
labels.Refresh();
var go = map.Terrain.transform.Find(MapScene.RouteName);
Assert.IsTrue(go.GetComponent<MeshRenderer>().enabled);
Assert.AreEqual(3 * 2 * MapBuilder.RingVertices, go.GetComponent<MeshFilter>().sharedMesh.vertexCount);
CollectionAssert.AreEqual(new[] { "1", "2" }, ui.Root.Query<Label>(className: MapLabelsPresenter.RouteTurnClass).ToList().Select(x => x.text).ToList());
map.ShowRoute(System.Array.Empty<(int, int, int)>());
labels.Refresh();
Assert.IsFalse(go.GetComponent<MeshRenderer>().enabled);
Assert.IsEmpty(ui.Root.Query<Label>(className: MapLabelsPresenter.RouteTurnClass).ToList());
}
finally { Object.DestroyImmediate(map.gameObject); }
}
/// <summary>R-MOVE-008 on screen: in Move's pick, a click on an unlit hex a route reaches gives the go-to, and the card
/// says how many turns remain after this one.</summary>
[Test]
public void AClickBeyondTheLitHexesGivesAGoTo()
{
var map = BuildMap();
using var ui = new UiTestKit();
try
{
var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);
var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
layer.Show(bridge.Content, bridge.State);
var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(),
selectedUnit: () => layer.Selected is string sel ? layer.Tokens.First(p => p.Token.Unit.Id == sel) : (PlacedToken?)null,
showReachable: map.ShowReachable, showRoute: map.ShowRoute);
var golani = layer.Tokens.Single(p => p.Token.Unit.Id == "golani");
var id = UnitCard.SimUnit(C, bridge.State, golani.Token.Unit)!.Value;
var lit = Movement.Reachable(C, bridge.State, id).Keys.ToHashSet();
var none = new Dictionary<int, int>();
var far = C.Hexes.Where(h => h.Land && !lit.Contains((h.Q, h.R)) && (h.Q, h.R) != (golani.Q, golani.R))
.Select(h => (h.Q, h.R)).First(h => Movement.Route(C, bridge.State, id, h.Q, h.R, none).LastOrDefault().Turn == 2);
GameRoot.OnHexClicked(map, layer, info, golani.Q, golani.R);
UiTestKit.Press(ui.Q<Button>("info-move"));
GameRoot.OnHexClicked(map, layer, info, far.Q, far.R);
Assert.AreEqual((Movement.GoTo, $"{far.Q},{far.R}"), (bridge.State.Units[id].Order, bridge.State.Units[id].OrderTarget));
StringAssert.Contains(Text.Format("unit.go_to_given", 1), ui.Q<Label>("info-settlements").text);
info.Dispose();
}
finally { Object.DestroyImmediate(map.gameObject); }
}
/// <summary>R-ENEMY-005 on screen (the owner's ruling on #2087, 1 November 2026): the card of a unit on an operation
/// card's go-to counts the turns of the card's march, which goes round an enemy-held place it was not sent to, not those
/// of the player's own route through it. Golani stands at 3,12, sent by a card to 10,5 beyond enemy-held Acre (8,7): on the
/// 4.4 km grid (#1796) no start and target within 7 hexes of Nazareth (8,11) make the way round cost a turn, so it is Acre.</summary>
[Test]
public void ACardOrderedUnitsCardCountsTheWayRound()
{
var map = BuildMap();
using var ui = new UiTestKit();
try
{
var session = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
var id = UnitCard.SimUnit(C, session.State, Units.Single(e => e.Id == "golani"))!.Value;
var u = session.State.Units[id];
session.State.Units[id] = new Unit(u.Id, u.Type, 3, 12, u.Service, u.Side, u.Strength, Movement.GoTo, "10,5", u.HomeCity, u.Full);
session.State.CardOrders[id] = new System.DateTime(1949, 2, 24);
var bridge = new SimBridge(session, Text);
// Any committed order re-runs the turn's preview, in which the march takes this turn's step (RunOrders).
var other = UnitCard.SimUnit(C, session.State, Units.Single(e => e.Id == "carmeli"))!.Value;
Assert.IsNull(bridge.Queue(new UnitOrder(other, Orders.Hold)));
var now = bridge.Session.Now;
var plain = Movement.Route(C, now.State, id, 10, 5, now.Spent);
var card = Movement.Route(C, now.State, id, 10, 5, now.Spent, card: true);
Assert.IsTrue(now.State.CardOrders.ContainsKey(id), "the card's order still stands");
Assert.IsTrue(plain.Any(h => (h.Q, h.R) == (8, 7)) && !card.Any(h => (h.Q, h.R) == (8, 7)), "the player's route crosses Acre, the card's goes round");
Assert.AreNotEqual(plain[plain.Count - 1].Turn, card[card.Count - 1].Turn, "the way round costs a turn, so the card shows which route it counts");
var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
layer.Show(bridge.Content, bridge.State);
var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(),
selectedUnit: () => layer.Selected is string sel ? layer.Tokens.First(p => p.Token.Unit.Id == sel) : (PlacedToken?)null,
showReachable: map.ShowReachable, showRoute: map.ShowRoute);
var golani = layer.Tokens.Single(p => p.Token.Unit.Id == "golani");
GameRoot.OnHexClicked(map, layer, info, golani.Q, golani.R);
var shown = ui.Q<Label>("info-settlements").text;
StringAssert.Contains(Text.Format("unit.go_to_given", card[card.Count - 1].Turn - 1), shown);
StringAssert.DoesNotContain(Text.Format("unit.go_to_given", plain[plain.Count - 1].Turn - 1), shown);
info.Dispose();
}
finally { Object.DestroyImmediate(map.gameObject); }
}
/// <summary>Spec 8.1: on touch, the first tap on an unlit reachable route previews it and the second gives the go-to.</summary>
[Test]
public void AGoToNeedsASecondTapOnTouch()
{
var map = BuildMap();
using var ui = new UiTestKit();
try
{
var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);
var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
layer.Show(bridge.Content, bridge.State);
var shown = new List<IReadOnlyList<(int q, int r, int turn)>>();
var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(),
selectedUnit: () => layer.Selected is string sel ? layer.Tokens.First(p => p.Token.Unit.Id == sel) : (PlacedToken?)null,
showReachable: map.ShowReachable, showRoute: route => shown.Add(route));
var golani = layer.Tokens.Single(p => p.Token.Unit.Id == "golani");
var id = UnitCard.SimUnit(C, bridge.State, golani.Token.Unit)!.Value;
var lit = Movement.Reachable(C, bridge.State, id).Keys.ToHashSet();
var far = C.Hexes.Where(h => h.Land && !lit.Contains((h.Q, h.R)) && (h.Q, h.R) != (golani.Q, golani.R))
.Select(h => (h.Q, h.R)).First(h => Movement.Route(C, bridge.State, id, h.Q, h.R, new Dictionary<int, int>()).Count > 0);
GameRoot.OnHexClicked(map, layer, info, golani.Q, golani.R);
UiTestKit.Press(ui.Q<Button>("info-move"));
GameRoot.OnHexClicked(map, layer, info, far.Q, far.R, touch: true);
Assert.IsEmpty(bridge.Session.Committed, "the first tap only previews");
Assert.IsNotEmpty(shown.Last(), "the route is visible after the first tap");
GameRoot.OnHexClicked(map, layer, info, far.Q, far.R, touch: true);
Assert.AreEqual(Movement.GoTo, bridge.State.Units[id].Order);
info.Dispose();
}
finally { Object.DestroyImmediate(map.gameObject); }
}
/// <summary>Spec 8.1: a hovered route hides when the mouse leaves the map, and the same hex shows it again on return
/// (the hover's cache is cleared with it, not only the map's overlay).</summary>
[Test]
public void AHoveredRouteShowsAgainAfterTheMouseLeavesTheMap()
{
var map = BuildMap();
using var ui = new UiTestKit();
try
{
var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);
var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
layer.Show(bridge.Content, bridge.State);
var shown = new List<IReadOnlyList<(int q, int r, int turn)>>();
var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(),
selectedUnit: () => layer.Selected is string sel ? layer.Tokens.First(p => p.Token.Unit.Id == sel) : (PlacedToken?)null,
showReachable: map.ShowReachable, showRoute: route => shown.Add(route));
var golani = layer.Tokens.Single(p => p.Token.Unit.Id == "golani");
var id = UnitCard.SimUnit(C, bridge.State, golani.Token.Unit)!.Value;
var lit = Movement.Reachable(C, bridge.State, id).Keys.ToHashSet();
var far = C.Hexes.Where(h => h.Land && !lit.Contains((h.Q, h.R)) && (h.Q, h.R) != (golani.Q, golani.R))
.Select(h => (h.Q, h.R)).First(h => Movement.Route(C, bridge.State, id, h.Q, h.R, new Dictionary<int, int>()).Count > 0);
GameRoot.OnHexClicked(map, layer, info, golani.Q, golani.R);
UiTestKit.Press(ui.Q<Button>("info-move"));
info.ShowRouteTo(far.Q, far.R);
Assert.IsNotEmpty(shown.Last(), "precondition: the hover shows the route");
info.HideRoute();
Assert.IsEmpty(shown.Last(), "the mouse left the map");
var calls = shown.Count;
info.HideRoute();
Assert.AreEqual(calls, shown.Count, "hiding again redraws nothing");
info.ShowRouteTo(far.Q, far.R);
Assert.IsNotEmpty(shown.Last(), "back on the same hex, the route shows again");
info.Dispose();
}
finally { Object.DestroyImmediate(map.gameObject); }
}
/// <summary>R-MOVE-009 on screen: a go-to that arrives at the next turn's start says so in the toast, by the unit's name.</summary>
[Test]
public void ARouteThatArrivesSaysSo()
{
using var ui = new UiTestKit();
var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);
using var toast = new ToastPresenter(ui.Root, bridge, Text) { Units = Units };
var none = new Dictionary<int, int>();
var lit = Movement.Reachable(C, bridge.State, 0).Keys.ToHashSet();
var far = C.Hexes.Where(h => h.Land && !lit.Contains((h.Q, h.R)))
.Select(h => (h.Q, h.R)).First(h => Movement.Route(C, bridge.State, 0, h.Q, h.R, none).LastOrDefault().Turn == 2);
Assert.IsNull(bridge.Queue(new UnitOrder(0, Movement.GoTo, far.Q, far.R)));
bridge.EndTurn();
Assert.IsEmpty(bridge.Session.Committed, "route work happens before this turn has a player order");
Assert.AreEqual(bridge.Session.Now.State.Hash(), bridge.State.Hash(), "spec6.3/8.1: the map shows the route-start preview");
Assert.AreEqual((far.Q, far.R), (bridge.State.Units[0].Q, bridge.State.Units[0].R));
var golaniName = Units.Single(u => u.Id == C.StartingForces[0].Row).Name;
StringAssert.Contains(golaniName, ui.Q<Label>("toast").text);
}
/// <summary>The smoke-orders golden (slice 4): GameRoot.SmokeOrders hides turn 1's event card, gives GoldenRun.SmokeMove
/// through the unit card (a click on the unit, Move, a click on the lit hex), ends the turn with End Turn, and ends on the state the sim's
/// PlaySmokeOrders pins in the golden manifest.</summary>
[Test]
public void TheSmokeOrdersRunGivesItsMoveThroughTheCardAndEndsOnTheGolden()
{
var map = BuildMap();
using var ui = new UiTestKit();
try
{
var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);
using var toast = new ToastPresenter(ui.Root, bridge, Text);
System.Action<int>? select = null;
using var hud = new HudPresenter(ui.Root, bridge, Text, id => select?.Invoke(id)); // wires End Turn and the unit cycle
using var card = new EventCardPresenter(ui.Root, bridge, Text, null);
Assert.IsTrue(ui.Root.Q("root").ClassListContains(EventCardPresenter.OpenClass), "precondition: turn 1's card is open, as in the player");
var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
layer.Show(bridge.Content, bridge.State);
using var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(),
selectedUnit: () => layer.Selected is string sel ? layer.Tokens.First(p => p.Token.Unit.Id == sel) : (PlacedToken?)null,
showReachable: map.ShowReachable);
select = id =>
{
var row = layer.Tokens.Single(p => UnitCard.SimUnit(C, bridge.State, p.Token.Unit) == id).Token.Unit.Id;
layer.Select(row); info.ShowUnit();
};
var log = new List<string>();
var run = GameRoot.SmokeOrders(ui.Root, bridge, layer, (q, r) => GameRoot.OnHexClicked(map, layer, info, q, r), log.Add);
while (run.MoveNext()) { }
var golden = GoldenRun.PlaySmokeOrders(C);
Assert.AreEqual(System.FormattableString.Invariant($"SMOKE ORDERS OK {golden.Date:yyyy-MM-dd} {golden.Hash()}"), log.Last(), string.Join("\n", log));
var move = (Move)bridge.LastBatch.Single();
var expected = GoldenRun.SmokeMove(C, GameSession.New(C, GoldenRun.Seed, Mode.Historical).State);
Assert.AreEqual((expected.Unit, expected.Q, expected.R), (move.Unit, move.Q, move.R), "the one order End Turn sent");
}
finally { Object.DestroyImmediate(map.gameObject); }
}
/// <summary>A click that misses the lit hex queues no Move: the smoke-orders run fails and ends no turn.</summary>
[Test]
public void ASmokeOrdersRunWhoseMoveIsNotQueuedFails()
{
var map = BuildMap();
using var ui = new UiTestKit();
try
{
var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);
System.Action<int>? select = null;
using var hud = new HudPresenter(ui.Root, bridge, Text, id => select?.Invoke(id));
var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
layer.Show(bridge.Content, bridge.State);
using var info = new InfoPanelPresenter(ui.Root, bridge, Text, new Dictionary<string, string>(),
selectedUnit: () => layer.Selected is string sel ? layer.Tokens.First(p => p.Token.Unit.Id == sel) : (PlacedToken?)null);
select = id =>
{
var row = layer.Tokens.Single(p => UnitCard.SimUnit(C, bridge.State, p.Token.Unit) == id).Token.Unit.Id;
layer.Select(row); info.ShowUnit();
};
int clicks = 0, turn = bridge.State.Turn;
var log = new List<string>();
var run = GameRoot.SmokeOrders(ui.Root, bridge, layer, (q, r) => { if (clicks++ == 0) GameRoot.OnHexClicked(map, layer, info, q, r); }, log.Add);
while (run.MoveNext()) { }
StringAssert.StartsWith("SMOKE FAIL", log.Last(), string.Join("\n", log));
Assert.IsFalse(log.Any(l => l.StartsWith("SMOKE ORDERS OK")));
Assert.AreEqual(turn, bridge.State.Turn, "no turn ended");
}
finally { Object.DestroyImmediate(map.gameObject); }
}
/// <summary>"smoke-orders" is its own whole flag: it starts the one-turn run and is not the "smoke" flag.</summary>
[Test]
public void SmokeOrdersIsItsOwnFlag()
{
var none = new string[0];
Assert.IsTrue(GameRoot.SmokeOrdersRequested("http://localhost/?smoke-orders", none, true));
Assert.IsTrue(GameRoot.SmokeOrdersRequested("http://localhost/?golden&smoke-orders", none, true));
Assert.IsFalse(GameRoot.SmokeOrdersRequested("http://localhost/?smoke-orders-x", none, true));
Assert.IsFalse(GameRoot.SmokeOrdersRequested("http://localhost/?smoke=5", none, true));
Assert.AreEqual(0, GameRoot.SmokeTurns("http://localhost/?smoke-orders", none, true), "not the smoke flag");
Assert.IsTrue(GameRoot.SmokeOrdersRequested(null, new[] { "Statecraft", "-smoke-orders" }, false));
Assert.IsFalse(GameRoot.SmokeOrdersRequested("http://localhost/?smoke-orders", new[] { "Statecraft" }, false), "desktop reads only the command line");
}
[TestCase(false)] [TestCase(true)]
public void EscapeClearsTheUnitOrHexWithoutGivingAnOrder(bool hebrew)
{
var text = hebrew ? UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml") : Text;
using var ui = new UiTestKit();
var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical); var bridge = new SimBridge(g, text);
var golani = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a).Single(t => t.Unit.Id == "golani");
PlacedToken? selected = new PlacedToken(golani, new AnchorSpot(0, 0, 0, 0, false));
var towns = SettlementPlacer.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", SettlementPlacer.DefaultFileName))).ToDictionary(t => t.Id, t => t.Name);
using var info = new InfoPanelPresenter(ui.Root, bridge, text, towns, selectedUnit: () => selected);
using var nav = new ScreenNav(ui.Root);
static void Cancel(VisualElement target)
{
using var e = NavigationCancelEvent.GetPooled(); e.target = target; target.SendEvent(e);
}
info.ShowUnit(); Assert.IsTrue(info.ShowsUnit);
nav.Open("settings"); Cancel(ui.Root);
Assert.IsNull(nav.Current, "first Escape closes the covering screen");
Assert.IsTrue(info.ShowsUnit, "the same Cancel does not also dismiss the underlying selection");
var move = ui.Q<Button>("info-move");
move.Focus(); Assert.AreSame(move, move.focusController?.focusedElement, "precondition: the focus is on Move");
Cancel(move);
Assert.IsFalse(info.ShowsUnit, "Escape from a card control dismisses the unit card");
Assert.AreSame(ui.Q<VisualElement>("map-focus"), move.focusController?.focusedElement, "the focus goes to the map stop, not lost with the hidden Move");
info.Show(golani.StateUnit!.Q, golani.StateUnit!.R); Assert.IsNotNull(info.Selected);
Cancel(ui.Q<VisualElement>("info-panel")); Assert.IsNull(info.Selected, "Escape dismisses the hex panel too");
Assert.IsEmpty(bridge.Queued, "closing selection does not alter the turn's orders");
}
[Test]
public void PioneerSelectionClearsMilitaryPicksAndEscapeGivesNoOrder()
{
using var ui = new UiTestKit(); var t = Text;
var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
var token = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a).Single(x => x.Unit.Id == "golani");
PlacedToken? shown = new PlacedToken(token, new AnchorSpot(0, 0, 0, 0, false));
var golani = g.State.Units[UnitCard.SimUnit(C, g.State, token.Unit)!.Value];
var id = PioneerCardTests.Add(g.State, golani.Q, golani.R);
var b = new SimBridge(g, t); IReadOnlyCollection<(int q, int r)>? reach = null;
using var p = new InfoPanelPresenter(ui.Root, b, t, C.SettlementHexes.ToDictionary(x => x.Id, x => x.Id), selectedUnit: () => shown,
showReachable: x => reach = x, clearSelection: () => shown = null);
p.ShowUnit(); Assert.IsNotEmpty(reach!);
var select = typeof(InfoPanelPresenter).GetMethod("ShowPioneer");
Assert.IsNotNull(select, "a pioneer selection transition is absent on base");
select!.Invoke(p, new object[] { id }); Assert.IsNull(shown); Assert.IsEmpty(reach!); Assert.IsFalse(p.MovePicking);
Assert.IsTrue(p.ShowsUnit); Assert.IsTrue(p.Escape()); Assert.IsFalse(p.ShowsUnit);
Assert.IsNull(p.Selected); Assert.IsEmpty(b.Session.Committed); Assert.IsEmpty(b.Queued);
}
}