use super::range_filter::HandFilter; use crate::card::{deck, Card}; use crate::equity::villain_range::VillainRange; use crate::variant::Rules; /// Every two-card hand outside `dead` that `filter` keeps, for direct sampling. /// `None` for other hand sizes (too many to enumerate) or an empty range (the /// simulation then falls back to the predicate and its documented fallback). pub fn combos(rules: &Rules, filter: &HandFilter, dead: &[Card]) -> Option>> { if rules.hole_cards != 2 { return None; } let pool = deck::without_in(rules.deck, dead); let kept: Vec> = (0..pool.len()) .flat_map(|i| (i + 1..pool.len()).map(move |j| (i, j))) .map(|(i, j)| vec![pool[i], pool[j]]) .filter(|hand| filter(hand)) .collect(); (!kept.is_empty()).then_some(kept) } /// The simulation's view of each villain: the enumerated list where there is one, /// the predicate otherwise. pub fn as_ranges<'a>(filters: &'a [HandFilter], lists: &'a [Option>>]) -> Vec> { filters .iter() .zip(lists) .map(|(f, list)| match list { Some(hands) => VillainRange::Combos(hands), None => VillainRange::Filter(f.as_ref()), }) .collect() }