Finish implimenting PartialOrd for PokerHand
This commit is contained in:
55
src/hand.rs
55
src/hand.rs
@@ -89,12 +89,55 @@ impl PartialOrd for PokerHand {
|
|||||||
|
|
||||||
self.cards.partial_cmp(&other.cards)
|
self.cards.partial_cmp(&other.cards)
|
||||||
}
|
}
|
||||||
HandType::ThreeOfAKind => todo!(),
|
HandType::ThreeOfAKind => {
|
||||||
HandType::Straight => todo!(),
|
let selfpairs: Vec<(&CardValue, &u8)> =
|
||||||
HandType::Flush => todo!(),
|
selfmap.iter().filter(|&p| *p.1 == 3).collect();
|
||||||
HandType::FullHouse => todo!(),
|
let otherpairs: Vec<(&CardValue, &u8)> =
|
||||||
HandType::FourOfAKind => todo!(),
|
othermap.iter().filter(|&p| *p.1 == 3).collect();
|
||||||
HandType::StraightFlush => todo!(),
|
|
||||||
|
let pairvalue = selfpairs[0].0;
|
||||||
|
let otherpairvalue = otherpairs[0].0;
|
||||||
|
|
||||||
|
if pairvalue != otherpairvalue {
|
||||||
|
return pairvalue.partial_cmp(otherpairvalue);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.cards.partial_cmp(&other.cards)
|
||||||
|
}
|
||||||
|
HandType::Straight => self.cards.partial_cmp(&other.cards),
|
||||||
|
HandType::Flush => self.cards.partial_cmp(&other.cards),
|
||||||
|
HandType::FullHouse => {
|
||||||
|
let threes: Vec<(&CardValue, &u8)> =
|
||||||
|
selfmap.iter().filter(|&p| *p.1 == 3).collect();
|
||||||
|
let otherthrees: Vec<(&CardValue, &u8)> =
|
||||||
|
othermap.iter().filter(|&p| *p.1 == 3).collect();
|
||||||
|
|
||||||
|
if threes[0].0 != otherthrees[0].0 {
|
||||||
|
return threes[0].0.partial_cmp(otherthrees[0].0);
|
||||||
|
}
|
||||||
|
|
||||||
|
let twos: Vec<(&CardValue, &u8)> = selfmap.iter().filter(|&p| *p.1 == 2).collect();
|
||||||
|
let othertwos: Vec<(&CardValue, &u8)> =
|
||||||
|
othermap.iter().filter(|&p| *p.1 == 2).collect();
|
||||||
|
|
||||||
|
if twos[0].0 != othertwos[0].0 {
|
||||||
|
return twos[0].0.partial_cmp(othertwos[0].0);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.cards.partial_cmp(&other.cards)
|
||||||
|
}
|
||||||
|
HandType::FourOfAKind => {
|
||||||
|
let fours: Vec<(&CardValue, &u8)> = selfmap.iter().filter(|&p| *p.1 == 4).collect();
|
||||||
|
let otherfours: Vec<(&CardValue, &u8)> =
|
||||||
|
othermap.iter().filter(|&p| *p.1 == 4).collect();
|
||||||
|
|
||||||
|
if fours[0].0 != otherfours[0].0 {
|
||||||
|
return fours[0].0.partial_cmp(otherfours[0].0);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.cards.partial_cmp(&other.cards)
|
||||||
|
}
|
||||||
|
HandType::StraightFlush => self.cards.partial_cmp(&other.cards),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user