import type { CardGamePlays } from "./games/card-game-rules.ts"; import type { CardGameKind } from "./games/card-games.constants.ts"; import type { CardGameRules } from "./games/card-games.types.ts"; /** * THE FRIENDLY FRONT DOOR: start any game by name, let the computers take * their turns, and play yours. Everything here is a thin layer over each * game's `CardGameRules`, which a caller can always reach for directly. */ /** A game of that kind, in progress. * * @example * ```ts * import { newGame } from "@johnmorrisdotca/toranpu"; * import type { GameOf } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * const value: GameOf<"hearts"> = game; * console.log(value.phase); * ``` */ export type GameOf = CardGamePlays[K]["game"]; /** A move in a game of that kind. * * @example * ```ts * import { newGame, rulesFor } from "@johnmorrisdotca/toranpu"; * import type { MoveOf } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * const value: MoveOf<"hearts"> = rulesFor("hearts").moves(game)[0]!; * console.log(value); * ``` */ export type MoveOf = CardGamePlays[K]["move"]; /** How to seat a new game. Everything but `players` has a sensible default. * * @example * ```ts * import type { NewGameOptions } from "@johnmorrisdotca/toranpu"; * * const value: NewGameOptions = { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 }; * console.log(value.seed); * ``` */ export type NewGameOptions = { /** One name a seat. The number of names is the number of players. */ players: readonly string[]; /** How long the game lasts, in its own terms (`CARD_GAME_TABLES`); the usual length when left out. */ size?: number; /** The seed every deal is shuffled from; a random one when left out. The same seed deals the same cards. */ seed?: number; /** One a seat: true where a computer plays. Seats not given are people's. */ computers?: readonly boolean[]; }; /** A game's rules by its kind, with its own game and move types. * * @param kind - The named card game or sound kind. * @returns A game's rules by its kind, with its own game and move types. * * @example * ```ts * import { newGame, rulesFor } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * console.log(rulesFor("hearts").moves(game).length); * ``` */ export declare function rulesFor(kind: K): CardGameRules, MoveOf>; /** A seed for a game nobody asked for by number: a whole number from 1 to 2³¹ − 1. * * @returns A seed for a game nobody asked for by number: a whole number from 1 to 2³¹ − 1. * * @example * ```ts * import { randomSeed } from "@johnmorrisdotca/toranpu"; * * console.log(Number.isInteger(randomSeed())); * ``` */ export declare function randomSeed(): number; /** * A new game of that kind, or null when the game is not offered for that * table (too many players, or a size it does not play to). * * ```ts * const game = newGame("hearts", { players: ["You", "Ann", "Ben", "Cy"], computers: [false, true, true, true] }); * ``` * * @param kind - The named card game or sound kind. * @param options - Options for this call; omitted fields retain their documented defaults. * @returns A new game of that kind, or null when the game is not offered for that table (too many players, or a size it does not play to). ```ts const game = newGame("hearts", { players: ["You", "Ann", "Ben", "Cy"], computers: [false, true, true, true] }); ``` * * @example * ```ts * import { newGame } from "@johnmorrisdotca/toranpu"; * * console.log(newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })?.hands.map((hand) => hand.length)); * ``` */ export declare function newGame(kind: K, options: NewGameOptions): GameOf | null; /** * Every computer move due, played in turn until a person is to move or the * game is over. Returns the game and the moves the computers made, in order, * so a table can show them one at a time. * * @param kind - The named card game or sound kind. * @param game - The current native game; applying a move returns a new state. * @returns Every computer move due, played in turn until a person is to move or the game is over. Returns the game and the moves the computers made, in order, so a table can show them one at a time. * * @example * ```ts * import { newGame, playComputers } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * console.log(playComputers("hearts", game).moves.length); * ``` */ export declare function playComputers(kind: K, game: GameOf): { game: GameOf; moves: MoveOf[]; };