Pure CFR+ core over a 169-class abstraction, push/fold and open/call/3-bet games, Nash/Kuhn/plausibility/lookup tests, chartgen binary, frozen equity and charts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
2.6 KiB
Rust
85 lines
2.6 KiB
Rust
//! Exact chance weights between two hand classes, with card removal.
|
|
//!
|
|
//! The deal is "player 0 gets a combo, player 1 gets a combo disjoint from it", all ordered
|
|
//! pairs equally likely. The weight of the class pair `(i, j)` is the number of such disjoint
|
|
//! combo pairs, so a hand that blocks the opponent's cards (AA vs AKs) is counted exactly,
|
|
//! not approximated. Probabilities are those counts over the grand total.
|
|
|
|
use super::hand_class::{class_combos, class_exists, CLASS_COUNT};
|
|
use crate::card::Card;
|
|
use crate::variant::DeckRule;
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct ChanceTable {
|
|
deck: DeckRule,
|
|
counts: Vec<u32>,
|
|
total: u64,
|
|
}
|
|
|
|
fn combos_in(deck: DeckRule, class: usize) -> Vec<[Card; 2]> {
|
|
class_combos(class)
|
|
.into_iter()
|
|
.filter(|h| h.iter().all(|c| deck.contains(c.rank)))
|
|
.collect()
|
|
}
|
|
|
|
pub fn chance_table(deck: DeckRule) -> ChanceTable {
|
|
let combos: Vec<Vec<[Card; 2]>> = (0..CLASS_COUNT)
|
|
.map(|c| if class_exists(deck, c) { combos_in(deck, c) } else { Vec::new() })
|
|
.collect();
|
|
let counts: Vec<u32> = (0..CLASS_COUNT * CLASS_COUNT)
|
|
.map(|k| {
|
|
let (a, b) = (&combos[k / CLASS_COUNT], &combos[k % CLASS_COUNT]);
|
|
a.iter()
|
|
.map(|x| b.iter().filter(|y| !x.iter().any(|c| y.contains(c))).count() as u32)
|
|
.sum()
|
|
})
|
|
.collect();
|
|
let total = counts.iter().map(|c| *c as u64).sum();
|
|
ChanceTable { deck, counts, total }
|
|
}
|
|
|
|
impl ChanceTable {
|
|
pub fn deck(&self) -> DeckRule {
|
|
self.deck
|
|
}
|
|
|
|
/// Number of ordered disjoint combo pairs over all class pairs.
|
|
pub fn total(&self) -> u64 {
|
|
self.total
|
|
}
|
|
|
|
/// Disjoint ordered combo pairs `(a in i, b in j)`; 0 outside the grid.
|
|
pub fn disjoint_combos(&self, i: usize, j: usize) -> u32 {
|
|
if i < CLASS_COUNT && j < CLASS_COUNT {
|
|
self.counts[i * CLASS_COUNT + j]
|
|
} else {
|
|
0
|
|
}
|
|
}
|
|
|
|
pub fn probability(&self, i: usize, j: usize) -> f64 {
|
|
if self.total == 0 {
|
|
0.0
|
|
} else {
|
|
self.disjoint_combos(i, j) as f64 / self.total as f64
|
|
}
|
|
}
|
|
|
|
/// Number of combos of the class that exist in the deck.
|
|
pub fn combos(&self, class: usize) -> u32 {
|
|
if class_exists(self.deck, class) {
|
|
combos_in(self.deck, class).len() as u32
|
|
} else {
|
|
0
|
|
}
|
|
}
|
|
|
|
/// All joint probabilities, row-major `[i * CLASS_COUNT + j]`.
|
|
pub fn joint(&self) -> Vec<f64> {
|
|
(0..CLASS_COUNT * CLASS_COUNT)
|
|
.map(|k| self.probability(k / CLASS_COUNT, k % CLASS_COUNT))
|
|
.collect()
|
|
}
|
|
}
|