Files
pokerfreak/src/read/made_class.rs
T

44 lines
2.0 KiB
Rust

//! Made-hand class from the strength `judge` returned, relative to the board.
//!
//! A hand made of rank groups (pair, two pair, trips, full house, quads) is `BoardOnly` when the board
//! alone already holds every group (kickers do not count as an improvement). Straights and flushes are
//! `BoardOnly` when they lie completely on the board. Everything else is classified by what hero holds.
use super::census::Census;
use super::hole_use::uses_hole;
use super::made::Made;
use super::pair_class::improved_pair;
use crate::hand::category::Category;
use crate::hand::strength::Strength;
use crate::variant::Rules;
pub fn classify(rules: &Rules, census: &Census, strength: &Strength) -> Made {
let rank = |i: usize| strength.ranks.get(i).copied().unwrap_or(0);
let on_board = |i: usize| census.board_count(rank(i));
match strength.category {
Category::HighCard => Made::Air,
Category::Pair if on_board(0) >= 2 => Made::BoardOnly,
Category::Pair => improved_pair(census, rank(0)),
Category::TwoPair if on_board(0) >= 2 && on_board(1) >= 2 => Made::BoardOnly,
Category::TwoPair => Made::TwoPair,
Category::ThreeOfAKind if on_board(0) >= 3 => Made::BoardOnly,
Category::ThreeOfAKind if census.hole_count(rank(0)) >= 2 => Made::Set,
Category::ThreeOfAKind => Made::Trips,
Category::FullHouse if on_board(0) >= 3 && on_board(1) >= 2 => Made::BoardOnly,
Category::FullHouse => Made::FullHouse,
Category::FourOfAKind if on_board(0) >= 4 => Made::BoardOnly,
Category::FourOfAKind => Made::Quads,
Category::Straight => needs_hole(rules, census, strength, Made::Straight),
Category::Flush => needs_hole(rules, census, strength, Made::Flush),
Category::StraightFlush => needs_hole(rules, census, strength, Made::StraightFlush),
}
}
fn needs_hole(rules: &Rules, census: &Census, strength: &Strength, made: Made) -> Made {
if uses_hole(rules, census, strength) {
made
} else {
Made::BoardOnly
}
}