Files
pokerfreak/src/engine/range_combos.rs
T
mmintelandClaude Opus 5.5 81e8083c0d Perf 16.11.: Wartezeit statt Rechenzeit belegt, Rake-Showdown und Kombo-Listen bit-identisch schneller
- Messlaeufe rechnen nur Minuten (LBR 2000 Haende 57 CPU-min, 6-max 20 000 Deals 15-18 CPU-min);
  die 10 h der Nacht 15./16.11. waren ein Stillstand aller Idle-Laeufe (01:19-11:20), keine Rechnung.
  MULTIWAY=voll kostet +0-4 %, nicht 4x.
- TrSolver: Showdown mit Rake ohne Allokation (show_raked_into).
- Equity: Gegner-Kombos als flache [Card; 2]-Liste (combo_list, VillainRange::Pairs).
- LBR 1,18x (Fingerabdruck ea0779c77e255f95, 28 598 Antworten, Dump byte-gleich),
  6-max 1,13x / 1,17x mit MULTIWAY=voll (md5 aller Bloecke = Queue-Binary).
- Profiler ohne Adminrechte: messung/perf/werkzeug/stichprobe.py; Bericht messung/perf/BERICHT.md
  (GPU: nein; Statistik: Fruehstopp auch fuer Gewinner).
- messung_perf/rate nach messung/perf/rate (Ordner des Live-Stands).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 13:05:49 +01:00

75 lines
2.7 KiB
Rust

use super::range_filter::HandFilter;
use crate::card::{deck, Card};
use crate::equity::villain_range::VillainRange;
use crate::variant::Rules;
/// Every two-card hand outside `dead` that `filter` keeps, for direct sampling.
/// `None` for other hand sizes (too many to enumerate) or an empty range (the
/// simulation then falls back to the predicate and its documented fallback).
pub fn combos(rules: &Rules, filter: &HandFilter, dead: &[Card]) -> Option<Vec<Vec<Card>>> {
// Omaha (ab 4 Lochkarten): gesampelte konkrete Holdings statt voller Enumeration.
if rules.hole_cards >= 4 {
return super::omaha_combos::sample(rules, filter, dead);
}
if rules.hole_cards != 2 {
return None;
}
let pool = deck::without_in(rules.deck, dead);
let kept: Vec<Vec<Card>> = (0..pool.len())
.flat_map(|i| (i + 1..pool.len()).map(move |j| (i, j)))
.filter(|&(i, j)| filter(&[pool[i], pool[j]]))
.map(|(i, j)| vec![pool[i], pool[j]])
.collect();
(!kept.is_empty()).then_some(kept)
}
/// A villain's enumerated hands: flat pairs for two-card games, else the hands of `combos`.
pub enum List {
Pairs(Vec<[Card; 2]>),
Hands(Vec<Vec<Card>>),
}
/// `combos` without one allocation per hand for two-card games: the same hands in the same order
/// (`None` exactly when `combos` gives `None`).
pub fn combo_list(rules: &Rules, filter: &HandFilter, dead: &[Card]) -> Option<List> {
if rules.hole_cards != 2 {
return combos(rules, filter, dead).map(List::Hands);
}
let pool = deck::without_in(rules.deck, dead);
let mut kept: Vec<[Card; 2]> = Vec::new();
for i in 0..pool.len() {
for j in i + 1..pool.len() {
if filter(&[pool[i], pool[j]]) {
kept.push([pool[i], pool[j]]);
}
}
}
(!kept.is_empty()).then_some(List::Pairs(kept))
}
/// `as_ranges` over `combo_list` results.
pub fn as_ranges_list<'a>(filters: &'a [HandFilter], lists: &'a [Option<List>]) -> Vec<VillainRange<'a>> {
filters
.iter()
.zip(lists)
.map(|(f, list)| match list {
Some(List::Pairs(p)) => VillainRange::Pairs(p),
Some(List::Hands(h)) => VillainRange::Combos(h),
None => VillainRange::Filter(f.as_ref()),
})
.collect()
}
/// The simulation's view of each villain: the enumerated list where there is one,
/// the predicate otherwise.
pub fn as_ranges<'a>(filters: &'a [HandFilter], lists: &'a [Option<Vec<Vec<Card>>>]) -> Vec<VillainRange<'a>> {
filters
.iter()
.zip(lists)
.map(|(f, list)| match list {
Some(hands) => VillainRange::Combos(hands),
None => VillainRange::Filter(f.as_ref()),
})
.collect()
}