Files
wikideck/server/game/engine-port.ts
T
claudeandClaude Opus 5.5 7fef46e38e Peer-hosted game modes: mode schema, node API, host credit, three example modes
Modes are inert JSON (shared/game/modes.ts): rule overrides on the engine's
DEFAULT_RULESET, re-validated by parseRuleset; card-mapping presets from a
fixed list; deck policy and limits. server/game/ publishes this node's modes,
discovers configured peers' modes as data (byte cap, timeout, pinned origin),
and hosts lobbies, snake drafts and matches with the deterministic engine.
Finished matches are off-chain JSONL records with seed, decks and action log
(replayable). Per-mode and host leaderboards. Docs in docs/game/HOSTING.md,
including security notes and an on-chain host-reward proposal.

One mount line in server/testnet/http.ts; no consensus changes.

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

36 lines
1.7 KiB
TypeScript

/**
* The slice of the engine API (docs/game/ENGINE_API.md) the mode host uses.
* The host is engine-agnostic behind this port: the real binding lives in engine-binding.ts,
* tests use a tiny stub. Card and state values are opaque to the host.
*/
export type Seat = 0 | 1;
export type MatchOutcome = { winner: Seat | null; reason?: string };
export interface EnginePort<Rules = unknown, Card = unknown, State = unknown, Action = unknown> {
readonly defaultRuleset: Rules;
/** Strict engine-side validation of a merged ruleset. Throws on anything invalid. */
parseRuleset(value: unknown): Rules;
deckSize(rules: Rules): number;
starterDeck(rules: Rules, seed: string): Card[];
/** Deterministic pool of non-NFT preview cards, for draft modes. */
previewPool(rules: Rules, seed: string, size: number): Card[];
/** Throws if the deck is not legal under the rules. */
validateDeck(rules: Rules, cards: Card[]): void;
cardPower(card: Card): number;
withPower(card: Card, power: number): Card;
/** Wikipedia page id of a card, if it has one (for live/trending mappings). */
cardPageId(card: Card): number | null;
/** Public, JSON-safe summary shown in a draft pool. */
cardSummary(card: Card): unknown;
createMatch(rules: Rules, decks: [Card[], Card[]], seed: string): State;
legalActions(state: State, seat: Seat): Action[];
applyAction(state: State, seat: Seat, action: Action): State;
/** Optional engine-level concede, so a resignation is part of the replayable action log. */
concedeAction?(seat: Seat): Action;
isOver(state: State): boolean;
result(state: State): MatchOutcome;
/** What one seat may see (hides the opponent's hand and staged plays). */
viewFor(state: State, seat: Seat): unknown;
}