sim-balance: no opponent queue-count in bot input (hand totals), invariance test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 00:07:57 -05:00
co-authored by Claude Opus 5.5
parent b75a094397
commit 64b739e9d3
2 changed files with 20 additions and 2 deletions
+3 -2
View File
@@ -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[]];
+17
View File
@@ -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<any, any>;
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`);
}
});