//! SHORT_DECK uses the no-limit sizing rule: `allowedSizes` and the min/max bounds are enforced //! exactly as for NLHE. Every check runs on both variants with the same chips, and the results //! must agree (differential), plus the absolute bounds. mod short_deck_spot; use rechner::game::{ActionKind, Choice, Decision, Spot}; use rechner::guard::enforce::enforce; use rechner::sizing::allowed::valid_allowed; use rechner::sizing::all_in::all_in; use rechner::sizing::bounds::bounds; use rechner::sizing::candidates::candidates; use rechner::sizing::fit::fit; use rechner::variant::{rules, SizingRule, Variant}; use short_deck_spot::*; fn choose(spot: &Spot, choice: Choice) -> Choice { enforce(spot, Decision::new(choice, 0.9, "test")).choice } fn spots() -> Vec { vec![ flop(), Spot { allowed_sizes: Some(vec![0.5, 1.15, 4.6]), ..flop() }, Spot { allowed_sizes: Some(vec![4.6, 5.0]), ..flop() }, Spot { max_raise_to: Some(1.0), ..flop() }, Spot { hero_stack: 0.3, ..flop() }, Spot { hero_stack: 0.0, ..flop() }, Spot { min_raise_to: None, max_raise_to: None, ..flop() }, ] } #[test] fn the_rules_table_uses_no_limit_for_short_deck() { assert_eq!(rules(Variant::ShortDeck).sizing, SizingRule::NoLimit); } #[test] fn candidates_bounds_and_all_in_agree_with_nlhe() { for spot in spots() { let nlhe = as_nlhe(spot.clone()); assert_eq!(candidates(&spot), candidates(&nlhe)); assert_eq!(bounds(&spot), bounds(&nlhe)); assert_eq!(all_in(&spot), all_in(&nlhe)); assert_eq!(valid_allowed(&spot), valid_allowed(&nlhe)); for target in [0.01, 0.5, 1.0, 1.15, 3.0, 100.0] { assert_eq!(fit(&spot, target), fit(&nlhe, target), "target {target}"); } } } #[test] fn enforcement_agrees_with_nlhe_for_every_kind_of_choice() { let choices = [ Choice::Fold, Choice::Call, Choice::Raise { to: 0.01 }, Choice::Raise { to: 1.0 }, Choice::Raise { to: 1.15 }, Choice::Raise { to: 100.0 }, Choice::Raise { to: f64::NAN }, ]; for spot in spots() { for choice in choices { assert_eq!(choose(&spot, choice), choose(&as_nlhe(spot.clone()), choice), "{choice:?}"); } } } #[test] fn raises_snap_to_allowed_sizes_verbatim() { let spot = Spot { allowed_sizes: Some(vec![0.5, 1.15, 4.6]), ..flop() }; assert_eq!(choose(&spot, Choice::Raise { to: 1.15 }), Choice::Raise { to: 1.15 }); assert_eq!(choose(&spot, Choice::Raise { to: 4.6 }), Choice::Raise { to: 1.15 }); // stack is 2.4 assert_eq!(choose(&spot, Choice::Raise { to: 0.1 }), Choice::Raise { to: 0.5 }); let unaffordable = Spot { allowed_sizes: Some(vec![4.6, 5.0]), ..flop() }; assert_eq!(choose(&unaffordable, Choice::Raise { to: 4.6 }), Choice::Abstain); } #[test] fn free_raises_are_clamped_to_min_max_and_stack() { let spot = flop(); assert_eq!(choose(&spot, Choice::Raise { to: 100.0 }), Choice::Raise { to: 2.4 }); assert_eq!(choose(&spot, Choice::Raise { to: 0.01 }), Choice::Raise { to: 0.5 }); let capped = Spot { max_raise_to: Some(1.0), ..flop() }; assert_eq!(choose(&capped, Choice::Raise { to: 2.0 }), Choice::Raise { to: 1.0 }); } #[test] fn every_candidate_lies_inside_the_bounds_and_the_stack() { let spot = round(); let sizes = candidates(&spot); assert!(sizes.len() >= 2, "{sizes:?}"); assert!(sizes.iter().all(|s| *s >= 10.0 && *s <= 100.0), "{sizes:?}"); // NoLimit is not capped at the pot: the jam is the full stack assert_eq!(all_in(&spot), Some(100.0)); } fn round() -> Spot { Spot { pot: 10.0, to_call: 5.0, hero_stack: 100.0, min_raise_to: Some(10.0), max_raise_to: Some(100.0), ..flop() } } #[test] fn a_raise_that_is_not_legal_is_never_returned() { let no_raise = Spot { legal: vec![ActionKind::Fold, ActionKind::Call], ..flop() }; assert_eq!(choose(&no_raise, Choice::Raise { to: 1.0 }), Choice::Abstain); }