feat(hint): unify the vs_ai idle hint online + offline (server-enforced, monotonic)
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 15s
CI / ui (pull_request) Successful in 1m28s
CI / conformance (pull_request) Successful in 9s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m43s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 15s
CI / ui (pull_request) Successful in 1m28s
CI / conformance (pull_request) Successful in 9s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m43s
Online vs_ai hints were broken: #207 made the vs_ai hint button always-enabled and wallet-free (assuming all vs_ai = the offline idle-gate), but the backend still served online vs_ai from the allowance/wallet, so over-clicking hit ErrNoHintsLeft -> a generic error toast. Now online vs_ai uses the SAME idle-gate model as offline. Backend: Hint() for a vs_ai game skips the allowance/wallet and increments no hints_used (owner: vs_ai counts toward no hint statistic), and is idle-gated from the SERVER clock -- it returns ErrHintLocked (code hint_locked) until the robot's last move + 30 min, else serves the top move. GameState/StateView expose hint_unlock_left_seconds (server-computed seconds remaining; 0 for a human game / first move / not-your-turn). Pure helper hintUnlockLeftSeconds unit-tested. Wire: StateView gains hint_unlock_left_seconds (FlatBuffers, additive); pkg/wire + gateway transcode carry it (round-trip test). Client: the gate counts down from a MONOTONIC clock (performance.now()) anchored to the source's seconds-left when it lands (on load from the view; to the full window when the robot moves), so a client clock change cannot skew it and a relaunch re-reads a fresh value. The vs_ai hint button (online + offline) shows the lock + toast; doHint handles the hint_locked backstop by re-syncing. Replaces #207's absolute hintUnlockAtMs on the wire/model/delta (the offline record keeps the absolute for persistence; the view exposes seconds-left). Docs FUNCTIONAL(+_ru)/ARCHITECTURE updated. Verified: go build/vet + game/server/transcode tests (+ new hintUnlockLeftSeconds); ui check 0 / unit 490 / e2e 198 (one pre-existing webkit offline flake) / app entry 114.2/115.
This commit is contained in:
@@ -1252,13 +1252,14 @@ an *Offline* chip and confines play to on-device `vs_ai` games. The **offline lo
|
||||
device-local games** (reconstructed by replaying the IndexedDB move journal) and its New-vs-AI entry
|
||||
creates one through the in-browser engine — the same game screen then drives it, the robot replying
|
||||
locally; online-only affordances (the Stats tab, the friend/random options in New Game) are disabled
|
||||
or hidden. A local `vs_ai` hint is unlimited and wallet-free but idle-gated (unlocked ~30 min into a
|
||||
stuck turn). The gate is a **persisted wall-clock unlock instant** (`hintUnlockAtMs` on the record +
|
||||
the game view, stamped from the robot's reply, carried on the move delta), so the wait survives a
|
||||
relaunch — but it is **sanitised on read** (capped at `now + window`, `lib/hints` + `source.ts`) so a
|
||||
device clock the player sets **back** cannot push the unlock away and freeze the gate; a clock set
|
||||
**forward** merely opens the hint early, harmless for a solo game. An online `vs_ai` game will gate the
|
||||
same way but from the server's clock (a follow-up). To have data ready before the switch, the **Profile advertises the current dictionary
|
||||
or hidden. A `vs_ai` hint (online and offline alike) is unlimited and wallet-free but idle-gated
|
||||
(unlocked ~30 min into a stuck turn), and counts toward no hint statistic. The **source** reports the
|
||||
**seconds left** (`hint_unlock_left_seconds` on the game view) — computed by the **backend from the
|
||||
server clock** online (which also enforces the gate, returning `hint_locked` for an early request),
|
||||
and by the offline source from the device clock (persisted, capped at the window). The **client
|
||||
anchors a MONOTONIC countdown** (`performance.now()`, `lib/hints`) to that seconds-left when it lands
|
||||
(on load, and to the full window when the robot moves), so a client clock change cannot skew it, and
|
||||
a relaunch re-reads a fresh value so the wait is not forgotten. To have data ready before the switch, the **Profile advertises the current dictionary
|
||||
version per variant** (`dict_versions`,
|
||||
filled from the registry on the existing cold-start profile request — no extra round-trip), and an
|
||||
eligible installed PWA (standalone web + confirmed email) **background-preloads** those dictionaries
|
||||
|
||||
+5
-5
@@ -220,11 +220,11 @@ personal hint wallet once the per-game allowance is spent. Against the robot
|
||||
anti-frustration aid: one unlocks only after the player has been **stuck ~30 minutes
|
||||
on a turn** (timed from the robot's last move; the very first move, before the robot
|
||||
has played, is exempt). While gated the hint button carries a small **🔒 lock** and a
|
||||
tap shows how long remains; the lock lifts live at the mark. The wait **persists across
|
||||
leaving and reopening the app**, so a stuck turn is not forgotten. It stays robust to a
|
||||
device clock change: the remaining is capped at the window, so a clock set back cannot
|
||||
freeze it, and a clock set forward merely opens the hint early — harmless in a solo game.
|
||||
The game ends when the
|
||||
tap shows how long remains; the lock lifts live at the mark. The same gate applies **online and
|
||||
offline**: the countdown runs on a **steady in-app timer**, not the device clock, so changing the
|
||||
clock cannot skew it, and a relaunch re-reads the remaining time so a stuck turn is not forgotten.
|
||||
Online the **server enforces** it from its own clock (which the player cannot touch); a vs_ai hint
|
||||
counts toward no hint statistic. The game ends when the
|
||||
bag empties and a player clears their rack, after 6 consecutive scoreless turns,
|
||||
by resignation, or by the per-game move timeout (5 minutes to 24 hours, default
|
||||
24 hours): a missed turn auto-resigns, except while the player is inside their
|
||||
|
||||
@@ -227,10 +227,11 @@ e-mail) либо ввод фразы. Активные игры форфейтя
|
||||
анти-фрустрация: подсказка открывается, только когда игрок **застрял на ходу ~30 минут**
|
||||
(отсчёт от последнего хода робота; самый первый ход, до хода робота, исключён). Пока гейт
|
||||
закрыт, кнопка подсказки несёт маленький **🔒 замок**, а тап показывает, сколько осталось;
|
||||
замок снимается вживую в нужный момент. Отсчёт **переживает выход и повторный вход в
|
||||
приложение**, так что застрявший ход не забывается. И он устойчив к переводу часов: остаток
|
||||
ограничен окном, поэтому перевод назад не заморозит гейт, а перевод вперёд просто откроет
|
||||
подсказку раньше — безвредно в соло-игре. Партия
|
||||
замок снимается вживую в нужный момент. Один и тот же гейт работает **онлайн и офлайн**: отсчёт
|
||||
идёт по **ровному внутриигровому таймеру**, а не по системным часам, поэтому их перевод его не
|
||||
собьёт, а повторный вход перечитывает остаток — застрявший ход не забывается. Онлайн гейт
|
||||
**принуждает сервер** по своим часам (их игрок не тронет); vs_ai-подсказка не учитывается ни в
|
||||
одной статистике подсказок. Партия
|
||||
завершается, когда мешок пуст и игрок выложил стойку, после 6 подряд бесплодных
|
||||
ходов, по сдаче, либо по таймауту хода (от 5 минут до 24 часов, дефолт 24 часа):
|
||||
пропущенный ход означает авто-сдачу, кроме как когда игрок внутри своего
|
||||
|
||||
Reference in New Issue
Block a user