Added a basic deck
This commit is contained in:
33
card_stuffs/Cargo.lock
generated
33
card_stuffs/Cargo.lock
generated
@@ -13,9 +13,17 @@ name = "card_stuffs"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.93"
|
||||
@@ -34,6 +42,31 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4"
|
||||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.27.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f64def088c51c9510a8579e3c5d67c65349dcf755e5479ad3d010aa6454e2c32"
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.27.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c77a8c5abcaf0f9ce05d62342b7d298c346515365c36b673df4ebe3ced01fde8"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.98"
|
||||
|
||||
@@ -5,4 +5,6 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.96"
|
||||
strum = "0.27.1"
|
||||
strum_macros = "0.27.1"
|
||||
thiserror = "2.0.11"
|
||||
|
||||
@@ -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