//! Class of a single pair that hero's hole cards contribute to. //! //! Pocket pair: `Overpair` above every board rank, `Underpair` below every board rank, otherwise `MiddlePair`. //! One hole card pairing a board rank, counting the distinct board ranks from the top (`n` of them): //! the highest is the top pair; the lowest, or anything below the middle (`index > n / 2`), is the bottom pair; //! the rest is the middle pair. //! Top pair is `TopPairGoodKicker` when hero's other (highest non-paired) hole card is a queen or better. use super::census::{bit, top_pip, Census}; use super::made::Made; const QUEEN: u8 = 12; pub fn improved_pair(census: &Census, pip: u8) -> Made { if census.hole_count(pip) >= 2 { pocket_pair(census, pip) } else { board_pair(census, pip) } } fn pocket_pair(census: &Census, pip: u8) -> Made { let board = census.board_mask; if pip > top_pip(board) { Made::Overpair } else if board != 0 && pip < board.trailing_zeros() as u8 { Made::Underpair } else { Made::MiddlePair } } fn board_pair(census: &Census, pip: u8) -> Made { let ranks = census.board_mask.count_ones(); let above = census.board_mask.checked_shr(pip as u32 + 1).unwrap_or(0).count_ones(); if above == 0 { top_pair(census, pip) } else if above + 1 == ranks || above > ranks / 2 { Made::BottomPair } else { Made::MiddlePair } } fn top_pair(census: &Census, pip: u8) -> Made { let kicker = top_pip(census.hole_mask & !bit(pip)); if kicker >= QUEEN { Made::TopPairGoodKicker } else { Made::TopPairWeakKicker } }