188 lines
5.1 KiB
Rust
188 lines
5.1 KiB
Rust
//! Draws: flush, straight (windows from the deck, ace low per deck), combo, backdoor, none.
|
|
use pokerfreak::card::Card;
|
|
use pokerfreak::read::draw::Draw;
|
|
use pokerfreak::read::hand_read::read;
|
|
use pokerfreak::variant::{rules, Variant};
|
|
|
|
fn cs(text: &str) -> Vec<Card> {
|
|
Card::parse_list(text).expect("cards")
|
|
}
|
|
|
|
fn draw(variant: Variant, hole: &str, board: &str) -> Draw {
|
|
read(&rules(variant), &cs(hole), &cs(board)).expect("read").draw
|
|
}
|
|
|
|
fn nl(hole: &str, board: &str) -> Draw {
|
|
draw(Variant::Nlhe, hole, board)
|
|
}
|
|
|
|
#[test]
|
|
fn flush_draw() {
|
|
assert_eq!(nl("Ah 5h", "Kh 9h 2c"), Draw::Flush);
|
|
assert_eq!(nl("Ah 5h", "Kh 9h 2c 7d"), Draw::Flush);
|
|
}
|
|
|
|
#[test]
|
|
fn flush_draw_with_one_hole_card_on_a_monotone_flop() {
|
|
assert_eq!(nl("Ah 5c", "Kh 9h 2h"), Draw::Flush);
|
|
}
|
|
|
|
#[test]
|
|
fn four_suited_board_cards_are_not_a_hero_draw() {
|
|
assert_eq!(nl("Ac 5d", "Kh 9h 2h 7h"), Draw::None);
|
|
}
|
|
|
|
#[test]
|
|
fn open_ended_straight_draw() {
|
|
assert_eq!(nl("9h 8c", "7d 6s 2c"), Draw::OpenEnded);
|
|
}
|
|
|
|
#[test]
|
|
fn double_gutshot_counts_as_open_ended() {
|
|
// 4 completes 3-7, 8 completes 5-9: two different ranks.
|
|
assert_eq!(nl("5h 7c", "3d 6s 9c"), Draw::OpenEnded);
|
|
}
|
|
|
|
#[test]
|
|
fn gutshot() {
|
|
assert_eq!(nl("9h 7c", "6d 5s Kc"), Draw::Gutshot);
|
|
}
|
|
|
|
#[test]
|
|
fn ace_high_end_draw_is_a_gutshot() {
|
|
assert_eq!(nl("Ah Kc", "Qd Js 2c"), Draw::Gutshot);
|
|
}
|
|
|
|
#[test]
|
|
fn ace_low_draws_in_full_deck() {
|
|
// A-2-3-4 only completes with the five.
|
|
assert_eq!(nl("Ah 2c", "3d 4s Kc"), Draw::Gutshot);
|
|
// 2-3-4-5 completes with the ace or the six.
|
|
assert_eq!(nl("2h 3c", "4d 5s Kc"), Draw::OpenEnded);
|
|
}
|
|
|
|
#[test]
|
|
fn board_straight_draw_without_hero_cards_is_no_draw() {
|
|
assert_eq!(nl("2h 2d", "6c 7s 8d 9h"), Draw::None);
|
|
}
|
|
|
|
#[test]
|
|
fn combo_flush_plus_straight() {
|
|
assert_eq!(nl("9h 8h", "7h 6c 2h"), Draw::Combo);
|
|
}
|
|
|
|
#[test]
|
|
fn combo_flush_plus_pair() {
|
|
assert_eq!(nl("Ah 9h", "9c 5h 2h"), Draw::Combo);
|
|
}
|
|
|
|
#[test]
|
|
fn backdoor_flush_on_the_flop() {
|
|
assert_eq!(nl("Ah Kh", "7h 5c 2d"), Draw::Backdoor);
|
|
}
|
|
|
|
#[test]
|
|
fn backdoor_straight_on_the_flop() {
|
|
assert_eq!(nl("9h 8c", "6d Kh 2c"), Draw::Backdoor);
|
|
}
|
|
|
|
#[test]
|
|
fn backdoor_only_exists_on_the_flop() {
|
|
assert_eq!(nl("9h 8c", "6d Kh 2c 3s"), Draw::None);
|
|
assert_eq!(nl("Ah Kh", "7h 5c 2d 9s"), Draw::None);
|
|
}
|
|
|
|
#[test]
|
|
fn no_draws_on_the_river() {
|
|
assert_eq!(nl("Ah 5h", "Kh 9h 2c 7d Jc"), Draw::None);
|
|
assert_eq!(nl("9h 8c", "7d 6s 2c Kd Kc"), Draw::None);
|
|
}
|
|
|
|
#[test]
|
|
fn made_straight_or_better_reports_no_draw() {
|
|
assert_eq!(nl("9h 8c", "7d 6s 5c"), Draw::None);
|
|
assert_eq!(nl("Ah 5h", "Kh 9h 2h"), Draw::None);
|
|
}
|
|
|
|
#[test]
|
|
fn dry_hand_has_no_draw() {
|
|
assert_eq!(nl("Ah Kd", "9c 6s 2d"), Draw::None);
|
|
}
|
|
|
|
#[test]
|
|
fn draw_order_is_weakest_first() {
|
|
assert!(Draw::None < Draw::Backdoor && Draw::Backdoor < Draw::Gutshot);
|
|
assert!(Draw::Gutshot < Draw::OpenEnded && Draw::OpenEnded < Draw::Flush && Draw::Flush < Draw::Combo);
|
|
}
|
|
|
|
// --- nut flush draw ---
|
|
|
|
fn nut(variant: Variant, hole: &str, board: &str) -> bool {
|
|
read(&rules(variant), &cs(hole), &cs(board)).expect("read").nut_draw
|
|
}
|
|
|
|
#[test]
|
|
fn nut_flush_draw_holds_the_ace_of_the_suit() {
|
|
assert!(nut(Variant::Nlhe, "Ah 5h", "Kh 9h 2c"));
|
|
}
|
|
|
|
#[test]
|
|
fn holding_the_highest_missing_card_is_the_nut_draw() {
|
|
// The ace of hearts is on the board, so the king is the nut card.
|
|
assert!(nut(Variant::Nlhe, "Kh 5h", "Ah 9h 2c"));
|
|
assert!(!nut(Variant::Nlhe, "Qh 5h", "Ah 9h 2c"));
|
|
}
|
|
|
|
#[test]
|
|
fn non_nut_flush_draw_and_no_draw() {
|
|
assert!(!nut(Variant::Nlhe, "Kh 5h", "Qh 9h 2c"));
|
|
assert!(!nut(Variant::Nlhe, "Ah Kd", "9c 6s 2d"));
|
|
}
|
|
|
|
#[test]
|
|
fn nut_draw_is_false_once_the_flush_is_made() {
|
|
assert!(!nut(Variant::Nlhe, "Ah 5h", "Kh 9h 2h"));
|
|
}
|
|
|
|
// --- Omaha-5 ---
|
|
|
|
#[test]
|
|
fn plo5_flush_draw_needs_exactly_two_hole_cards_with_two_board_cards() {
|
|
assert_eq!(draw(Variant::Plo5, "Ah 2h 3s Qc 8d", "Kh 7h 4c 9d"), Draw::Flush);
|
|
assert!(nut(Variant::Plo5, "Ah 2h 3s Qc 8d", "Kh 7h 4c 9d"));
|
|
}
|
|
|
|
#[test]
|
|
fn plo5_one_suited_hole_card_is_not_a_flush_draw() {
|
|
assert_eq!(draw(Variant::Plo5, "Ah 2c 2d 8s 8c", "Kh 7h 4h 9c"), Draw::None);
|
|
assert_ne!(draw(Variant::Plo5, "Ah 2c 2d 8s 8c", "Kh 7h 4c 9d"), Draw::Flush);
|
|
assert!(!nut(Variant::Plo5, "Ah 2c 2d 8s 8c", "Kh 7h 4h 9c"));
|
|
}
|
|
|
|
#[test]
|
|
fn plo5_straight_draw_needs_two_hole_ranks() {
|
|
// Hole 8 9 with board 6 7: the 5 or the T completes, each with exactly two hole cards.
|
|
assert_eq!(draw(Variant::Plo5, "8h 9d Ac Ad 2s", "6c 7s Kd"), Draw::OpenEnded);
|
|
// Only one hole rank in each window on this turn board: no draw.
|
|
assert_eq!(draw(Variant::Plo5, "8h 2d 2c Ad Ks", "6c 7s Qd 9h"), Draw::None);
|
|
}
|
|
|
|
// --- Short deck ---
|
|
|
|
#[test]
|
|
fn short_deck_ace_low_gutshot() {
|
|
// A-6-7-8-9 is the lowest straight: A 6 7 9 needs the 8.
|
|
assert_eq!(draw(Variant::ShortDeck, "As 9d", "6c 7h Kd"), Draw::Gutshot);
|
|
}
|
|
|
|
#[test]
|
|
fn short_deck_wheel_window_supplies_the_second_end() {
|
|
// 9 8 7 6: the T completes 6-T, the ace completes A-6-7-8-9 (no five in this deck).
|
|
assert_eq!(draw(Variant::ShortDeck, "9h 8c", "7d 6s Kc"), Draw::OpenEnded);
|
|
}
|
|
|
|
#[test]
|
|
fn short_deck_flush_draw() {
|
|
assert_eq!(draw(Variant::ShortDeck, "Ah Kh", "Qh 9h 7c"), Draw::Flush);
|
|
}
|