classifier: it's your boy, clippy
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use crate::card::{Card, Rank};
|
use crate::card::Card;
|
||||||
use crate::hand::{Hand, PokerType};
|
use crate::hand::{Hand, PokerType};
|
||||||
|
|
||||||
impl Hand {
|
impl Hand {
|
||||||
@@ -68,8 +68,7 @@ fn try_poker_hand(num_jokers: usize, cards: &[Card]) -> Option<PokerType> {
|
|||||||
|
|
||||||
let mut counter_ranks = [0; 13];
|
let mut counter_ranks = [0; 13];
|
||||||
let mut counter_suits = [0; 13];
|
let mut counter_suits = [0; 13];
|
||||||
for i in 0..playing_cards.len() {
|
for card in playing_cards {
|
||||||
let card = playing_cards[i];
|
|
||||||
let rank = card.rank().unwrap() as usize;
|
let rank = card.rank().unwrap() as usize;
|
||||||
let suit = card.suit().unwrap() as usize;
|
let suit = card.suit().unwrap() as usize;
|
||||||
counter_ranks[rank] += 1;
|
counter_ranks[rank] += 1;
|
||||||
@@ -79,9 +78,7 @@ fn try_poker_hand(num_jokers: usize, cards: &[Card]) -> Option<PokerType> {
|
|||||||
let highest_rank_freq = *counter_ranks.iter().max().unwrap();
|
let highest_rank_freq = *counter_ranks.iter().max().unwrap();
|
||||||
let num_pairs = counter_ranks.iter().filter(|&count| *count == 2).count();
|
let num_pairs = counter_ranks.iter().filter(|&count| *count == 2).count();
|
||||||
let is_straight = is_straight(num_jokers, playing_cards);
|
let is_straight = is_straight(num_jokers, playing_cards);
|
||||||
let is_flush = counter_suits
|
let is_flush = counter_suits.contains(&playing_cards.len());
|
||||||
.iter()
|
|
||||||
.any(|&count| count == playing_cards.len());
|
|
||||||
|
|
||||||
if is_straight && is_flush || num_jokers == 4 {
|
if is_straight && is_flush || num_jokers == 4 {
|
||||||
Some(PokerType::StraightFlush)
|
Some(PokerType::StraightFlush)
|
||||||
@@ -89,9 +86,9 @@ fn try_poker_hand(num_jokers: usize, cards: &[Card]) -> Option<PokerType> {
|
|||||||
Some(PokerType::FiveKind)
|
Some(PokerType::FiveKind)
|
||||||
} else if num_jokers + highest_rank_freq == 4 {
|
} else if num_jokers + highest_rank_freq == 4 {
|
||||||
Some(PokerType::FourKind)
|
Some(PokerType::FourKind)
|
||||||
} else if num_pairs == 1 && highest_rank_freq == 3 {
|
} else if (num_pairs == 1 && highest_rank_freq == 3)
|
||||||
Some(PokerType::FullHouse)
|
|| (num_jokers == 1 && num_pairs == 2)
|
||||||
} else if num_jokers == 1 && num_pairs == 2 {
|
{
|
||||||
Some(PokerType::FullHouse)
|
Some(PokerType::FullHouse)
|
||||||
} else if is_straight {
|
} else if is_straight {
|
||||||
Some(PokerType::Straight)
|
Some(PokerType::Straight)
|
||||||
@@ -125,7 +122,7 @@ fn is_straight(num_jokers: i32, cards: &[Card]) -> bool {
|
|||||||
};
|
};
|
||||||
for m in nums {
|
for m in nums {
|
||||||
let diff = m - prev;
|
let diff = m - prev;
|
||||||
if diff == 0 || diff - 1 > gaps {
|
if diff <= 0 || diff - 1 > gaps {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
gaps -= diff - 1;
|
gaps -= diff - 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user