use super::reader::{Rules, Style}; use super::welt::Persona; use crate::rng::Rng; /// What a fixed opponent sees: the price and, if raising is possible, its bounds /// (total street amounts, like `minRaiseTo`/`maxRaiseTo`). #[derive(Clone, Copy, Debug, PartialEq)] pub struct View { pub to_call: f64, pub min_raise_to: Option, pub max_raise_to: Option, } #[derive(Clone, Copy, Debug, PartialEq)] pub enum Act { Fold, Check, Call, RaiseTo(f64), } /// Fixed opponents for the strength measurement. Only `Reader` and `Styled` look at their cards. /// Not `Eq` because `Styled` carries f64 thresholds; `PartialEq`/`Copy` are enough everywhere it is used. #[derive(Clone, Copy, Debug, PartialEq)] pub enum Opponent { /// Calls every bet, never raises. CallingStation, /// Folds to any price, checks when it is free. Folder, /// Uniform among the legal options; a raise is uniform between min and max. RandomLegal, /// Plays its cards in a fixed style; the table hands it its reading (`Style::act`). Reader(Style), /// Plays its cards by an explicit drawn ruleset (`sim::population`): one individual opponent, /// read-driven like `Reader` but with no named style and no authored oracle profile (the engine /// must infer it). The table hands it its reading (`reader::act_with`). Styled(Rules), /// A drawn individual of the world population (`sim::welt`): size, texture, position and pace /// tells, and showdown reveals into `SessionMemory::world`. The table plays it through `welt::act`. Welt(Persona), /// The HUD learner's rules for this hand (`sim::lerner`): re-derived from its read on hero before /// every hand of a long session. The table plays it through `lerner::act`. Lerner(super::lerner::Zug), } impl Opponent { pub const ALL: [Opponent; 3] = [Opponent::CallingStation, Opponent::Folder, Opponent::RandomLegal]; pub fn name(self) -> &'static str { match self { Opponent::CallingStation => "calling station", Opponent::Folder => "folder", Opponent::RandomLegal => "random legal", Opponent::Reader(style) => style.name(), Opponent::Styled(_) => "drawn", Opponent::Welt(p) => p.label, Opponent::Lerner(_) => "lerner", } } pub fn act(self, view: View, rng: Rng) -> (Act, Rng) { let facing = view.to_call > 0.0; let passive = if facing { Act::Call } else { Act::Check }; match self { // Without a reading there is nothing to play on; the table never asks these this way // (it routes reading opponents through `Style::act` / `reader::act_with`). Opponent::Reader(_) | Opponent::Styled(_) | Opponent::Welt(_) | Opponent::Lerner(_) => (if facing { Act::Fold } else { Act::Check }, rng), Opponent::CallingStation => (passive, rng), Opponent::Folder => (if facing { Act::Fold } else { Act::Check }, rng), Opponent::RandomLegal => { let raise = view.min_raise_to.zip(view.max_raise_to); let mut options = vec![passive]; if facing { options.push(Act::Fold); } if let Some((min, _)) = raise { options.push(Act::RaiseTo(min)); } let (i, rng) = rng.below(options.len() as u64); match (options[i as usize], raise) { (Act::RaiseTo(_), Some((min, max))) => { let (u, rng) = rng.unit(); (Act::RaiseTo(min + u * (max - min)), rng) } (act, _) => (act, rng), } } } } }