casino_cards

Crates.iocasino_cards
lib.rscasino_cards
version1.0.0
sourcesrc
created_at2024-07-14 19:50:30.88441
updated_at2024-08-30 15:33:13.78197
descriptionA library that provides a deck of playing cards that can be used for various card games.
homepage
repositoryhttps://github.com/winstonrc/casino/tree/main/crates/casino_cards
max_upload_size
id1303210
size35,524
Winston Cooke (winstonrc)

documentation

README

crates.io Cards Test

casino_cards

A library that provides a deck of playing cards that can be used for various card games.

Usage

Deck creation

use casino_cards::deck::Deck;

fn main() {
    let mut deck = Deck::new();
    deck.shuffle();

    let card1 = deck.deal();
    // A card can be inserted at a specified position in the deck.
    deck.insert(12, card);

    let card2 = deck.deal();
    // A card can be inserted at the bottom of the deck.
    deck.insert_at_bottom(card2);

    let card3 = deck.deal();
    // A card can be inserted at the middle of the deck.
    deck.insert_at_middle(card3);

    let card4 = deck.deal();
    // A card can be inserted at the top of the deck.
    deck.insert_at_top(card4);

    deck.shuffle();
}

Card creation

use casino_cards::card;
use casino_cards::card::{Card, Rank, Suit};

fn main() {
    // A card can be created with the new() method.
    let two_of_diamonds = Card::new(Rank::Two, Suit::Diamond);

    // Or a card can be created by using a macro.
    let two_of_clubs = card!(Two, Club);
}

Hand creation

use casino_cards::card::Card;
use casino_cards::deck::Deck;
use casino_cards::hand::Hand;

fn main() {
    let mut deck = Deck::new();
    deck.shuffle()

    // A hand can be created by pushing cards into it.
    let card1 = deck.deal();
    let card2 = deck.deal();
    let mut hand = Hand::new();
    hand.push(card1);
    hand.push(card2);

    // Or a hand can be created from an existing Vec<Card>.
    let mut cards: Vec<Card> = Vec::new();
    let card3 = deck.deal();
    let card4 = deck.deal();
    cards.push(card3);
    cards.push(card4);
    let mut hand2 = Hand::new_from_cards(cards);
}
Commit count: 0

cargo fmt