Added a basic deck
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
use thiserror::Error;
|
||||
use anyhow::Result;
|
||||
use strum::IntoEnumIterator;
|
||||
use strum_macros::EnumIter;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive(PartialEq, Debug, EnumIter, Copy, Clone)]
|
||||
pub enum Suit {
|
||||
Heart,
|
||||
Diamond,
|
||||
@@ -38,7 +39,7 @@ impl fmt::Display for Suit {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive(PartialEq, Debug, EnumIter, Copy, Clone)]
|
||||
pub enum Value {
|
||||
Ace,
|
||||
Two,
|
||||
@@ -133,6 +134,30 @@ impl Card {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Deck {
|
||||
pub cards: Vec<Card>
|
||||
}
|
||||
|
||||
impl Default for Deck {
|
||||
fn default() -> Deck {
|
||||
let mut array = Vec::new();
|
||||
for suit in Suit::iter() {
|
||||
for value in Value::iter() {
|
||||
array.push(
|
||||
Card {
|
||||
suit: suit,
|
||||
value: value,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Deck {
|
||||
cards: array,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
@@ -173,4 +198,11 @@ mod tests {
|
||||
assert!(false, "Cards are not adjacent - should be an error")
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_a_whole_deck() {
|
||||
let d = Deck::default();
|
||||
assert_eq!(d.cards.len(), 52); // Probably should test whether all cards are in... eh
|
||||
println!("{:#?}", d);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user