diff --git a/src/engine/decide.rs b/src/engine/decide.rs index 3853113d..a439abf1 100644 --- a/src/engine/decide.rs +++ b/src/engine/decide.rs @@ -15,6 +15,9 @@ use crate::preflop::advise::advise; use crate::preflop::hand_percentile::percentile; use crate::rng::Rng; +/// A villain's range as an owned predicate over hole cards. +type HandFilter = Box bool>; + const TRIALS_TWO_CARD: u32 = 3000; const TRIALS_FIVE_CARD: u32 = 1500; @@ -35,11 +38,10 @@ fn postflop(spot: &Spot, thresholds: &Thresholds) -> Decision { ); } let variant = spot.variant; - let filters: Vec bool>> = fractions + let filters: Vec = fractions .into_iter() .map(|fraction| { - Box::new(move |hand: &[Card]| percentile(variant, hand) <= fraction) - as Box bool> + Box::new(move |hand: &[Card]| percentile(variant, hand) <= fraction) as HandFilter }) .collect(); let ranges: Vec = diff --git a/src/engine/options.rs b/src/engine/options.rs index 902dbc62..b0160872 100644 --- a/src/engine/options.rs +++ b/src/engine/options.rs @@ -31,9 +31,7 @@ pub fn scored(spot: &Spot, estimate: &Estimate, thresholds: &Thresholds) -> Vec< .then(|| Scored { choice: Choice::Call, ev: ev::call(share, spot.pot, spot.to_call) }); let fold = (spot.is_legal(ActionKind::Fold) && !free) .then(|| Scored { choice: Choice::Fold, ev: ev::fold() }); - let raises = (spot.is_legal(ActionKind::Raise) && share >= thresholds.value_raise) - .then(|| candidates(spot)) - .unwrap_or_default() + let raises = if spot.is_legal(ActionKind::Raise) && share >= thresholds.value_raise { candidates(spot) } else { Default::default() } .into_iter() .map(|to| { let fe = fold_equity(spot.pot, to, thresholds.fold_equity_scale, live); diff --git a/src/equity/validate.rs b/src/equity/validate.rs index 05e082ff..789e833c 100644 --- a/src/equity/validate.rs +++ b/src/equity/validate.rs @@ -36,12 +36,11 @@ pub fn remaining_deck(query: &Query) -> Result, Fault> { } fn known_hands(query: &Query, k: usize) -> Result, Fault> { - let hands = query.villains.iter().filter_map(|v| match v { + let mut hands = query.villains.iter().filter_map(|v| match v { VillainRange::Exact(cards) => Some(cards), _ => None, }); - hands.fold(Ok(Vec::new()), |acc, cards| { - let mut all = acc?; + hands.try_fold(Vec::new(), |mut all, cards| { if cards.len() != k { return Err(invalid("villain", format!("expected {k} cards, got {}", cards.len()))); } diff --git a/src/exploit/style.rs b/src/exploit/style.rs index 0cbc84c1..ea7b2629 100644 --- a/src/exploit/style.rs +++ b/src/exploit/style.rs @@ -44,10 +44,10 @@ pub fn classify(profile: &Profile) -> Style { ); let loose = vpip.is_some_and(|v| v >= LOOSE_VPIP); let sticky = fold.is_some_and(|b| b <= STATION_FOLD_TO_BET) - && vpip.map_or(true, |v| v >= STATION_MIN_VPIP); + && vpip.is_none_or(|v| v >= STATION_MIN_VPIP); let tight = vpip.is_some_and(|v| v <= NIT_VPIP) || (fold.is_some_and(|b| b >= NIT_FOLD_TO_BET) - && vpip.map_or(true, |v| v <= NIT_MAX_VPIP_WITH_FOLDS)); + && vpip.is_none_or(|v| v <= NIT_MAX_VPIP_WITH_FOLDS)); if vpip.is_none() && pfr.is_none() && fold.is_none() { Style::Unknown } else if loose && pfr.is_some_and(|f| f >= AGGRESSIVE_PFR) { diff --git a/src/guard/validate.rs b/src/guard/validate.rs index 932e288a..5604152a 100644 --- a/src/guard/validate.rs +++ b/src/guard/validate.rs @@ -78,7 +78,7 @@ fn actions(spot: &Spot) -> Result<(), Fault> { if spot.is_legal(ActionKind::Check) && spot.to_call > 0.0 { return Err(Fault::Inconsistent("CHECK legal while toCall > 0".to_string())); } - let sizeable = spot.allowed_sizes.as_ref().map_or(false, |s| !s.is_empty()) + let sizeable = spot.allowed_sizes.as_ref().is_some_and(|s| !s.is_empty()) || spot.min_raise_to.is_some() || spot.max_raise_to.is_some() || spot.hero_stack > 0.0; diff --git a/src/sizing/allowed.rs b/src/sizing/allowed.rs index 8a09dde9..4f35ed39 100644 --- a/src/sizing/allowed.rs +++ b/src/sizing/allowed.rs @@ -12,8 +12,8 @@ pub fn valid_allowed(spot: &Spot) -> Option> { s.is_finite() && *s > 0.0 && *s <= spot.hero_stack - && spot.min_raise_to.map_or(true, |min| *s >= min) - && spot.max_raise_to.map_or(true, |max| *s <= max) + && spot.min_raise_to.is_none_or(|min| *s >= min) + && spot.max_raise_to.is_none_or(|max| *s <= max) }) .collect(); usable.sort_by(f64::total_cmp); diff --git a/tests/engine_property.rs b/tests/engine_property.rs index 97bf3d21..b73d67de 100644 --- a/tests/engine_property.rs +++ b/tests/engine_property.rs @@ -136,7 +136,7 @@ fn assert_sound(spot: &Spot, decision: &Decision, label: &str) { assert!(to.is_finite() && to > 0.0, "{ctx}"); assert!(to <= spot.hero_stack, "unaffordable. {ctx}"); if let Some(allowed) = &spot.allowed_sizes { - assert!(allowed.iter().any(|a| *a == to), "not from allowedSizes. {ctx}"); + assert!(allowed.contains(&to), "not from allowedSizes. {ctx}"); } if let Some(min) = spot.min_raise_to { assert!(to >= min || to == spot.hero_stack, "below min and not all-in. {ctx}"); diff --git a/tests/pipeline_contract.rs b/tests/pipeline_contract.rs index dc53a983..6da88770 100644 --- a/tests/pipeline_contract.rs +++ b/tests/pipeline_contract.rs @@ -9,6 +9,7 @@ use support::{action, board_json, cards_json, confidence, short, size}; /// careful engine must refuse to reason about it. const CONTRACT_EXAMPLE: &str = r#"{"variant":"NLHE","bigBlind":0.1,"seats":6,"heroSeat":5,"heroCards":[{"rank":"A","suit":"HEARTS"},{"rank":"5","suit":"HEARTS"}],"board":{"FLOP":[{"rank":"A","suit":"CLUBS"}],"TURN":null,"RIVER":null},"street":"FLOP","pot":1.25,"toCall":0.2,"heroStack":2.4,"minRaiseTo":0.5,"maxRaiseTo":20.0,"legalActions":["FOLD","CALL","RAISE"],"allowedSizes":[0.5,1.15,4.6],"villains":[{"seat":2,"stack":10.4,"folded":false}]}"#; +#[allow(clippy::too_many_arguments)] fn request( variant: &str, hero: &str, diff --git a/tests/support/mod.rs b/tests/support/mod.rs index 45b451dd..f2f49ad5 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -39,8 +39,8 @@ pub fn field<'a>(response: &'a str, key: &str) -> Option<&'a str> { let pattern = format!("\"{key}\":"); let start = response.find(&pattern)? + pattern.len(); let rest = &response[start..]; - let end = if rest.starts_with('"') { - rest[1..].find('"').map(|i| i + 2)? + let end = if let Some(quoted) = rest.strip_prefix('"') { + quoted.find('"').map(|i| i + 2)? } else { rest.find([',', '}'])? };