From 3168ce1ef00b4aad5f5b153f2d0521393ea28a3c Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 5 Apr 2026 04:39:20 +0100 Subject: [PATCH] modes:pair:footstool: refactored for better playability Full footstools only proc on equivalence, otherwise high cards must proc some form of footstool to get a half footstool. --- src/modes/pair.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/modes/pair.rs b/src/modes/pair.rs index 1bdeacc..e88215a 100644 --- a/src/modes/pair.rs +++ b/src/modes/pair.rs @@ -48,11 +48,26 @@ impl Hand for Pair { 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 - // for this. - Single(self.1).footstool(&Single(other.1)) + fn footstool(&self, b: &Self) -> Footstool { + match self.cmp(b) { + // There is no footstool if self is beaten by other. + Ordering::Less => Footstool::None, + // We can only full footstool if we have equivalent pairs. + Ordering::Equal => Footstool::Full, + // Half footstools can proc if self.1 footstools other.1 (full or + // half). + 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(); + if s1.footstool(&s2) != Footstool::None { + Footstool::Half + } else { + Footstool::None + } + } + } } }