28 releases
0.5.2 | Aug 26, 2024 |
---|---|
0.5.1 | Mar 23, 2024 |
0.5.0 | Dec 17, 2023 |
0.4.20 | Oct 3, 2023 |
0.3.8 | Oct 12, 2020 |
#113 in Game dev
Used in 2 crates
140KB
3.5K
SLoC
cardpack.rs
Generic pack of cards library written in Rust. The goals of the library include:
- Various types of decks of cards.
- Internationalization support.
- Ability to create custom sorts for a specific pack of cards.
Usage
fn main() {
let pack = cardpack::Pack::french_deck();
let mut shuffled = pack.cards().shuffle();
let sb = shuffled.draw(2).unwrap();
let bb = shuffled.draw(2).unwrap();
println!("small blind: {}", sb.by_symbol_index());
println!("big blind: {}", bb.by_symbol_index());
println!();
println!("flop : {}", shuffled.draw(3).unwrap().by_symbol_index());
println!("turn : {}", shuffled.draw(1).unwrap().by_symbol_index());
println!("river: {}", shuffled.draw(1).unwrap().by_symbol_index());
}
Examples
The library has several demo programs in the examples directory.
For the traditional French Deck:
$> cargo run --example traditional
Long in English and German:
Ace of Spades
Ass von Spaten
King of Spades
König von Spaten
Queen of Spades
Dame von Spaten
...
Short Symbols in en-US: A♠ K♠ Q♠ J♠ 10♠ 9♠ 8♠ 7♠ 6♠ 5♠ 4♠ 3♠ 2♠ A♥ K♥ Q♥ J♥ 10♥ 9♥ 8♥ 7♥ 6♥ 5♥ 4♥ 3♥ 2♥ A♦ K♦ Q♦ J♦ 10♦ 9♦ 8♦ 7♦ 6♦ 5♦ 4♦ 3♦ 2♦ A♣ K♣ Q♣ J♣ 10♣ 9♣ 8♣ 7♣ 6♣ 5♣ 4♣ 3♣ 2♣
Short Symbols in de : A♠ K♠ D♠ B♠ 10♠ 9♠ 8♠ 7♠ 6♠ 5♠ 4♠ 3♠ 2♠ A♥ K♥ D♥ B♥ 10♥ 9♥ 8♥ 7♥ 6♥ 5♥ 4♥ 3♥ 2♥ A♦ K♦ D♦ B♦ 10♦ 9♦ 8♦ 7♦ 6♦ 5♦ 4♦ 3♦ 2♦ A♣ K♣ D♣ B♣ 10♣ 9♣ 8♣ 7♣ 6♣ 5♣ 4♣ 3♣ 2♣
Short Letters in en-US: AS KS QS JS 10S 9S 8S 7S 6S 5S 4S 3S 2S AH KH QH JH 10H 9H 8H 7H 6H 5H 4H 3H 2H AD KD QD JD 10D 9D 8D 7D 6D 5D 4D 3D 2D AC KC QC JC 10C 9C 8C 7C 6C 5C 4C 3C 2C
Short Letters in de : AS KS DS BS 10S 9S 8S 7S 6S 5S 4S 3S 2S AH KH DH BH 10H 9H 8H 7H 6H 5H 4H 3H 2H AD KD DD BD 10D 9D 8D 7D 6D 5D 4D 3D 2D AK KK DK BK 10K 9K 8K 7K 6K 5K 4K 3K 2K
Shuffle Deck: 8C 2H QC 9D 4S 10D 8D 6D 5H JS 5D KS 6C 9H 6H JC KC 3H 7C 3C 8H 7H 4H 5C 5S 4C AC 4D AH QH QS JD 9S 2S 3S 2C 10S JH 9C KH 10H 7D 10C KD 8S 6S 7S QD AD 2D 3D AS
Sort Deck: AS KS QS JS 10S 9S 8S 7S 6S 5S 4S 3S 2S AH KH QH JH 10H 9H 8H 7H 6H 5H 4H 3H 2H AD KD QD JD 10D 9D 8D 7D 6D 5D 4D 3D 2D AC KC QC JC 10C 9C 8C 7C 6C 5C 4C 3C 2C
Also included are example programs for spades
, pinochle
, skat
, canasta
,
euchre
, handandfoot
and tarot
as well as example poker
and bridge
hands.
Details
The goal of this library is to be able to support the creation of card decks of various sizes and suits. Out of the box, the library supports:
- French Deck
- Short Deck
- Skat
- Tarot with Major and Minor Arcana
The project takes advantage of Project Fluent's Rust support to offer internationalization. Current languages supported are English and German.
Responsibilities
- Represent a specific type of card deck.
- Validate that a collection of cards is valid for that type of deck.
- Create a textual representation of a deck that can be serialized and deserialized.
- Shuffle a deck
- Verify that a specific card is playable given a set of discards.
- Determine if two deck types are translatable.
References
Other Deck of Cards Libraries
- ascclemens/cards
- locka99/deckofcards-rs
- vsupalov/cards-rs
- droundy/bridge-cards
- Tarot Libraries
Dependencies
Dev Dependencies
- rstest - Fixture-based test framework for Rust
TODO
Dependencies
~7–16MB
~202K SLoC