From d8235b6edd152f8243bcd84ffaab9c6d24d55a17 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 7 Apr 2026 12:49:26 +0100 Subject: [PATCH] modes:triple: new file encoding a Triple with new implemented Not a difficult function to think about: we just don't want a situation where we have all jokers. --- big-c.org | 2 +- src/modes/triple.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/modes/triple.rs 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, + } + } +}