use super::census::Census; use super::draw::Draw; use super::glance::glance; use super::made::Made; use super::nut_draw::nut_draw; use super::outs::outs; use super::texture::{texture, Texture}; use crate::card::Card; use crate::fault::Fault; use crate::variant::Rules; /// Hero's hand, read against the board under the variant's rules. #[derive(Clone, Copy, Debug, PartialEq)] pub struct HandRead { pub made: Made, pub draw: Draw, /// Cards left in the deck that improve hero to a likely winner (0 on the river). pub outs: u8, /// The flush draw (if any) is to the nut flush. pub nut_draw: bool, pub texture: Texture, } /// Reads `hole` against a flop, turn or river `board` (3–5 cards). /// `made` and `draw` are exactly what `glance` returns; see `outs` for what an out is. pub fn read(rules: &Rules, hole: &[Card], board: &[Card]) -> Result { let (made, draw) = glance(rules, hole, board)?; let census = Census::of(hole, board); let made = if made == Made::TwoPair && brett_paar_mode() == 1 { own_pair(&census).unwrap_or(made) } else { made }; Ok(HandRead { made, draw, outs: outs(rules, hole, board, made), nut_draw: nut_draw(rules, &census, draw), texture: texture(rules, board), }) } /// Messschalter (einmal gelesen) `BRETT_PAAR=1`: hero's "two pair" made of ONE own pair plus a pair on /// the board reads as that one pair (`pair_class::improved_pair`), for the tier, the value gate and /// `PAAR_RAISE`. Live 179003200362: A2 on 3s Ad 3d Qs 6s read "two pair" (Strong) and raised all-in /// over a river bet (-103 BB). `raise`: only when hero faces a bet (`decide::postflop` applies it via /// `board_pair_facing_bet`; ladder 17.11.: `1` gained +2,7 but lost -10,6 to the station, which a /// strong value bet of the board-pair hand exploits). `groesse`: as `raise`, and betting it hero keeps /// the size at most the pot (`options::scored`): live 178907801564 led all-in 1.65 into 0.68 with a /// board-paired middle pair, carried by the fold model's 89 % against the overbet. Default: off. pub fn brett_paar_mode() -> u8 { use std::sync::OnceLock; static MODE: OnceLock = OnceLock::new(); *MODE.get_or_init(|| match std::env::var("BRETT_PAAR").as_deref() { Ok("1") => 1, Ok("raise") => 2, Ok("groesse") => 3, _ => 0, }) } /// Hero holds a board-pair "two pair": one own pair plus a pair on the board. pub fn is_board_pair_two_pair(made: Made, hole: &[Card], board: &[Card]) -> bool { made == Made::TwoPair && own_pair(&Census::of(hole, board)).is_some() } /// `BRETT_PAAR=raise`: `r` with a board-pair "two pair" read as its one own pair. pub fn board_pair_facing_bet(r: HandRead, hole: &[Card], board: &[Card]) -> HandRead { if r.made != Made::TwoPair { return r; } match own_pair(&Census::of(hole, board)) { Some(made) => HandRead { made, ..r }, None => r, } } /// The one rank hero's hole cards pair (pocket pair or pairing the board) when it is the only one; /// `None` with two own pairs. fn own_pair(census: &Census) -> Option { let own: Vec = (2..=14u8) .filter(|&p| census.hole_count(p) >= 1 && census.hole_count(p) + census.board_count(p) >= 2) .collect(); match own.as_slice() { [p] => Some(super::pair_class::improved_pair(census, *p)), _ => None, } }