import type { CardId } from "../card-games.types.ts"; import type { GinGame, GinMove } from "./gin-rummy.types.ts"; /** * A COMPUTER AT THE GIN RUMMY TABLE: it takes the discard only when the card * goes straight into a meld, throws the card that leaves the least deadwood * (the highest of those that tie, and never one the other player has shown * they are collecting when another will do), and knocks the moment it can. * * It reads a view of the game (`ginView`): its own hand, the discard pile and * what the other player took from it — and nothing of their hand or the stock. * * @example * ```ts * import { CARD_GAME_TABLES, newGame } from "@johnmorrisdotca/toranpu"; * import type { GinView } from "@johnmorrisdotca/toranpu/gin-rummy"; * import { ginView } from "@johnmorrisdotca/toranpu/gin-rummy"; * * const names = Array.from({ length: CARD_GAME_TABLES.ginRummy.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * const game = newGame("ginRummy", { players: names, seed: 42 })!; * const value: GinView = ginView(game); * console.log(value.hand.length); * ``` */ export type GinView = { hand: readonly CardId[]; phase: GinGame["phase"]; /** The card on top of the discard pile, if any. */ top: CardId | null; /** The card just taken from the pile, which may not go straight back. */ taken: CardId | null; /** Every card the other player has taken from the discard pile this hand and still holds: the table watched them take it. */ theirPicks: readonly CardId[]; }; /** The part of the game the seat to play can see, which is all its computer is given. * * @param game - The current native game; applying a move returns a new state. * @returns The part of the game the seat to play can see, which is all its computer is given. * * @example * ```ts * import { CARD_GAME_TABLES, newGame } from "@johnmorrisdotca/toranpu"; * import { ginView } 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(ginView(game)); * ``` */ export declare function ginView(game: GinGame): GinView; /** The move a computer in the seat to play makes: always one the rules allow. * * @param game - The current native game; applying a move returns a new state. * @returns The move a computer in the seat to play makes: always one the rules allow. * * @example * ```ts * import { CARD_GAME_TABLES, newGame } from "@johnmorrisdotca/toranpu"; * import { ginComputer } 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(ginComputer(game)); * ``` */ export declare function ginComputer(game: GinGame): GinMove; /** Whether the discard would go straight into a meld: the hand with it and its best throw has less deadwood than now. * * @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 the discard would go straight into a meld: the hand with it and its best throw has less deadwood than now. * * @example * ```ts * import { wanted } from "@johnmorrisdotca/toranpu/gin-rummy"; * * console.log(wanted(["3H", "4H"], "5H")); * ``` */ export declare function wanted(hand: readonly CardId[], card: CardId): boolean; /** The card to throw: the one leaving the least deadwood; of those, not a card the other player could use, and the highest. * * @param view - The player-visible game information used by a computer. * @returns The card to throw: the one leaving the least deadwood; of those, not a card the other player could use, and the highest. * * @example * ```ts * import { CARD_GAME_TABLES, newGame, rulesFor } from "@johnmorrisdotca/toranpu"; * import { chooseThrow, ginView } 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 })!; * const rules = rulesFor("ginRummy"); * for (let setup = 0; setup < 100 && game.phase !== "discard" && game.phase !== "over"; setup += 1) { * const next = rules.play(game, rules.computer(game)); * if (next === null) throw new Error("Unexpected illegal setup move"); * game = next; * } * if (game.phase !== "discard") throw new Error("Setup did not reach discard"); * console.log(chooseThrow(ginView(game))); * ``` */ export declare function chooseThrow(view: GinView): CardId; /** * A player a test can play at random who still ends a hand: a random * draw and a random throw, but a knock whenever the card thrown allows one. * A player choosing every move uniformly would almost never knock, and hand * after hand would run the stock down to a draw with nobody scoring. * * @param game - The current native game; applying a move returns a new state. * @param random - A source of numbers in [0, 1), such as seededRandom(seed). * @returns A player a test can play at random who still ends a hand: a random draw and a random throw, but a knock whenever the card thrown allows one. A player choosing every move uniformly would almost never knock, and hand after hand would run the stock down to a draw with nobody scoring. * * @example * ```ts * import { CARD_GAME_TABLES, newGame } from "@johnmorrisdotca/toranpu"; * import { ginSensible } from "@johnmorrisdotca/toranpu/gin-rummy"; * import { seededRandom } from "@johnmorrisdotca/toranpu/deck"; * * const names = Array.from({ length: CARD_GAME_TABLES.ginRummy.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * let game = newGame("ginRummy", { players: names, seed: 42 })!; * console.log(ginSensible(game, seededRandom(42))); * ``` */ export declare function ginSensible(game: GinGame, random: () => number): GinMove;