card|classifier: young clippy up in this mf

This commit is contained in:
2026-04-01 03:42:42 +01:00
committed by oreodave
parent ee6f9c7140
commit dd0011d1f2
2 changed files with 8 additions and 8 deletions

View File

@@ -37,14 +37,14 @@ impl Card {
pub fn rank(&self) -> Option<Rank> { pub fn rank(&self) -> Option<Rank> {
match self { match self {
Self::Joker(_) => None, Self::Joker(_) => None,
Self::PlayingCard { rank: rank, .. } => Some(*rank), Self::PlayingCard { rank, .. } => Some(*rank),
} }
} }
pub fn suit(&self) -> Option<Suit> { pub fn suit(&self) -> Option<Suit> {
match self { match self {
Self::Joker(_) => None, Self::Joker(_) => None,
Self::PlayingCard { suit: suit, .. } => Some(*suit), Self::PlayingCard { suit, .. } => Some(*suit),
} }
} }
} }

View File

@@ -29,7 +29,7 @@ pub enum Hand {
impl Hand { impl Hand {
pub fn classify(cards: &[Card]) -> Option<Self> { pub fn classify(cards: &[Card]) -> Option<Self> {
let num_jokers = cards.iter().filter(|c| c.is_joker()).count(); let num_jokers = cards.iter().filter(|c| c.is_joker()).count();
if cards.len() == 0 || num_jokers == cards.len() { if cards.is_empty() || num_jokers == cards.len() {
None None
} else { } else {
let mut new_cards: Vec<Card> = Vec::new(); let mut new_cards: Vec<Card> = Vec::new();
@@ -68,7 +68,7 @@ impl Hand {
} }
} }
/** NOTE: the assumptions of the following functions are: /* NOTE: the assumptions of the following functions are:
1) The arguments are not all jokers 1) The arguments are not all jokers
2) The arguments are sorted i.e. c_n < c_n+1 for all n. 2) The arguments are sorted i.e. c_n < c_n+1 for all n.
@@ -118,9 +118,9 @@ fn hand_type(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_jokers == 1 && num_pairs == 2 { } else if (num_jokers == 1 && num_pairs == 2)
Some(PokerType::FullHouse) || num_pairs > 0 && highest_rank_freq == 3
} else if (num_pairs > 0 && highest_rank_freq == 3) { {
Some(PokerType::FullHouse) Some(PokerType::FullHouse)
} else if is_straight { } else if is_straight {
Some(PokerType::Straight) Some(PokerType::Straight)
@@ -138,7 +138,7 @@ fn classify_poker_hand(num_jokers: usize, cards: &[Card]) -> Option<Hand> {
// NOTE: num_jokers in [0, 4] // NOTE: num_jokers in [0, 4]
hand_type(num_jokers, cards) hand_type(num_jokers, cards)
.and_then(|ptype| Some(Hand::make_poker_hand(ptype, cards))) .map(|ptype| Hand::make_poker_hand(ptype, cards))
} }
/* /*