Play: bots see only viewFor output (MatchView.engine = { view, seat })

Per night-lead's rule on #5 the adapter no longer exposes MatchState to
bots; a test checks no RNG state, seed or deck order leaks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 23:55:58 -05:00
co-authored by Claude Opus 5.5
parent fa1fee98f8
commit c4636530ef
4 changed files with 123 additions and 113 deletions
+1 -1
View File
@@ -98,7 +98,7 @@ export function OnlinePlay({ mode, playerName, onExit, onFinish }: {
const phase = status?.phase; const phase = status?.phase;
// ----- match ----- // ----- match -----
if ((phase === 'playing' || phase === 'finished') && status?.state) { if ((phase === 'playing' || phase === 'finished') && status?.state) {
const view = viewFromPlayerView(status.state); const view = { ...viewFromPlayerView(status.state), engine: { view: status.state, seat: seat.seat } };
const legal = uiActions(status.legalActions ?? []); const legal = uiActions(status.legalActions ?? []);
const opp = status.players.find((_, i) => i !== seat.seat)?.name ?? 'Opponent'; const opp = status.players.find((_, i) => i !== seat.seat)?.name ?? 'Opponent';
const act = (a: UIAction) => { const act = (a: UIAction) => {
+2 -1
View File
@@ -68,7 +68,8 @@ export const engine = {
for (const l of state.lanes) for (const side of l.cards) for (const c of side) titles.set(c.card.cardId, c.card.title); for (const l of state.lanes) for (const side of l.cards) for (const c of side) titles.set(c.card.cardId, c.card.title);
const log = state.log.filter(e => e.t !== 'draw') const log = state.log.filter(e => e.t !== 'draw')
.map(e => logLine(e, me, id => titles.get(id) ?? 'a card')).filter((x): x is string => !!x).slice(-30); .map(e => logLine(e, me, id => titles.get(id) ?? 'a card')).filter((x): x is string => !!x).slice(-30);
return { ...viewFromPlayerView(viewFor(state, me), { log, capacity: i => laneCapacity(state, i) }), engine: { state, seat: me } }; const pv = viewFor(state, me);
return { ...viewFromPlayerView(pv, { log, capacity: i => laneCapacity(state, i) }), engine: { view: pv, seat: me } };
}, },
isOver: (s: MatchState) => isOver(s), isOver: (s: MatchState) => isOver(s),
result(state: MatchState, me: PlayerId): ResultView { result(state: MatchState, me: PlayerId): ResultView {
+3 -3
View File
@@ -1,6 +1,6 @@
// UI-side view models for the Play section. Screens consume only these; adapter.ts maps the // UI-side view models for the Play section. Screens consume only these; adapter.ts maps the
// shared/game engine (docs/game/ENGINE_API.md) onto them. // shared/game engine (docs/game/ENGINE_API.md) onto them.
import type { Action, GameCard, MatchResult, MatchState, PlayerId, Ruleset, Stat } from '../../shared/game/index.ts'; import type { Action, GameCard, MatchResult, PlayerId, PlayerView, Ruleset, Stat } from '../../shared/game/index.ts';
export type PlayerIndex = PlayerId; export type PlayerIndex = PlayerId;
export type { Stat }; export type { Stat };
@@ -56,8 +56,8 @@ export type MatchView = {
log: string[]; // newest last, this seat's events only log: string[]; // newest last, this seat's events only
waitingForOpponent: boolean; waitingForOpponent: boolean;
over: boolean; over: boolean;
/** For bots that reuse shared/bots (ui-b): the full state and this seat. Never render it. */ /** For engine-level bots (ui-b): this seat's hidden-information view only (night-lead: never the full MatchState). */
engine?: { state: MatchState; seat: PlayerId }; engine?: { view: PlayerView; seat: PlayerId };
}; };
export type UIAction = ( export type UIAction = (
+9
View File
@@ -106,3 +106,12 @@ test('peer mode lists are parsed defensively', () => {
assert.equal(m.players, 3); assert.equal(m.players, 3);
assert.deepEqual(parseModeList('nope', { self: true, origin: '' }), []); assert.deepEqual(parseModeList('nope', { self: true, origin: '' }), []);
}); });
test('bots get only the hidden-information view, never the full match state', () => {
const s = engine.createMatch(DEFAULT_RULESET, [starterDeck(), opponentDeck('v')], 'view-only');
const v = engine.view(s, 1);
assert.ok(v.engine?.view);
const json = JSON.stringify(v);
assert.ok(!json.includes('"rng"') && !json.includes('"seed"'), 'no RNG state or seed');
assert.ok(!('deck' in (v.engine!.view as object)), 'no deck order');
});