Files
wikideck/tests/game/build.ts
T
claudeandClaude Opus 5.5 0f2363199b game: v1 keywords and Portals (DESIGN cf2fceb §10), card derivation (§1, §10.1), unit/property/golden tests
- keywords.ts: viral, rising, local, encyclopedic, nostalgic, translated (v1);
  edition, obscure, wildcard (off by default); §10.3 Portals with capacity,
  allOnTopic and topicBonus hooks; isOnTopic, keywordEnabled, hiddenFrom
- ruleset.ts: §10.3 default Topic pool, keyword/portal param defaults
- starter.ts: placeholder loaners carry their faction keyword (§10.1)
- derive.ts: percentile -> fame -> cost -> power, home, trend, keyword choice
- tests: game-keywords, game-derive, game-property, game-golden (§12, todo
  until core implements the frozen §3-§7 rules)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 23:12:38 -05:00

55 lines
2.7 KiB
TypeScript

/** Hand-built boards for keyword and Portal unit tests (engine-b). */
import {
DEFAULT_RULESET, KEYWORDS, PORTALS, Rng, cardPower, createMatch, lanePower, starterDeck,
type CardInPlay, type EffectContext, type GameCard, type MatchState, type PlayerId, type Stat, type TopicDef,
} from '../../shared/game/index.ts';
export const topic = (stat: Stat, portal: string | null = null, id = portal ?? `plain-${stat}`): TopicDef =>
({ id, name: id, stat, portal });
/** Empty board, turn 1; lanes are depth / attention / reach plain Topics unless given. */
export function board(topics: TopicDef[] = [topic('depth'), topic('attention'), topic('reach')], revealed = true): MatchState {
const state = createMatch(DEFAULT_RULESET, [starterDeck('a'), starterDeck('b')], 'keyword-test');
state.lanes = topics.map(t => ({ topic: t, revealed, cards: [[], []] as [CardInPlay[], CardInPlay[]] }));
return state;
}
let serial = 0;
export function card(overrides: Partial<GameCard> = {}): GameCard {
serial++;
return { cardId: `t${serial}`, pageId: 1000 + serial, title: `Card ${serial}`, faction: 'Culture', rarity: 'Common',
cost: 2, power: 2, home: 'attention', trend: 0, keyword: null, source: 'loaner', ...overrides };
}
/** Put a card in a lane with no effects (mutates). */
export function place(state: MatchState, owner: PlayerId, lane: number, c: GameCard, turn = state.turn): CardInPlay {
const inPlay: CardInPlay = { card: c, owner, lane, turn, bonus: 0 };
state.lanes[lane].cards[owner].push(inPlay);
return inPlay;
}
export function ctxFor(state: MatchState, params: Record<string, number> | undefined, lane: number): EffectContext {
return { state, rng: new Rng(1), params: params ?? {}, lane, log: () => {} };
}
/** Place a card and fire its keyword's onReveal, as the engine does at reveal (mutates). */
export function reveal(state: MatchState, owner: PlayerId, lane: number, c: GameCard): CardInPlay {
const inPlay = place(state, owner, lane, c);
const keyword = c.keyword ? KEYWORDS[c.keyword] : undefined;
keyword?.onReveal?.(ctxFor(state, state.ruleset.keywordParams[keyword.id], lane), inPlay);
return inPlay;
}
export function endOfTurn(state: MatchState, self: CardInPlay): void {
const keyword = self.card.keyword ? KEYWORDS[self.card.keyword] : undefined;
keyword?.endOfTurn?.(ctxFor(state, state.ruleset.keywordParams[keyword.id], self.lane), self);
}
export function topicBonus(state: MatchState, lane: number, scoring: boolean): [number, number] {
const id = state.lanes[lane].topic.portal;
const portal = id ? PORTALS[id] : undefined;
return portal?.topicBonus?.(ctxFor(state, state.ruleset.portalParams[id!], lane), scoring) ?? [0, 0];
}
export { cardPower, lanePower };