forked from WikiDeck/wikideck
Modes: draft pool from the engine's frozen loaner cards (previewPool, #29)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,18 +1,23 @@
|
||||
/** Binds the mode host to the real engine through its public API (shared/game/index.ts). */
|
||||
import { DEFAULT_RULESET, parseRuleset, starterDeck, loanerCard, STARTER_POOL, validateDeck, createMatch,
|
||||
import { DEFAULT_RULESET, parseRuleset, starterDeck, previewPool as engineLoaners, validateDeck, createMatch,
|
||||
legalActions, applyAction, isOver, result, viewFor, Rng,
|
||||
type Action, type GameCard, type MatchState, type Ruleset } from '../../shared/game/index.ts';
|
||||
import type { EnginePort, Seat } from './engine-port.ts';
|
||||
|
||||
/**
|
||||
* Deterministic pool of loaner (non-NFT) cards for draft modes: seeded shuffles of the
|
||||
* starter pool, one copy per round, never exceeding the ruleset's per-page copy limit.
|
||||
* Deterministic pool of loaner (non-NFT) cards for draft modes: seeded shuffles of the engine's
|
||||
* frozen loaner cards (`previewPool(rules)`, derived with the mode's rules), one copy per round,
|
||||
* never exceeding the ruleset's per-page copy limit. Copies get distinct cardIds.
|
||||
*/
|
||||
export function previewPool(rules: Ruleset, seed: string, size: number): GameCard[] {
|
||||
const rng = Rng.fromSeed(`draft-pool:${seed}`);
|
||||
const loaners = engineLoaners(rules);
|
||||
const pool: GameCard[] = [];
|
||||
for (let copy = 0; pool.length < size && copy < rules.maxCopiesPerPage; copy++) {
|
||||
for (const spec of rng.shuffle(STARTER_POOL)) { if (pool.length >= size) break; pool.push(loanerCard(spec, copy)); }
|
||||
for (const card of rng.shuffle(loaners)) {
|
||||
if (pool.length >= size) break;
|
||||
pool.push({ ...card, cardId: `${card.cardId}:${copy}` });
|
||||
}
|
||||
}
|
||||
return pool;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import express from 'express';
|
||||
import type { AddressInfo } from 'node:net';
|
||||
import { gameRouter } from '../server/game/index.ts';
|
||||
import { previewPool } from '../server/game/engine-binding.ts';
|
||||
import { DEFAULT_RULESET, STARTER_POOL, replay, parseRuleset } from '../shared/game/index.ts';
|
||||
import { DEFAULT_RULESET, replay, parseRuleset, previewPool as engineLoaners } from '../shared/game/index.ts';
|
||||
import { parseMode, resolveRuleset, MODE_SCHEMA_VERSION } from '../shared/game/modes.ts';
|
||||
import { ModeListSchema } from '../shared/game/modes.ts';
|
||||
|
||||
@@ -134,7 +134,8 @@ test('modes api: draft preview pool is deterministic and deck-legal', () => {
|
||||
assert.deepEqual(p1, p2);
|
||||
assert.equal(p1.length, 30);
|
||||
assert.equal(new Set(p1.map(c => c.cardId)).size, 30);
|
||||
assert.equal(previewPool(DEFAULT_RULESET, 'x', 100).length, STARTER_POOL.length * DEFAULT_RULESET.maxCopiesPerPage);
|
||||
assert.equal(previewPool(DEFAULT_RULESET, 'x', 100).length, engineLoaners(DEFAULT_RULESET).length * DEFAULT_RULESET.maxCopiesPerPage);
|
||||
assert.ok(p1.every(c => c.check === 'loaner' && c.source === 'loaner'), 'only engine loaner data');
|
||||
});
|
||||
|
||||
test('modes api: the rule examples in HOSTING.md are valid modes', () => {
|
||||
|
||||
Reference in New Issue
Block a user