import type { CardId } from "../card-games.types.ts"; import type { CribbageCount, CribbageGame, CribbageMove } from "./cribbage.types.ts"; /** * CRIBBAGE: the rules, and nothing else. * * Two players, six cards each. Each lays two away to the crib, which is the * dealer's, and the top of the pack is cut as the starter (a jack cut scores * the dealer two, "his heels"). Then the pegging: from the dealer's other * hand, the players lay their cards in turn, calling the running total, which * may not pass thirty-one. Fifteen and thirty-one score two; a pair two, three * alike six, four alike twelve; a run of three or more, in any order, a point * a card. A player who cannot play says go, and the other plays on while they * can; whoever played last scores one for the go (or the two for thirty-one), * and the count starts again. The last card of all scores one. Then the show: * each hand of four, with the starter, scores two for every fifteen, two a * pair, a point a card of every run, four for a flush in the hand (five with * the starter; the crib only for all five) and one for the jack of the * starter's suit ("his nobs"). The other player shows first, then the dealer, * then the dealer's crib. The first to the game's total wins, the moment they * reach it. * * Pure: every function returns a new game and leaves the one given alone. */ /** How many play Cribbage here: two. * * @example * ```ts * import { CRIBBAGE_SEATS } from "@johnmorrisdotca/toranpu/cribbage"; * console.log(CRIBBAGE_SEATS); * ``` */ export declare const CRIBBAGE_SEATS = 2; /** A card's worth in the count: ace one, court cards ten. * * @param card - The physical card or card id to read, draw or play. * @returns A card's worth in the count: ace one, court cards ten. * * @example * ```ts * import { cardValue } from "@johnmorrisdotca/toranpu/cribbage"; * * console.log(cardValue("JS")); * ``` */ export declare function cardValue(card: CardId): number; /** The seat that deals this hand: the first seat, then the other, turn about. * * @param deal - The deal number or dealing specification. * @returns The seat that deals this hand: the first seat, then the other, turn about. * * @example * ```ts * import { dealerOf } from "@johnmorrisdotca/toranpu/cribbage"; * * console.log(dealerOf(0)); * ``` */ export declare function dealerOf(deal: number): number; /** The seat that is not this one. * * @param seat - The zero-based player seat. * @returns The seat that is not this one. * * @example * ```ts * import { otherOf } from "@johnmorrisdotca/toranpu/cribbage"; * * console.log(otherOf(0)); * ``` */ export declare function otherOf(seat: number): number; /** A hand sorted as a player holds it: ace low to king, by rank then suit. * * @param hand - The player’s held cards, or the hand number for a deal. * @returns A hand sorted as a player holds it: ace low to king, by rank then suit. * * @example * ```ts * import { sortCribbage } from "@johnmorrisdotca/toranpu/cribbage"; * * console.log(sortCribbage(["JS", "5H", "AC"])); * ``` */ export declare function sortCribbage(hand: readonly CardId[]): CardId[]; /** A new game of Cribbage for these players (one name a seat) at this size, dealt from the seed `dealt`, or null for a table Cribbage 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 Cribbage for these players (one name a seat) at this size, dealt from the seed `dealt`, or null for a table Cribbage 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 { startCribbage } from "@johnmorrisdotca/toranpu/cribbage"; * * const names = Array.from({ length: CARD_GAME_TABLES.cribbage.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * console.log(startCribbage(CARD_GAME_TABLES.cribbage.defaultSize, names, undefined, 42)?.phase); * ``` */ export declare function startCribbage(size: number, players: readonly string[], _language?: unknown, dealt?: number, computers?: readonly boolean[]): CribbageGame | null; /** The cards a seat may play on the count now: any that keeps it to thirty-one. * * @param hand - The player’s held cards, or the hand number for a deal. * @param count - The requested number of cards, sounds or layout positions. * @returns The cards a seat may play on the count now: any that keeps it to thirty-one. * * @example * ```ts * import { cribbagePlayable } from "@johnmorrisdotca/toranpu/cribbage"; * * console.log(cribbagePlayable(["AS", "5H", "KS"], 25)); * ``` */ export declare function cribbagePlayable(hand: readonly CardId[], count: number): CardId[]; /** Every way to lay two of a hand away. * * @param hand - The player’s held cards, or the hand number for a deal. * @returns Every way to lay two of a hand away. * * @example * ```ts * import { cribPairs } from "@johnmorrisdotca/toranpu/cribbage"; * * console.log(cribPairs(["AS", "2H", "3D", "4C", "5S", "6H"]).slice(0, 3)); * ``` */ export declare function cribPairs(hand: readonly CardId[]): [CardId, CardId][]; /** 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 { cribbageMoves } from "@johnmorrisdotca/toranpu/cribbage"; * * const names = Array.from({ length: CARD_GAME_TABLES.cribbage.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * let game = newGame("cribbage", { players: names, seed: 42 })!; * console.log(cribbageMoves(game)); * ``` */ export declare function cribbageMoves(game: CribbageGame): CribbageMove[]; /** What laying the last card of `cards` scores, the count now `count`: fifteen, thirty-one, pairs and runs. * * @param cards - The cards in their current order. * @param count - The requested number of cards, sounds or layout positions. * @returns What laying the last card of `cards` scores, the count now `count`: fifteen, thirty-one, pairs and runs. * * @example * ```ts * import { pegPoints } from "@johnmorrisdotca/toranpu/cribbage"; * * console.log(pegPoints(["5H", "5D", "5C"], 15)); * ``` */ export declare function pegPoints(cards: readonly CardId[], count: number): { points: number; why: string[]; }; /** What four cards and the starter are worth in the show. A crib's flush counts only when all five are one suit. * * @param four - The four cards retained for cribbage scoring. * @param starter - The turned-up starter card. * @param crib - Whether the scored hand is the crib. * @returns What four cards and the starter are worth in the show. A crib's flush counts only when all five are one suit. * * @example * ```ts * import { showCount } from "@johnmorrisdotca/toranpu/cribbage"; * * console.log(showCount(["5H", "5D", "5C", "JS"], "5S")); * ``` */ export declare function showCount(four: readonly CardId[], starter: CardId, crib?: boolean): CribbageCount; /** 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 { playCribbage } from "@johnmorrisdotca/toranpu/cribbage"; * * const names = Array.from({ length: CARD_GAME_TABLES.cribbage.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * let game = newGame("cribbage", { players: names, seed: 42 })!; * console.log(playCribbage(game, rulesFor("cribbage").moves(game)[0]!)?.moves.length); * ``` */ export declare function playCribbage(game: CribbageGame, move: CribbageMove): CribbageGame | null; /** The first to the total. * * @param game - The current native game; applying a move returns a new state. * @returns The first to the total. * * @example * ```ts * import { CARD_GAME_TABLES, newGame } from "@johnmorrisdotca/toranpu"; * import { cribbageWinners } from "@johnmorrisdotca/toranpu/cribbage"; * * const names = Array.from({ length: CARD_GAME_TABLES.cribbage.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * let game = newGame("cribbage", { players: names, seed: 42 })!; * console.log(cribbageWinners(game)); * ``` */ export declare function cribbageWinners(game: CribbageGame): number[];