diff --git a/shared/bots/game-adapter.ts b/shared/bots/game-adapter.ts index 20329bc..c1cb167 100644 --- a/shared/bots/game-adapter.ts +++ b/shared/bots/game-adapter.ts @@ -57,7 +57,8 @@ export function evaluateFor(state: MatchState, seat: Seat): number { let lane = 0, total = 0; for (const [a, b] of lanes) { lane += Math.tanh((a - b) / scale); total += a - b; } const me = state.players[seat], them = state.players[other(seat)]; - const handEdge = (me.hand.length - me.queue.length - (them.hand.length - them.queue.length)) * 0.02; + // Hand sizes include queued cards on both sides: the opponent's queue size is hidden information. + const handEdge = (me.hand.length - them.hand.length) * 0.02; const unspent = energyLeft(me) * -0.01; // nudge greedy to use its energy const v = (lane + Math.tanh(total / 20) * 0.3) / (state.lanes.length + 0.3) + handEdge + unspent; return Math.max(-1, Math.min(1, v)); @@ -74,7 +75,7 @@ export function stateFromView(view: PlayerView, rng: Rng, filler: readonly GameC const me = view.you, them = other(me); const players = [] as unknown as [PlayerState, PlayerState]; players[me] = { deck: draw(view.deckCount), hand: view.hand, energy: view.energy, queue: view.queue, committed: view.committed, afk: 0, carry: 0 }; - players[them] = { deck: draw(view.opponent.deckCount), hand: draw(view.opponent.handCount), energy: view.energy, queue: [], committed: false, afk: 0, carry: 0 }; + players[them] = { deck: draw(view.opponent.deckCount), hand: draw(view.opponent.handCount + view.opponent.queuedCount), energy: view.energy, queue: [], committed: false, afk: 0, carry: 0 }; let seq = 0; const lanes = view.lanes.map(l => { const cards = [] as unknown as [CardInPlay[], CardInPlay[]]; diff --git a/tests/bots-sim.test.ts b/tests/bots-sim.test.ts index 7f4bfc3..6ecd420 100644 --- a/tests/bots-sim.test.ts +++ b/tests/bots-sim.test.ts @@ -48,3 +48,20 @@ test('bots only return legal actions on shared/game', { skip: !existsSync(new UR assert.ok(engine.isOver(s), `${name} match did not finish`); } }); + +test('seat 1 bot input does not depend on what seat 0 has queued', { skip: !existsSync(new URL('../shared/game/index.ts', import.meta.url)) }, async () => { + const { gameEngine, stateFromView, evaluateFor, starterPoolCards } = await import('../shared/bots/game-adapter.ts'); + const engine = gameEngine as EngineAdapter; + const decks = engine.decks(engine.rulesets()[0]); + for (let seed = 1; seed <= 20; seed++) { + const s0 = engine.createMatch(engine.rulesets()[0], [decks[0], decks[1]], seed); + const plays = engine.legalActions(s0, 0).filter((a: any) => a.type === 'play'); + if (!plays.length) continue; + const s1 = engine.applyAction(s0, plays[0]); + const s2 = engine.applyAction(s1, { type: 'commit', player: 0 }); + const pool = starterPoolCards(); + const ev = (s: any) => evaluateFor(stateFromView(engine.observe!(s, 1) as any, mulberry32(9), pool), 1); + assert.equal(ev(s1), ev(s0), `seed ${seed}: queued play changed seat 1's evaluation`); + assert.equal(ev(s2), ev(s0), `seed ${seed}: commit changed seat 1's evaluation`); + } +});