forked from WikiDeck/wikideck
Refs #55. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
36 lines
2.1 KiB
TypeScript
36 lines
2.1 KiB
TypeScript
/**
|
|
* WikiDeck Duel public API. Spec: docs/game/DUEL_API.md.
|
|
* Contracts PR: types and ruleset only. engine.ts (createDuel, legalActions,
|
|
* applyAction, viewFor, logFor, replay, ...) lands in the engine alpha PR and
|
|
* implements DuelEngineApi below; build against that interface until then.
|
|
*/
|
|
export * from './types.ts';
|
|
export * from './ruleset.ts';
|
|
|
|
import type { DuelAction, DuelCard, DuelResult, DuelRuleset, DuelState, LogEvent, PlayerView, Seat } from './types.ts';
|
|
|
|
/** The engine's function surface (implemented by shared/duel/engine.ts). All pure; inputs are never mutated. */
|
|
export interface DuelEngineApi {
|
|
/** Throws if the deck is illegal: size ≠ deckSize, duplicate cardId, > maxCopiesPerPage of one pageId, bad stats, > maxKeywords. */
|
|
validateDeck(rules: DuelRuleset, cards: DuelCard[]): void;
|
|
/** Shuffle both decks from `seed`, deal opening hands, phase 'mulligan'. */
|
|
createDuel(rules: DuelRuleset, decks: [DuelCard[], DuelCard[]], seed: string): DuelState;
|
|
/** Atomic legal actions for `seat`; [] if `seat` is not the one to act (concede is always accepted by applyAction but not listed). */
|
|
legalActions(state: DuelState, seat: Seat): DuelAction[];
|
|
/** Returns a new state. Throws on an illegal action. */
|
|
applyAction(state: DuelState, seat: Seat, action: DuelAction): DuelState;
|
|
/** Seat that must act now, or null when over. Mulligan: the lowest seat not yet ready. */
|
|
toAct(state: DuelState): Seat | null;
|
|
isOver(state: DuelState): boolean;
|
|
result(state: DuelState): DuelResult | null;
|
|
viewFor(state: DuelState, seat: Seat): PlayerView;
|
|
/** Per-seat log: the opponent's draws (and other hidden-zone cards) are masked. */
|
|
logFor(state: DuelState, seat: Seat): LogEvent[];
|
|
/** Deterministic: same inputs → identical state (and log). */
|
|
replay(rules: DuelRuleset, decks: [DuelCard[], DuelCard[]], seed: string, actions: { seat: Seat; action: DuelAction }[]): DuelState;
|
|
serialize(state: DuelState): string;
|
|
deserialize(text: string): DuelState;
|
|
/** Current power/toughness of a permanent after counters, buffs, statics and Connected. */
|
|
statsOf(state: DuelState, uid: string): { power: number; toughness: number };
|
|
}
|