import type { CardId } from "../card-games.types.ts"; import type { SpadesGame, SpadesMove, SpadesPlay } from "./spades.types.ts"; /** * SPADES: the rules, and nothing else. * * Four players in two partnerships, partners sitting across from each other. * Thirteen cards each; then each player, from the dealer's left, bids how many * tricks they will take — or nil, none at all. A partnership's contract is * its two bids added. Follow suit if you can; spades are trumps, and may not * be led until one has been played on another suit (unless the leader holds * nothing else). Make the contract and score ten a trick bid and one for * every trick over (a bag); fall short and lose ten a trick bid. Every ten * bags cost a hundred. Nil makes a hundred if its bidder takes no trick, and * costs a hundred if they take one. The first partnership to the game's total * wins — or, if one sinks to minus that total, the other does. * * Pure: every function returns a new game and leaves the one given alone. */ /** How many play Spades: four, in two partnerships. * * @example * ```ts * import { SPADES_SEATS } from "@johnmorrisdotca/toranpu/spades"; * console.log(SPADES_SEATS); * ``` */ export declare const SPADES_SEATS = 4; /** The tricks in a deal of Spades: thirteen. * * @example * ```ts * import { SPADES_TRICKS } from "@johnmorrisdotca/toranpu/spades"; * console.log(SPADES_TRICKS); * ``` */ export declare const SPADES_TRICKS = 13; /** The bid that means no tricks at all. * * @example * ```ts * import { NIL } from "@johnmorrisdotca/toranpu/spades"; * console.log(NIL); * ``` */ export declare const NIL = 0; /** A card's height in a trick: ace high. * * @param card - The physical card or card id to read, draw or play. * @returns A card's height in a trick: ace high. * * @example * ```ts * import { spadesHeight } from "@johnmorrisdotca/toranpu/spades"; * * console.log(spadesHeight("AS")); * ``` */ export declare function spadesHeight(card: CardId): number; /** A seat's partnership: 0 for seats 0 and 2, 1 for seats 1 and 3. * * @param seat - The zero-based player seat. * @returns A seat's partnership: 0 for seats 0 and 2, 1 for seats 1 and 3. * * @example * ```ts * import { teamOf } from "@johnmorrisdotca/toranpu/spades"; * * console.log(teamOf(3)); * ``` */ export declare function teamOf(seat: number): 0 | 1; /** The seat across the table. * * @param seat - The zero-based player seat. * @returns The seat across the table. * * @example * ```ts * import { partnerOf } from "@johnmorrisdotca/toranpu/spades"; * * console.log(partnerOf(1)); * ``` */ export declare function partnerOf(seat: number): number; /** A hand sorted as a player holds it: diamonds, clubs, hearts, spades, low to high within each. * * @param hand - The player’s held cards, or the hand number for a deal. * @returns A hand sorted as a player holds it: diamonds, clubs, hearts, spades, low to high within each. * * @example * ```ts * import { sortSpades } from "@johnmorrisdotca/toranpu/spades"; * * console.log(sortSpades(["AS", "KH", "2C"])); * ``` */ export declare function sortSpades(hand: readonly CardId[]): CardId[]; /** The seat that deals this deal: the first seat, then round to the left. * * @param deal - The deal number or dealing specification. * @returns The seat that deals this deal: the first seat, then round to the left. * * @example * ```ts * import { dealerOf } from "@johnmorrisdotca/toranpu/spades"; * * console.log(dealerOf(0)); * ``` */ export declare function dealerOf(deal: number): number; /** A new game of Spades for these players (one name a seat) at this size, dealt from the seed `dealt`, or null for a table Spades 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 Spades for these players (one name a seat) at this size, dealt from the seed `dealt`, or null for a table Spades 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 { startSpades } from "@johnmorrisdotca/toranpu/spades"; * * const names = Array.from({ length: CARD_GAME_TABLES.spades.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * console.log(startSpades(CARD_GAME_TABLES.spades.defaultSize, names, undefined, 42)?.phase); * ``` */ export declare function startSpades(size: number, players: readonly string[], _language?: unknown, dealt?: number, computers?: readonly boolean[]): SpadesGame | null; /** The cards the seat to play may lay on the trick now. * * @param game - The current native game; applying a move returns a new state. * @returns The cards the seat to play may lay on the trick now. * * @example * ```ts * import { CARD_GAME_TABLES, newGame, rulesFor } from "@johnmorrisdotca/toranpu"; * import { spadesPlayable } from "@johnmorrisdotca/toranpu/spades"; * * const names = Array.from({ length: CARD_GAME_TABLES.spades.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * let game = newGame("spades", { players: names, seed: 42 })!; * const rules = rulesFor("spades"); * for (let setup = 0; setup < 100 && game.phase !== "playing" && 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 !== "playing") throw new Error("Setup did not reach playing"); * console.log(spadesPlayable(game)); * ``` */ export declare function spadesPlayable(game: SpadesGame): CardId[]; /** Who takes a finished trick (or is winning one still being played): the highest spade, or else the highest card of the suit led. * * @param trick - The cards and seats in the current trick. * @returns Who takes a finished trick (or is winning one still being played): the highest spade, or else the highest card of the suit led. * * @example * ```ts * import { spadesTrickWinner } from "@johnmorrisdotca/toranpu/spades"; * * console.log(spadesTrickWinner([{ seat: 0, card: "AC" }, { seat: 1, card: "2S" }, { seat: 2, card: "KC" }, { seat: 3, card: "QC" }])); * ``` */ export declare function spadesTrickWinner(trick: readonly SpadesPlay[]): number; /** The bids open to a player: nil, or one to thirteen tricks. * * @example * ```ts * import { SPADES_BIDS } from "@johnmorrisdotca/toranpu/spades"; * console.log(SPADES_BIDS); * ``` */ export declare const SPADES_BIDS: readonly number[]; /** 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 { spadesMoves } from "@johnmorrisdotca/toranpu/spades"; * * const names = Array.from({ length: CARD_GAME_TABLES.spades.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * let game = newGame("spades", { players: names, seed: 42 })!; * console.log(spadesMoves(game)); * ``` */ export declare function spadesMoves(game: SpadesGame): SpadesMove[]; /** * What one partnership made of a deal: its contract (the two bids, a nil * counting none) made or not, each nil made or not, and the overtricks — the * tricks over the contract, and any trick a nil bidder took — as bags. * * @param bids - Bids by seat, in seat order. * @param tricks - The number of tricks won. * @param team - The zero-based team index. * @returns What one partnership made of a deal: its contract (the two bids, a nil counting none) made or not, each nil made or not, and the overtricks — the tricks over the contract, and any trick a nil bidder took — as bags. * * @example * ```ts * import { partnershipScore } from "@johnmorrisdotca/toranpu/spades"; * * console.log(partnershipScore([3, 4, 3, 3], [4, 3, 3, 3], 0)); * ``` */ export declare function partnershipScore(bids: readonly number[], tricks: readonly number[], team: 0 | 1): { points: number; bags: number; }; /** 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 { playSpades } from "@johnmorrisdotca/toranpu/spades"; * * const names = Array.from({ length: CARD_GAME_TABLES.spades.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * let game = newGame("spades", { players: names, seed: 42 })!; * console.log(playSpades(game, rulesFor("spades").moves(game)[0]!)?.moves.length); * ``` */ export declare function playSpades(game: SpadesGame, move: SpadesMove): SpadesGame | null; /** The partnership with the higher score wins, both its seats. * * @param game - The current native game; applying a move returns a new state. * @returns The partnership with the higher score wins, both its seats. * * @example * ```ts * import { CARD_GAME_TABLES, newGame } from "@johnmorrisdotca/toranpu"; * import { spadesWinners } from "@johnmorrisdotca/toranpu/spades"; * * const names = Array.from({ length: CARD_GAME_TABLES.spades.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * let game = newGame("spades", { players: names, seed: 42 })!; * console.log(spadesWinners(game)); * ``` */ export declare function spadesWinners(game: SpadesGame): number[]; /** A partnership's contract this deal: its bids added, a nil counting none; null while either has still to bid. * * @param game - The current native game; applying a move returns a new state. * @param team - The zero-based team index. * @returns A partnership's contract this deal: its bids added, a nil counting none; null while either has still to bid. * * @example * ```ts * import { CARD_GAME_TABLES, newGame } from "@johnmorrisdotca/toranpu"; * import { contractOf } from "@johnmorrisdotca/toranpu/spades"; * * const names = Array.from({ length: CARD_GAME_TABLES.spades.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`); * let game = newGame("spades", { players: names, seed: 42 })!; * console.log(contractOf(game, 0)); * ``` */ export declare function contractOf(game: SpadesGame, team: 0 | 1): number | null;