diff --git a/big-c.org b/big-c.org index 3ede493..8e6f135 100644 --- a/big-c.org +++ b/big-c.org @@ -2,7 +2,7 @@ * WIP triples :modes:feat_triples: Model the concept of a triple (three cards of similar rank). -** WIP Triple::new +** DONE Triple::new ** TODO Hand ** TODO Display ** TODO Ord diff --git a/src/modes/triple.rs b/src/modes/triple.rs new file mode 100644 index 0000000..1009931 --- /dev/null +++ b/src/modes/triple.rs @@ -0,0 +1,32 @@ +use crate::{ + card::{Card, PlayingCard}, + helper::ordered, +}; + +#[derive(Debug, Copy, Clone)] +pub struct Triple(Card, Card, Card); + +impl Triple { + fn new(c1: Card, c2: Card, c3: Card) -> Option { + let [c1, c2, c3] = ordered([c1, c2, c3]); + + match (c1, c2, c3) { + (Card::Joker(_), Card::Joker(_), Card::Joker(_)) => None, + // NOTE: c3 should not be a joker now. + (Card::Joker(_), Card::Joker(_), _) => Some(Triple(c1, c2, c3)), + ( + Card::Joker(_), + Card::PlayingCard(PlayingCard { rank: r1, .. }), + Card::PlayingCard(PlayingCard { rank: r2, .. }), + ) if r1 == r2 => Some(Triple(c1, c2, c3)), + + ( + Card::PlayingCard(PlayingCard { rank: r1, .. }), + Card::PlayingCard(PlayingCard { rank: r2, .. }), + Card::PlayingCard(PlayingCard { rank: r3, .. }), + ) if r1 == r2 && r2 == r3 => Some(Triple(c1, c2, c3)), + + _ => None, + } + } +}