Die Welt soll nichts verraten. Woerter, die ein Gegenueber implizieren (echt vs. unecht, live, Mensch), sind aus Prosa, Kommentaren und Docstrings raus; Namen (mensch_ruhe_s, echte_chops) und der Altwert "echt" im Spielplan bleiben. Nur Kommentare und Docstrings angefasst, damit keine Einrueckung faellt.
49 lines
1.8 KiB
Rust
49 lines
1.8 KiB
Rust
//! Outs: unseen cards of the deck (minus hole and board) after which hero's class improves.
|
|
//!
|
|
//! An unseen card counts when the class gets better and it is
|
|
//! - a straight, flush, full house, quads or straight flush (any hand), or
|
|
//! - for a hand with one pair of its own (underpair.. overpair): two pair, set or trips made with
|
|
//! a rank hero holds. A card that only pairs the board does not count.
|
|
//!
|
|
//! Whether the card also helps an opponent is not looked at. No outs on the river.
|
|
|
|
use super::census::Census;
|
|
use super::made::Made;
|
|
use super::made_class::classify;
|
|
use crate::card::{Card, Rank, Suit};
|
|
use crate::hand::showdown::judge;
|
|
use crate::variant::Rules;
|
|
|
|
pub fn outs(rules: &Rules, hole: &[Card], board: &[Card], current: Made) -> u8 {
|
|
if board.len() >= 5 {
|
|
return 0;
|
|
}
|
|
Rank::ALL
|
|
.iter()
|
|
.filter(|rank| rules.deck.contains(**rank))
|
|
.flat_map(|rank| Suit::ALL.iter().map(move |suit| Card::new(*rank, *suit)))
|
|
.filter(|card| !hole.contains(card) && !board.contains(card))
|
|
.filter(|card| improves(rules, hole, board, current, *card))
|
|
.count() as u8
|
|
}
|
|
|
|
fn improves(rules: &Rules, hole: &[Card], board: &[Card], current: Made, card: Card) -> bool {
|
|
let mut next = [card; 5];
|
|
next[..board.len()].copy_from_slice(board);
|
|
next[board.len()] = card;
|
|
let next = &next[..=board.len()];
|
|
let census = Census::of(hole, next);
|
|
judge(rules, hole, next).ok().is_some_and(|strength| {
|
|
let after = classify(rules, &census, &strength);
|
|
after > current
|
|
&& (after >= Made::Straight
|
|
|| (has_own_pair(current)
|
|
&& after >= Made::TwoPair
|
|
&& census.hole_count(card.rank.value()) > 0))
|
|
})
|
|
}
|
|
|
|
fn has_own_pair(made: Made) -> bool {
|
|
(Made::Underpair..=Made::Overpair).contains(&made)
|
|
}
|