A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Tools: web_check presses "Skip the opening" before End turn, so the nightly start-screen pass works again (Refs #530) (#2103)
Eyal Golan70b743a2251d
diff --git a/tools/tests/test_web_check.py b/tools/tests/test_web_check.pyindex f36d72ef3..8a4d7d23c 100644--- a/tools/tests/test_web_check.py+++ b/tools/tests/test_web_check.py@@ -290,14 +290,18 @@ class FakeGame:TURN lines are fed by the test). The unit card is EN_CARD, its rows mirrored in Hebrew: a probe names the element underit (a "map" one is taken by the map), and a click on Skip skips a unit."""- def __init__(self, units=0, card=None, hebrew=False, answers=True):+ def __init__(self, units=0, card=None, hebrew=False, answers=True, opening=None):self.tail, self.units, self.answers = wc.ConsoleTail(), units, answersself.card, self.hebrew, self.actions, self.turn = card or EN_CARD, hebrew, [], 1+ self.opening = opening # #530: the opening's layout while it covers the window (top bar included), until Skipdef nav(self, what):self.tail.feed(f"NAV f=1 t=1 {what}")def at(self, x, y):+ if self.opening is not None:+ return next((name for (x0, x1, y0, y1), name in self.opening if x0 <= x <= x1 and y0 <= y <= y1),+ "opening-card" if 440 <= x <= 1480 else "opening-layer")if self.hebrew:x = wc.INFO_PANEL_LEFT + wc.INFO_PANEL_RIGHT - xinside = wc.INFO_PANEL_LEFT <= x <= wc.INFO_PANEL_RIGHT and y >= 1080 - wc.INFO_PANEL_BOTTOM - wc.INFO_PANEL_MAX_HEIGHT@@ -310,7 +314,12 @@ class FakeGame:if not self.answers or not at:returnx, y = (int(v) for v in at.split(","))- if kind == "click" and (x, y) in (wc.END_TURN, wc.END_TURN_HE):+ if kind == "click" and self.opening is not None: # the opening takes every click while it shows+ target = self.at(x, y)+ self.nav(f"ui click count=1 target={target}")+ if target == "opening-skip":+ self.opening = None+ elif kind == "click" and (x, y) in (wc.END_TURN, wc.END_TURN_HE):self.nav("ui click count=1 target=end-turn")if self.units == 0:self.tail.feed(f"TURN {self.turn} 1948-06-15 hash bb")@@ -333,6 +342,15 @@ EN_CARD = [((84, 536, 1010, 1064), "info-reason"), ((96, 200, 976, 1002), "info-# Skip second in its line: found along the line, not at its start.SECOND_CARD = [((84, 536, 1010, 1064), "info-reason"), ((96, 180, 976, 1002), "info-move"), ((186, 300, 976, 1002), "info-skip"),((84, 536, 960, 1009), "VisualElement")]+# The opening's first panel (#530) at 1920x1080, as middle-button probes of the 0.3.3 nightly build found it: its Back, Next+# and Skip row is centred under the prose. English: Skip starts at the centre. Hebrew: the row is mirrored and the centre+# falls in a gap between buttons (the unnamed row, VisualElement). FAR: Skip is off both scan columns, found along the row.+EN_OPENING = [((811, 873, 552, 598), "opening-back"), ((885, 947, 552, 598), "opening-next"),+ ((960, 1108, 552, 598), "opening-skip"), ((805, 1114, 548, 602), "VisualElement")]+HE_OPENING = [((800, 948, 582, 628), "opening-skip"), ((966, 1028, 582, 628), "opening-next"),+ ((1040, 1102, 582, 628), "opening-back"), ((794, 1108, 578, 632), "VisualElement")]+FAR_OPENING = [((900, 1000, 560, 600), "opening-next"), ((1100, 1200, 560, 600), "opening-skip")]+NO_SKIP_OPENING = [((900, 1000, 560, 600), "opening-next")]NO_SKIP_CARD = [((84, 536, 1010, 1064), "info-reason"), ((96, 180, 976, 1002), "info-move"), ((84, 536, 960, 1009), "VisualElement")]@@ -393,6 +411,49 @@ def test_end_turn_fails_when_its_click_misses_end_turn():_end_turn(FakeGame(answers=False))()[email protected]("hebrew,layout", [(False, EN_OPENING), (True, HE_OPENING), (False, FAR_OPENING)])+def test_end_turn_skips_the_opening_that_covers_it_as_a_player_does(hebrew, layout, capsys):+ """#530: after New game the opening covers the top bar, so the first End turn click reaches the opening. EndTurn presses+ the opening's own Skip, found with middle-button probes, then End turn again."""+ game = FakeGame(hebrew=hebrew, opening=layout)+ end_turn = wc.END_TURN_HE if hebrew else wc.END_TURN+ assert _end_turn(game)() == 0 and game.opening is None+ clicks = [a for a in game.actions if a.startswith("click:")]+ assert clicks[0] == clicks[2] == _clicks(end_turn)[0] and len(clicks) == 3, "End turn, Skip, End turn"+ x, y = (int(v) for v in clicks[1].split(":")[1].split(","))+ assert next(name for (x0, x1, y0, y1), name in layout if x0 <= x <= x1 and y0 <= y <= y1) == "opening-skip"+ assert game.tail.wait(wc.TURN_STATE, 0, 0) is not None+ out = capsys.readouterr().out+ assert "the click reached opening-layer" in out and f"click opening-skip at ({x}, {y})" in out+++def test_end_turn_fails_on_an_opening_without_skip():+ with pytest.raises(ValueError, match="OPENING FAIL the opening covers End turn, but no opening-skip"):+ _end_turn(FakeGame(opening=NO_SKIP_OPENING))()+++def test_end_turn_fails_when_the_opening_is_still_there_after_skip():+ game = FakeGame(opening=EN_OPENING)++ def stuck(action): # Skip is pressed, but the opening stays over End turn+ layout = game.opening+ game(action)+ game.opening = layout+ with pytest.raises(ValueError, match="END TURN FAIL the click at \\(1840, 45\\) did not press end-turn .*reached opening-layer"):+ wc.EndTurn(stuck, game.tail, False, settle=lambda s: None, answer=0.05, turn_wait=0.05)()+++def test_start_screen_check_skips_the_opening_after_new_game():+ game = FakeGame(opening=EN_OPENING)+ check = wc.StartScreenCheck(game, recording=False, hebrew=False, buttons=_buttons(), tail=game.tail, settle=lambda s: None)+ check.feed("GAME OK 1948-05-15 turn 0 hash aa")+ clicks = [a for a in game.actions if a.startswith("click:")]+ assert clicks[:2] == _clicks(AT["start-new-game"], wc.END_TURN) and clicks[-1] == _clicks(wc.END_TURN)[0]+ assert game.opening is None+ check.feed("TURN 1 1948-06-15 hash bb")+ assert check.done++def test_a_click_that_does_not_press_skip_fails():game = FakeGame(units=1)probe_at = game.atdiff --git a/tools/web_check.py b/tools/web_check.pyindex e3cb91ec5..d246a7d48 100644--- a/tools/web_check.py+++ b/tools/web_check.py@@ -18,7 +18,8 @@ Options: --query Q (page URL query, without '?'), --expect TEXT (repeatable), ----persistence (play one normal turn, wait for its matching IndexedDB commit, reload and Continue, then play anotherturn and reload as soon as its matching commit arrives; both reloads must report the saved date, turn and hash), --startscreen new|recording (#908: on a freshprofile, the real start screen every player sees first: "new" presses New game, "recording" first presses Play the-recording and waits for RECORDING playing; then End turn must log TURN 1, pressing "Skip this turn" on each unit End+recording and waits for RECORDING playing; then End turn must log TURN 1, first pressing "Skip the opening" when the+opening (#530) takes End turn's click, then "Skip this turn" on each unit Endturn selects while units still need orders (EndTurn; --persistence ends its turns so too); any console Exception, RECORDING failed orBOOT FAIL fails the run; add --query lang=he for the Hebrew layout). Both runs add ?navlog and click the start screen'sbuttons where its "start buttons" line says they are (StartButtons).@@ -499,6 +500,13 @@ ORDER_ROW = {"build-camp", "build-housing", "info-defence", "info-primary-orders"info-skip", "info-attack", "info-send-home", "info-reinforce"}ABOVE_ORDERS = {"info-title", "info-subtitle", "info-region", "info-settlements", "info-localities", "info-placement"}SKIP = "info-skip"+# The opening (#530): after New game, once opening.yaml is reviewed, three stills cover the whole window, top bar included+# (Statecraft.uss .opening-open), so End turn's click reaches the opening until the player presses "Skip the opening" (or+# Next through it). Its Back, Next and Skip row (Game.uxml .opening-actions) is centred under prose whose height changes+# with the panel and the language, so Skip is found where the game draws it, like the unit card's: down two columns 30 px+# apart (a button is wider than that, the row's gaps narrower) to the row, then along it.+OPENING, OPENING_SKIP = "opening-", "opening-skip"+OPENING_ROW = {"opening-back", "opening-next", OPENING_SKIP}# Well over the units a turn has needing orders (8 on a new game, 9 on turn 2, 0.3.0 RC): a turn that never ends fails.MAX_SKIPS = 40@@ -508,25 +516,22 @@ class EndTurn:of ending the turn, so press that unit's "Skip this turn" and End turn again, until the game logs the next TURN line, atmost `max_skips` times (GameRoot.Smoke's loop, through the browser). The unit card's buttons move with its text, soSkip is found where the game draws it: a middle-button probe reports the element under it (?navlog NAV_DOWN) and acts- on nothing (a left press on the card's text can move the unit, NAV_MAP), then a left click presses Skip. A missed End- turn, a probe the map takes, a card with no Skip, or a turn that never ends fails at once. Returns the number of Skips."""+ on nothing (a left press on the card's text can move the unit, NAV_MAP), then a left click presses Skip. When the+ opening (#530) takes the first End turn click, its own Skip is pressed the same way and End turn clicked again. A+ missed End turn, a probe the map takes, a card or an opening with no Skip, or a turn that never ends fails at once.+ Returns the number of units Skipped."""def __init__(self, action, tail: ConsoleTail, hebrew: bool, settle=time.sleep, max_skips=MAX_SKIPS, answer=5.0,turn_wait=3.0, viewport=VIEWPORT):self.action, self.tail, self.hebrew, self.settle = action, tail, hebrew, settleself.max_skips, self.answer, self.turn_wait = max_skips, answer, turn_waitself.point = END_TURN_HE if hebrew else END_TURN- self.bottom = viewport[1] - INFO_PANEL_BOTTOM+ self.viewport, self.bottom = viewport, viewport[1] - INFO_PANEL_BOTTOMself.skip_at: tuple[int, int] | None = None # where Skip was last: cards of one kind keep it theredef __call__(self) -> int:for skips in range(self.max_skips + 1):- since = self.tail.mark()- x, y = self.point- print(f"click end-turn at ({x}, {y})")- self.action(f"click:{x},{y}")- if self.tail.wait(NAV_CLICK, since, self.answer, "end-turn") is None:- raise ValueError(f"END TURN FAIL the click at ({x}, {y}) did not press end-turn within {self.answer:g} s")+ since = self.click_end_turn(opening=skips == 0) # the opening shows only before a new game's first turnif self.tail.wait(TURN_STATE, since, self.turn_wait) is not None:print(f"END TURN the turn ended after {skips} Skip(s)")return skips@@ -538,6 +543,50 @@ class EndTurn:return skipsraise ValueError(f"END TURN FAIL End turn still selected a unit needing orders after {self.max_skips} Skips")+ def click_end_turn(self, opening: bool) -> int:+ """Clicks End turn; the console mark before the click that pressed it. With `opening`, a click the opening takes is+ answered as a player does: its Skip (skip_opening), then End turn again."""+ x, y = self.point+ since = self.tail.mark()+ print(f"click end-turn at ({x}, {y})")+ self.action(f"click:{x},{y}")+ if self.tail.wait(NAV_CLICK, since, self.answer, "end-turn") is not None:+ return since+ other = self.tail.wait(NAV_CLICK, since, 0)+ reached = f" (the click reached {other.group(1)})" if other else ""+ if opening and other is not None and other.group(1).startswith(OPENING):+ print(f"END TURN the click reached {other.group(1)}: the opening covers End turn, so press its Skip")+ self.skip_opening()+ self.settle(1) # the top bar shows again+ return self.click_end_turn(opening=False)+ raise ValueError(f"END TURN FAIL the click at ({x}, {y}) did not press end-turn within {self.answer:g} s{reached}")++ def skip_opening(self) -> None:+ """Presses the opening's Skip where the game draws it (OPENING_ROW), found with middle-button probes."""+ cx, seen, row = self.viewport[0] // 2, [], None+ for y in range(PROBE_INSET, self.viewport[1] - PROBE_INSET, 10):+ for x in (cx, cx - 30):+ target = self.press(x, y)+ seen.append(target)+ if target in OPENING_ROW:+ row = (x, y)+ break+ if row is not None:+ break+ points = [] if row is None else [row] + [(x, row[1]) for dx in range(10, cx, 10) for x in (cx + dx, cx - dx)]+ for x, y in points:+ if (target := self.press(x, y)) == OPENING_SKIP:+ since = self.tail.mark()+ print(f"click {OPENING_SKIP} at ({x}, {y})")+ self.action(f"click:{x},{y}")+ if self.tail.wait(NAV_CLICK, since, self.answer, OPENING_SKIP) is None:+ raise ValueError(f"OPENING FAIL the click at ({x}, {y}) did not press {OPENING_SKIP} within "+ f"{self.answer:g} s")+ return+ seen.append(target)+ raise ValueError(f"OPENING FAIL the opening covers End turn, but no {OPENING_SKIP} was found (its row at y "+ f"{row[1] if row else 'none'}; pressed {', '.join(dict.fromkeys(seen))})")+def skip(self, since: int) -> bool:"""Clicks the shown unit card's Skip; False when the turn ended after all (a late TURN line), so nothing was pressed."""if self.skip_at is not None and self.probe(*self.skip_at):