- 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>
94 lines
3.9 KiB
Rust
94 lines
3.9 KiB
Rust
//! Dealing from a pool that is rearranged in place (private to one simulation run).
|
|
//!
|
|
//! The pool is only ever permuted, so any arrangement is a uniform starting point for the next
|
|
//! partial Fisher-Yates pass; the arrangement itself never leaks out of `monte_carlo`.
|
|
//!
|
|
//! `Pool` keeps, next to the cards, where each card sits (by `Card::index`), so finding a card is one
|
|
//! lookup instead of a scan; every swap updates both. The swaps themselves are exactly those of the
|
|
//! plain slice version, so the arrangement (and every deal after it) is the same.
|
|
|
|
use crate::card::Card;
|
|
use crate::rng::Rng;
|
|
|
|
/// Attempts a `Filter` range gets per hand before the last sample is accepted unfiltered.
|
|
pub const MAX_FILTER_ATTEMPTS: u32 = 200;
|
|
|
|
/// The cards still to deal from, and the position of each (`at[card.index()]`; `u8::MAX` for cards
|
|
/// not in the pool).
|
|
pub struct Pool {
|
|
pub cards: Vec<Card>,
|
|
at: [u8; 64],
|
|
}
|
|
|
|
impl Pool {
|
|
pub fn new(cards: Vec<Card>) -> Pool {
|
|
let mut at = [u8::MAX; 64];
|
|
for (i, c) in cards.iter().enumerate() {
|
|
at[c.index() as usize] = i as u8;
|
|
}
|
|
Pool { cards, at }
|
|
}
|
|
|
|
pub fn len(&self) -> usize {
|
|
self.cards.len()
|
|
}
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
self.cards.is_empty()
|
|
}
|
|
|
|
fn swap(&mut self, i: usize, j: usize) {
|
|
self.cards.swap(i, j);
|
|
self.at[self.cards[i].index() as usize] = i as u8;
|
|
self.at[self.cards[j].index() as usize] = j as u8;
|
|
}
|
|
}
|
|
|
|
/// Moves `count` uniformly chosen cards from `pool[front..]` to `pool[front..front + count]`.
|
|
pub fn shuffle_front(pool: &mut Pool, front: usize, count: usize, rng: Rng) -> Rng {
|
|
(0..count).fold(rng, |rng, i| {
|
|
let (offset, rng) = rng.below((pool.len() - front - i) as u64);
|
|
pool.swap(front + i, front + i + offset as usize);
|
|
rng
|
|
})
|
|
}
|
|
|
|
/// Deals `count` cards at `front`, re-sampling while `accept` refuses (bounded).
|
|
/// Fallback: after `MAX_FILTER_ATTEMPTS` refusals the last sample is kept, i.e. a range that
|
|
/// (almost) never matches degrades to a uniformly random hand instead of failing the run.
|
|
pub fn deal(pool: &mut Pool, front: usize, count: usize, accept: &dyn Fn(&[Card]) -> bool, rng: Rng) -> Rng {
|
|
let mut rng = rng;
|
|
for _ in 0..MAX_FILTER_ATTEMPTS {
|
|
rng = shuffle_front(pool, front, count, rng);
|
|
if accept(&pool.cards[front..front + count]) {
|
|
break;
|
|
}
|
|
}
|
|
rng
|
|
}
|
|
|
|
/// Deals one of `combos` at `front`: a uniformly chosen hand, re-chosen while one of its
|
|
/// cards is gone (dead or dealt), bounded by `MAX_FILTER_ATTEMPTS`. Fallback: an empty list,
|
|
/// or no hand left after the attempts, deals `count` random cards instead.
|
|
pub fn deal_combo<H: AsRef<[Card]>>(pool: &mut Pool, front: usize, count: usize, combos: &[H], rng: Rng) -> Rng {
|
|
let mut rng = rng;
|
|
for _ in 0..if combos.is_empty() { 0 } else { MAX_FILTER_ATTEMPTS } {
|
|
let (i, next) = rng.below(combos.len() as u64);
|
|
rng = next;
|
|
let combo = combos[i as usize].as_ref();
|
|
// In `pool[front..]`: in the pool, at or behind `front`.
|
|
let available = combo.len() == count && combo.iter().all(|c| pool.at[c.index() as usize] as usize >= front && pool.at[c.index() as usize] != u8::MAX);
|
|
if available {
|
|
for (k, card) in combo.iter().enumerate() {
|
|
// The card's place if it is in `pool[front + k..]`, else `front + k` (a no-op swap):
|
|
// what the scan `front + k + position(..).unwrap_or(0)` gave.
|
|
let p = pool.at[card.index() as usize] as usize;
|
|
let at = if p >= front + k && p < pool.len() && pool.cards[p] == *card { p } else { front + k };
|
|
pool.swap(front + k, at);
|
|
}
|
|
return rng;
|
|
}
|
|
}
|
|
shuffle_front(pool, front, count, rng)
|
|
}
|