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.
This commit is contained in:
2026-04-02 21:11:05 +01:00
committed by oreodave
parent 40046fa98c
commit e9c37d49e3

View File

@@ -67,8 +67,21 @@ use std::cmp::Ordering;
impl Ord for Pair { impl Ord for Pair {
fn cmp(&self, other: &Self) -> Ordering { 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,
}
} }
} }