This is a card game framework written in Typescript. This package contains the framework and useful components, including functionality to display a card game in the command line.
Implementations of a card game must share a certain set of exports to be able to be run, see Hearts for an up-to-date example.
Contributions of games to the library are welcome on the Github.
We use SemVer for versioning. For the versions available, see the tags on this repository.
See also the list of contributors who participated in this project.
A controller is a class extending AbstractController that is initialized at state load time that wraps a slice of the state and has complete control over that state. For example, the HandsController has control over the cards found in each player's hand. Controllers can also define dependencies on other controllers, as the DeckController does for the HandsController, which allows them to have more advanced or sophisticated functionality that helps to reduce verbosity in the game transitions for shared functionality (e.g. dealing out cards to hands). Controllers are responsible for modifying (through user defined functions) and validating their underlying state and transforming it for the handlers (i.e. hiding data that isn't to be known).
Parent class of controllers, which own a slice of state
Handles state for players' hands Has children classes that allow for hiding and showing the hands to handlers
Stores bets for players
Stores whether the game has ended
Controls the data for the handlers
Controls a deck for the game
Keeps track of the state of the game
Allows for controlling the handlers
Subclass of abstract controller that shows the state for all handlers
Handles state for players' hands and shows it to handlers
Handles state for players' hands but keeps it hidden from handlers
Handles the state for meld type games
Holds the names for the players
Handles the params for a game
Handles scores for players
Subclass of abstract controller for a controller with no state
Handles state for trick based games
Controls state around whose turn it is for something
Controls state around who the game is currently waiting for
Controllers indexed by a string
Gets the handler state of controllers
Gets the providers that would produce controllers
Gets the associated controllers out of providers
The providers that will exist once the dependency tree is run (assuming no loops) by removing items whose dependencies cannot be fulfilled
Every controller has an associated provider which defines the dependent controllers and handles the initialization of the state and construction of the controller object.
Provides the handlers controller
Provides a controller
Controller providers indexed by a string
Class to represent cards in a deck
Class representing N standard 54 card decks' draw and discard pile, tracking the top card
A class representing a run (or straight flush) of at least four cards being in sequential order and of the same suit, potentially containing wilds
Parent class for three card sets and four card runs
A class for the rank of a card like 'TWO' or 'KING'
Class / Enum representing the possible suits in a deck
A class representing a three (or more) of a kind
Allows for implementing a new game type.
A set of utility functions that are helpful when writing event handlers
Class that steps though the game using the game state transitions
A class used to track the current state of the game
Class that allows calls to the handlers
Class for validating and merging incoming events
Gives a nicer way to setup a game
The reserved names that the default controllers use
The type of the default controllers, once initialized from their providers in buildDefaultProviders
Standard states for the state machine with special purposes
Builds the event handler interface by combining various validators and merger components together
Wraps the classes in a game library into one common interface to make usages less verbose and to hide internal implementation details
A handler is the interface by which a player (or bot) reacts to various events. There are the SystemHandler events, allowing for reacting to generic status messages and whoever the game is currently waiting on, and also whatever events are defined by the individual games (like prompting for a discard or a bid), which allow the handler to respond with proper response messages that mutate the state. Handler instances are joined in a HandlerChain, which allows for more shared functionality by only implementing a few of all the needed handlers.
A chain of handlers, where the first that can handle an event will handle it
Interface to listen for all system events (e.g. message and waiting)
Interface to listen for message events
Interface to listen for all system events (e.g. message and waiting)
Interface to listen for waiting events
An element that can listen to events and push response messages
A Message is a serializable element of communication, which takes two flavors: status/game-generated events which inform handlers about what has changed in the game state, as well as response/handler-generated events which tell the game that a handler would like to respond to something (like an opportunity to bid, discard, or play a card). A Presentable should contain a message that can be displayed to an end user, as well as any other data that may be helpful for a bot to process the event without parsing the message.
Designates that a player is dealer
Class that denotes to a handler that they have been dealt or drawn a card
Class that denotes to a handler that a player has discarded a card
Designates a card to be discarded
Class denoting to handlers that the round has ended
Class that denotes to a handler that a certain player is leading this round
A serializable object designating a change in the game state. A Message is a serializable element of communication, which takes two flavors: status/game-generated events which inform handlers about what has changed in the game state, as well as response/handler-generated events which tell the game that a handler would like to respond to something (like an opportunity to bid, discard, or play a card). A Presentable should contain a message that can be displayed to an end user, as well as any other data that may be helpful for a bot to process the event without parsing the message.
Designates that a player ran out of cards
A class designating to a handler that anpther player has picked up a card, or that a card was not picked up at all
Designates that a card is to be played and optionally data to be set for this player
A class designating that a player put down cards on the table
A class designating that the deck was reshuffled
Empty message for adding spacing
Class that denotes to a handler that a card was flipped over
Class that presents each display element one at a time
Prompts questions to the user using the Inquirer library
A class to designate an error
Sends the messages or forms over a protocol
Class used to lazily provide a value
A queue that handlers push messages to to return them to the driver. Seamlessly handles async items and sync items.
A class to designate an error
Class that handles how material is presented to the end user
Interface describing the different forms of questions that can be posed to the user over a variety of mediums
Generic interface for a medium that can have messages sent over channels
Interface for describing the changes in the state of the game and the effect on the game state
Things the library knows how to write out as a human-readable string
Things that the library knows how to serialize and deserialize
Checks whether it is possible to construct a four card run with the given cards
Returns all possible combinations of the provided items
Deserializes from a string
Function to be used with filter that checks that the current item is not equal to any previous item
Type guard for making sure a value is not undefined or void
Type guard for whether a value is a promise (or promise-like)
Creates serializable objects out of plain object values
Writes a value to a string
Util function allowing for iterating over multiple arrays item by item