//! Showdown under the variant rules: category order and the low ace. //! //! References (published short deck / six-plus hold'em rules, Wikipedia "Six-plus hold'em", //! and the standard ranking, Wikipedia "List of poker hands"): //! * R1 a flush beats a full house in short deck (standard: the other way round); //! * R2 the ace plays low in the lowest straight: A-6-7-8-9 (A-2-3-4-5 in the full deck); //! * R3 A-2-3-4-5 cannot occur in short deck, the ranks do not exist; //! * R4 6-7-8-9-T is the next straight above A-6-7-8-9; //! * R5 a straight still beats three of a kind here (some rule sets swap them, ours does not). use rechner::card::Card; use rechner::fault::Fault; use rechner::hand::category::Category; use rechner::hand::showdown::{best, judge}; use rechner::hand::strength::Strength; use rechner::variant::{rules, HoleUsage, Variant}; fn cs(text: &str) -> Vec { Card::parse_list(text).expect("cards") } fn short(hole: &str, board: &str) -> Strength { judge(&rules(Variant::ShortDeck), &cs(hole), &cs(board)).expect("strength") } fn nlhe(hole: &str, board: &str) -> Strength { judge(&rules(Variant::Nlhe), &cs(hole), &cs(board)).expect("strength") } #[test] fn r1_flush_beats_full_house_in_short_deck() { let board = "Kh 7h 6h Ks 9c"; let flush = short("Ah 8h", board); let boat = short("Kd 7c", board); assert_eq!(flush.category, Category::Flush); assert_eq!(boat.category, Category::FullHouse); assert!(flush > boat); assert!(boat < flush); } #[test] fn r1_full_house_still_beats_flush_with_standard_rules() { let board = "Kh 7h 6h Ks 9c"; assert!(nlhe("Kd 7c", board) > nlhe("Ah 8h", board)); // `best` is the standard-rules function whatever the caller thinks of the deck. let usage = HoleUsage::BestFiveOfAll; let flush = best(usage, &cs("Ah 8h"), &cs(board)).expect("flush"); let boat = best(usage, &cs("Kd 7c"), &cs(board)).expect("boat"); assert!(boat > flush); } #[test] fn a_higher_flush_beats_a_lower_one_and_a_bigger_boat_beats_a_smaller_one() { let board = "Kh 7h 6h Ks 9c"; assert!(short("Ah 8h", board) > short("Th 8h", board)); let boat_board = "Kh Kd 7c 7h 9s"; assert!(short("Ks 6c", boat_board) > short("7s 6c", boat_board)); } #[test] fn r2_ace_low_straight_is_a_nine_high_straight() { let s = short("Ah 6c", "7d 8s 9h Kc Qd"); assert_eq!(s.category, Category::Straight); assert_eq!(s.ranks[0], 9); } #[test] fn r2_the_full_deck_wheel_is_unchanged() { let s = nlhe("Ah 2c", "3d 4s 5h Kc Qd"); assert_eq!(s.category, Category::Straight); assert_eq!(s.ranks[0], 5); } #[test] fn r2_ace_six_seven_eight_nine_is_no_straight_in_the_full_deck() { assert_eq!(nlhe("Ah 6c", "7d 8s 9h Kc Qd").category, Category::HighCard); } #[test] fn r3_a_wheel_cannot_exist_in_short_deck() { let out = judge(&rules(Variant::ShortDeck), &cs("Ah 2c"), &cs("3d 4s 5h Kc Qd")); assert!(matches!(out, Err(Fault::Invalid { .. })), "{out:?}"); let low_card = judge(&rules(Variant::ShortDeck), &cs("Ah Kc"), &cs("Qd Js 5h")); assert!(matches!(low_card, Err(Fault::Invalid { .. })), "{low_card:?}"); } #[test] fn ace_low_needs_all_four_cards_ace_six_seven_eight_ten_is_not_a_straight() { assert_eq!(short("Ah 6c", "7d 8s Th Kc Qd").category, Category::HighCard); } #[test] fn r4_six_to_ten_beats_ace_to_nine() { let board = "7d 8s 9h Kc Kd"; let low = short("Ah 6s", board); let next = short("Th 6c", board); assert_eq!(low.category, Category::Straight); assert_eq!(next.category, Category::Straight); assert!(next > low); } #[test] fn the_broadway_straight_is_the_highest() { let top = short("Ah Kc", "Qd Js Th 6c 7c"); let jack_high = short("Jh Tc", "9d 8s 7h 6c Kc"); assert_eq!(top.category, Category::Straight); assert_eq!(top.ranks[0], 14); assert!(top > jack_high); } #[test] fn straight_flush_ace_to_nine_suited() { let s = short("Ah 6h", "7h 8h 9h Kc Kd"); assert_eq!(s.category, Category::StraightFlush); assert_eq!(s.ranks[0], 9); // with the full-deck ladder those cards are only a flush assert_eq!(nlhe("Ah 6h", "7h 8h 9h Kc Kd").category, Category::Flush); } #[test] fn the_lowest_straight_flush_still_beats_four_of_a_kind() { let board = "7h 8h 9h Kc Kd"; assert!(short("Ah 6h", board) > short("Kh Ks", board)); assert_eq!(short("Kh Ks", board).category, Category::FourOfAKind); } #[test] fn a_ten_high_straight_flush_beats_the_ace_low_one() { let board = "7h 8h 9h Kc Kd"; assert!(short("Th 6h", board) > short("Ah 6h", board)); } #[test] fn r5_a_straight_beats_three_of_a_kind() { let straight = short("Th 9d", "8c 7s 6h Kd Kc"); let trips = short("Ah Ad", "Ac 9s 8h 6d Jc"); assert_eq!(straight.category, Category::Straight); assert_eq!(trips.category, Category::ThreeOfAKind); assert!(straight > trips); } #[test] fn short_deck_category_ladder_is_flush_over_full_house_and_otherwise_standard() { let ladder = [ short("Ah Kd", "9c 8s 6h Td Jc"), short("Ah Ad", "9c 8s 6h Td Jc"), short("Ah Kd", "As Kc 8s 6h Td"), short("Ah Ad", "Ac 9s 8h 6d Jc"), short("Th 9d", "8c 7s 6h Kd Kc"), short("Ah Ad", "Ac Ks Kd 9c 7h"), short("Ah 9h", "Kh 7h 6h Qs Jd"), short("Ah Ad", "Ac As 9s 7h 6d"), short("Th 9h", "8h 7h 6h Ks Kd"), ]; let categories: Vec = ladder.iter().map(|s| s.category).collect(); assert_eq!( categories, [ Category::HighCard, Category::Pair, Category::TwoPair, Category::ThreeOfAKind, Category::Straight, Category::FullHouse, Category::Flush, Category::FourOfAKind, Category::StraightFlush, ] ); assert!(ladder.windows(2).all(|w| w[0] < w[1]), "{ladder:?}"); } #[test] fn the_comparison_is_antisymmetric_and_transitive_over_a_ladder() { let a = short("Ah 8h", "Kh 7h 6h Ks 9c"); // flush let b = short("Kd 7c", "Kh 7h 6h Ks 9c"); // full house let c = short("Th 9d", "8c 7s 6h Kd Kc"); // straight assert!(a > b && b > c && a > c); assert!(b.partial_cmp(&a) == Some(std::cmp::Ordering::Less)); } #[test] fn equal_strength_means_a_split_pot() { let board = "Qh Jd 9c 8s 6h"; assert_eq!(short("Ah Kd", board), short("Ac Ks", board)); } #[test] fn the_board_playing_splits_even_with_the_ace_low_straight() { let board = "Ah 6c 7d 8s 9h"; assert_eq!(short("Kc Kd", board), short("Qc Qd", board)); } #[test] fn kicker_comparison_is_unchanged_by_the_short_deck() { let board = "Ad 8c 7h 6s Th"; assert!(short("Ah Kc", board) > short("As Qc", board)); } #[test] fn omaha_rules_through_judge_are_unchanged() { let plo = rules(Variant::Plo5); let hole = cs("Ah Kh Qd Jc 9s"); let board = cs("Th 5h 2h Kc 3d"); assert_eq!(judge(&plo, &hole, &board), best(HoleUsage::ExactlyTwoHole, &hole, &board)); } #[test] fn judge_with_the_standard_rules_equals_best() { let hole = cs("Ah Kh"); let board = cs("Qh Jh Th 2c 3d"); assert_eq!( judge(&rules(Variant::Nlhe), &hole, &board), best(HoleUsage::BestFiveOfAll, &hole, &board) ); } #[test] fn duplicates_are_still_inconsistent_in_short_deck() { let out = judge(&rules(Variant::ShortDeck), &cs("Ah Ah"), &cs("7d 8s 9h")); assert!(matches!(out, Err(Fault::Inconsistent(_))), "{out:?}"); }