Gin Rummy
This crate models the mechanics of gin rummy: strongly typed cards and melds, an exact deadwood solver, and a rules-driven state machine for complete two-player rounds and games.
Gin rummy ranks the ace LOW: A-2-3 is a run, Q-K-A is not, and an ace counts
one point of deadwood. Rank therefore encodes A = 1 through K = 13, unlike
crates for ace-high games such as contract-bridge whose patterns this crate
otherwise follows.
Hands are written as four dot-separated suit groups in ascending order,
clubs first: "A23.456.789.T" holds ♣A ♣2 ♣3 ♦4 ♦5 ♦6 ♥7 ♥8 ♥9 ♠10.
Modules
hand: cards and card sets —Suit,Rank,Card,Holding,Handmeld: sets, runs, and the deadwood solver —Meld,Melds,best_melds,deadwoodround: one deal from upcard to showdown —Round,Phase,RoundResultgame: the scoreboard across deals —Game,FinalScorerules: scoring configuration —Rules,Shutoutdeck(featurerand): shuffled dealing —Deck
Feature flags
rand: shuffled dealing (Deck,Round::deal,Game::deal)serde: serialization for every public type, with validated deserialization of mid-gameRoundsnapshots
Quick start
Deadwood analysis needs no features:
use ;
let hand = "A23.456.789.T".?;
assert_eq!;
println!;
# Ok::
A complete bot-vs-bot game with the rand feature:
#
#
#
#
#
#
Examples
deadwood: parse hands from the command line and print their best melds —cargo run --example deadwood -- "45.456.567.789"simulate: greedy bots play a full game —cargo run --features rand --example simulate