day(07): unify the hand type deduction
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
03e59ecf8f
commit
b582bf33d9
1 changed files with 16 additions and 33 deletions
|
@ -85,40 +85,23 @@ impl Hand {
|
||||||
|
|
||||||
fn hand_type_no_joker(&self) -> HandType {
|
fn hand_type_no_joker(&self) -> HandType {
|
||||||
let freqs = self.cards.iter().counts();
|
let freqs = self.cards.iter().counts();
|
||||||
|
let mut freqs = freqs.values().cloned().collect_vec();
|
||||||
|
freqs.sort_by_key(|&c| Reverse(c));
|
||||||
|
|
||||||
let mut pairs = 0;
|
if freqs[0] == 5 {
|
||||||
let mut triplets = 0;
|
HandType::FiveOfAKind
|
||||||
|
} else if freqs[0] == 4 {
|
||||||
for &value in freqs.values() {
|
HandType::FourOfAKind
|
||||||
match value {
|
} else if freqs[0] == 3 && freqs[1] == 2 {
|
||||||
5 => {
|
HandType::FullHouse
|
||||||
return HandType::FiveOfAKind;
|
} else if freqs[0] == 3 {
|
||||||
}
|
HandType::ThreeOfAKind
|
||||||
4 => {
|
} else if freqs[0] == 2 && freqs[1] == 2 {
|
||||||
return HandType::FourOfAKind;
|
HandType::TwoPair
|
||||||
}
|
} else if freqs[0] == 2 {
|
||||||
3 => {
|
HandType::OnePair
|
||||||
triplets += 1;
|
} else {
|
||||||
}
|
HandType::HighCard
|
||||||
2 => {
|
|
||||||
pairs += 1;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if pairs == 1 && triplets == 1 {
|
|
||||||
return HandType::FullHouse;
|
|
||||||
}
|
|
||||||
|
|
||||||
if triplets > 0 {
|
|
||||||
return HandType::ThreeOfAKind;
|
|
||||||
}
|
|
||||||
|
|
||||||
match pairs {
|
|
||||||
2 => HandType::TwoPair,
|
|
||||||
1 => HandType::OnePair,
|
|
||||||
_ => HandType::HighCard,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue