Crates.io | rust_cards |
lib.rs | rust_cards |
version | 0.1.2 |
source | src |
created_at | 2021-07-19 05:42:26.176779 |
updated_at | 2021-07-20 06:11:15.760696 |
description | Simulates playing cards |
homepage | |
repository | https://github.com/ottobrown/rust_cards |
max_upload_size | |
id | 424595 |
size | 13,322 |
A simple library for simulating playing cards
A Card is a struct with 2 fields, elements of the enums Suit and Value. A Hand is a struct consisting of a Vec of Card
Suit ----↓
Card ----→ [Card Card Card Card Card] --→ Hand
Value ---↑
Creates a deck, shuffles it, and pops the top 5 cards onto a Hand
use rust_cards::cards::Card;
use rust_cards::hand::Hand;
fn main() {
let mut deck = Hand::full_deck();
deck = deck.shuffle();
//pops the top 5 cards off the deck and puts them in a hand
let top_five_cards = Hand::from(
vec![
deck.pop_top(),
deck.pop_top(),
deck.pop_top(),
deck.pop_top(),
deck.pop_top(),
]
);
for card in top_five_cards.vec {
println!("{}", card.string())
}
}
creates a hand consinsting of A♠, 2♥, 3♦, 4♣
use rust_cards::cards::Card;
use rust_cards::hand::Hand;
use rust_cards::cards::Suit;
use rust_cards::cards::Value;
fn main() {
let set_hand = Hand::from(
vec![
Card::new(Value::Ace, Suit::Spade),
Card::new(Value::Two, Suit::Heart),
Card::new(Value::Three, Suit::Diamond),
Card::new(Value::Four, Suit::Club)
]
);
for card in set_hand.vec {
println!("{}", card.string())
}
//A♠
//2♥
//3♦
//4♣
}
##License MIT or Apache-2.0