//! Best-hand selection per variant family and its failure modes. //! Omaha rule (exactly 2 hole + exactly 3 board): standard Omaha rules, Wikipedia "Omaha hold 'em". use rechner::card::Card; use rechner::fault::Fault; use rechner::hand::category::Category; use rechner::hand::showdown::best; use rechner::hand::strength::Strength; use rechner::variant::HoleUsage; use rechner::variant::HoleUsage::{BestFiveOfAll as Holdem, ExactlyTwoHole as Omaha}; fn cs(text: &str) -> Vec { Card::parse_list(text).expect("cards") } fn run(usage: HoleUsage, hole: &str, board: &str) -> Strength { best(usage, &cs(hole), &cs(board)).expect("strength") } #[test] fn holdem_picks_best_five_of_seven() { assert_eq!(run(Holdem, "Ah Kh", "Qh Jh Th 2c 3d").category, Category::StraightFlush); } #[test] fn holdem_board_plays() { let a = run(Holdem, "2c 3d", "Ah Kh Qh Jh Th"); let b = run(Holdem, "4c 5d", "Ah Kh Qh Jh Th"); assert_eq!(a, b); assert_eq!(a.category, Category::StraightFlush); } #[test] fn holdem_works_with_five_and_six_cards() { assert_eq!(run(Holdem, "Ah Ad", "Ac Ks 2d").category, Category::ThreeOfAKind); assert_eq!(run(Holdem, "Ah Ad", "Ac Ks 2d 9h").category, Category::ThreeOfAKind); } #[test] fn holdem_kicker_split_and_win() { let board = "Ah Kd 7c 4s 2d"; assert_eq!(run(Holdem, "Ac Qd", board), run(Holdem, "As Qh", board)); assert!(run(Holdem, "Ac Jd", board) < run(Holdem, "As Qh", board)); } #[test] fn holdem_seven_card_flush_beats_straight() { assert_eq!(run(Holdem, "9h 8h", "7h 6h Ad Tc 2h").category, Category::Flush); } #[test] fn holdem_two_trips_make_a_full_house() { let s = run(Holdem, "Ah Ad", "Ac Kd Ks Kh 2c"); assert_eq!(s.category, Category::FullHouse); // Aces full of kings outranks kings full of queens. assert!(s > run(Holdem, "Qh Qd", "Qc Kd Ks Kh 2c")); } #[test] fn omaha_needs_two_hole_cards_for_a_flush() { let board = "Kh Qh 9h 4h 2c"; assert_ne!(run(Omaha, "Ah 7c 7d 3s 3c", board).category, Category::Flush); assert_eq!(run(Holdem, "Ah 7c", board).category, Category::Flush); assert_eq!(run(Omaha, "Ah 7h 3s 3c 8d", board).category, Category::Flush); } #[test] fn omaha_board_straight_does_not_play_without_two_hole_cards() { let board = "5h 6d 7c 8s 9d"; assert_eq!(run(Holdem, "Ac Ad", board).category, Category::Straight); assert_eq!(run(Omaha, "Ac Ad 2c 2d Kh", board).category, Category::Pair); } #[test] fn omaha_exactly_two_blocks_quads_from_three_hole_cards() { let s = run(Omaha, "Ac Ad Ah 2c 3d", "As Kd 7c 8h 9d"); assert_eq!(s.category, Category::ThreeOfAKind); } #[test] fn omaha_picks_the_best_of_all_pairings() { // 9h 8h + 7h 6h 5c is a straight flush only with 5h; here 9h 8h + 7h 6h 2h is a flush. let s = run(Omaha, "9h 8h Ac Kd 2s", "7h 6h 5c Tc 2h"); assert_eq!(s.category, Category::Flush); } #[test] fn omaha_five_hole_cards_nut_flush_beats_lower_flush() { let board = "2h 5h 9h Kd 3c"; let nut = run(Omaha, "Ah 4h Kc Qc Jd", board); let low = run(Omaha, "8h 7h Ac Qc Jd", board); assert_eq!(nut.category, Category::Flush); assert!(nut > low); } #[test] fn omaha_split_pot_on_identical_best_five() { let board = "Ah Kd Qc Jh Ts"; assert_eq!(run(Omaha, "2c 3c 4d 5d 6d", board), run(Omaha, "2d 3d 4c 5c 6c", board)); } #[test] fn omaha_needs_three_board_cards() { assert!(best(Omaha, &cs("Ac Ad Kc Kd Qh"), &cs("2c 3d 4h")).is_ok()); assert!(best(Omaha, &cs("Ac Ad Kc Kd Qh"), &cs("2c 3d")).is_err()); } #[test] fn bad_input_is_a_fault_never_a_panic() { assert!(matches!(best(Holdem, &cs("Ah Kh"), &cs("Qh Jh")), Err(Fault::Invalid { .. }))); assert!(matches!(best(Holdem, &cs("Ah Kh"), &cs("Qh Jh Th 2c 3d 4s")), Err(Fault::Invalid { .. }))); assert!(best(Holdem, &[], &[]).is_err()); assert!(best(Holdem, &cs("Ah Ah"), &cs("Qh Jh Th")).is_err()); assert!(best(Holdem, &cs("Ah Kh"), &cs("Ah Jh Th")).is_err()); assert!(best(Omaha, &cs("Ac"), &cs("2c 3d 4h")).is_err()); assert!(best(Omaha, &cs("Ac Ac Kc Kd Qh"), &cs("2c 3d 4h")).is_err()); }