import type { FreeCellMove, FreeCellPile, FreeCellTable } from "./freecell.types.ts"; /** * THE RULES OF FREECELL, pure: every function returns a new table and leaves * the one it was given alone, as the engine does and as Klondike's rules do * (`solitaire/klondike.ts`), so a game is its deal and its moves. * * The rules as the site plays them: * - The whole deck is dealt face up into eight columns, from the left, one * card to each in turn: the first four columns take seven cards, the rest six. * - A column is built down in alternating colours, a red 6 on a black 7, and * any card may go into an empty column. * - A free cell holds one card, any card. The classic game has four; the * set-up offers three or two for a harder one. * - Each suit's foundation is built up from its Ace. A card at home stays home. * - Only the top card of a column moves, but a run in order may go as a whole * where it could have gone a card at a time through the free cells and the * empty columns (`mostCarried`) — the "supermove" every program allows. */ /** How many columns the tableau has. * * @example * ```ts * import { COLUMNS } from "@johnmorrisdotca/toranpu/freecell"; * console.log(COLUMNS); * ``` */ export declare const COLUMNS = 8; /** How many ranks a suit has, ace to king. * * @example * ```ts * import { RANKS_A_SUIT } from "@johnmorrisdotca/toranpu/freecell"; * console.log(RANKS_A_SUIT); * ``` */ export declare const RANKS_A_SUIT = 13; /** The columns, as a move names them. * * @example * ```ts * import { COLUMN_PILES } from "@johnmorrisdotca/toranpu/freecell"; * console.log(COLUMN_PILES); * ``` */ export declare const COLUMN_PILES: readonly ["1", "2", "3", "4", "5", "6", "7", "8"]; /** The free cells, as a move names them: as many as the game is played with, from the first. * * @example * ```ts * import { CELL_PILES } from "@johnmorrisdotca/toranpu/freecell"; * console.log(CELL_PILES); * ``` */ export declare const CELL_PILES: readonly ["a", "b", "c", "d"]; /** 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/freecell"; * console.log(FOUNDATION_PILES); * ``` */ export declare const FOUNDATION_PILES: readonly ["S", "H", "D", "C"]; /** Every pile's letter, for a move written down to be read back. * * @example * ```ts * import { FREECELL_PILES } from "@johnmorrisdotca/toranpu/freecell"; * console.log(FREECELL_PILES); * ``` */ export declare const FREECELL_PILES: ReadonlySet; /** 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/freecell"; * * 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/freecell"; * * 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/freecell"; * * 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/freecell"; * * console.log(isColumnPile("1")); * ``` */ export declare function isColumnPile(pile: FreeCellPile): boolean; /** Whether a pile a move names is a free cell. * * @param pile - The pile to inspect or arrange. * @returns Whether a pile a move names is a free cell. * * @example * ```ts * import { isCellPile } from "@johnmorrisdotca/toranpu/freecell"; * * console.log(isCellPile("a")); * ``` */ export declare function isCellPile(pile: FreeCellPile): 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/freecell"; * * console.log(isFoundationPile("S")); * ``` */ export declare function isFoundationPile(pile: FreeCellPile): 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/freecell"; * * console.log(columnAt("1")); * ``` */ export declare function columnAt(pile: FreeCellPile): number; /** Which free cell, from 0, a pile a move names is. * * @param pile - The pile to inspect or arrange. * @returns Which free cell, from 0, a pile a move names is. * * @example * ```ts * import { cellAt } from "@johnmorrisdotca/toranpu/freecell"; * * console.log(cellAt("a")); * ``` */ export declare function cellAt(pile: FreeCellPile): 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/freecell"; * * console.log(foundationAt("S")); * ``` */ export declare function foundationAt(pile: FreeCellPile): number; /** 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/freecell"; * * console.log(foundationPileOf(0)); * ``` */ export declare function foundationPileOf(card: number): FreeCellPile; /** Deal a deck (card numbers, the first dealt first) into a table with so many free cells: one card to each column in turn. * * @param deck - The deck in its current order; the input is left unchanged. * @param cells - The number of available free cells. * @returns Deal a deck (card numbers, the first dealt first) into a table with so many free cells: one card to each column in turn. * * @example * ```ts * import { dealFreeCell, dealOfSeed, deckOf } from "@johnmorrisdotca/toranpu/freecell"; * * console.log(dealFreeCell(deckOf(dealOfSeed(42))!, 4).tableau.map((column) => column.length)); * ``` */ export declare function dealFreeCell(deck: readonly number[], cells: number): FreeCellTable; /** Whether `upper` may lie on `lower` in a column: one lower, of the other colour. * * @param lower - The inclusive lower bound. * @param upper - The inclusive upper bound. * @returns Whether `upper` may lie on `lower` in a column: one lower, of the other colour. * * @example * ```ts * import { follows } from "@johnmorrisdotca/toranpu/freecell"; * * console.log(follows(16, 4)); * ``` */ export declare function follows(lower: number, upper: number): 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/freecell"; * * console.log(fitsFoundation(0, [0, 0, 0, 0])); * ``` */ export declare function fitsFoundation(card: number, foundation: readonly number[]): boolean; /** How many cards on top of a column are in order, each on the one under it: the most a single carry could ever take. * * @param column - The column index, or its bottom-to-top cards where an array is accepted. * @returns How many cards on top of a column are in order, each on the one under it: the most a single carry could ever take. * * @example * ```ts * import { runLength } from "@johnmorrisdotca/toranpu/freecell"; * * console.log(runLength([4, 16])); * ``` */ export declare function runLength(column: readonly number[]): number; /** * The most cards a carry may take, as though moved one at a time: one more * than the empty free cells, doubled for every empty column but the one the * cards are going to. * * @param table - The native solitaire table; move helpers leave the input unchanged. * @param toEmptyColumn - Whether the destination tableau column is empty. * @returns The most cards a carry may take, as though moved one at a time: one more than the empty free cells, doubled for every empty column but the one the cards are going to. * * @example * ```ts * import { dealFreeCell, dealOfSeed, deckOf, mostCarried } from "@johnmorrisdotca/toranpu/freecell"; * * const table = dealFreeCell(deckOf(dealOfSeed(42))!, 4); * console.log(mostCarried(table, false)); * ``` */ export declare function mostCarried(table: FreeCellTable, toEmptyColumn: boolean): number; /** The top card of a pile, or undefined where it holds none (a foundation's top is its suit at its count). * * @param table - The native solitaire table; move helpers leave the input unchanged. * @param pile - The pile to inspect or arrange. * @returns The top card of a pile, or undefined where it holds none (a foundation's top is its suit at its count). * * @example * ```ts * import { dealFreeCell, dealOfSeed, deckOf, topOf } from "@johnmorrisdotca/toranpu/freecell"; * * const table = dealFreeCell(deckOf(dealOfSeed(42))!, 4); * console.log(topOf(table, "a")); * ``` */ export declare function topOf(table: FreeCellTable, pile: FreeCellPile): number | undefined; /** 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 { dealFreeCell, dealOfSeed, deckOf, movesFrom, playFreeCell } from "@johnmorrisdotca/toranpu/freecell"; * * const table = dealFreeCell(deckOf(dealOfSeed(42))!, 4); * console.log(playFreeCell(table, movesFrom(table)[0]!)?.tableau.map((column) => column.length)); * ``` */ export declare function playFreeCell(table: FreeCellTable, move: FreeCellMove): FreeCellTable | null; /** * How many cards a carry from one column to another takes, where it is not * the player's to say: onto a card, the one count whose foot fits it. Into an * empty column any count up to the most would do, so none is chosen here. * * @param table - The native solitaire table; move helpers leave the input unchanged. * @param from - The source position or source state specified by this API. * @param to - The destination position or state specified by this API. * @returns The unique legal carried-card count for a nonempty destination, or null when there is no such count or the destination is empty and the player must choose. * * @example * ```ts * import { countOnto, dealFreeCell, dealOfSeed, deckOf } from "@johnmorrisdotca/toranpu/freecell"; * * const table = dealFreeCell(deckOf(dealOfSeed(42))!, 4); * console.log(countOnto(table, "1", "2")); * ``` */ export declare function countOnto(table: FreeCellTable, from: FreeCellPile, to: FreeCellPile): number | 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 { dealFreeCell, dealOfSeed, deckOf, freeCellWon } from "@johnmorrisdotca/toranpu/freecell"; * * const table = dealFreeCell(deckOf(dealOfSeed(42))!, 4); * console.log(freeCellWon(table)); * ``` */ export declare function freeCellWon(table: FreeCellTable): boolean; /** Every move the rules allow from a table, one of each (the longest run into an empty column), for a stuck-game check. * * @param table - The native solitaire table; move helpers leave the input unchanged. * @returns Every move the rules allow from a table, one of each (the longest run into an empty column), for a stuck-game check. * * @example * ```ts * import { dealFreeCell, dealOfSeed, deckOf, movesFrom } from "@johnmorrisdotca/toranpu/freecell"; * * const table = dealFreeCell(deckOf(dealOfSeed(42))!, 4); * console.log(movesFrom(table).slice(0, 5)); * ``` */ export declare function movesFrom(table: FreeCellTable): FreeCellMove[];