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:
@@ -290,10 +290,9 @@ export class LocalSource implements GameLoopSource {
|
||||
private emitRobot(entry: Live, moves: LocalMove[]): void {
|
||||
const set = this.listeners.get(entry.record.id);
|
||||
if (!set) return;
|
||||
const hintUnlockAtMs = this.hintUnlock(entry);
|
||||
for (const m of moves) {
|
||||
const game = this.gameView(entry);
|
||||
const ev: PushEvent = { kind: 'opponent_moved', gameId: entry.record.id, move: this.moveRecord(entry.record.variant, m), game, bagLen: entry.game.bagLength, hintUnlockAtMs };
|
||||
const ev: PushEvent = { kind: 'opponent_moved', gameId: entry.record.id, move: this.moveRecord(entry.record.variant, m), game, bagLen: entry.game.bagLength };
|
||||
for (const cb of set) cb(ev);
|
||||
}
|
||||
if (entry.game.isOver) {
|
||||
@@ -342,11 +341,14 @@ export class LocalSource implements GameLoopSource {
|
||||
|
||||
// --- shape builders --------------------------------------------------------
|
||||
|
||||
// The vs_ai idle-hint unlock instant, sanitised on read: capped at now + the window so a device
|
||||
// clock set back cannot push it far ahead and freeze the gate (the client counts down from here).
|
||||
// 0 while open (a human-first opening, no robot move yet).
|
||||
private hintUnlock(entry: Live): number {
|
||||
return entry.record.hintUnlockAtMs ? Math.min(entry.record.hintUnlockAtMs, Date.now() + HINT_GATE_MS) : 0;
|
||||
// The vs_ai idle-hint seconds left, from the stored unlock instant (device wall clock, persisted
|
||||
// for the offline record) minus now — capped at the window so a device clock set back cannot push
|
||||
// it far ahead and freeze the gate, ceiled to whole seconds and floored at 0. The client anchors a
|
||||
// monotonic countdown to this; 0 while open (a human-first opening, no robot move yet).
|
||||
private hintUnlockLeft(entry: Live): number {
|
||||
if (!entry.record.hintUnlockAtMs) return 0;
|
||||
const leftMs = Math.min(HINT_GATE_MS, entry.record.hintUnlockAtMs - Date.now());
|
||||
return leftMs > 0 ? Math.ceil(leftMs / 1000) : 0;
|
||||
}
|
||||
|
||||
private stateView(entry: Live): StateView {
|
||||
@@ -359,7 +361,7 @@ export class LocalSource implements GameLoopSource {
|
||||
bagLen: entry.game.bagLength,
|
||||
hintsRemaining: 1,
|
||||
walletBalance: 0,
|
||||
hintUnlockAtMs: this.hintUnlock(entry),
|
||||
hintUnlockLeftSeconds: this.hintUnlockLeft(entry),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user