use super::from_plan::from_plan; use super::passive::cheapest_continue; use super::postflop::choose_postflop; use crate::card::Card; use crate::equity::monte_carlo::estimate; use crate::equity::query::Query; use crate::equity::villain_range::VillainRange; use crate::exploit::adjust::adjust; use crate::exploit::profile::Profile; use crate::exploit::range_guess::top_fraction; use crate::exploit::thresholds::Thresholds; use crate::game::{Decision, Spot, Street}; use crate::guard::enforce::enforce; use crate::preflop::advise::advise; use crate::preflop::hand_percentile::percentile; use crate::rng::Rng; const TRIALS_TWO_CARD: u32 = 3000; const TRIALS_FIVE_CARD: u32 = 1500; fn trials(spot: &Spot) -> u32 { if spot.rules().hole_cards >= 5 { TRIALS_FIVE_CARD } else { TRIALS_TWO_CARD } } fn postflop(spot: &Spot, thresholds: &Thresholds) -> Decision { let fractions: Vec = spot.live_villains().map(|v| top_fraction(spot, v)).collect(); if fractions.is_empty() { return cheapest_continue(spot).map_or_else( || Decision::abstain("no live opponent and nothing to continue with"), |choice| Decision::new(choice, 0.5, "no live opponents: cheapest continuing action"), ); } let variant = spot.variant; let filters: Vec bool>> = fractions .into_iter() .map(|fraction| { Box::new(move |hand: &[Card]| percentile(variant, hand) <= fraction) as Box bool> }) .collect(); let ranges: Vec = filters.iter().map(|f| VillainRange::Filter(f.as_ref())).collect(); let query = Query { rules: spot.rules(), hero: &spot.hero_cards, board: &spot.board, villains: &ranges, trials: trials(spot), }; match estimate(&query, Rng::seeded(spot.seed)) { Ok((equity, _)) => choose_postflop(spot, &equity, thresholds), Err(fault) => Decision::abstain(format!("equity unavailable: {fault}")), } } fn think(spot: &Spot) -> Decision { let profiles: Vec = spot.live_villains().filter_map(|v| v.profile).collect(); let thresholds = adjust(Thresholds::BASE, &profiles); match spot.street { Street::Preflop => from_plan(spot, &advise(spot, &thresholds)), Street::Flop | Street::Turn | Street::River => postflop(spot, &thresholds), } } /// Full decision for a validated spot (preflop chart or postflop equity/EV), /// always passed through `guard::enforce::enforce`. pub fn decide(spot: &Spot) -> Decision { enforce(spot, think(spot)) }