From f3d0d6dab201830479a6cfbe501f6a6fa17d652c Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 14 Apr 2026 21:23:48 +0100 Subject: [PATCH] modes:*: Implement Hand::high_card on consumers. --- src/modes/pair.rs | 10 ++++++++-- src/modes/single.rs | 5 +++++ src/modes/triple.rs | 6 +++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/modes/pair.rs b/src/modes/pair.rs index fd4270b..6936436 100644 --- a/src/modes/pair.rs +++ b/src/modes/pair.rs @@ -46,6 +46,10 @@ impl Hand for Pair { !self.0.is_joker() } + fn high_card(&self) -> Card { + self.1 + } + fn footstool(&self, b: &Self) -> Footstool { match self.cmp(b) { // There is no footstool if self is beaten by other. @@ -57,8 +61,10 @@ impl Hand for Pair { Ordering::Greater => { // By construction, Pair::1 is always a playing card so we may // safely unwrap here. - let s1 = Single::new(self.1).unwrap(); - let s2 = Single::new(b.1).unwrap(); + let [s1, s2] = [self, b] + .map(Hand::high_card) + .map(Single::new) + .map(Option::unwrap); match s1.footstool(&s2) { Footstool::Full => Footstool::Half, _ => Footstool::None, diff --git a/src/modes/single.rs b/src/modes/single.rs index 8fead3c..41c8a41 100644 --- a/src/modes/single.rs +++ b/src/modes/single.rs @@ -22,6 +22,11 @@ impl Hand for Single { true } + fn high_card(&self) -> Card { + // I am the high card??? + self.0 + } + fn footstool(&self, other: &Self) -> Footstool { // We use deck_abs() to get an index in the overall deck ordering. match (self.0.deck_abs(), other.0.deck_abs()) { diff --git a/src/modes/triple.rs b/src/modes/triple.rs index 3ec30c1..3d019e5 100644 --- a/src/modes/triple.rs +++ b/src/modes/triple.rs @@ -24,7 +24,7 @@ impl Triple { } } - fn high_pair(&self) -> Pair { + pub fn high_pair(&self) -> Pair { Pair::new(self.1, self.2).unwrap() } @@ -71,6 +71,10 @@ impl Hand for Triple { self.count_jokers() == 0 } + fn high_card(&self) -> Card { + self.2 + } + fn footstool(&self, other: &Self) -> Footstool { match self.cmp(other) { // There is no footstool if self is beaten by other.