//! Preflop strength of the 81 two-card classes of the short deck (630 combos). //! The table is ranked by all-in equity against one random short deck hand; see //! `preflop::short_deck_ranking` for how it was produced. use rechner::card::{deck, Card}; use rechner::preflop::hand_percentile::percentile; use rechner::preflop::short_deck_percentile::short_deck_percentile; use rechner::preflop::short_deck_ranking::RANKING; use rechner::variant::{DeckRule, Variant}; fn hand(text: &str) -> Vec { Card::parse_list(text).expect("valid cards") } fn pct(text: &str) -> f64 { percentile(Variant::ShortDeck, &hand(text)) } fn all_combos() -> Vec> { let cards = deck::of(DeckRule::SHORT); (0..cards.len()) .flat_map(|i| (i + 1..cards.len()).map(move |j| (i, j))) .map(|(i, j)| vec![cards[i], cards[j]]) .collect() } #[test] fn the_ranking_has_81_distinct_classes() { assert_eq!(RANKING.len(), 81); let mut sorted: Vec<&str> = RANKING.to_vec(); sorted.sort_unstable(); sorted.dedup(); assert_eq!(sorted.len(), 81); // 9 pairs, 36 suited, 36 offsuit assert_eq!(RANKING.iter().filter(|c| c.len() == 2).count(), 9); assert_eq!(RANKING.iter().filter(|c| c.ends_with('s')).count(), 36); assert_eq!(RANKING.iter().filter(|c| c.ends_with('o')).count(), 36); } #[test] fn the_ranking_names_only_ranks_from_six_up() { assert!(RANKING.iter().all(|c| c.chars().take(2).all(|r| "AKQJT9876".contains(r)))); } #[test] fn there_are_630_combos() { assert_eq!(all_combos().len(), 630); } #[test] fn every_combo_gets_a_percentile_in_the_open_unit_interval_and_the_mean_is_one_half() { let all: Vec = all_combos().iter().map(|c| short_deck_percentile(c)).collect(); assert!(all.iter().all(|p| *p > 0.0 && *p < 1.0)); let mean = all.iter().sum::() / all.len() as f64; assert!((mean - 0.5).abs() < 1e-9, "{mean}"); } #[test] fn suits_inside_a_class_do_not_matter() { assert_eq!(pct("Ah Kh"), pct("Ac Kc")); assert_eq!(pct("Ah Kd"), pct("As Kc")); assert_eq!(pct("Ah Ad"), pct("Ac As")); assert_eq!(pct("Kh Ah"), pct("Ah Kh")); } #[test] fn aces_are_the_best_hand_and_the_percentile_is_combo_weighted() { // AA is 6 of 630 combos; the middle of that block is 3/630 assert!((pct("Ah Ad") - 3.0 / 630.0).abs() < 1e-12, "{}", pct("Ah Ad")); assert!(pct("Ah Ad") < pct("Kh Kd")); } #[test] fn pairs_descend() { let pairs = ["Ah Ad", "Kh Kd", "Qh Qd", "Jh Jd", "Th Td", "9h 9d", "8h 8d", "7h 7d", "6h 6d"]; let values: Vec = pairs.iter().map(|p| pct(p)).collect(); assert!(values.windows(2).all(|w| w[0] < w[1]), "{values:?}"); } #[test] fn suited_beats_offsuit_and_higher_beats_lower_in_the_same_shape() { assert!(pct("Ah Kh") < pct("Ah Kd")); assert!(pct("Ah Kh") < pct("Ah Qh")); assert!(pct("Kh Kd") < pct("Ah Kh")); assert!(pct("Th 9h") < pct("Th 7h")); assert!(pct("Th 9h") < pct("Th 9d")); } #[test] fn the_weakest_hands_are_low_unconnected_offsuit_cards() { assert_eq!(RANKING[80], "76o"); assert!(pct("7c 6d") > 0.98, "{}", pct("7c 6d")); assert!(pct("Ah Ad") < 0.05); assert!(pct("6c 7d") > pct("Ah Ad")); } #[test] fn invalid_hands_are_one() { assert_eq!(pct("Ah"), 1.0); assert_eq!(pct(""), 1.0); assert_eq!(pct("Ah Kd Qc"), 1.0); assert_eq!(pct("Ah Ah"), 1.0); assert_eq!(pct("Ah 5h"), 1.0, "a five does not exist in the short deck"); assert_eq!(pct("2c 3d"), 1.0); assert_eq!(pct("Ah Kd Qc Jh Th"), 1.0); } #[test] fn the_dispatch_follows_the_deck_not_the_variant_name() { // the same two cards are valid in both decks but rank differently let nlhe = percentile(Variant::Nlhe, &hand("Ah Ad")); let short = percentile(Variant::ShortDeck, &hand("Ah Ad")); assert!(nlhe < short, "AA is 6/1326 of the full deck, 6/630 of the short one: {nlhe} {short}"); // hold'em is untouched assert!(percentile(Variant::Nlhe, &hand("7c 2d")) > 0.93); } #[test] fn a_hand_from_the_full_deck_is_not_ranked_by_the_short_deck() { assert_eq!(short_deck_percentile(&hand("Ah 5h")), 1.0); }