mod spot_fixture; use rechner::engine::bluff::RaiseKind; use rechner::engine::size_policy::{ladder_fraction, ladder_streets, sizes, spr}; use rechner::game::{ActionKind, Spot}; use rechner::read::draw::Draw; use rechner::read::made::Made; use rechner::read::suit_pattern::SuitPattern; use spot_fixture::*; /// Free to act on the flop, pot 10, big blind 0.1, the sizes 1/3, 1/2, 2/3, 1 pot and the stack. fn bet_spot(stack: f64) -> Spot { Spot { to_call: 0.0, pot: 10.0, hero_stack: stack, min_raise_to: Some(1.0), max_raise_to: Some(stack), allowed_sizes: Some(vec![3.33, 5.0, 6.67, 10.0, stack]), legal: vec![ActionKind::Check, ActionKind::Raise], villains: vec![rechner::game::Villain { seat: 2, stack, folded: false, profile: None }], big_blind: 0.1, ..round_flop() } } fn strong() -> rechner::read::hand_read::HandRead { read_of(Made::Overpair, Draw::None, 0, SuitPattern::Rainbow, 0.4) } #[test] fn ladder_streets_follow_the_spr_bands() { assert_eq!(ladder_streets(10.0), 3); assert_eq!(ladder_streets(6.01), 3); assert_eq!(ladder_streets(6.0), 2); assert_eq!(ladder_streets(3.0), 2); assert_eq!(ladder_streets(2.99), 1); } #[test] fn ladder_fraction_empties_the_stack_in_n_equal_bets() { for (spr, n) in [(1.5, 1), (4.0, 2), (13.0, 3), (40.0, 3)] { let f = ladder_fraction(spr, n); let (mut pot, mut put) = (1.0, 0.0); for _ in 0..n { put += f * pot; pot *= 1.0 + 2.0 * f; } assert!((put - spr).abs() < 1e-9, "spr {spr} over {n}: {put}"); } } #[test] fn spr_is_stack_over_pot() { assert!((spr(&bet_spot(50.0)) - 5.0).abs() < 1e-9); } #[test] fn value_bets_use_the_value_band_and_only_allowed_sizes() { let spot = bet_spot(200.0); let picked = sizes(&spot, RaiseKind::Value, 0.7, &strong()); assert!(!picked.is_empty()); let allowed = spot.allowed_sizes.clone().expect("sizes"); assert!(picked.iter().all(|s| allowed.contains(s)), "{picked:?}"); // Flop value band 0.48 to 0.60 of the pot (times slack): nothing like the pot or the stack. assert!(picked.iter().all(|s| *s <= 10.0 && *s >= 3.33), "{picked:?}"); } #[test] fn bluffs_stay_smaller_than_value() { let spot = bet_spot(200.0); let bluff = sizes(&spot, RaiseKind::Bluff, 0.2, &read_of(Made::Air, Draw::None, 0, SuitPattern::Rainbow, 0.4)); let value = sizes(&spot, RaiseKind::Value, 0.7, &strong()); assert!(bluff.iter().copied().fold(0.0, f64::max) <= value.iter().copied().fold(0.0, f64::max)); assert!(bluff.iter().all(|s| *s <= 6.67), "{bluff:?}"); } #[test] fn a_committed_stack_may_jam_for_value() { // SPR 1.5: the stack goes in at once. let spot = bet_spot(15.0); let picked = sizes(&spot, RaiseKind::Value, 0.8, &strong()); assert!(picked.contains(&15.0), "{picked:?}"); } #[test] fn thin_hands_do_not_stack_off() { let spot = bet_spot(15.0); let thin = read_of(Made::TopPairWeakKicker, Draw::None, 0, SuitPattern::Rainbow, 0.2); let picked = sizes(&spot, RaiseKind::Value, 0.64, &thin); assert!(!picked.contains(&15.0), "{picked:?}"); } /// Live hand 178493100165: hero re-raises to 1.12 of 1.94 over a raise to 0.36 (big blind 0.02). Called, /// 0.82 stays behind in a pot of 2.70 (SPR 0.30 < 0.5): no man's land. The shove and a small raise are not. #[test] fn a_raise_that_leaves_under_half_a_pot_behind_is_no_mans_land() { use rechner::engine::size_policy::in_no_mans_land; let spot = Spot { to_call: 0.24, pot: 0.70, hero_stack: 1.94, min_raise_to: Some(0.48), max_raise_to: Some(1.94), allowed_sizes: None, legal: vec![ActionKind::Fold, ActionKind::Call, ActionKind::Raise], villains: vec![rechner::game::Villain { seat: 2, stack: 3.0, folded: false, profile: None }], big_blind: 0.02, ..round_flop() }; assert!(in_no_mans_land(&spot, 1.12)); assert!(!in_no_mans_land(&spot, 1.94)); assert!(!in_no_mans_land(&spot, 0.60)); }