What it does
A card is plain data: a uid, a suit, a rank and whether it is face up. buildDeck makes one or more ordered
decks, each card with a uid that stays unique across all of them, so you can key sprites by it even with two decks
on the table. shuffledDeck shuffles through the engine's seeded random stream, so a seed reproduces a deal exactly,
for daily deals, replays and tests.
The helpers answer the questions every card game asks: a card's name ("Ace of Spades"), its short id, its colour, its label and whether it is a court card. A pile is an id, a kind and its cards, and four stacking tests say whether one card may go on another under the usual rules, so a patience game's moves are a line each.
Features
- Decks of any shape — any number of decks, and any subset of suits and ranks, such as a piquet deck, euchre or two suits.
- Seeded shuffles —
shuffledDeck(seed)deals the same order every time;shuffletakes any of the engine's random streams. - Unique card ids — every card's
uidstays unique across mixed decks. - Names and labels —
cardName,cardId,suitColor,rankLabel,isCourtand each suit's glyph. - Piles —
makePileandtop, with the kinds stock, waste, foundation, tableau and cell. - Stacking rules —
stackAlternating,stackSameSuit,stackDescendingandstackFoundation.
Good for
- Patience games such as Klondike or FreeCell, with the
solitairepack on top. - Dealer games like blackjack, which needs only this pack for its shoe.
- Card games of your own, whose rules use the deck, the piles and the stacking tests.
- Games with a short deck, such as piquet or euchre, built from a subset of ranks.
Make it yours
The pack has no options; the choices are in the calls. A blackjack shoe is six full decks shuffled together from a
seed; a piquet hand is one deck of ranks 1 and 7 to 13; a two-suit game is { suits: ['spades', 'hearts'] }. Pile
kinds use patience names, but a pile is only an id, a kind and its cards, so any game can use them for hands,
discard piles or the table.
A quick look
A seeded piquet deck, a hand dealt from it, and a stacking test:
const piquet = game.cards.shuffledDeck(seed, 1, { ranks: [1, 7, 8, 9, 10, 11, 12, 13] });
const hand = piquet.splice(0, 12);
if (game.cards.stackAlternating(card, game.cards.top(column)!)) column.cards.push(card);
Works with
solitaire— Klondike, FreeCell, Spider and variants, with undo, hints and a solver.blackjack— a dealer table built on this deck.card-art— card faces and backs painted with no image files.card-motion— cards that glide, flip and deal in styles.
Good to know
- The French deck only: four suits and thirteen ranks, with no jokers.
- It holds no game rules beyond the stacking tests; dealing, turns and scoring belong to your game or a rules pack.
- It draws nothing: pair it with
card-artfor faces andcard-motionfor movement.






