import type { KlondikeColumn, KlondikeMove, KlondikePile, KlondikeRules, KlondikeTable } from "./klondike.types.ts"; /** * THE RULES OF KLONDIKE, pure: every function returns a new table and leaves * the one it was given alone, as the engine does, so a game is its deal and * its moves, and a table read back from a kept run is exactly the one its * moves make. * * The rules as the site plays them: * - Seven columns dealt from the left, one card more in each, the top card of * each face up; the other twenty-four are the stock. * - Turn one card or three from the stock onto the waste (`draw`). Once the * stock is empty the waste may be turned back over as the stock, as many * times as the passes allow (`recycle`): unlimited, three passes in all, or one. * - A column is built down in alternating colours; any face-up run may move * as a whole onto a card one higher of the other colour, and only a King, or * a run headed by one, may fill an empty column. * - Each suit's foundation is built up from its Ace. A foundation's top card * may come back down onto a column. * - A face-down card left on top of a column turns over by itself. */ /** How many columns the tableau has. * * @example * ```ts * import { COLUMNS } from "@johnmorrisdotca/toranpu/klondike"; * console.log(COLUMNS); * ``` */ export declare const COLUMNS = 7; /** How many ranks a suit has, ace to king. * * @example * ```ts * import { RANKS_A_SUIT } from "@johnmorrisdotca/toranpu/klondike"; * console.log(RANKS_A_SUIT); * ``` */ export declare const RANKS_A_SUIT = 13; /** The foundations' letters, in `SUITS` order (spades, hearts, diamonds, clubs), as a card id writes a suit. * * @example * ```ts * import { FOUNDATION_PILES } from "@johnmorrisdotca/toranpu/klondike"; * console.log(FOUNDATION_PILES); * ``` */ export declare const FOUNDATION_PILES: readonly ["S", "H", "D", "C"]; /** The columns, as a move names them. * * @example * ```ts * import { COLUMN_PILES } from "@johnmorrisdotca/toranpu/klondike"; * console.log(COLUMN_PILES); * ``` */ export declare const COLUMN_PILES: readonly ["1", "2", "3", "4", "5", "6", "7"]; /** A card's suit, 0 to 3 in `SUITS` order. * * @param card - The packed card number from 0 to 51. * @returns A card's suit, 0 to 3 in `SUITS` order. * * @example * ```ts * import { suitOf } from "@johnmorrisdotca/toranpu/klondike"; * * console.log(suitOf(0)); * ``` */ export declare const suitOf: (card: number) => number; /** A card's rank, 1 for an ace to 13 for a king. * * @param card - The packed card number from 0 to 51. * @returns A card's rank, 1 for an ace to 13 for a king. * * @example * ```ts * import { rankOf } from "@johnmorrisdotca/toranpu/klondike"; * * console.log(rankOf(0)); * ``` */ export declare const rankOf: (card: number) => number; /** Hearts and diamonds, the second and third suits. * * @param card - The packed card number from 0 to 51. * @returns Hearts and diamonds, the second and third suits. * * @example * ```ts * import { redCard } from "@johnmorrisdotca/toranpu/klondike"; * * console.log(redCard(13)); * ``` */ export declare const redCard: (card: number) => boolean; /** Whether a pile a move names is a column. * * @param pile - The pile to inspect or arrange. * @returns Whether a pile a move names is a column. * * @example * ```ts * import { isColumnPile } from "@johnmorrisdotca/toranpu/klondike"; * * console.log(isColumnPile("1")); * ``` */ export declare function isColumnPile(pile: KlondikePile): boolean; /** Whether a pile a move names is a suit's foundation. * * @param pile - The pile to inspect or arrange. * @returns Whether a pile a move names is a suit's foundation. * * @example * ```ts * import { isFoundationPile } from "@johnmorrisdotca/toranpu/klondike"; * * console.log(isFoundationPile("S")); * ``` */ export declare function isFoundationPile(pile: KlondikePile): boolean; /** Which column, from 0, a pile a move names is. * * @param pile - The pile to inspect or arrange. * @returns Which column, from 0, a pile a move names is. * * @example * ```ts * import { columnAt } from "@johnmorrisdotca/toranpu/klondike"; * * console.log(columnAt("1")); * ``` */ export declare function columnAt(pile: KlondikePile): number; /** Which foundation, from 0 in `SUITS` order, a pile a move names is. * * @param pile - The pile to inspect or arrange. * @returns Which foundation, from 0 in `SUITS` order, a pile a move names is. * * @example * ```ts * import { foundationAt } from "@johnmorrisdotca/toranpu/klondike"; * * console.log(foundationAt("S")); * ``` */ export declare function foundationAt(pile: KlondikePile): number; /** Deal a deck (card numbers, the first dealt first) into a table: column by column along each row, as a dealer does. * * @param deck - The deck in its current order; the input is left unchanged. * @param rules - The game-specific rules or solver rules. * @returns Deal a deck (card numbers, the first dealt first) into a table: column by column along each row, as a dealer does. * * @example * ```ts * import { dealKlondike, dealOfSeed, deckOf } from "@johnmorrisdotca/toranpu/klondike"; * * console.log(dealKlondike(deckOf(dealOfSeed(42))!, { draw: 3, passes: 3 }).stock.length); * ``` */ export declare function dealKlondike(deck: readonly number[], rules: KlondikeRules): KlondikeTable; /** Whether a card may go onto a column: onto a card one higher of the other colour, or a King onto an empty one. * * @param card - The packed card number from 0 to 51. * @param column - The zero-based tableau column. * @returns Whether a card may go onto a column: onto a card one higher of the other colour, or a King onto an empty one. * * @example * ```ts * import { fitsColumn } from "@johnmorrisdotca/toranpu/klondike"; * * console.log(fitsColumn(16, { down: 0, cards: [4] })); * ``` */ export declare function fitsColumn(card: number, column: KlondikeColumn): boolean; /** Whether a card may go onto its suit's foundation now. * * @param card - The packed card number from 0 to 51. * @param foundation - The foundation index or state being checked. * @returns Whether a card may go onto its suit's foundation now. * * @example * ```ts * import { fitsFoundation } from "@johnmorrisdotca/toranpu/klondike"; * * console.log(fitsFoundation(0, [0, 0, 0, 0])); * ``` */ export declare function fitsFoundation(card: number, foundation: readonly number[]): boolean; /** * Which card of a column a carry to `to` would take: the one face-up card whose * run fits there, or null. A column's face-up cards are a single run, so only * one card in it can be one below the target's top, and only its foot can be a King. * * @param table - The native solitaire table; move helpers leave the input unchanged. * @param column - The zero-based tableau column. * @param to - The destination position or state specified by this API. * @returns Which card of a column a carry to `to` would take: the one face-up card whose run fits there, or null. A column's face-up cards are a single run, so only one card in it can be one below the target's top, and only its foot can be a King. * * @example * ```ts * import { carriedFrom, dealKlondike, dealOfSeed, deckOf } from "@johnmorrisdotca/toranpu/klondike"; * * const table = dealKlondike(deckOf(dealOfSeed(42))!, { draw: 3, passes: 3 }); * console.log(carriedFrom(table, 0, "2")); * ``` */ export declare function carriedFrom(table: KlondikeTable, column: number, to: KlondikePile): number | null; /** How many times the waste may still be turned back: passes less one, less those already made. * * @param table - The native solitaire table; move helpers leave the input unchanged. * @returns How many times the waste may still be turned back: passes less one, less those already made. * * @example * ```ts * import { dealKlondike, dealOfSeed, deckOf, recyclesLeft } from "@johnmorrisdotca/toranpu/klondike"; * * const table = dealKlondike(deckOf(dealOfSeed(42))!, { draw: 3, passes: 3 }); * console.log(recyclesLeft(table)); * ``` */ export declare function recyclesLeft(table: KlondikeTable): number; /** The table after a move, or null where the rules refuse it. * * @param table - The native solitaire table; move helpers leave the input unchanged. * @param move - The native move to validate or apply. * @returns The table after a move, or null where the rules refuse it. * * @example * ```ts * import { dealKlondike, dealOfSeed, deckOf, movesFrom, playKlondike } from "@johnmorrisdotca/toranpu/klondike"; * * const table = dealKlondike(deckOf(dealOfSeed(42))!, { draw: 3, passes: 3 }); * console.log(playKlondike(table, movesFrom(table)[0]!)?.stock.length); * ``` */ export declare function playKlondike(table: KlondikeTable, move: KlondikeMove): KlondikeTable | null; /** Whether every card is home. * * @param table - The native solitaire table; move helpers leave the input unchanged. * @returns Whether every card is home. * * @example * ```ts * import { dealKlondike, dealOfSeed, deckOf, klondikeWon } from "@johnmorrisdotca/toranpu/klondike"; * * const table = dealKlondike(deckOf(dealOfSeed(42))!, { draw: 3, passes: 3 }); * console.log(klondikeWon(table)); * ``` */ export declare function klondikeWon(table: KlondikeTable): boolean; /** Whether every card on the columns is face up: from here the game plays itself out (`autoFinish`). * * @param table - The native solitaire table; move helpers leave the input unchanged. * @returns Whether every card on the columns is face up: from here the game plays itself out (`autoFinish`). * * @example * ```ts * import { allFaceUp, dealKlondike, dealOfSeed, deckOf } from "@johnmorrisdotca/toranpu/klondike"; * * const table = dealKlondike(deckOf(dealOfSeed(42))!, { draw: 3, passes: 3 }); * console.log(allFaceUp(table)); * ``` */ export declare function allFaceUp(table: KlondikeTable): boolean; /** The foundation a card goes to. * * @param card - The packed card number from 0 to 51. * @returns The foundation a card goes to. * * @example * ```ts * import { foundationPileOf } from "@johnmorrisdotca/toranpu/klondike"; * * console.log(foundationPileOf(0)); * ``` */ export declare function foundationPileOf(card: number): KlondikePile; /** * Every move the rules allow from this table, in a fixed order: to the * foundations first, then onto the columns, then the stock. The table's own * list, for a solver and a stuck-game check; a person's move is checked by * `playKlondike` alone. * * @param table - The native solitaire table; move helpers leave the input unchanged. * @returns Every move the rules allow from this table, in a fixed order: to the foundations first, then onto the columns, then the stock. The table's own list, for a solver and a stuck-game check; a person's move is checked by `playKlondike` alone. * * @example * ```ts * import { dealKlondike, dealOfSeed, deckOf, movesFrom } from "@johnmorrisdotca/toranpu/klondike"; * * const table = dealKlondike(deckOf(dealOfSeed(42))!, { draw: 3, passes: 3 }); * console.log(movesFrom(table).slice(0, 5)); * ``` */ export declare function movesFrom(table: KlondikeTable): KlondikeMove[];