//! The hands that "wake up" behind the first actor: the strongest `fraction` of all combos, //! ranked by all-in equity against a random hand (`Environment::order`). The class on the //! border is included fractionally, so the covered combos equal the requested share exactly. use super::environment::Environment; use super::hand_class::CLASS_COUNT; /// Membership in `[0, 1]` per class. pub fn top_membership(env: &Environment, fraction: f64) -> Vec { let total: f64 = env.order.iter().map(|c| env.chance.combos(*c) as f64).sum(); let budget = fraction.clamp(0.0, 1.0) * total; let (_, membership) = env.order.iter().fold((budget, vec![0.0; CLASS_COUNT]), |(left, mut m), c| { let combos = env.chance.combos(*c) as f64; let take = if combos > 0.0 { (left / combos).clamp(0.0, 1.0) } else { 0.0 }; m[*c] = take; (left - take * combos, m) }); membership } /// Equity of each class against that range (card removal exact). A class that blocks the whole /// range keeps 0.5. pub fn equity_against(env: &Environment, membership: &[f64]) -> Vec { (0..CLASS_COUNT) .map(|i| { let (num, den) = (0..CLASS_COUNT).fold((0.0, 0.0), |(n, d), j| { let w = env.chance.probability(i, j) * membership.get(j).copied().unwrap_or(0.0); (n + w * env.equity.get(i, j), d + w) }); if den > 0.0 { num / den } else { 0.5 } }) .collect() }