import type { CardId } from "../card-games.types.ts"; import type { GinGame, GinLayout, GinMeld, GinMove } from "./gin-rummy.types.ts"; /** * GIN RUMMY: the rules, and nothing else. * * Two players, ten cards each; the rest is the stock, its top card turned up * to start the discard pile. On your turn draw one card — the stock's top or * the discard pile's — then throw one onto the pile (never the one you just * took from it). Melds are three or four of a rank, or three or more in a row * of one suit, ace low. Every card in no meld is deadwood: an ace one, a face * card ten, the rest their number. With ten or fewer points of deadwood you * may knock instead of throwing: the other player lays their own melds, lays * off what fits onto yours, and the difference in deadwood is yours — unless * they have as little or less, which is an undercut and theirs, with 25 more. * Knock with no deadwood at all and it is gin: 25 and all their deadwood, and * nothing laid off. With two cards left in the stock and nobody out, the hand * is drawn. The first to the game's total wins. * * Pure: every function returns a new game and leaves the one given alone. */ /** How many play Gin Rummy: two. * * @example * ```ts * import { GIN_SEATS } from "@johnmorrisdotca/toranpu/gin-rummy"; * console.log(GIN_SEATS); * ``` */ export declare const GIN_SEATS = 2; /** The most deadwood a player may knock with. * * @example * ```ts * import { KNOCK_MOST } from "@johnmorrisdotca/toranpu/gin-rummy"; * console.log(KNOCK_MOST); * ``` */ export declare const KNOCK_MOST = 10; /** The bonus for gin, and for an undercut. * * @example * ```ts * import { GIN_BONUS } from "@johnmorrisdotca/toranpu/gin-rummy"; * console.log(GIN_BONUS); * ``` */ export declare const GIN_BONUS = 25; /** The bonus for an undercut: the defender has no more deadwood than the knocker. * * @example * ```ts * import { UNDERCUT_BONUS } from "@johnmorrisdotca/toranpu/gin-rummy"; * console.log(UNDERCUT_BONUS); * ``` */ export declare const UNDERCUT_BONUS = 25; /** A card's deadwood: an ace one, the numbers their number, a jack, queen or king ten. * * @param card - The physical card or card id to read, draw or play. * @returns A card's deadwood: an ace one, the numbers their number, a jack, queen or king ten. * * @example * ```ts * import { deadwoodValue } from "@johnmorrisdotca/toranpu/gin-rummy"; * * console.log(deadwoodValue("KS")); * ``` */ export declare function deadwoodValue(card: CardId): number; /** What a list of cards counts as deadwood, added up. * * @param cards - The cards in their current order. * @returns What a list of cards counts as deadwood, added up. * * @example * ```ts * import { deadwoodOf } from "@johnmorrisdotca/toranpu/gin-rummy"; * * console.log(deadwoodOf(["AS", "KS"])); * ``` */ export declare function deadwoodOf(cards: readonly CardId[]): number; /** A hand sorted as a player holds it: by suit (spades, hearts, clubs, diamonds, as the colours alternate), ace low. * * @param hand - The player’s held cards, or the hand number for a deal. * @returns A hand sorted as a player holds it: by suit (spades, hearts, clubs, diamonds, as the colours alternate), ace low. * * @example * ```ts * import { sortGin } from "@johnmorrisdotca/toranpu/gin-rummy"; * * console.log(sortGin(["KH", "3H", "AS"])); * ``` */ export declare function sortGin(hand: readonly CardId[]): CardId[]; /** Whether these cards are a meld: three or four of a rank, or three or more in a row in one suit. * * @param cards - The cards in their current order. * @returns Whether these cards are a meld: three or four of a rank, or three or more in a row in one suit. * * @example * ```ts * import { isMeld } from "@johnmorrisdotca/toranpu/gin-rummy"; * * console.log(isMeld(["3H", "4H", "5H"])); * ``` */ export declare function isMeld(cards: readonly CardId[]): boolean; /** Every meld that can be made from these cards: each set of three or four, and each run of three or more. * * @param hand - The player’s held cards, or the hand number for a deal. * @returns Every meld that can be made from these cards: each set of three or four, and each run of three or more. * * @example * ```ts * import { meldsIn } from "@johnmorrisdotca/toranpu/gin-rummy"; * * console.log(meldsIn(["3H", "4H", "5H", "AS"])); * ``` */ export declare function meldsIn(hand: readonly CardId[]): GinMeld[]; /** * The hand laid out to leave the least deadwood: the melds chosen, none * sharing a card, and what is left. Searched exhaustively over the cards as * a bitmask, which for eleven cards at most is quick. * * @param hand - The player’s held cards, or the hand number for a deal. * @returns The hand laid out to leave the least deadwood: the melds chosen, none sharing a card, and what is left. Searched exhaustively over the cards as a bitmask, which for eleven cards at most is quick. * * @example * ```ts * import { bestLayout } from "@johnmorrisdotca/toranpu/gin-rummy"; * * console.log(bestLayout(["3H", "4H", "5H", "AS"])); * ``` */ export declare function bestLayout(hand: readonly CardId[]): GinLayout; /** The deadwood left in a hand at its best. * * @param hand - The player’s held cards, or the hand number for a deal. * @returns The deadwood left in a hand at its best. * * @example * ```ts * import { deadwoodIn } from "@johnmorrisdotca/toranpu/gin-rummy"; * * console.log(deadwoodIn(["3H", "4H", "5H", "AS"])); * ``` */ export declare function deadwoodIn(hand: readonly CardId[]): number; /** A new game of Gin Rummy for these players (one name a seat) at this size, dealt from the seed `dealt`, or null for a table Gin Rummy is not offered for. `computers` says, one a seat, which seats a computer plays; the third argument is unused. * * @param size - The game’s length or size, as defined by its table specification. * @param players - The player names in seat order. * @param _language - An unused legacy language argument retained for compatibility. * @param dealt - The numeric seed used to deal the game. * @param computers - Flags by seat: true where a computer controls that seat. * @returns A new game of Gin Rummy for these players (one name a seat) at this size, dealt from the seed `dealt`, or null for a table Gin Rummy is not offered for. `computers` says, one a seat, which seats a computer plays; the third argument is unused. * * @example * ```ts * import { CARD_GAME_TABLES } from "@johnmorrisdotca/toranpu"; * import { startGin } from "@johnmorrisdotca/toranpu/gin-rummy"; * * const names = Array.from({ length: CARD_GAME_TABLES.ginRummy.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * console.log(startGin(CARD_GAME_TABLES.ginRummy.defaultSize, names, undefined, 42)?.phase); * ``` */ export declare function startGin(size: number, players: readonly string[], _language?: unknown, dealt?: number, computers?: readonly boolean[]): GinGame | null; /** Whether throwing this card, from a hand of eleven, leaves little enough deadwood to knock with. * * @param hand - The player’s held cards, or the hand number for a deal. * @param card - The physical card or card id to read, draw or play. * @returns Whether throwing this card, from a hand of eleven, leaves little enough deadwood to knock with. * * @example * ```ts * import { canKnockWith } from "@johnmorrisdotca/toranpu/gin-rummy"; * * console.log(canKnockWith(["3H", "4H", "5H", "7S", "8S", "9S", "8C", "8D", "8H", "AS", "KD"], "KD")); * ``` */ export declare function canKnockWith(hand: readonly CardId[], card: CardId): boolean; /** Every move the seat to play may make now; none once the game is over. * * @param game - The current native game; applying a move returns a new state. * @returns Every move the seat to play may make now; none once the game is over. * * @example * ```ts * import { CARD_GAME_TABLES, newGame } from "@johnmorrisdotca/toranpu"; * import { ginMoves } from "@johnmorrisdotca/toranpu/gin-rummy"; * * const names = Array.from({ length: CARD_GAME_TABLES.ginRummy.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * let game = newGame("ginRummy", { players: names, seed: 42 })!; * console.log(ginMoves(game)); * ``` */ export declare function ginMoves(game: GinGame): GinMove[]; /** * The defender's side of a knock: their own melds first, then every card left * that fits one of the knocker's melds laid off onto it — a run grown one card * at a time, so a six can follow the five just laid. * * @param defender - The defending player’s hand or melds. * @param knockerMelds - The knocking player’s declared melds. * @returns The defender's side of a knock: their own melds first, then every card left that fits one of the knocker's melds laid off onto it — a run grown one card at a time, so a six can follow the five just laid. * * @example * ```ts * import { layOff } from "@johnmorrisdotca/toranpu/gin-rummy"; * * console.log(layOff(["6H", "AS"], [["3H", "4H", "5H"]])); * ``` */ export declare function layOff(defender: readonly CardId[], knockerMelds: readonly GinMeld[]): { layout: GinLayout; laidOff: CardId[]; melds: GinMeld[]; }; /** The game after that move, with the move added to its record, or null for a move the rules refuse. * * @param game - The current native game; applying a move returns a new state. * @param move - The native move to validate or apply. * @returns The game after that move, with the move added to its record, or null for a move the rules refuse. * * @example * ```ts * import { CARD_GAME_TABLES, newGame, rulesFor } from "@johnmorrisdotca/toranpu"; * import { playGin } from "@johnmorrisdotca/toranpu/gin-rummy"; * * const names = Array.from({ length: CARD_GAME_TABLES.ginRummy.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * let game = newGame("ginRummy", { players: names, seed: 42 })!; * console.log(playGin(game, rulesFor("ginRummy").moves(game)[0]!)?.moves.length); * ``` */ export declare function playGin(game: GinGame, move: GinMove): GinGame | null; /** The first to the game's total wins. * * @param game - The current native game; applying a move returns a new state. * @returns The first to the game's total wins. * * @example * ```ts * import { CARD_GAME_TABLES, newGame } from "@johnmorrisdotca/toranpu"; * import { ginWinners } from "@johnmorrisdotca/toranpu/gin-rummy"; * * const names = Array.from({ length: CARD_GAME_TABLES.ginRummy.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * let game = newGame("ginRummy", { players: names, seed: 42 })!; * console.log(ginWinners(game)); * ``` */ export declare function ginWinners(game: GinGame): number[];