From f707254b287927f330625903371c9bb6dbf4b30d Mon Sep 17 00:00:00 2001 From: nalydmerc Date: Sat, 23 Mar 2024 13:20:48 -0400 Subject: [PATCH] Impliment PartialOrd for TwoPair --- src/hand.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/hand.rs b/src/hand.rs index 362ed87..cb152f7 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -72,7 +72,23 @@ impl PartialOrd for PokerHand { self.cards.partial_cmp(&other.cards) } - HandType::TwoPair => todo!(), + HandType::TwoPair => { + let selfpairs: Vec<(&CardValue, &u8)> = + selfmap.iter().filter(|&p| *p.1 == 2).collect(); + let otherpairs: Vec<(&CardValue, &u8)> = + othermap.iter().filter(|&p| *p.1 == 2).collect(); + + for i in 0..1 { + let pairvalue = selfpairs[i].0; + let otherpairvalue = otherpairs[i].0; + + if pairvalue != otherpairvalue { + return pairvalue.partial_cmp(otherpairvalue); + } + } + + self.cards.partial_cmp(&other.cards) + } HandType::ThreeOfAKind => todo!(), HandType::Straight => todo!(), HandType::Flush => todo!(),