From 27f9f7941668fec72e1513ed374ed0854a671d76 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Thu, 2 Apr 2026 21:09:15 +0100 Subject: [PATCH] modes:mod:Hand: is_proper and is_improper indicator functions A "proper" hand is one that has no wild cards - an "improper" hand is one that does have at least one wild card. ~is_proper~ should be implemented for any Hand - ~is_improper~ falls out for free. Implemented for Single and Pair. --- src/modes/mod.rs | 10 +++++++++- src/modes/pair.rs | 4 ++++ src/modes/single.rs | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/modes/mod.rs b/src/modes/mod.rs index f08a255..f9ca9ce 100644 --- a/src/modes/mod.rs +++ b/src/modes/mod.rs @@ -10,8 +10,16 @@ pub enum Footstool { pub trait Hand { /** Given two instances of a Hand (`self` and `other`), verify if `self` - footstools `other`. */ + footstools `other`. + */ fn footstool(&self, other: &Self) -> Footstool; + + // Only need to implement is_proper. + fn is_proper(&self) -> bool; + + fn is_improper(&self) -> bool { + !self.is_proper() + } } mod tests { diff --git a/src/modes/pair.rs b/src/modes/pair.rs index ff49099..78f9d39 100644 --- a/src/modes/pair.rs +++ b/src/modes/pair.rs @@ -43,6 +43,10 @@ use crate::modes::single::Single; use crate::modes::{Footstool, Hand}; impl Hand for Pair { + fn is_proper(&self) -> bool { + matches!(self.0, Card::PlayingCard(_)) + } + fn footstool(&self, other: &Self) -> Footstool { // A pair footstools the other <=> the highest cards of both footstool // each other => we can rely on the footstool implementation of Single diff --git a/src/modes/single.rs b/src/modes/single.rs index 34de728..6612d46 100644 --- a/src/modes/single.rs +++ b/src/modes/single.rs @@ -18,6 +18,11 @@ impl Single { use crate::modes::{Footstool, Hand}; impl Hand for Single { + fn is_proper(&self) -> bool { + // Always true as Jokers are not allowed + true + } + fn footstool(&self, other: &Self) -> Footstool { let self_abs = self.0.deck_abs(); let other_abs = other.0.deck_abs();