#card-game #card #poker #game

rummy

a crate for the card game Rummy

5 releases

0.1.4 Jul 7, 2024
0.1.3 Jun 30, 2024
0.1.2 Jun 30, 2024
0.1.1 Jun 18, 2024
0.1.0 Jun 18, 2024

#107 in Games

Download history

246 downloads per month

MIT license

94KB
2.5K SLoC

rummy

This crate models the card game Rummy. It supports configuration and different popular variants (WIP).

NOTE: this crate is in early development; expect nothing to stay stable.

Use

Modules

A typical import of this crate will look like this:

use rummy::game::{
    actions::{
        AllActions, DiscardActions, DrawActions, PlayActions, PlayableActions, RoundEndActions,
        TransitionResult,
    },
    phases::{DiscardPhase, DrawPhase, GamePhase, PlayPhase, PlayablePhase, RoundEndPhase},
    state::{Score, State},
    variants::standard::{StandardRummy, StandardRummyGame},
};

A breakdown of the modules:

  • actions: Traits that split up possible actions for each phase of a Rummy game.
  • phases: Different phases of a Rummy game; used as state for the game's typestate.
  • state: State of a Rummy game, common across all variants.
  • variants: The game itself; contains different variants of Rummy.

Starting a game

// initialize a list of player IDs
let player_ids = vec![1, 2, 3, 4];

// pass it into a variant's `quickstart`
let game = StandardRummyGame::quickstart(player_ids); 

// we initialize at round 0 in `RoundEndPhase`, so we must advance to the next round
let game = game.to_next_round();

Alternatively, you can configure the game by setting a config:

// the config struct for standard Rummy
let game_config = StandardRummyConfig { /* ... */ };

// and for the deck itself
let deck_config = DeckConfig { /* ... */ };

// we pass both into the variant's `new`
let game = StandardRummyGame::quickstart(player_ids, game_config, deck_config); 

Transitions

Certain actions, such as forming melds, can result in immediate transitions to a different gamephase. Calling these functions consumes the game and returns a TransitionResult.

WIP

Example

Use cargo run --examples rummy to run a command-line implementation of this crate.

Dependencies

~0.6–1.3MB
~27K SLoC