import type { CardGameKind } from "./games/card-games.constants.ts"; import type { GameOf, MoveOf } from "./play.ts"; import { type Language } from "./strings.ts"; /** * A GAME WRITTEN OUT AND READ BACK, whichever of the ten it is: as JSON with * a format number, as the short code each game's own `encode` writes, as a * record in words for a person, and as CSV for a spreadsheet. * * What is written is never a hand: it is the table (the game, how long it * lasts, the names, which seats a computer plays), the seed and every move. * What is read is never trusted: the game is started from its table and seed * and every move is played through the rules again, so the answer is exactly * the game those moves make, or nothing. */ /** The shape of the JSON this package writes. It goes up only when a reader of the old shape would be wrong about the new one. * * @example * ```ts * import { SAVE_FORMAT } from "@johnmorrisdotca/toranpu"; * console.log(SAVE_FORMAT); * ``` */ export declare const SAVE_FORMAT = 1; /** A game as `toJSON` writes it. * * @example * ```ts * import { newGame, savedGame } from "@johnmorrisdotca/toranpu"; * import type { SavedGame } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * const value: SavedGame<"hearts"> = savedGame("hearts", game); * console.log(value.seed); * ``` */ export type SavedGame = { /** The shape of this object: `SAVE_FORMAT`. */ format: typeof SAVE_FORMAT; /** What wrote it, such as `"toranpu 1.2.0"`. For people; nothing reads it back. */ generator: string; /** Which game: `"hearts"`, `"ginRummy"`… */ game: K; /** How long the game lasts, in its own terms (`CARD_GAME_TABLES`). */ size: number; /** One name a seat. */ players: string[]; /** One a seat: true where a computer plays. */ computers: boolean[]; /** The seed every deal is shuffled from. */ seed: number; /** Every move so far, in order. */ moves: MoveOf[]; }; /** A game read back: which game it is, and the game itself. * * @example * ```ts * import { fromJSON, newGame, toJSON } from "@johnmorrisdotca/toranpu"; * import type { ReadGame } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * const value: ReadGame = fromJSON(toJSON("hearts", game))!; * console.log(value.kind); * ``` */ export type ReadGame = { [K in CardGameKind]: { kind: K; game: GameOf; }; }[CardGameKind]; /** One move of a record: which seat made it, and the move. * * @example * ```ts * import { newGame, rulesFor } from "@johnmorrisdotca/toranpu"; * import type { RecordedMove } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * const value: RecordedMove<"hearts"> = { seat: 0, move: rulesFor("hearts").moves(game)[0]! }; * console.log(value.seat); * ``` */ export type RecordedMove = { seat: number; move: MoveOf; }; /** A game as the object `toJSON` writes: its table, its seed and its moves. * * @param kind - The named card game or sound kind. * @param game - The current native game; applying a move returns a new state. * @returns A game as the object `toJSON` writes: its table, its seed and its moves. * * @example * ```ts * import { newGame, savedGame } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * console.log(savedGame("hearts", game)); * ``` */ export declare function savedGame(kind: K, game: GameOf): SavedGame; /** A game as JSON, two spaces deep, with the format's number first. `fromJSON` reads it back. * * @param kind - The named card game or sound kind. * @param game - The current native game; applying a move returns a new state. * @returns A game as JSON, two spaces deep, with the format's number first. `fromJSON` reads it back. * * @example * ```ts * import { newGame, toJSON } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * console.log(toJSON("hearts", game)); * ``` */ export declare function toJSON(kind: K, game: GameOf): string; /** A game as its code: the one line its own rules' `encode` writes. Shorter than the JSON, and what Itsutsu keeps. * * @param kind - The named card game or sound kind. * @param game - The current native game; applying a move returns a new state. * @returns A game as its code: the one line its own rules' `encode` writes. Shorter than the JSON, and what Itsutsu keeps. * * @example * ```ts * import { newGame, toCode } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * console.log(toCode("hearts", game)); * ``` */ export declare function toCode(kind: K, game: GameOf): string; /** * A game from text that `toJSON` or `toCode` wrote, whichever game it is. * Nothing in it is trusted: every move is played through the rules again, and * a move the rules refuse means the text is not a game. Null for text that is * not JSON, names no game, is of a later format than this version reads, or * cannot be played out. * * @param text - The notation, encoded state or saved text to read. * @returns A game from text that `toJSON` or `toCode` wrote, whichever game it is. Nothing in it is trusted: every move is played through the rules again, and a move the rules refuse means the text is not a game. null for text that is not JSON, names no game, is of a later format than this version reads, or cannot be played out. * * @example * ```ts * import { fromJSON, newGame, toJSON } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * console.log(fromJSON(toJSON("hearts", game))?.kind); * ``` */ export declare function fromJSON(text: string): ReadGame | null; /** A game from its code or its JSON: the same as `fromJSON`, under the name that pairs with `toCode`. * * @param text - The notation, encoded state or saved text to read. * @returns The reconstructed game, or null when the code or JSON does not represent a supported legal game. * * @example * ```ts * import { fromCode, newGame, toCode } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * console.log(fromCode(toCode("hearts", game))?.kind); * ``` */ export declare const fromCode: typeof fromJSON; /** * Every move of a game with the seat that made it, in order, found by playing * the game through again from its seed. Null if the moves do not play out, * which a game the rules made never does. * * @param kind - The named card game or sound kind. * @param game - The current native game; applying a move returns a new state. * @returns Every move of a game with the seat that made it, in order, found by playing the game through again from its seed. null if the moves do not play out, which a game the rules made never does. * * @example * ```ts * import { newGame, recordOf } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * console.log(recordOf("hearts", game)); * ``` */ export declare function recordOf(kind: K, game: GameOf): RecordedMove[] | null; /** * A game as a record a person can read: a heading, a numbered line a move * with who made it, and how it stands. In English unless said. * * It names every card, the ones passed face down too. It is a record for * afterwards, not something to show a player while the game is on. * * @param kind - The named card game or sound kind. * @param game - The current native game; applying a move returns a new state. * @param language - English or Japanese for the displayed words. * @returns A game as a record a person can read: a heading, a numbered line a move with who made it, and how it stands. In English unless said. It names every card, the ones passed face down too. It is a record for afterwards, not something to show a player while the game is on. * * @example * ```ts * import { newGame, toText } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * console.log(toText("hearts", game)); * ``` */ export declare function toText(kind: K, game: GameOf, language?: Language): string; /** The columns of the CSV, in order. * * @example * ```ts * import { CSV_COLUMNS } from "@johnmorrisdotca/toranpu"; * console.log(CSV_COLUMNS); * ``` */ export declare const CSV_COLUMNS: readonly ["move", "seat", "player", "action", "cards", "detail", "text"]; /** * A game's moves as CSV for a spreadsheet: a header, then a row a move, with * its number from 1, the seat from 1 and its player, the kind of move * (`play`, `bid`, `pass`…), the cards it names as two-letter ids with spaces * between, the move itself as JSON, and the move in English. Lines end CRLF, * as RFC 4180 has it. It is for reading, and is not read back. * * @param kind - The named card game or sound kind. * @param game - The current native game; applying a move returns a new state. * @returns A game's moves as CSV for a spreadsheet: a header, then a row a move, with its number from 1, the seat from 1 and its player, the kind of move (`play`, `bid`, `pass`…), the cards it names as two-letter ids with spaces between, the move itself as JSON, and the move in English. Lines end CRLF, as RFC 4180 has it. It is for reading, and is not read back. * * @example * ```ts * import { newGame, toCSV } from "@johnmorrisdotca/toranpu"; * * const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!; * console.log(toCSV("hearts", game)); * ``` */ export declare function toCSV(kind: K, game: GameOf): string;