Decks as data, with two-letter Spanish suit codes
Context and problem
The next games planned are Spanish-deck games, starting with Chinchón
(#132, docs/plans/spanish-deck.md). Today all
three cores hard-code the French deck, 52 cards plus jokers, inside Canasta’s rules. A Spanish
deck (40 or 48 cards, suits oros, copas, espadas and bastos) needs the deck to be something a rule
set names, and Spanish cards need codes that can never be mistaken for French ones in a scenario.
Options considered
For the deck:
- Keep the French deck in Canasta’s code and add Spanish decks inside each new game.
- Decks as data, in
spec/decks/, read by a cards module that every game uses.
For the card codes:
- One lowercase suit letter (
1o,7c,12e), the plan’s first proposal. It doesn’t clash with French codes, butcandCare easy to mistype in hand-written scenarios. - A deck prefix (
s:7c), the plan’s fallback, which makes every pile and hand in the JSON longer. - A two-letter suit:
or,co,es,ba.
Decision
Eduardo chose decks as data and two-letter suit codes on 2026-11-24 (#134):
spec/decks/french.json,spanish-40.json(ranks 1–7, 10 sota, 11 caballo, 12 rey) andspanish-48.json(adds 8 and 9). Each lists its ranks, suits, joker count and canonical order.- A rule set names its deck:
official.jsonandfamily.jsonget"deck": "french", since every rule set has every field. - Each game declares the decks it can be played with (for example
spec/games/canasta.json: French only; a future Chinchón: the Spanish decks). A rule set’sdeckmust be one of its game’s decks, so a Canasta rule set namingspanish-40fails to load, and a rule set with nodeckis invalid: there’s no silent fallback to French. Added by Eduardo on 2026-11-24. - The “Deck” display setting (Four colours / Red and black) only colours French cards. It isn’t a deck type, and the spec keeps the two apart.
- Spanish codes are rank plus suit:
1or,7co,11ba(caballo de bastos),12es(rey de espadas). Jokers stayJK. Each parser reads only its own deck’s alphabet. - A cards module in each core, separate from Canasta’s rules, holds the deck, card, parse and format code, PCG32 and the shuffle, with mirrored names in Swift, Kotlin and Rust.
- Canasta behaves exactly as before. Drawing Spanish cards and any Spanish game are out of scope.
This is being implemented in #134.
Consequences
Good
- A Spanish code can never be confused with a French one (
7C,10H), and a stray French code in a Spanish deck fails to parse with a clear error. - Today’s French shuffle vectors must stay identical, which makes the refactor safe to check: every existing scenario, parity case and behaviour test passes unchanged.
- The cards module is game-agnostic: in each core, it is the first code a second game can use as it is.
Bad
- Work in all three cores, plus parse, format and invalid-file cases for each deck, with no change a player can see.
- Spanish codes are a character longer than French ones in every hand and pile in the JSON.
- A new rule-set field, which every rule set and every platform’s model must carry.
- A game’s allowed decks are one more thing each core checks when it loads a rule set.
More information
- Issue: #134; plan:
#132, section 1 of
docs/plans/spanish-deck.md. - The cards and parity format today: spec/README.md; the game and platform boundary: docs/architecture.md.