viewFor: stop leaking the opponent's queue size during planning (DESIGN §5.3)

Remove PlayerView.opponent.queuedCount and keep queued cards in handCount, so
the opponent's view doesn't change until commit. Regression test: the view is
byte-identical before and after queuing and undoing. Found by night-review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 00:12:35 -05:00
co-authored by Claude Opus 5.5
parent 4a4941c6ff
commit eecb4f9c07
4 changed files with 31 additions and 4 deletions
+1 -1
View File
@@ -169,7 +169,7 @@ interface CardInPlay { card: GameCard; owner: 0 | 1; lane: number; turn: number;
interface PlayerView { interface PlayerView {
you: 0 | 1; ruleset; turn; phase; initiative; you: 0 | 1; ruleset; turn; phase; initiative;
energy: number; energyLeft: number; hand: GameCard[]; queue: { cardId; lane }[]; committed; deckCount; energy: number; energyLeft: number; hand: GameCard[]; queue: { cardId; lane }[]; committed; deckCount;
opponent: { handCount; deckCount; queuedCount; committed }; // never their cards or queue opponent: { handCount; deckCount; committed }; // §5.3: nothing about their queue (cards, count or energy) until reveal
lanes: { topic: TopicDef /* stat always; id/name/portal masked until portalRevealed */, portalRevealed, cards: [mine, theirs], lanes: { topic: TopicDef /* stat always; id/name/portal masked until portalRevealed */, portalRevealed, cards: [mine, theirs],
cardPower: [number[], number[]], power: [mine, theirs], leader: 'you' | 'opponent' | null }[]; cardPower: [number[], number[]], power: [mine, theirs], leader: 'you' | 'opponent' | null }[];
result: MatchResult | null; result: MatchResult | null;
+1 -1
View File
@@ -399,7 +399,7 @@ export function viewFor(state: MatchState, you: PlayerId): PlayerView {
you, ruleset: state.ruleset, turn: state.turn, phase: state.phase, initiative: state.initiative, you, ruleset: state.ruleset, turn: state.turn, phase: state.phase, initiative: state.initiative,
energy: me.energy, energyLeft: me.energy - queuedCost(me), hand: me.hand, queue: me.queue, energy: me.energy, energyLeft: me.energy - queuedCost(me), hand: me.hand, queue: me.queue,
committed: me.committed, deckCount: me.deck.length, committed: me.committed, deckCount: me.deck.length,
opponent: { handCount: opp.hand.length - opp.queue.length, deckCount: opp.deck.length, queuedCount: opp.queue.length, committed: opp.committed }, opponent: { handCount: opp.hand.length, deckCount: opp.deck.length, committed: opp.committed },
lanes: state.lanes.map((lane, index) => { lanes: state.lanes.map((lane, index) => {
const power = lanePower(state, index); const power = lanePower(state, index);
const mine = power[you], theirs = power[them]; const mine = power[you], theirs = power[them];
+5 -1
View File
@@ -208,7 +208,11 @@ export interface PlayerView {
queue: QueuedPlay[]; queue: QueuedPlay[];
committed: boolean; committed: boolean;
deckCount: number; deckCount: number;
opponent: { handCount: number; deckCount: number; queuedCount: number; committed: boolean }; /**
* DESIGN §5.3: planning is hidden. handCount still counts queued cards and no
* opponent energy is exposed, so nothing changes while they queue; only `committed` does.
*/
opponent: { handCount: number; deckCount: number; committed: boolean };
lanes: { lanes: {
/** Always visible; `portal` is null until the Portal is revealed. */ /** Always visible; `portal` is null until the Portal is revealed. */
topic: TopicDef; topic: TopicDef;
+24 -1
View File
@@ -88,7 +88,6 @@ test('queued plays are hidden until reveal; undo refunds; committed seats get no
assert.ok(play, 'turn 1 should have a 1-cost play'); assert.ok(play, 'turn 1 should have a 1-cost play');
state = applyAction(state, play); state = applyAction(state, play);
assert.equal(viewFor(state, 0).energyLeft, 0); assert.equal(viewFor(state, 0).energyLeft, 0);
assert.equal(viewFor(state, 1).opponent.queuedCount, 1);
assert.equal(JSON.stringify(viewFor(state, 1)).includes(`"${play.cardId}"`), false); assert.equal(JSON.stringify(viewFor(state, 1)).includes(`"${play.cardId}"`), false);
assert.equal(viewFor(applyAction(state, { type: 'undo', player: 0, cardId: play.cardId }), 0).energyLeft, 1); assert.equal(viewFor(applyAction(state, { type: 'undo', player: 0, cardId: play.cardId }), 0).energyLeft, 1);
state = commit(state, 0); state = commit(state, 0);
@@ -111,6 +110,30 @@ test('viewFor never leaks the opponent hand, deck order, queue, seed or RNG stat
assert.deepEqual(view.hand.map(c => c.cardId), state.players[0].hand.map(c => c.cardId)); assert.deepEqual(view.hand.map(c => c.cardId), state.players[0].hand.map(c => c.cardId));
}); });
test('planning is hidden: the opponent view is identical before and after queuing, until commit', () => {
for (let seed = 0; seed < 10; seed++) {
let state = createMatch(DEFAULT_RULESET, decks(`plan-${seed}`), seed);
for (let turn = 0; turn < 4 && !isOver(state); turn++) {
const before = JSON.stringify(viewFor(state, 1));
let queued = 0;
for (;;) {
const play = legalActions(state, 0).find(a => a.type === 'play');
if (!play) break;
state = applyAction(state, play);
queued++;
assert.equal(JSON.stringify(viewFor(state, 1)), before, `seed ${seed} turn ${state.turn}: view changed after ${queued} queued`);
}
if (queued) {
const undo = legalActions(state, 0).find(a => a.type === 'undo')!;
assert.equal(JSON.stringify(viewFor(applyAction(state, undo), 1)), before, 'undo must not show either');
}
state = commit(state, 0);
assert.equal(viewFor(state, 1).opponent.committed, true);
state = commit(state, 1);
}
}
});
test('energy: energyByTurn + carry (max 1) of unspent energy', () => { test('energy: energyByTurn + carry (max 1) of unspent energy', () => {
let state = createMatch(DEFAULT_RULESET, [flatDeck(1, 'a'), flatDeck(1, 'b')], 3); let state = createMatch(DEFAULT_RULESET, [flatDeck(1, 'a'), flatDeck(1, 'b')], 3);
const first = state.players[0].hand[0].cardId; const first = state.players[0].hand[0].cardId;