Reference
Klondike
import { … } from "@johnmorrisdotca/toranpu/klondike";
3.9 kB minified and gzipped, with everything it imports (measured with esbuild)
Klondike, the Solitaire: its table, its rules, its moves written as text, a solver, and what a tap on the table means.
Exports
| Name | Kind | What it is |
|---|---|---|
allFaceUp | function | Whether every card on the columns is face up: from here the game plays itself out (autoFinish). |
bestFirst | function | A winning line from this table — every move a replay of it makes, the settling ones included — or null when none was found within budget tables. |
BestFirstGame | type | A BEST-FIRST SEARCH for a card game played alone, shared by FreeCell's solver and Spider's (freecell/solve.ts, spider/solve.ts). |
carriedFrom | function | Which card of a column a carry to to would take: the one face-up card whose run fits there, or null. |
COLUMN_PILES | constant | The columns, as a move names them. |
columnAt | function | Which column, from 0, a pile a move names is. |
COLUMNS | constant | How many columns the tableau has. |
dealKlondike | function | Deal a deck (card numbers, the first dealt first) into a table: column by column along each row, as a dealer does. |
dealOf | function | A deal string from card numbers. |
dealOfSeed | function | The deal of a seed: the site's one shuffle (shuffledDeck), written down. |
deckOf | function | The deck a deal string names, as card numbers, or null for one that is not a whole deck. |
decodeMoves | function | A move list read back, or null for one with a character that is no move. |
DRAW_CODE | constant | The letter a draw from the stock is written as, in a move list. |
encodeMove | function | One move written as text: one or two letters. |
encodeMoves | function | A list of moves written as text, one after another with nothing between. |
finishingMoves | function | THE GAME PLAYS ITSELF OUT once every card on the columns is face up: the moves that bring the rest home, found by the solver on a small budget (a table with nothing hidden is solved in a handful of tables), or null while a card is still face down or no way home is found — then the player goes on. |
fitsColumn | function | Whether a card may go onto a column: onto a card one higher of the other colour, or a King onto an empty one. |
fitsFoundation | function | Whether a card may go onto its suit's foundation now. |
FOUNDATION_PILES | constant | The foundations' letters, in SUITS order (spades, hearts, diamonds, clubs), as a card id writes a suit. |
foundationAt | function | Which foundation, from 0 in SUITS order, a pile a move names is. |
foundationPileOf | function | The foundation a card goes to. |
homeMove | function | The move that sends a top card home, if it can go: what a double tap does. |
isColumnPile | function | Whether a pile a move names is a column. |
isFoundationPile | function | Whether a pile a move names is a suit's foundation. |
isSafeHome | function | Whether a card is one the solver treats as home safely: exported for its test. |
KlondikeColumn | type | One of the seven columns: its cards from the bottom up, of which the first down lie face down. |
KlondikeMove | type | One move: turn cards from the stock (draw), turn the waste back over (recycle), or carry cards from one pile to another. |
KlondikePile | type | A place on the table a move names: the stock s, the waste w, a suit's foundation by its letter (S H D C, as a card id writes a suit), or a column 1–7. |
KlondikeRules | type | How the game was set up: cards turned from the stock at a time, and how many times through the stock (Infinity for no limit). |
KlondikeTable | type | A game of Klondike as it stands: every pile, and the rules it is played under. |
klondikeWon | function | Whether every card is home. |
liftable | function | The cards a person can take hold of from a spot, the one held and every one on it, or none: the waste's top card, a foundation's top card, or any face-up card of a column with the run on top of it. |
moveFor | function | The move that carries the cards held at from to to, if the rules allow exactly those cards there. |
movesFrom | function | Every move the rules allow from this table, in a fixed order: to the foundations first, then onto the columns, then the stock. |
pileCards | function | The cards of a pile, bottom first, as the table holds them. |
playKlondike | function | The table after a move, or null where the rules refuse it. |
rankOf | function | A card's rank, 1 for an ace to 13 for a king. |
RANKS_A_SUIT | constant | How many ranks a suit has, ace to king. |
RECYCLE_CODE | constant | The letter turning the waste back over is written as, in a move list. |
recyclesLeft | function | How many times the waste may still be turned back: passes less one, less those already made. |
redCard | function | Hearts and diamonds, the second and third suits. |
replay | function | A game played out from its deal: every table it passed through, the first the deal, or null where the deal is not a deck or a move is one the rules refuse. |
solveKlondike | function | A winning line from this table — every move, the safe ones home included, that a replay of it makes — or null when none was found within budget tables. |
stockMove | function | What a press on the stock does: turn it, or turn the waste back over, or nothing once the passes are spent. |
stuck | function | Whether nothing can be done but give up: no card can move anywhere, and the stock can be neither turned nor turned back. |
suitOf | function | A card's suit, 0 to 3 in SUITS order. |
TableSpot | type | A card on the table, as a person points at it: the pile, and its place from the bottom (-1 for the pile's empty place). |