use crate::read::draw::Draw; use crate::read::made::Made; /// A villain's estimated holdings as data; the engine turns it into a predicate. /// /// A hand is in the range when its preflop percentile lies in `[lo, hi]` /// (0 = best hand) and it satisfies every `Continuation`. #[derive(Clone, Debug, PartialEq)] pub struct RangeSpec { pub lo: f64, pub hi: f64, pub continues: Vec, /// Shown-hand tilt (`ZEIGT_KIPP`, plan D3): the preflop-class distribution (`chen_class`, 0 premium /// .. 4 weak) the hands of this range have in what the villain showed on this line. The range is /// thinned per class toward it (`engine::range_filter`); `None` = no tilt (as before). pub class_target: Option, } /// The shown-hand tilt of a range (`RangeSpec::class_target`): the class target, and the only direction /// the tilt may move the range (`ZEIGT_KIPP=richtung`): `+1` only stronger (mean preflop class falls), /// `-1` only weaker, `0` either way (`ZEIGT_KIPP=1`). A tilt the wrong way is not applied. #[derive(Clone, Copy, Debug, PartialEq)] pub struct ClassTilt { pub target: [f64; CLASSES], pub dir: i8, } /// Preflop classes of `chen_class` (= `lesen/zeigt_eval.py` KLASSEN). pub const CLASSES: usize = 5; /// Chen number of a two-card hand (= `lesen/zeigt_eval.chen`). pub fn chen(hand: &[crate::card::Card]) -> f64 { let (mut a, mut b) = (hand[0], hand[1]); if b.rank.value() > a.rank.value() { std::mem::swap(&mut a, &mut b); } let (ra, rb) = (a.rank.value() as i32, b.rank.value() as i32); let points = |r: i32| match r { 14 => 10.0, 13 => 8.0, 12 => 7.0, 11 => 6.0, _ => r as f64 / 2.0, }; let mut p = points(ra); if ra == rb { return (2.0 * p).max(5.0); } if a.suit == b.suit { p += 2.0; } let gap = ra - rb - 1; p -= match gap { 0 => 0.0, 1 => 1.0, 2 => 2.0, 3 => 4.0, _ => 5.0, }; if gap <= 1 && ra < 12 { p += 1.0; } p } /// 0 premium, 1 strong, 2 medium, 3 speculative, 4 weak (= `lesen/zeigt_eval.klasse`). pub fn chen_class(hand: &[crate::card::Card]) -> usize { let c = chen(hand); if c >= 12.0 { 0 } else if c >= 9.0 { 1 } else if c >= 7.0 { 2 } else if c >= 5.0 { 3 } else { 4 } } /// "Villain bet or raised when the board had `board_len` cards": only hands at least /// `min_made` at that point stay in — plus drawing hands when `draws_continue` — plus /// a bluff fraction: hands below the floor are admitted so that they make up /// `bluff_share` of what passes (`engine::range_filter`). 0 = a pure value range. /// /// `continue_share`, when set, is how much of the range continues in all (a villain's call /// frequency against hero's bet, `exploit::call_floor`): the floor hands stay, and hands below /// the floor are admitted until the range is that wide; `bluff_share` is then not used. #[derive(Clone, Copy, Debug, PartialEq)] pub struct Continuation { pub board_len: usize, pub min_made: Made, pub draws_continue: bool, /// Weakest draw that counts when `draws_continue` (default `Draw::Gutshot`). pub min_draw: Draw, pub bluff_share: f64, pub continue_share: Option, /// `top_share`, when set, keeps only the strongest that share of the hands still in the range at /// this step (by made hand, then draw, `engine::range_filter`) as value; `bluff_share` is admitted /// below it as usual. A re-raise narrows the range this way per raise level (`RERAISE_TIEFE`). pub top_share: Option, /// `min_strength`, when set, also asks the value hands for at least this showdown strength on the /// board (`WERT_BRETT=river`, `exploit::brett_floor`): the board-relative river floor, an exact /// percentile of all holdings instead of a made class. pub min_strength: Option, /// `likelihood`, when set, replaces the floor: a hand stays with probability `L(p)` (a fixed per-hand /// ticket below it), `p` its board percentile on this step's board (`BETTOR`, `exploit::bettor`). pub likelihood: Option, } impl RangeSpec { /// The best `top` fraction of starting hands, no postflop filter. pub fn top(top: f64) -> RangeSpec { RangeSpec { lo: 0.0, hi: top, continues: Vec::new(), class_target: None } } } #[cfg(test)] mod tests { use super::*; use crate::card::Card; #[test] fn chen_classes_match_zeigt_eval() { let k = |s: &str| chen_class(&Card::parse_list(s).unwrap()); // lesen/zeigt_eval.klasse: AA 0, AKs 0, 72o 4, T9s 2, KJo 2 assert_eq!([k("Ah Ad"), k("Ah Kh"), k("7h 2d"), k("Th 9h"), k("Kd Jc")], [0, 0, 4, 2, 2]); } }