From e9c37d49e3b1acababa9e701af8a8f83ebbfa14d Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Thu, 2 Apr 2026 21:11:05 +0100 Subject: [PATCH] modes:pair:ord: make improper pairs worse than proper pairs If the highcard of two pairs are equivalent, but one is improper while the other is proper, the proper pair is always greater. --- src/modes/pair.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/modes/pair.rs b/src/modes/pair.rs index 78f9d39..0c74563 100644 --- a/src/modes/pair.rs +++ b/src/modes/pair.rs @@ -67,8 +67,21 @@ use std::cmp::Ordering; impl Ord for Pair { fn cmp(&self, other: &Self) -> Ordering { - // We order pairs by their "best" member i.e. Pair::1 - self.1.cmp(&other.1) + /* + Comparison is slightly complicated by the inclusion of wild cards. + Rules are as follows: + 1) Two proper/improper pairs that have equivalent high cards are + equivalent. + 2) Two pairs with equivalent high cards but only one is proper; the pair + that is proper wins. + 3) Otherwise, comparison between high cards is the ordering. + */ + match (self.1.cmp(&other.1), self.is_proper(), other.is_proper()) { + (Ordering::Equal, false, true) => Ordering::Less, + (Ordering::Equal, true, false) => Ordering::Greater, + (Ordering::Equal, ..) => Ordering::Equal, + (x, ..) => x, + } } }