import type { Card, CardCode, Rank, Suit, SuitColour } from "./cards.types.ts"; /** * THE DECK, AND WHAT ANY CARD GAME DOES WITH IT BEFORE ITS OWN RULES BEGIN: * make one, shuffle it from a seed, deal it out, and write it down. * * Pure: every function returns new arrays and leaves what it was given alone, * so a game can keep its deck and replay a deal exactly. The shuffle is * seeded (`random.ts`), so a seed kept with a game's moves re-deals the same * cards in every browser, and reloading a page can never deal again. */ /** A fresh deck in the order a new pack is sorted: spades ace to king, then hearts, diamonds, clubs. * * @returns A fresh deck in the order a new pack is sorted: spades ace to king, then hearts, diamonds, clubs. * * @example * ```ts * import { freshDeck } from "@johnmorrisdotca/toranpu/deck"; * * console.log(freshDeck().slice(0, 4)); * ``` */ export declare function freshDeck(): Card[]; /** A deck shuffled from a seed: the same seed, the same order, in every browser and every test. * * @param seed - The numeric seed that reproduces the same shuffle or deal. * @returns A deck shuffled from a seed: the same seed, the same order, in every browser and every test. * * @example * ```ts * import { shuffledDeck } from "@johnmorrisdotca/toranpu/deck"; * * console.log(shuffledDeck(42).slice(0, 7)); * ``` */ export declare function shuffledDeck(seed: number): Card[]; /** A card's colour: red for hearts and diamonds, black for spades and clubs. * * @param card - The physical card or card id to read, draw or play. * @returns A card's colour: red for hearts and diamonds, black for spades and clubs. * * @example * ```ts * import { colourOf } from "@johnmorrisdotca/toranpu/deck"; * * const card = { suit: "spades", rank: 1 } as const; * console.log(colourOf(card)); * ``` */ export declare function colourOf(card: Card): SuitColour; /** Whether a card is a heart or a diamond. * * @param card - The physical card or card id to read, draw or play. * @returns Whether a card is a heart or a diamond. * * @example * ```ts * import { isRed } from "@johnmorrisdotca/toranpu/deck"; * * const card = { suit: "spades", rank: 1 } as const; * console.log(isRed(card)); * ``` */ export declare function isRed(card: Card): boolean; /** Whether two card objects are the same card. * * @param a - The first card or value to compare. * @param b - The second card or value to compare. * @returns Whether two card objects are the same card. * * @example * ```ts * import { cardFromId, sameCard } from "@johnmorrisdotca/toranpu/deck"; * * const card = { suit: "spades", rank: 1 } as const; * console.log(sameCard(card, cardFromId("AS")!)); * ``` */ export declare function sameCard(a: Card, b: Card): boolean; /** The card's place in a fresh deck, 0 to 51. * * @param card - The physical card or card id to read, draw or play. * @returns The card's place in a fresh deck, 0 to 51. * * @example * ```ts * import { cardIndex } from "@johnmorrisdotca/toranpu/deck"; * * const card = { suit: "spades", rank: 1 } as const; * console.log(cardIndex(card)); * ``` */ export declare function cardIndex(card: Card): number; /** The card at a place in a fresh deck, 0 to 51. Throws for a place that is not one. * * @param index - The zero-based deck or seat position. * @returns The card at a place in a fresh deck, 0 to 51. Throws for a place that is not one. * * @example * ```ts * import { cardAt } from "@johnmorrisdotca/toranpu/deck"; * * console.log(cardAt(0)); * ``` */ export declare function cardAt(index: number): Card; /** One character for a card (`CARD_ALPHABET`). * * @param card - The physical card or card id to read, draw or play. * @returns One character for a card (`CARD_ALPHABET`). * * @example * ```ts * import { cardCode } from "@johnmorrisdotca/toranpu/deck"; * * const card = { suit: "spades", rank: 1 } as const; * console.log(cardCode(card)); * ``` */ export declare function cardCode(card: Card): CardCode; /** The card a character names, or null for one that names none — a kept string is read, never trusted. * * @param code - The encoded card or game state. * @returns The card a character names, or null for one that names none — a kept string is read, never trusted. * * @example * ```ts * import { cardCode, cardFromCode } from "@johnmorrisdotca/toranpu/deck"; * * const card = { suit: "spades", rank: 1 } as const; * console.log(cardFromCode(cardCode(card))); * ``` */ export declare function cardFromCode(code: string): Card | null; /** * "QS", "TH", "AC": the two-character id card players write, rank then suit, * with `T` for the ten. For a game that keys its state by a readable id; a * kept deal is written with `cardCode`, one character a card. * * @param card - The physical card or card id to read, draw or play. * @returns "QS", "TH", "AC": the two-character id card players write, rank then suit, with `T` for the ten. For a game that keys its state by a readable id; a kept deal is written with `cardCode`, one character a card. * * @example * ```ts * import { cardId } from "@johnmorrisdotca/toranpu/deck"; * * const card = { suit: "spades", rank: 1 } as const; * console.log(cardId(card)); * ``` */ export declare function cardId(card: Card): string; /** The card a two-character id names, or null. Lower case is read too. * * @param id - The physical card id to read. * @returns The card a two-character id names, or null. Lower case is read too. * * @example * ```ts * import { cardFromId } from "@johnmorrisdotca/toranpu/deck"; * * console.log(cardFromId("AS")); * ``` */ export declare function cardFromId(id: string): Card | null; /** A run of cards as a string, one character each. * * @param cards - The cards in their current order. * @returns A run of cards as a string, one character each. * * @example * ```ts * import { freshDeck, writeCards } from "@johnmorrisdotca/toranpu/deck"; * * console.log(writeCards(freshDeck().slice(0, 5))); * ``` */ export declare function writeCards(cards: readonly Card[]): string; /** A string of card characters read back, or null if any character names no card. * * @param text - The notation, encoded state or saved text to read. * @returns A string of card characters read back, or null if any character names no card. * * @example * ```ts * import { readCards } from "@johnmorrisdotca/toranpu/deck"; * * console.log(readCards("AS KH TD")); * ``` */ export declare function readCards(text: string): Card[] | null; /** Whether a string is a whole deck: fifty-two cards, each exactly once. * * @param text - The notation, encoded state or saved text to read. * @returns Whether a string is a whole deck: fifty-two cards, each exactly once. * * @example * ```ts * import { freshDeck, isWholeDeck, writeCards } from "@johnmorrisdotca/toranpu/deck"; * * console.log(isWholeDeck(writeCards(freshDeck()))); * ``` */ export declare function isWholeDeck(text: string): boolean; /** "Q♥": the short name a corner shows. * * @param card - The physical card or card id to read, draw or play. * @returns "Q♥": the short name a corner shows. * * @example * ```ts * import { cardShortName } from "@johnmorrisdotca/toranpu/deck"; * * const card = { suit: "spades", rank: 1 } as const; * console.log(cardShortName(card)); * ``` */ export declare function cardShortName(card: Card): string; /** "queen of hearts": the name a screen reader says. * * @param card - The physical card or card id to read, draw or play. * @returns "queen of hearts": the name a screen reader says. * * @example * ```ts * import { cardName } from "@johnmorrisdotca/toranpu/deck"; * * const card = { suit: "spades", rank: 1 } as const; * console.log(cardName(card)); * ``` */ export declare function cardName(card: Card): string; /** * Deal one card at a time round the table, as a dealer does: `hands` hands of * `each` cards, dealt from the top (the start of the array), and what is left. * * @param deck - The deck in its current order; the input is left unchanged. * @param hands - The hands by seat, or the number of hands where numeric. * @param each - The number of cards dealt to each hand. * @returns Deal one card at a time round the table, as a dealer does: `hands` hands of `each` cards, dealt from the top (the start of the array), and what is left. * * @example * ```ts * import { dealRound, shuffledDeck } from "@johnmorrisdotca/toranpu/deck"; * * console.log(dealRound(shuffledDeck(42), 4, 5).hands.map((hand) => hand.length)); * ``` */ export declare function dealRound(deck: readonly Card[], hands: number, each: number): { hands: Card[][]; rest: Card[]; }; /** Deal the whole deck round the table: the first hands get one more where it does not divide evenly. * * @param deck - The deck in its current order; the input is left unchanged. * @param hands - The hands by seat, or the number of hands where numeric. * @returns Deal the whole deck round the table: the first hands get one more where it does not divide evenly. * * @example * ```ts * import { dealAll, shuffledDeck } from "@johnmorrisdotca/toranpu/deck"; * * console.log(dealAll(shuffledDeck(42), 4).map((hand) => hand.length)); * ``` */ export declare function dealAll(deck: readonly Card[], hands: number): Card[][]; /** Take `count` from the top: what was taken, and what is left. * * @param deck - The deck in its current order; the input is left unchanged. * @param count - The requested number of cards, sounds or layout positions. * @returns Take `count` from the top: what was taken, and what is left. * * @example * ```ts * import { shuffledDeck, take } from "@johnmorrisdotca/toranpu/deck"; * * console.log(take(shuffledDeck(42), 5).taken); * ``` */ export declare function take(deck: readonly Card[], count: number): { taken: Card[]; rest: Card[]; }; /** A hand sorted by suit (the fresh-deck order) and then by rank: how a player arranges one. * * @param cards - The cards in their current order. * @param rankOrder - A function that gives each rank its sorting value. * @param suitOrder - The suit order for sorting a hand. * @returns A hand sorted by suit (the fresh-deck order) and then by rank: how a player arranges one. * * @example * ```ts * import { shuffledDeck, sortedHand } from "@johnmorrisdotca/toranpu/deck"; * * console.log(sortedHand(shuffledDeck(42).slice(0, 7))); * ``` */ export declare function sortedHand(cards: readonly Card[], rankOrder?: (rank: Rank) => number, suitOrder?: readonly Suit[]): Card[];