Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e5c26e35fd | |||
| 521c2afcda |
+18
-8
@@ -19,19 +19,19 @@ pub trait Game {
|
|||||||
/// card_game supports up to 4 identifiably separate decks.
|
/// card_game supports up to 4 identifiably separate decks.
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
pub enum Deck {
|
pub enum Deck {
|
||||||
Deck1,
|
Deck1 = 0b00,
|
||||||
Deck2,
|
Deck2 = 0b01,
|
||||||
Deck3,
|
Deck3 = 0b10,
|
||||||
Deck4,
|
Deck4 = 0b11,
|
||||||
}
|
}
|
||||||
impl Deck {
|
impl Deck {
|
||||||
pub const fn new(deck: u8) -> Option<Self> {
|
pub const fn new(deck: u8) -> Option<Self> {
|
||||||
use Deck::*;
|
use Deck::*;
|
||||||
Some(match deck {
|
Some(match deck {
|
||||||
1 => Deck1,
|
0b00 => Deck1,
|
||||||
2 => Deck2,
|
0b01 => Deck2,
|
||||||
3 => Deck3,
|
0b10 => Deck3,
|
||||||
4 => Deck4,
|
0b11 => Deck4,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -46,6 +46,16 @@ pub enum Suit {
|
|||||||
}
|
}
|
||||||
impl Suit {
|
impl Suit {
|
||||||
pub const SUITS: [Self; 4] = [Self::Spades, Self::Hearts, Self::Clubs, Self::Diamonds];
|
pub const SUITS: [Self; 4] = [Self::Spades, Self::Hearts, Self::Clubs, Self::Diamonds];
|
||||||
|
pub const fn new(suit: u8) -> Option<Self> {
|
||||||
|
use Suit::*;
|
||||||
|
Some(match suit {
|
||||||
|
0b00 => Spades,
|
||||||
|
0b01 => Hearts,
|
||||||
|
0b10 => Clubs,
|
||||||
|
0b11 => Diamonds,
|
||||||
|
_ => return None,
|
||||||
|
})
|
||||||
|
}
|
||||||
/// Is the suit red.
|
/// Is the suit red.
|
||||||
pub const fn is_red(self) -> bool {
|
pub const fn is_red(self) -> bool {
|
||||||
self as u8 & 0b01 != 0
|
self as u8 & 0b01 != 0
|
||||||
|
|||||||
Reference in New Issue
Block a user