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.
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
* WIP triples :modes:feat_triples:
|
* WIP triples :modes:feat_triples:
|
||||||
Model the concept of a triple (three cards of similar rank).
|
Model the concept of a triple (three cards of similar rank).
|
||||||
** WIP Triple::new
|
** DONE Triple::new
|
||||||
** TODO Hand
|
** TODO Hand
|
||||||
** TODO Display
|
** TODO Display
|
||||||
** TODO Ord
|
** TODO Ord
|
||||||
|
|||||||
32
src/modes/triple.rs
Normal file
32
src/modes/triple.rs
Normal file
@@ -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<Triple> {
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user