Files
pokerfreak/src/sim/luck.rs
T
mmintel 836c16c9a4 Sprechweise geputzt: kein echt/live/Mensch mehr in Kommentaren und Texten
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.
2026-11-01 22:11:05 +01:00

79 lines
3.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! Luck correction for the strength measurement (in the spirit of AIVAT).
//!
//! At every board deal the term `pot × (share after the card − expected share before it)` is
//! subtracted from hero's result. The share is hero's showdown share against the players'
//! actual cards. Before the card, its expectation is taken over every card the deal could
//! still have put there (deck minus all hole cards and the visible board). So the term has
//! expectation zero whatever the value function is: the correction cannot bias the win rate,
//! it only removes the part of the result that the cards decided.
//!
//! Exact enumeration when at most two board cards are missing; before the flop a seed-fixed
//! Monte Carlo average, which is an unbiased estimate of that expectation and keeps the
//! correction unbiased.
use crate::card::{deck, Card};
use crate::hand::showdown::best;
use crate::rng::Rng;
use crate::variant::HoleUsage;
const FLOP_SAMPLES: usize = 600;
/// Hero's expected showdown share with `board` known so far. `` holds the hole cards of
/// every player still in the hand, hero at `hero`; `dead` are cards out of the deck (all
/// hole cards, folded ones included).
pub fn share(live: &[[Card; 2]], hero: usize, board: &[Card], dead: &[Card], rng: Rng) -> f64 {
let mut out: Vec<Card> = dead.to_vec();
out.extend_from_slice(board);
let pool = deck::without(&out);
let missing = 5 - board.len();
let mut full = board.to_vec();
match missing {
0 => showdown_share(live, hero, board),
1 => {
let total: f64 = pool.iter().map(|c| {
full.truncate(board.len());
full.push(*c);
showdown_share(live, hero, &full)
}).sum();
total / pool.len() as f64
}
2 => {
let mut total = 0.0;
let mut count = 0usize;
for (i, a) in pool.iter().enumerate() {
for b in &pool[i + 1..] {
full.truncate(board.len());
full.extend([*a, *b]);
total += showdown_share(live, hero, &full);
count += 1;
}
}
total / count as f64
}
_ => {
let mut rng = rng;
let mut total = 0.0;
for _ in 0..FLOP_SAMPLES {
let (cards, next) = deck::draw(&pool, missing, rng).expect("enough cards");
rng = next;
full.truncate(board.len());
full.extend(cards);
total += showdown_share(live, hero, &full);
}
total / FLOP_SAMPLES as f64
}
}
}
fn showdown_share(live: &[[Card; 2]], hero: usize, board: &[Card]) -> f64 {
let strengths: Vec<_> = live
.iter()
.map(|h| best(HoleUsage::BestFiveOfAll, h, board).expect("valid cards"))
.collect();
let top = *strengths.iter().max().expect("a live player");
if strengths[hero] != top {
return 0.0;
}
1.0 / strengths.iter().filter(|s| **s == top).count() as f64
}