Night 1: viewFor no longer leaks the opponent's queue size (DESIGN §5.3) #38

Merged
claude merged 1 commits from night/engine/view-queue-leak into night/2026-11-16 2026-11-17 05:54:57 +00:00
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 {
you: 0 | 1; ruleset; turn; phase; initiative;
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],
cardPower: [number[], number[]], power: [mine, theirs], leader: 'you' | 'opponent' | 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,
energy: me.energy, energyLeft: me.energy - queuedCost(me), hand: me.hand, queue: me.queue,
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) => {
const power = lanePower(state, index);
const mine = power[you], theirs = power[them];
+5 -1
View File
@@ -208,7 +208,11 @@ export interface PlayerView {
queue: QueuedPlay[];
committed: boolean;
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: {
/** Always visible; `portal` is null until the Portal is revealed. */
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');
state = applyAction(state, play);
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(viewFor(applyAction(state, { type: 'undo', player: 0, cardId: play.cardId }), 0).energyLeft, 1);
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));
});
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', () => {
let state = createMatch(DEFAULT_RULESET, [flatDeck(1, 'a'), flatDeck(1, 'b')], 3);
const first = state.players[0].hand[0].cardId;