Another little module, this one implementing several different kinds of playing cards: playingCards github repo.
This just implements the cards/decks themselves, and a couple of basic actions (>SHUFFLE
, >DEAL
, and >DISCARD
) for interacting with them. It doesn’t implement any in-game playing card game mechanics.
The main utility the module provides is juggling all of the vocabulary for the individual cards. Specifically it does this without implementing each individual card as a separate in-game object.
I won’t bother to walk through all of the module internals here (unless someone is interested in them), but there’s a bunch of gymnastics happening to adjust logical rankings and vocab likelihoods and so on.
Very simple version is:
- Game implementor creates an instance of some
Deck
subclass - The
Deck
, when initialized, automagically creates a singlePlayingCardUnthing
andPlayingCardType
instance for its specific playing card type - The
PlayingCardUnthing
handles card-related actions when there are no card-related objects in scope - The
PlayingCardType
handles the slight-of-hand needed to map the vocabulary for individual cards (“3C” or “three of clubs”) to the in-game object currently best suited to handle it (usually based on whether or not the player is currently holding the card in question).
PlayingCardType
also has a report manager that handles merging action reports involving invividual cards. >DEAL
ing cards creates aPlayingCardHand
instance for each player receiving cards, unless they already have one. Under the hood the instance is moved into and out of the actor’s inventory as appropriate (so they’re never holding a “hand” containing no cards)>DISCARD
ing cards creates aDiscardPile
instance (if one doesn’t already exist for the deck the cards came from). It’s an in-game object provided mostly for flavor, but examining it will provide an approximate description of how many cards have been discarded.
By default the module includes support for the familiar 52-card French-suited deck via StandardDeck
. It also includes definitions for the 40-card Spanish-suited deck, hanafuda cards, and the 78-card tarot deck (using the Waite-Rider suit and arcana names). Support for each of these decks can be enabled at compile time by specifying a preprocessor flag (-D PLAYING_CARDS_SPANISH
, -D PLAYING_CARDS_HANAFUDA
, and -D PLAYING_CARDS_TAROT
, respectively).
I’m separately working on a module for implementing in-game card games, but that’s not done yet—I started out writing just a draw poker implementation, and refactoring that I broke out the card/deck definitions, and I’m currently thinking I want to write a generic card game module and make poker a special case of it, but I might change my mind.