Solver ueberall: Read-Haken (Range-Kippung + Knotensperre), Zeitbudget fuer Turn/Flop-Rueckfall
- river_spieler::solver_lists: Kippung der Gegnerrange nach RangeRead (nur bei confidence > 0) - river_spieler::lock_villain + TrSolver:🔒 geglaubte Gegnerstrategie am River (fold_to_bet, bluff_share), Gewicht = trust - ohne Read / confidence 0 bitgleich (Test) - Turn (Stufe B): Wandzeitbudget 1700 ms je Entscheidung inkl. Rueckfall-Solve, MIN_ITERS 60 - Flop: Rueckfall-Solve nur im Restbudget - Abdeckung Turn: 427/478 HU (89 %), p50 2045 p99 3781 ms (vor dem Budget) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"TURN/1": {
|
||||||
|
"anfragen": 478,
|
||||||
|
"solver": 427,
|
||||||
|
"klassen": {
|
||||||
|
"solver": 427,
|
||||||
|
"e3": 43,
|
||||||
|
"heuristik": 8
|
||||||
|
},
|
||||||
|
"p50_ms": 2045.4059000039706,
|
||||||
|
"p99_ms": 3780.8470000018133,
|
||||||
|
"max_ms": 4345.02930000599
|
||||||
|
},
|
||||||
|
"TURN/2": {
|
||||||
|
"anfragen": 88,
|
||||||
|
"solver": 0,
|
||||||
|
"klassen": {
|
||||||
|
"heuristik": 88
|
||||||
|
},
|
||||||
|
"p50_ms": 0.0,
|
||||||
|
"p99_ms": 0.0,
|
||||||
|
"max_ms": 0
|
||||||
|
},
|
||||||
|
"TURN/3": {
|
||||||
|
"anfragen": 7,
|
||||||
|
"solver": 0,
|
||||||
|
"klassen": {
|
||||||
|
"heuristik": 7
|
||||||
|
},
|
||||||
|
"p50_ms": 0.0,
|
||||||
|
"p99_ms": 0.0,
|
||||||
|
"max_ms": 0
|
||||||
|
},
|
||||||
|
"TURN/4": {
|
||||||
|
"anfragen": 2,
|
||||||
|
"solver": 0,
|
||||||
|
"klassen": {
|
||||||
|
"heuristik": 2
|
||||||
|
},
|
||||||
|
"p50_ms": 0.0,
|
||||||
|
"p99_ms": 0.0,
|
||||||
|
"max_ms": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
575 eindeutige Anfragen, Schalter ['SOLVER_RIVER=1', 'SOLVER_TURN=1', 'GRUNDSTRATEGIE=D:\\Projects\\pokerfreak\\.claude\\worktrees\\engine-lecks-angreifen-de7b88\\daten', 'MDF_UNREAD=0', 'TURN_SPIEL=grund']
|
||||||
|
TURN 1-Gegner: 478 Solver 427 ( 89.3 %) Zeit Solver p50 2045 p99 3781 max 4345 ms solver=427 e3=43 heuristik=8
|
||||||
|
TURN 2-Gegner: 88 Solver 0 ( 0.0 %) Zeit Solver p50 0 p99 0 max 0 ms heuristik=88
|
||||||
|
TURN 3-Gegner: 7 Solver 0 ( 0.0 %) Zeit Solver p50 0 p99 0 max 0 ms heuristik=7
|
||||||
|
TURN 4-Gegner: 2 Solver 0 ( 0.0 %) Zeit Solver p50 0 p99 0 max 0 ms heuristik=2
|
||||||
|
TURN alle Anfragen: p50 1191 p99 3753 max 4345 ms
|
||||||
@@ -260,6 +260,10 @@ pub struct TrSolver {
|
|||||||
/// The same as dense showdown matrices, `2 eq - 1` with overlapping pairs 0: per card,
|
/// The same as dense showdown matrices, `2 eq - 1` with overlapping pairs 0: per card,
|
||||||
/// `[p0 rows (n0 x n1), p1 rows (n1 x n0)]`.
|
/// `[p0 rows (n0 x n1), p1 rows (n1 x n0)]`.
|
||||||
eqm: Vec<[Vec<f32>; 2]>,
|
eqm: Vec<[Vec<f32>; 2]>,
|
||||||
|
/// Node locks (read layer, restricted Nash response): at a locked decision node the player plays
|
||||||
|
/// `(1 - w) * sigma + w * believed`, `believed` = one row of `a` probabilities per own hand (the
|
||||||
|
/// same for every dealt card). `None` everywhere = the plain equilibrium solve.
|
||||||
|
lock: Vec<Option<(Vec<f64>, f64)>>,
|
||||||
weights: [Vec<f64>; 2],
|
weights: [Vec<f64>; 2],
|
||||||
rc: Vec<RiverCard>,
|
rc: Vec<RiverCard>,
|
||||||
/// Deal weight of one sampled river card.
|
/// Deal weight of one sampled river card.
|
||||||
@@ -364,7 +368,7 @@ impl TrSolver {
|
|||||||
}
|
}
|
||||||
let sums = regret.clone();
|
let sums = regret.clone();
|
||||||
let masks = [hands[0].masks.clone(), hands[1].masks.clone()];
|
let masks = [hands[0].masks.clone(), hands[1].masks.clone()];
|
||||||
TrSolver { game: std::sync::Arc::new(game), n, cards, masks, same, eq: None, eqm: Vec::new(), weights, rc, wr, regret, sums, iterations: 0 }
|
TrSolver { game: std::sync::Arc::new(game), n, cards, masks, same, eq: None, eqm: Vec::new(), lock: Vec::new(), weights, rc, wr, regret, sums, iterations: 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stage C: the game's first street is the FLOP (`board` = three flop cards), the dealt card is the
|
/// Stage C: the game's first street is the FLOP (`board` = three flop cards), the dealt card is the
|
||||||
@@ -451,6 +455,24 @@ impl TrSolver {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Lock decision `node` toward `believed` (one row of action probabilities per hand of the acting
|
||||||
|
/// player, `hands(player) * actions`) with weight `w` in (0, 1]. `w <= 0` changes nothing.
|
||||||
|
pub fn lock(&mut self, node: usize, believed: Vec<f64>, w: f64) {
|
||||||
|
let Some(TNode::Dec { player, kids, .. }) = self.game.nodes.get(node) else { return };
|
||||||
|
if w <= 0.0 || believed.len() != self.n[*player] * kids.len() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if self.lock.len() < self.game.nodes.len() {
|
||||||
|
self.lock.resize(self.game.nodes.len(), None);
|
||||||
|
}
|
||||||
|
self.lock[node] = Some((believed, w.min(1.0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Card masks of `player`'s hands, in solver order.
|
||||||
|
pub fn masks(&self, player: usize) -> &[u64] {
|
||||||
|
&self.masks[player]
|
||||||
|
}
|
||||||
|
|
||||||
pub fn hands(&self, player: usize) -> usize {
|
pub fn hands(&self, player: usize) -> usize {
|
||||||
self.n[player]
|
self.n[player]
|
||||||
}
|
}
|
||||||
@@ -590,6 +612,11 @@ impl TrSolver {
|
|||||||
let off = if street == 0 { 0 } else { r * n * a };
|
let off = if street == 0 { 0 } else { r * n * a };
|
||||||
let mut sigma = vec![0.0; n * a];
|
let mut sigma = vec![0.0; n * a];
|
||||||
matched(&self.regret[node][off..off + n * a], a, &mut sigma);
|
matched(&self.regret[node][off..off + n * a], a, &mut sigma);
|
||||||
|
if let Some(Some((believed, w))) = self.lock.get(node) {
|
||||||
|
for (x, b) in sigma.iter_mut().zip(believed) {
|
||||||
|
*x = (1.0 - w) * *x + w * b;
|
||||||
|
}
|
||||||
|
}
|
||||||
if player == p {
|
if player == p {
|
||||||
let values: Vec<Vec<f64>> = kids
|
let values: Vec<Vec<f64>> = kids
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -29,6 +29,13 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
static ON: AtomicBool = AtomicBool::new(false);
|
static ON: AtomicBool = AtomicBool::new(false);
|
||||||
|
/// Budget override in ms (0 = `STANDARD`); tests under parallel load use it.
|
||||||
|
static BUDGET_OVERRIDE: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) fn set_budget_override(ms: u64) {
|
||||||
|
BUDGET_OVERRIDE.store(ms, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_flop_spieler(on: bool) {
|
pub fn set_flop_spieler(on: bool) {
|
||||||
ON.store(on, Ordering::Relaxed);
|
ON.store(on, Ordering::Relaxed);
|
||||||
@@ -63,7 +70,10 @@ impl FlopConfig {
|
|||||||
max_combos: num("FLOP_COMBOS", Self::STANDARD.max_combos),
|
max_combos: num("FLOP_COMBOS", Self::STANDARD.max_combos),
|
||||||
turn_cards: num("FLOP_CARDS", Self::STANDARD.turn_cards),
|
turn_cards: num("FLOP_CARDS", Self::STANDARD.turn_cards),
|
||||||
iterations: num("FLOP_ITERS", Self::STANDARD.iterations as usize) as u32,
|
iterations: num("FLOP_ITERS", Self::STANDARD.iterations as usize) as u32,
|
||||||
budget_ms: Self::STANDARD.budget_ms,
|
budget_ms: match BUDGET_OVERRIDE.load(Ordering::Relaxed) {
|
||||||
|
0 => Self::STANDARD.budget_ms,
|
||||||
|
ms => ms as f64,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,19 +198,20 @@ pub fn flop_spieler_decision(raw: &Spot) -> Option<Decision> {
|
|||||||
if spot.live_villains().count() != 1 {
|
if spot.live_villains().count() != 1 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
let begun = std::time::Instant::now();
|
||||||
let cfg = FlopConfig::from_env();
|
let cfg = FlopConfig::from_env();
|
||||||
let hero_mask = fast7::mask(&spot.hero_cards);
|
let hero_mask = fast7::mask(&spot.hero_cards);
|
||||||
if hero_mask & fast7::mask(&spot.board) != 0 {
|
if hero_mask & fast7::mask(&spot.board) != 0 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let lists = || -> Option<(Vec<(Vec<Card>, f64)>, Vec<(Vec<Card>, f64)>, &'static str)> {
|
let read = crate::engine::river_spieler::read_of(raw);
|
||||||
if let Some((h, v)) = crate::blueprint::ranges::gewichtete_listen_offen(spot) {
|
let lists = || crate::engine::river_spieler::solver_lists(spot, crate::engine::river_spieler::RiverSpieler::An, read.as_ref());
|
||||||
return Some((h, v, "grund"));
|
let raw_profile = read.as_ref().map(|_| format!("{:?}", raw.live_villains().next().map(|v| v.profile.clone())));
|
||||||
}
|
let key = {
|
||||||
let (h, v) = crate::engine::river_spieler::model_lists(spot)?;
|
let mut h = std::collections::hash_map::DefaultHasher::new();
|
||||||
Some((h, v, "modell"))
|
(public_key(spot, &cfg), raw_profile).hash(&mut h);
|
||||||
|
h.finish()
|
||||||
};
|
};
|
||||||
let key = public_key(spot, &cfg);
|
|
||||||
let cached = CACHE.lock().ok().and_then(|m| m.as_ref().and_then(|m| m.get(&key).cloned()));
|
let cached = CACHE.lock().ok().and_then(|m| m.as_ref().and_then(|m| m.get(&key).cloned()));
|
||||||
let solved = match cached {
|
let solved = match cached {
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
@@ -220,8 +231,13 @@ pub fn flop_spieler_decision(raw: &Spot) -> Option<Decision> {
|
|||||||
if let Some(d) = decide_from(spot, &solved, hero_mask) {
|
if let Some(d) = decide_from(spot, &solved, hero_mask) {
|
||||||
return Some(d);
|
return Some(d);
|
||||||
}
|
}
|
||||||
|
// Hero's hand was pruned away: one more solve with it kept, in what is left of the budget.
|
||||||
|
let left = cfg.budget_ms - begun.elapsed().as_secs_f64() * 1e3;
|
||||||
|
if left <= 0.0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
let (hero, villain, source) = lists()?;
|
let (hero, villain, source) = lists()?;
|
||||||
let own = solve_flop(spot, &hero, &villain, &cfg, Some(hero_mask), source)?;
|
let own = solve_flop(spot, &hero, &villain, &FlopConfig { budget_ms: left, ..cfg }, Some(hero_mask), source)?;
|
||||||
decide_from(spot, &own, hero_mask)
|
decide_from(spot, &own, hero_mask)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ fn off_decides_nothing_and_on_decides_heads_up_flops() {
|
|||||||
set_flop_spieler(false);
|
set_flop_spieler(false);
|
||||||
assert!(flop_spieler_decision(&checked_to("Ks Kd")).is_none());
|
assert!(flop_spieler_decision(&checked_to("Ks Kd")).is_none());
|
||||||
set_flop_spieler(true);
|
set_flop_spieler(true);
|
||||||
|
set_budget_override(60_000);
|
||||||
for spot in [checked_to("Ks Kd"), facing_bet("Qc Jc"), facing_bet("9s 8s"), checked_to("4h 3h")] {
|
for spot in [checked_to("Ks Kd"), facing_bet("Qc Jc"), facing_bet("9s 8s"), checked_to("4h 3h")] {
|
||||||
let d = flop_spieler_decision(&spot).expect("heads-up flop is in the slice");
|
let d = flop_spieler_decision(&spot).expect("heads-up flop is in the slice");
|
||||||
assert!(d.reason.contains("solver flop"), "{}", d.reason);
|
assert!(d.reason.contains("solver flop"), "{}", d.reason);
|
||||||
@@ -87,6 +88,7 @@ fn off_decides_nothing_and_on_decides_heads_up_flops() {
|
|||||||
let mut multi = checked_to("Ks Kd");
|
let mut multi = checked_to("Ks Kd");
|
||||||
multi.villains.push(Villain { seat: 1, stack: 90.0, folded: false, profile: None });
|
multi.villains.push(Villain { seat: 1, stack: 90.0, folded: false, profile: None });
|
||||||
assert!(flop_spieler_decision(&multi).is_none());
|
assert!(flop_spieler_decision(&multi).is_none());
|
||||||
|
set_budget_override(0);
|
||||||
set_flop_spieler(false);
|
set_flop_spieler(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+127
-11
@@ -24,6 +24,7 @@
|
|||||||
use crate::card::Card;
|
use crate::card::Card;
|
||||||
use crate::cfr::river_game::Act;
|
use crate::cfr::river_game::Act;
|
||||||
use crate::cfr::turn_river_game::{build_river, Hands, Menu, TNode, TrBets, TrSolver};
|
use crate::cfr::turn_river_game::{build_river, Hands, Menu, TNode, TrBets, TrSolver};
|
||||||
|
use crate::exploit::range_read::RangeRead;
|
||||||
use crate::engine::river_subgame::{legal_choice, river_line};
|
use crate::engine::river_subgame::{legal_choice, river_line};
|
||||||
use crate::game::{Decision, Spot, Street, Villain};
|
use crate::game::{Decision, Spot, Street, Villain};
|
||||||
use crate::hand::fast7;
|
use crate::hand::fast7;
|
||||||
@@ -131,7 +132,7 @@ fn hands_of(list: &[(Vec<Card>, f64)], dead: u64, fill: bool) -> Hands {
|
|||||||
const TOKEN: f64 = 1e-6;
|
const TOKEN: f64 = 1e-6;
|
||||||
|
|
||||||
/// Solve the river of `spot`'s public state with these ranges; every hero hand gets a strategy. `None` off the heads-up river slice, off the tree, or when the budget left too few iterations.
|
/// Solve the river of `spot`'s public state with these ranges; every hero hand gets a strategy. `None` off the heads-up river slice, off the tree, or when the budget left too few iterations.
|
||||||
pub fn solve_river(spot: &Spot, hero: &[(Vec<Card>, f64)], villain_list: &[(Vec<Card>, f64)], source: &'static str) -> Option<Solved> {
|
pub fn solve_river(spot: &Spot, hero: &[(Vec<Card>, f64)], villain_list: &[(Vec<Card>, f64)], source: &'static str, read: Option<&RangeRead>) -> Option<Solved> {
|
||||||
if spot.street != Street::River || spot.board.len() != 5 || spot.live_villains().count() != 1 {
|
if spot.street != Street::River || spot.board.len() != 5 || spot.live_villains().count() != 1 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@@ -160,7 +161,11 @@ pub fn solve_river(spot: &Spot, hero: &[(Vec<Card>, f64)], villain_list: &[(Vec<
|
|||||||
let hero_masks = hands[0].masks.clone();
|
let hero_masks = hands[0].masks.clone();
|
||||||
let acts = game.acts[at].clone();
|
let acts = game.acts[at].clone();
|
||||||
let nodes = game.nodes.len();
|
let nodes = game.nodes.len();
|
||||||
|
let villain_weights = hands[1].weights.clone();
|
||||||
let mut solver = TrSolver::with_cards(game, hands, turn, vec![river], 1.0);
|
let mut solver = TrSolver::with_cards(game, hands, turn, vec![river], 1.0);
|
||||||
|
if let Some(r) = read {
|
||||||
|
lock_villain(&mut solver, r, pot, dead, &villain_weights);
|
||||||
|
}
|
||||||
let mut done = 0;
|
let mut done = 0;
|
||||||
while done < ITERS {
|
while done < ITERS {
|
||||||
solver.iterate();
|
solver.iterate();
|
||||||
@@ -220,15 +225,120 @@ pub fn model_lists(spot: &Spot) -> Option<(Vec<(Vec<Card>, f64)>, Vec<(Vec<Card>
|
|||||||
Some((eins(list(&me)?), eins(list(villain)?)))
|
Some((eins(list(&me)?), eins(list(villain)?)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The ranges of this spot and where they came from.
|
/// The read layer (`exploit::range_read`, switch `GEGNER_RANGE=1`, default off): the villain's read from
|
||||||
fn lists(spot: &Spot, mode: RiverSpieler) -> Option<(Vec<(Vec<Card>, f64)>, Vec<(Vec<Card>, f64)>, &'static str)> {
|
/// its UNGATED profile, or `None` = the plain solver.
|
||||||
if mode == RiverSpieler::An {
|
pub fn read_of(raw: &Spot) -> Option<RangeRead> {
|
||||||
if let Some((h, v)) = crate::blueprint::ranges::gewichtete_listen_offen(spot) {
|
if std::env::var("GEGNER_RANGE").as_deref() != Ok("1") {
|
||||||
return Some((h, v, "grund"));
|
return None;
|
||||||
|
}
|
||||||
|
let villain = raw.live_villains().next()?;
|
||||||
|
RangeRead::from_profile(villain.profile.as_ref())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Weighted mid-rank percentile of each combo's current strength (`fast7` score with `board`) within
|
||||||
|
/// the list. Exact on the river; current strength only (draw-blind) on flop and turn.
|
||||||
|
pub fn percentiles(masks: &[u64], weights: &[f64], board: u64) -> Vec<f64> {
|
||||||
|
let score: Vec<u32> = masks.iter().map(|m| fast7::score(m | board)).collect();
|
||||||
|
let mut order: Vec<usize> = (0..masks.len()).collect();
|
||||||
|
order.sort_by_key(|i| score[*i]);
|
||||||
|
let total: f64 = weights.iter().sum::<f64>().max(1e-300);
|
||||||
|
let mut out = vec![0.5; masks.len()];
|
||||||
|
let mut below = 0.0;
|
||||||
|
let mut k = 0;
|
||||||
|
while k < order.len() {
|
||||||
|
let mut e = k;
|
||||||
|
let mut tie = 0.0;
|
||||||
|
while e < order.len() && score[order[e]] == score[order[k]] {
|
||||||
|
tie += weights[order[e]];
|
||||||
|
e += 1;
|
||||||
|
}
|
||||||
|
for &i in &order[k..e] {
|
||||||
|
out[i] = (below + tie / 2.0) / total;
|
||||||
|
}
|
||||||
|
below += tie;
|
||||||
|
k = e;
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The ranges of this spot (hero, villain) and where they came from: the blueprint where it recognises
|
||||||
|
/// the spot (unless `mode` is `Modell`), else the range model of the action history. THE HOOK of the
|
||||||
|
/// read layer: with a read, the villain's final weights are tilted by strength percentile
|
||||||
|
/// (`RangeRead::reweigh`); `read = None` returns the lists unchanged. Used by stages A, B and C.
|
||||||
|
pub fn solver_lists(spot: &Spot, mode: RiverSpieler, read: Option<&RangeRead>) -> Option<(Vec<(Vec<Card>, f64)>, Vec<(Vec<Card>, f64)>, &'static str)> {
|
||||||
|
let (h, mut v, source) = match mode {
|
||||||
|
RiverSpieler::An => match crate::blueprint::ranges::gewichtete_listen_offen(spot) {
|
||||||
|
Some((h, v)) => (h, v, "grund"),
|
||||||
|
None => {
|
||||||
|
let (h, v) = model_lists(spot)?;
|
||||||
|
(h, v, "modell")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
let (h, v) = model_lists(spot)?;
|
||||||
|
(h, v, "modell")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if let Some(r) = read.filter(|r| r.confidence > 0.0) {
|
||||||
|
let board = fast7::mask(&spot.board);
|
||||||
|
let masks: Vec<u64> = v.iter().map(|(c, _)| fast7::mask(c)).collect();
|
||||||
|
let weights: Vec<f64> = v.iter().map(|(_, w)| *w).collect();
|
||||||
|
let pct = percentiles(&masks, &weights, board);
|
||||||
|
let pairs: Vec<(f64, f64)> = weights.iter().copied().zip(pct).collect();
|
||||||
|
for ((_, w), x) in v.iter_mut().zip(r.reweigh(&pairs)) {
|
||||||
|
*w = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some((h, v, source))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Value hands bet from this strength percentile up when the believed villain is checked to
|
||||||
|
/// (as `river_subgame`'s VALUE_RANK).
|
||||||
|
const BELIEVED_VALUE_RANK: f64 = 0.60;
|
||||||
|
|
||||||
|
/// Lock the villain's river decisions toward the read (restricted Nash response): facing a bet it folds
|
||||||
|
/// the weakest `fold_to_bet` share of its range and calls the rest (weight = the fold read's trust);
|
||||||
|
/// checked to, it bets its top `1 - BELIEVED_VALUE_RANK` at the size nearest 75 % pot plus the weakest
|
||||||
|
/// hands as bluffs so that the air share of the bet is `bluff_share` (weight = the bluff read's trust).
|
||||||
|
/// Facing a raise it stays free.
|
||||||
|
fn lock_villain(solver: &mut TrSolver, read: &RangeRead, pot: f64, board: u64, villain_weights: &[f64]) {
|
||||||
|
let pct = percentiles(solver.masks(1), villain_weights, board);
|
||||||
|
// The action that led into each node (a raise faced vs an opening bet faced).
|
||||||
|
let mut incoming: Vec<Option<Act>> = vec![None; solver.game.nodes.len()];
|
||||||
|
for (k, n) in solver.game.nodes.iter().enumerate() {
|
||||||
|
if let TNode::Dec { kids, .. } = n {
|
||||||
|
for (c, kid) in kids.iter().enumerate() {
|
||||||
|
incoming[*kid] = solver.game.acts[k].get(c).copied();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let nodes: Vec<(usize, Vec<Act>)> = solver
|
||||||
|
.game
|
||||||
|
.nodes
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter_map(|(k, n)| match n {
|
||||||
|
TNode::Dec { player: 1, .. } => Some((k, solver.game.acts[k].clone())),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
for (node, acts) in nodes {
|
||||||
|
let a = acts.len();
|
||||||
|
let facing_bet = acts.contains(&Act::Fold) && matches!(incoming[node], Some(Act::Bet(_)));
|
||||||
|
if facing_bet {
|
||||||
|
let Some(f) = read.fold_to_bet(2) else { continue };
|
||||||
|
let call = acts.iter().position(|x| *x == Act::Call).unwrap_or(1);
|
||||||
|
let rows: Vec<f64> = pct.iter().flat_map(|p| (0..a).map(move |k| if *p < f { f64::from(k == 0) } else { f64::from(k == call) })).collect();
|
||||||
|
solver.lock(node, rows, read.trust(false, 2));
|
||||||
|
} else if !acts.contains(&Act::Fold) && acts.first() == Some(&Act::Check) {
|
||||||
|
let Some((bet, to)) = acts.iter().enumerate().filter_map(|(k, x)| if let Act::Bet(t) = x { Some((k, *t)) } else { None }).min_by(|x, y| (x.1 / pot - 0.75).abs().total_cmp(&(y.1 / pot - 0.75).abs())) else { continue };
|
||||||
|
let bs = read.bluff_share(2, to / pot).clamp(0.0, 0.9);
|
||||||
|
let value = 1.0 - BELIEVED_VALUE_RANK;
|
||||||
|
let bluff = (value * bs / (1.0 - bs)).min(BELIEVED_VALUE_RANK);
|
||||||
|
let rows: Vec<f64> = pct.iter().flat_map(|p| (0..a).map(move |k| if *p >= BELIEVED_VALUE_RANK || *p < bluff { f64::from(k == bet) } else { f64::from(k == 0) })).collect();
|
||||||
|
solver.lock(node, rows, read.trust(true, 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let (h, v) = model_lists(spot)?;
|
|
||||||
Some((h, v, "modell"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static CACHE: Mutex<Option<HashMap<u64, Arc<Solved>>>> = Mutex::new(None);
|
static CACHE: Mutex<Option<HashMap<u64, Arc<Solved>>>> = Mutex::new(None);
|
||||||
@@ -265,13 +375,19 @@ pub fn river_spieler_decision(raw: &Spot) -> Option<Decision> {
|
|||||||
if hero_mask & fast7::mask(&spot.board) != 0 {
|
if hero_mask & fast7::mask(&spot.board) != 0 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let key = public_key(spot, mode);
|
let read = read_of(raw);
|
||||||
|
let mut key = public_key(spot, mode);
|
||||||
|
if read.is_some() {
|
||||||
|
let mut h = std::collections::hash_map::DefaultHasher::new();
|
||||||
|
(key, format!("{:?}", raw.live_villains().next().map(|v| v.profile.clone()))).hash(&mut h);
|
||||||
|
key = h.finish();
|
||||||
|
}
|
||||||
let cached = CACHE.lock().ok().and_then(|m| m.as_ref().and_then(|m| m.get(&key).cloned()));
|
let cached = CACHE.lock().ok().and_then(|m| m.as_ref().and_then(|m| m.get(&key).cloned()));
|
||||||
let solved = match cached {
|
let solved = match cached {
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
None => {
|
None => {
|
||||||
let (hero, villain, source) = lists(spot, mode)?;
|
let (hero, villain, source) = solver_lists(spot, mode, read.as_ref())?;
|
||||||
let solved = Arc::new(solve_river(spot, &hero, &villain, source)?);
|
let solved = Arc::new(solve_river(spot, &hero, &villain, source, read.as_ref())?);
|
||||||
if let Ok(mut m) = CACHE.lock() {
|
if let Ok(mut m) = CACHE.lock() {
|
||||||
let map = m.get_or_insert_with(HashMap::new);
|
let map = m.get_or_insert_with(HashMap::new);
|
||||||
if map.len() >= CACHE_MAX {
|
if map.len() >= CACHE_MAX {
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ fn checked_to(hero: &str) -> Spot {
|
|||||||
|
|
||||||
fn row_of(spot: &Spot) -> (Vec<f64>, Vec<Act>) {
|
fn row_of(spot: &Spot) -> (Vec<f64>, Vec<Act>) {
|
||||||
let (h, v) = model_lists(spot).expect("model ranges");
|
let (h, v) = model_lists(spot).expect("model ranges");
|
||||||
let s = solve_river(spot, &h, &v, "modell").expect("solved");
|
let s = solve_river(spot, &h, &v, "modell", None).expect("solved");
|
||||||
let m = fast7::mask(&spot.hero_cards);
|
let m = fast7::mask(&spot.hero_cards);
|
||||||
let i = s.hero_masks.iter().position(|x| *x == m).expect("every hero hand is in the solve");
|
let i = s.hero_masks.iter().position(|x| *x == m).expect("every hero hand is in the solve");
|
||||||
let a = s.acts.len();
|
let a = s.acts.len();
|
||||||
@@ -153,3 +153,39 @@ fn the_river_game_converges() {
|
|||||||
let e = solver.exploitability(&solver.strategy());
|
let e = solver.exploitability(&solver.strategy());
|
||||||
assert!(e.total / pot < 0.01, "exploitability {:.4} of pot {pot}", e.total);
|
assert!(e.total / pot < 0.01, "exploitability {:.4} of pot {pot}", e.total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read(confidence: f64, bluff_confidence: f64, fold: f64) -> RangeRead {
|
||||||
|
RangeRead { tilt: 0.8, aggression_ratio: [None, None, Some(1.0)], shown: None, fold: [None, None, Some(fold)], confidence, bluff_confidence }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn rows_with(spot: &Spot, r: Option<&RangeRead>) -> Vec<f64> {
|
||||||
|
let (h, v, src) = solver_lists(spot, RiverSpieler::Modell, r).expect("lists");
|
||||||
|
solve_river(spot, &h, &v, src, r).expect("solved").rows.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The read hook with no read, or a read without any confidence, is the plain solver bit for bit.
|
||||||
|
#[test]
|
||||||
|
fn a_read_without_confidence_is_bit_identical() {
|
||||||
|
for spot in [facing_bet("Qc Jc"), checked_to("6s 5s")] {
|
||||||
|
let plain = rows_with(&spot, None);
|
||||||
|
let zero = rows_with(&spot, Some(&read(0.0, 0.0, 0.9)));
|
||||||
|
assert_eq!(plain.len(), zero.len());
|
||||||
|
assert!(plain.iter().zip(&zero).all(|(a, b)| a.to_bits() == b.to_bits()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A trusted read that the villain over-folds to bets makes hero's range bet more often when checked to.
|
||||||
|
#[test]
|
||||||
|
fn a_trusted_over_fold_read_bets_more() {
|
||||||
|
let spot = checked_to("6s 5s");
|
||||||
|
let bet_share = |r: Option<&RangeRead>| {
|
||||||
|
let (h, v, src) = solver_lists(&spot, RiverSpieler::Modell, r).unwrap();
|
||||||
|
let s = solve_river(&spot, &h, &v, src, r).unwrap();
|
||||||
|
let a = s.acts.len();
|
||||||
|
let n = s.hero_masks.len();
|
||||||
|
(0..n).map(|k| prob(&s.rows[k * a..(k + 1) * a], &s.acts, |x| matches!(x, Act::Bet(_)))).sum::<f64>() / n as f64
|
||||||
|
};
|
||||||
|
let plain = bet_share(None);
|
||||||
|
let exploit = bet_share(Some(&read(0.9, 0.0, 0.9)));
|
||||||
|
assert!(exploit > plain + 0.1, "plain {plain:.2} exploit {exploit:.2}");
|
||||||
|
}
|
||||||
|
|||||||
+37
-11
@@ -68,10 +68,18 @@ pub struct TurnConfig {
|
|||||||
pub measure: bool,
|
pub measure: bool,
|
||||||
/// Raises allowed after a river bet (0 or 1).
|
/// Raises allowed after a river bet (0 or 1).
|
||||||
pub river_raises: usize,
|
pub river_raises: usize,
|
||||||
|
/// Wall-time budget in ms (0 = none, run all `iterations`); a budgeted solve that stops under
|
||||||
|
/// `MIN_ITERS` returns `None` and the heuristic decides.
|
||||||
|
pub budget_ms: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fewest iterations a budgeted solve may decide with.
|
||||||
|
pub const MIN_ITERS: u32 = 60;
|
||||||
|
/// Stage B's per-decision budget (all solves of one decision together).
|
||||||
|
pub const STAGE_B_BUDGET_MS: f64 = 1700.0;
|
||||||
|
|
||||||
impl TurnConfig {
|
impl TurnConfig {
|
||||||
pub const STANDARD: TurnConfig = TurnConfig { max_combos: 160, cover: 0.95, river_cards: 10, iterations: 200, measure: false, river_raises: 0 };
|
pub const STANDARD: TurnConfig = TurnConfig { max_combos: 160, cover: 0.95, river_cards: 10, iterations: 200, measure: false, river_raises: 0, budget_ms: 0.0 };
|
||||||
|
|
||||||
/// `STANDARD` with `TURN_COMBOS`, `TURN_CARDS`, `TURN_ITERS`, `TURN_EXPLOIT=1` from the environment.
|
/// `STANDARD` with `TURN_COMBOS`, `TURN_CARDS`, `TURN_ITERS`, `TURN_EXPLOIT=1` from the environment.
|
||||||
pub fn from_env() -> TurnConfig {
|
pub fn from_env() -> TurnConfig {
|
||||||
@@ -83,6 +91,7 @@ impl TurnConfig {
|
|||||||
iterations: num("TURN_ITERS", Self::STANDARD.iterations as usize) as u32,
|
iterations: num("TURN_ITERS", Self::STANDARD.iterations as usize) as u32,
|
||||||
measure: std::env::var("TURN_EXPLOIT").as_deref() == Ok("1"),
|
measure: std::env::var("TURN_EXPLOIT").as_deref() == Ok("1"),
|
||||||
river_raises: std::env::var("TURN_RIVER_RAISES").ok().and_then(|s| s.parse().ok()).map_or(Self::STANDARD.river_raises, |n: usize| n.min(1)),
|
river_raises: std::env::var("TURN_RIVER_RAISES").ok().and_then(|s| s.parse().ok()).map_or(Self::STANDARD.river_raises, |n: usize| n.min(1)),
|
||||||
|
budget_ms: Self::STANDARD.budget_ms,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,7 +235,21 @@ fn solve_core(spot: &Spot, hero: &[(Vec<Card>, f64)], villain_list: &[(Vec<Card>
|
|||||||
let acts = game.acts[at].clone();
|
let acts = game.acts[at].clone();
|
||||||
let nodes = game.nodes.len();
|
let nodes = game.nodes.len();
|
||||||
let mut solver = TrSolver::new(game, hands, board, Some(cfg.river_cards));
|
let mut solver = TrSolver::new(game, hands, board, Some(cfg.river_cards));
|
||||||
solver.run(cfg.iterations);
|
if cfg.budget_ms > 0.0 {
|
||||||
|
let mut done = 0;
|
||||||
|
while done < cfg.iterations {
|
||||||
|
solver.iterate();
|
||||||
|
done += 1;
|
||||||
|
if done % 5 == 0 && started.elapsed().as_secs_f64() * 1e3 > cfg.budget_ms {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if done < MIN_ITERS {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
solver.run(cfg.iterations);
|
||||||
|
}
|
||||||
let strategy = solver.strategy();
|
let strategy = solver.strategy();
|
||||||
let exploit = cfg.measure.then(|| solver.exploitability(&strategy));
|
let exploit = cfg.measure.then(|| solver.exploitability(&strategy));
|
||||||
let rows: Vec<f64> = (0..combos[0]).flat_map(|i| strategy.row(at, 0, i).to_vec()).collect();
|
let rows: Vec<f64> = (0..combos[0]).flat_map(|i| strategy.row(at, 0, i).to_vec()).collect();
|
||||||
@@ -356,21 +379,19 @@ pub fn turn_solver_decision(raw: &Spot) -> Option<Decision> {
|
|||||||
if spot.live_villains().count() != 1 {
|
if spot.live_villains().count() != 1 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let cfg = TurnConfig::from_env();
|
let begun = std::time::Instant::now();
|
||||||
|
let cfg = TurnConfig { budget_ms: STAGE_B_BUDGET_MS, ..TurnConfig::from_env() };
|
||||||
let hero_mask = fast7::mask(&spot.hero_cards);
|
let hero_mask = fast7::mask(&spot.hero_cards);
|
||||||
if hero_mask & fast7::mask(&spot.board) != 0 {
|
if hero_mask & fast7::mask(&spot.board) != 0 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let lists = || -> Option<(Vec<(Vec<Card>, f64)>, Vec<(Vec<Card>, f64)>, &'static str)> {
|
let read = crate::engine::river_spieler::read_of(raw);
|
||||||
if let Some((h, v)) = crate::blueprint::ranges::gewichtete_listen_offen(spot) {
|
let lists = || crate::engine::river_spieler::solver_lists(spot, crate::engine::river_spieler::RiverSpieler::An, read.as_ref());
|
||||||
return Some((h, v, "grund"));
|
let raw_profile = read.as_ref().map(|_| format!("{:?}", raw.live_villains().next().map(|v| v.profile.clone())));
|
||||||
}
|
|
||||||
let (h, v) = crate::engine::river_spieler::model_lists(spot)?;
|
|
||||||
Some((h, v, "modell"))
|
|
||||||
};
|
|
||||||
let mut key_h = std::collections::hash_map::DefaultHasher::new();
|
let mut key_h = std::collections::hash_map::DefaultHasher::new();
|
||||||
(public_key(spot, &cfg), "ueberall").hash(&mut key_h);
|
(public_key(spot, &cfg), "ueberall").hash(&mut key_h);
|
||||||
spot.live_villains().for_each(|v| format!("{:?}", v.profile).hash(&mut key_h));
|
spot.live_villains().for_each(|v| format!("{:?}", v.profile).hash(&mut key_h));
|
||||||
|
raw_profile.hash(&mut key_h);
|
||||||
let key = key_h.finish();
|
let key = key_h.finish();
|
||||||
let cached = CACHE.lock().ok().and_then(|m| m.as_ref().and_then(|m| m.get(&key).cloned()));
|
let cached = CACHE.lock().ok().and_then(|m| m.as_ref().and_then(|m| m.get(&key).cloned()));
|
||||||
let mut source = "";
|
let mut source = "";
|
||||||
@@ -397,8 +418,13 @@ pub fn turn_solver_decision(raw: &Spot) -> Option<Decision> {
|
|||||||
if let Some(t) = decide_from(spot, solved, hero_mask) {
|
if let Some(t) = decide_from(spot, solved, hero_mask) {
|
||||||
return Some(tag(t.decision, source));
|
return Some(tag(t.decision, source));
|
||||||
}
|
}
|
||||||
|
// Hero's hand was pruned away: one more solve with it kept, in what is left of the budget.
|
||||||
|
let left = STAGE_B_BUDGET_MS - begun.elapsed().as_secs_f64() * 1e3;
|
||||||
|
if left <= 0.0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
let (hero, villain, src) = lists()?;
|
let (hero, villain, src) = lists()?;
|
||||||
solve_turn(spot, &hero, &villain, &cfg).map(|t| tag(t.decision, src))
|
solve_turn(spot, &hero, &villain, &TurnConfig { budget_ms: left, ..cfg }).map(|t| tag(t.decision, src))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ fn range(n: usize, seed: u64, must: &[&str]) -> Vec<(Vec<Card>, f64)> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn cfg(iterations: u32) -> TurnConfig {
|
fn cfg(iterations: u32) -> TurnConfig {
|
||||||
TurnConfig { max_combos: 200, cover: 1.0, river_cards: 12, iterations, measure: true, river_raises: 1 }
|
TurnConfig { max_combos: 200, cover: 1.0, river_cards: 12, iterations, measure: true, river_raises: 1, budget_ms: 0.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -228,7 +228,7 @@ fn solve_time_at_table_size() {
|
|||||||
for (n, cards, iters, rr) in [(160usize, 10usize, 200u32, 0usize), (160, 10, 400, 0), (160, 10, 200, 1), (100, 10, 200, 0)] {
|
for (n, cards, iters, rr) in [(160usize, 10usize, 200u32, 0usize), (160, 10, 400, 0), (160, 10, 200, 1), (100, 10, 200, 0)] {
|
||||||
let spot = facing_bet("Ac Qd");
|
let spot = facing_bet("Ac Qd");
|
||||||
let (me, villain) = (range(n, 41, &["Ac Qd"]), range(n, 42, &[]));
|
let (me, villain) = (range(n, 41, &["Ac Qd"]), range(n, 42, &[]));
|
||||||
let c = TurnConfig { max_combos: n, cover: 1.0, river_cards: cards, iterations: iters, measure: true, river_raises: rr };
|
let c = TurnConfig { max_combos: n, cover: 1.0, river_cards: cards, iterations: iters, measure: true, river_raises: rr, budget_ms: 0.0 };
|
||||||
let s = solve_turn(&spot, &me, &villain, &c).unwrap();
|
let s = solve_turn(&spot, &me, &villain, &c).unwrap();
|
||||||
let e = s.solved.exploit.unwrap();
|
let e = s.solved.exploit.unwrap();
|
||||||
eprintln!(
|
eprintln!(
|
||||||
|
|||||||
Reference in New Issue
Block a user