O3: 6-max-Leiter (gemischte Population, Duplicate, je Position/Street/Entscheider) und Multiway-LBR

- sim::table: gemischter Tisch (play_hand_mixed: Gegner und Read je Sitz, Stacks je Sitz,
  Strasse+Grund der letzten Hero-Entscheidung); Zug waehlen/ausfuehren getrennt (fuer LBR-Abfragen)
- sim::sechsmax: 6 Sitze, Hero rotiert ueber alle Sitze je Deal, Lineup je Block, Memory je Gegner,
  Populationen misch/micro/nur:<typ>, Jammer-Typ, gemischte Stacks; gepaarter Vergleich je Spalte
- sim::table::lbr6: ein Sitz spielt lokale Best-Response mit Partikel-Ranges, gepaart gegen das
  Lineup-Mitglied auf demselben Sitz (Engine-Verlust als Ausnutzbarkeits-Mass)
- Regel-Gegner am gemischten Tisch: Stärke postflop gegen das ganze Feld (strength_field)
- reader::strength auf fast7 (bitgleich, Spec)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 22:32:35 +01:00
co-authored by Claude Opus 5.5
parent 1b7e132924
commit c3664b4e4b
8 changed files with 1673 additions and 156 deletions
+136 -7
View File
@@ -100,6 +100,9 @@ pub struct Dec {
pub equity: Option<f64>,
}
#[path = "lbr6.rs"]
pub mod lbr6;
struct Table<'a> {
setup: &'a HandSetup<'a>,
cost: TableCost,
@@ -128,6 +131,23 @@ struct Table<'a> {
world: Vec<WorldEvent>,
/// The pace of the world opponent's action in progress.
welt_tank: Option<f64>,
/// The opponent on each seat (hero's entry unused). `vec![setup.opponent; n]` everywhere except
/// the mixed table (`play_hand_mixed`, the 6-max ladder `sim::sechsmax`).
opps: Vec<Opponent>,
/// Per-seat reads (hero's entry unused); `Some` only on the mixed table, where it overrides
/// `setup.read` seat by seat.
seat_reads: Option<Vec<Option<Profile>>>,
/// Street and reason text of hero's last decision; kept only on the mixed table.
last: Option<(Street, String)>,
keep_last: bool,
/// The multiway LBR's state (`lbr6`); `None` on every other table.
br: Option<Box<lbr6::State>>,
/// Every seat's result after `run` (big blinds).
nets: Vec<f64>,
/// Postflop with more than two players live, a reading opponent's strength is its equity
/// against the whole field (`reader::strength_field`), not against one random hand. Only the
/// mixed table sets it; heads-up it changes nothing.
field_strength: bool,
}
impl Table<'_> {
@@ -216,12 +236,16 @@ impl Table<'_> {
// measures the exploit brain instead of playing it blind - unless the scenario hands a
// different read (blind = no profile, or the memory's snapshot).
let read = match self.setup.read {
HandRead::Oracle => super::reads::opponent_profile(self.setup.opponent),
HandRead::Oracle if self.seat_reads.is_none() => super::reads::opponent_profile(self.setup.opponent),
HandRead::Oracle => None,
HandRead::Given(p) => p,
};
let villains = (0..self.players())
.filter(|j| *j != i)
.map(|j| Villain { seat: j as u8 + 1, stack: self.stack[j], folded: self.folded[j], profile: read })
.map(|j| {
let profile = self.seat_reads.as_ref().map_or(read, |r| r[j]);
Villain { seat: j as u8 + 1, stack: self.stack[j], folded: self.folded[j], profile }
})
.collect();
let decision_seed = self.setup.seed ^ (self.result.hero_decisions as u64 + 1).wrapping_mul(0x9E37_79B9_7F4A_7C15);
Spot {
@@ -260,10 +284,16 @@ impl Table<'_> {
equity: decision.equity,
});
}
if self.keep_last {
self.last = Some((spot.street, decision.reason));
}
decision.choice
}
Err(_) => {
self.result.invalid += 1;
if self.keep_last {
self.last = Some((self.street, String::from("invalid")));
}
Choice::Abstain
}
};
@@ -283,8 +313,15 @@ impl Table<'_> {
fn reading(&self, i: usize) -> Reading {
let board = &self.setup.deal.board[..self.street.board_len()];
let seed = self.setup.seed ^ ((i as u64 + 1) << 32) ^ (self.street.board_len() as u64 + 1).wrapping_mul(0x51_7CC1);
let hole = &self.setup.deal.holes[i];
let live = self.live();
let strength = if self.field_strength && self.street != Street::Preflop && live > 2 {
super::reader::strength_field(hole, board, live - 1, Rng::seeded(seed))
} else {
strength(hole, board, Rng::seeded(seed))
};
Reading {
strength: strength(&self.setup.deal.holes[i], board, Rng::seeded(seed)),
strength,
pot: self.total.iter().sum(),
own_bet: self.bet[i],
preflop: self.street == Street::Preflop,
@@ -301,7 +338,7 @@ impl Table<'_> {
/// One action of seat `i`. For a world opponent (`Opponent::Welt`) the postflop action is also
/// logged as a `WorldEvent` (what an observer sees: street, texture, position, move, size, pace).
fn act(&mut self, i: usize) -> bool {
let welt = matches!(self.setup.opponent, Opponent::Welt(_)) && i != self.hero && self.street != Street::Preflop;
let welt = matches!(self.opps[i], Opponent::Welt(_)) && i != self.hero && self.street != Street::Preflop;
if !welt {
return self.act_inner(i);
}
@@ -339,10 +376,26 @@ impl Table<'_> {
fn act_inner(&mut self, i: usize) -> bool {
let view = self.view(i);
let act = if i == self.hero {
// Multiway LBR (`lbr6`): the best-responder's seat plays its own policy; before any other
// seat acts, the state is kept so its particles can be weighed by what it actually does.
if self.br.as_ref().is_some_and(|b| b.seat == i) {
let act = lbr6::decide(self, i, view);
return self.apply(i, view, act);
}
let before = self.br.is_some().then(|| self.snapshot());
let act = self.choose(i, view);
if let Some(before) = before {
lbr6::observe(self, &before, i, view, act);
}
self.apply(i, view, act)
}
/// What seat `i` (hero or a fixed opponent) plays facing `view`; advances the table's rng.
fn choose(&mut self, i: usize, view: View) -> Act {
if i == self.hero {
self.hero_act(view)
} else {
let (act, rng) = match self.setup.opponent {
let (act, rng) = match self.opps[i] {
Opponent::Welt(p) => {
let reading = self.reading(i);
let ctx = welt::Ctx {
@@ -391,7 +444,11 @@ impl Table<'_> {
};
self.rng = rng;
act
};
}
}
/// Carries out `act` of seat `i`; true when it raised.
fn apply(&mut self, i: usize, view: View, act: Act) -> bool {
match act {
Act::Fold => {
self.folded[i] = true;
@@ -547,6 +604,53 @@ impl<'a> Table<'a> {
trace,
world: Vec::new(),
welt_tank: None,
opps: vec![setup.opponent; n],
seat_reads: None,
last: None,
keep_last: false,
br: None,
nets: Vec::new(),
field_strength: false,
}
}
/// A copy of the state for a what-if query (`lbr6`): no trace, no LBR state.
fn snapshot(&self) -> Table<'a> {
self.with_setup(self.setup)
}
/// The same state at a table whose deal differs (another hole for one seat): the copy plays
/// the seat's policy on those cards with the SAME randomness the table had at this point.
fn with_setup<'b>(&self, setup: &'b HandSetup<'b>) -> Table<'b>
where
'a: 'b,
{
Table {
setup,
cost: self.cost,
lage: self.lage,
hero: self.hero,
stack: self.stack.clone(),
start: self.start.clone(),
bet: self.bet.clone(),
total: self.total.clone(),
folded: self.folded.clone(),
street: self.street,
max_bet: self.max_bet,
last_raise: self.last_raise,
history: self.history.clone(),
rng: self.rng,
result: self.result,
trace: None,
world: Vec::new(),
welt_tank: None,
opps: self.opps.clone(),
seat_reads: self.seat_reads.clone(),
last: None,
keep_last: false,
br: None,
nets: Vec::new(),
field_strength: self.field_strength,
}
}
@@ -575,6 +679,7 @@ impl<'a> Table<'a> {
self.result.hero_net = nets[self.hero];
self.result.rake = rake;
self.result.chips_lost = nets.iter().sum::<f64>() + rake;
self.nets = nets;
}
}
@@ -632,3 +737,27 @@ pub fn play_hand_history(setup: &HandSetup, cost: TableCost) -> (HandResult, Vec
t.run();
(t.result, t.history)
}
/// One hand at a MIXED table: `opponents[seat - 1]` plays each seat (hero's entry is ignored) and
/// `reads[seat - 1]` is the profile the engine sees on that seat (`setup.opponent` and `setup.read`
/// are then unused). Returns hero's result, the action history (for per-opponent memories) and the
/// street and reason text of hero's LAST decision (`start`: per-seat stacks, `None` = all `stack_bb`) (`None`: hero never had to act, e.g. a walk in the
/// big blind). The 6-max ladder (`sim::sechsmax`) and the multiway LBR are built on it. Reading
/// opponents judge their hand against the whole field postflop (`reader::strength_field`).
pub fn play_hand_mixed(
setup: &HandSetup,
cost: TableCost,
opponents: &[Opponent],
reads: &[Option<Profile>],
start: Option<&[f64]>,
) -> (HandResult, Vec<ActionRecord>, Option<(Street, String)>) {
assert_eq!(opponents.len(), setup.deal.holes.len(), "one opponent per seat");
assert_eq!(reads.len(), setup.deal.holes.len(), "one read per seat");
let mut t = Table::new(setup, cost, None, None, start.map(<[f64]>::to_vec));
t.opps = opponents.to_vec();
t.seat_reads = Some(reads.to_vec());
t.keep_last = true;
t.field_strength = true;
t.run();
(t.result, t.history, t.last)
}