mod spot_fixture; use rechner::engine::effective::effective; use rechner::engine::multiway::{ extra_call_margin, extra_value_raise, realized_share, semibluff_allowed, }; use rechner::engine::postflop::choose_postflop; use rechner::exploit::thresholds::Thresholds; use rechner::game::Choice; use rechner::read::draw::Draw; use rechner::read::made::Made; use rechner::read::suit_pattern::SuitPattern; use spot_fixture::*; const BASE: Thresholds = Thresholds::BASE; fn close(a: f64, b: f64) -> bool { (a - b).abs() < 1e-9 } #[test] fn heads_up_changes_nothing() { assert_eq!(realized_share(0.5, 1), 0.5); assert_eq!(extra_call_margin(1), 0.0); assert_eq!(extra_value_raise(1), 0.0); assert_eq!(realized_share(0.5, 0), 0.5); } #[test] fn each_extra_villain_discounts_equity_and_raises_the_bars() { assert!(close(realized_share(0.5, 4), 0.5 * 0.97f64.powi(3))); assert!(close(extra_call_margin(3), 0.02)); assert!(close(extra_value_raise(3), 0.10)); assert!(realized_share(0.5, 5) < realized_share(0.5, 4)); assert!(extra_value_raise(5) > extra_value_raise(4)); } #[test] fn semibluffs_need_at_most_two_villains() { assert!(semibluff_allowed(0) && semibluff_allowed(1) && semibluff_allowed(2)); assert!(!semibluff_allowed(3) && !semibluff_allowed(5)); } #[test] fn effective_thresholds_combine_texture_and_player_count() { // Medium hand, dry board (wetness 0.1): texture gives margin 0.034, value 0.652. let read = read_of(Made::MiddlePair, Draw::None, 0, SuitPattern::Rainbow, 0.1); let spot = with_villains(round_flop(), 3); let e = effective(&spot, 0.5, &BASE, &read); assert_eq!(e.villains, 3); assert!(close(e.share, 0.5 * 0.97 * 0.97), "{e:?}"); assert!(close(e.call_margin, 0.034 + 0.02), "{e:?}"); assert!(close(e.value_raise, 0.652 + 0.10), "{e:?}"); assert!(e.value_ok && e.raise_ok && !e.semibluff_ok); } #[test] fn folded_villains_do_not_count() { let mut spot = with_villains(round_flop(), 4); spot.villains[0].folded = true; spot.villains[1].folded = true; let e = effective(&spot, 0.5, &BASE, &neutral_read()); assert_eq!(e.villains, 2); assert!(e.semibluff_ok); } #[test] fn no_live_villain_counts_as_one() { let e = effective(&with_villains(round_flop(), 0), 0.5, &BASE, &neutral_read()); assert_eq!(e.villains, 1); assert_eq!(e.share, 0.5); } // round_flop: pot 10, 5 to call, break-even 1/3. #[test] fn a_share_that_calls_heads_up_folds_four_way() { let share = estimate(0.38, 0.002); let heads_up = choose_postflop(&with_villains(round_flop(), 1), &share, &BASE, &neutral_read()); assert_eq!(heads_up.choice, Choice::Call, "{heads_up:?}"); let four_way = choose_postflop(&with_villains(round_flop(), 4), &share, &BASE, &neutral_read()); assert_eq!(four_way.choice, Choice::Fold, "{four_way:?}"); } #[test] fn a_share_that_value_raises_heads_up_only_calls_three_way() { let share = estimate(0.64, 0.002); let heads_up = choose_postflop(&with_villains(round_flop(), 1), &share, &BASE, &neutral_read()); assert!(matches!(heads_up.choice, Choice::Raise { .. }), "{heads_up:?}"); let three_way = choose_postflop(&with_villains(round_flop(), 3), &share, &BASE, &neutral_read()); assert_eq!(three_way.choice, Choice::Call, "{three_way:?}"); } #[test] fn semibluff_works_two_way_but_not_three_way() { // Folds are independent per villain (`exploit::table_fold`), so two-way fold equity // is the square of one villain's. With foldy villains (scale 1.6: 0.67 each to a pot // raise) the semibluff pays two-way; three-way it is not allowed at all. let share = estimate(0.45, 0.005); let foldy = Thresholds { fold_equity_scale: 1.6, ..BASE }; let two = choose_postflop(&with_villains(round_flop(), 2), &share, &foldy, &flush_draw_read()); assert!(matches!(two.choice, Choice::Raise { .. }), "{two:?}"); let three = choose_postflop(&with_villains(round_flop(), 3), &share, &foldy, &flush_draw_read()); assert_eq!(three.choice, Choice::Call, "{three:?}"); } #[test] fn the_reason_names_the_player_count_when_multiway() { let d = choose_postflop( &with_villains(round_flop(), 3), &estimate(0.45, 0.002), &BASE, &neutral_read(), ); assert!(d.reason.contains("3-way"), "{}", d.reason); }