Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
146 lines
4.0 KiB
Rust
146 lines
4.0 KiB
Rust
//! Board texture: suit pattern, pairing, connectivity (deck-dependent windows), high card, wetness.
|
|
use rechner::card::{Card, Rank};
|
|
use rechner::read::pairing::Pairing;
|
|
use rechner::read::suit_pattern::SuitPattern;
|
|
use rechner::read::texture::{texture, Texture};
|
|
use rechner::variant::{rules, Variant};
|
|
|
|
fn cs(text: &str) -> Vec<Card> {
|
|
Card::parse_list(text).expect("cards")
|
|
}
|
|
|
|
fn full(board: &str) -> Texture {
|
|
texture(&rules(Variant::Nlhe), &cs(board))
|
|
}
|
|
|
|
fn short(board: &str) -> Texture {
|
|
texture(&rules(Variant::ShortDeck), &cs(board))
|
|
}
|
|
|
|
#[test]
|
|
fn empty_board_is_the_neutral_texture() {
|
|
let t = full("");
|
|
assert_eq!(t.suits, SuitPattern::Rainbow);
|
|
assert_eq!(t.pairing, Pairing::Unpaired);
|
|
assert_eq!(t.connectivity, 0);
|
|
assert_eq!(t.high, None);
|
|
assert_eq!(t.wetness, 0.0);
|
|
}
|
|
|
|
#[test]
|
|
fn dry_ace_seven_deuce_rainbow() {
|
|
let t = full("Ah 7c 2d");
|
|
assert_eq!(t.suits, SuitPattern::Rainbow);
|
|
assert_eq!(t.pairing, Pairing::Unpaired);
|
|
assert_eq!(t.high, Some(Rank::Ace));
|
|
// Only A-2 share a window (the wheel): 2 ranks.
|
|
assert_eq!(t.connectivity, 2);
|
|
assert!(t.wetness < 0.15, "wetness {}", t.wetness);
|
|
}
|
|
|
|
#[test]
|
|
fn king_seven_deuce_is_completely_dry() {
|
|
let t = full("Ks 7d 2c");
|
|
assert_eq!(t.connectivity, 1);
|
|
assert_eq!(t.wetness, 0.0);
|
|
}
|
|
|
|
#[test]
|
|
fn monotone_board() {
|
|
let t = full("Ah 7h 2h");
|
|
assert_eq!(t.suits, SuitPattern::Monotone);
|
|
assert!(t.wetness >= 0.4, "wetness {}", t.wetness);
|
|
}
|
|
|
|
#[test]
|
|
fn two_tone_board() {
|
|
assert_eq!(full("Ah 7h 2c").suits, SuitPattern::TwoTone);
|
|
}
|
|
|
|
#[test]
|
|
fn four_flush_on_the_turn() {
|
|
let t = full("Ah Kh 7h 2h");
|
|
assert_eq!(t.suits, SuitPattern::FourFlush);
|
|
assert!(t.wetness >= 0.5, "wetness {}", t.wetness);
|
|
}
|
|
|
|
#[test]
|
|
fn two_two_suit_split_is_two_tone() {
|
|
assert_eq!(full("Ah Kh 7c 2c").suits, SuitPattern::TwoTone);
|
|
}
|
|
|
|
#[test]
|
|
fn three_of_a_suit_on_four_cards_is_monotone() {
|
|
assert_eq!(full("Ah Kh 7h 2c").suits, SuitPattern::Monotone);
|
|
}
|
|
|
|
#[test]
|
|
fn connected_two_tone_jack_ten_nine() {
|
|
let t = full("Jh Th 9c");
|
|
assert_eq!(t.suits, SuitPattern::TwoTone);
|
|
assert_eq!(t.connectivity, 3);
|
|
assert_eq!(t.high, Some(Rank::Jack));
|
|
assert!(t.wetness >= 0.45, "wetness {}", t.wetness);
|
|
}
|
|
|
|
#[test]
|
|
fn connectivity_counts_ace_low_window_in_full_deck() {
|
|
assert_eq!(full("Ac 2d 3h 4s").connectivity, 4);
|
|
}
|
|
|
|
#[test]
|
|
fn broadway_board_has_five_connected_ranks() {
|
|
assert_eq!(full("Ac Kd Qh Js Th").connectivity, 5);
|
|
}
|
|
|
|
#[test]
|
|
fn short_deck_ace_low_window_is_ace_six_seven_eight_nine() {
|
|
assert_eq!(short("As 6d 7c").connectivity, 3);
|
|
// Same cards in the full deck: A is far from 6-7, only 6-7 share a window.
|
|
assert_eq!(full("As 6d 7c").connectivity, 2);
|
|
}
|
|
|
|
#[test]
|
|
fn short_deck_full_wheel_board() {
|
|
assert_eq!(short("As 6d 7c 8h 9s").connectivity, 5);
|
|
}
|
|
|
|
#[test]
|
|
fn pairing_levels() {
|
|
assert_eq!(full("Ks 7d 2c").pairing, Pairing::Unpaired);
|
|
assert_eq!(full("Ks Kd 7c").pairing, Pairing::Paired);
|
|
assert_eq!(full("7c 7d 2h 2s").pairing, Pairing::TwoPaired);
|
|
assert_eq!(full("7c 7d 7h").pairing, Pairing::Trips);
|
|
assert_eq!(full("7c 7d 7h 7s").pairing, Pairing::Heavy);
|
|
assert_eq!(full("7c 7d 7h 2s 2c").pairing, Pairing::Heavy);
|
|
}
|
|
|
|
#[test]
|
|
fn paired_board_is_a_little_wetter_than_its_unpaired_twin() {
|
|
let paired = full("Ks Kd 7c");
|
|
let unpaired = full("Ks 7d 2c");
|
|
assert!(paired.wetness > unpaired.wetness);
|
|
assert!(paired.wetness < 0.2);
|
|
}
|
|
|
|
#[test]
|
|
fn flush_texture_ordering() {
|
|
let rainbow = full("Qh 8c 3d").wetness;
|
|
let two_tone = full("Qh 8h 3d").wetness;
|
|
let monotone = full("Qh 8h 3h").wetness;
|
|
assert!(rainbow < two_tone && two_tone < monotone);
|
|
}
|
|
|
|
#[test]
|
|
fn connected_is_wetter_than_disconnected() {
|
|
assert!(full("8c 7d 6h").wetness > full("Kc 7d 2h").wetness);
|
|
}
|
|
|
|
#[test]
|
|
fn wetness_stays_in_unit_interval_on_extreme_boards() {
|
|
for board in ["Ah Kh Qh Jh Th", "7c 7d 7h 7s 2d", "Ac 2c 3c 4c 5c", "Ah Kh Qh Jh"] {
|
|
let w = full(board).wetness;
|
|
assert!((0.0..=1.0).contains(&w), "{board}: {w}");
|
|
}
|
|
}
|