Anfrage in turnier::such_anfrage (echte Stapel, bis 6 Plaetze, Geldkurve je lebendem Platz), eigener Dienst TURNIER_SUCHE_EXE/ADRESSE (Standard 127.0.0.1:47129, sharingan-turnier Zweig turnier-icm, Patch in messung/turnier-kern/sharingan-icm.patch). Ohne Schalter unveraendert. leiter.py: LEITER_ARM, LEITER_NEU_ENV. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
246 lines
9.3 KiB
Diff
246 lines
9.3 KiB
Diff
diff --git a/engine/nlhe/src/lib.rs b/engine/nlhe/src/lib.rs
|
|
index 1ec68af..7c8f269 100644
|
|
--- a/engine/nlhe/src/lib.rs
|
|
+++ b/engine/nlhe/src/lib.rs
|
|
@@ -165,6 +165,9 @@ pub struct State {
|
|
no_raise: u8,
|
|
/// 0 = live, 1 = everyone folded to one player, 2 = showdown.
|
|
term: u8,
|
|
+ /// Dead money in the pot from outside the betting (tournament antes, chips of players not in the
|
|
+ /// game); goes to the winner of the main pot. 0 in cash games.
|
|
+ dead: i32,
|
|
}
|
|
|
|
impl State {
|
|
@@ -187,6 +190,7 @@ impl State {
|
|
pending: 0,
|
|
no_raise: 0,
|
|
term: 0,
|
|
+ dead: 0,
|
|
};
|
|
for i in n..MAX_PLAYERS {
|
|
s.stack[i] = 0;
|
|
@@ -229,7 +233,15 @@ impl State {
|
|
}
|
|
#[inline]
|
|
pub fn pot(&self) -> i32 {
|
|
- self.total.iter().sum()
|
|
+ self.total.iter().sum::<i32>() + self.dead
|
|
+ }
|
|
+ /// Add dead money to the pot (tournament antes): counts in `pot()`, won with the main pot.
|
|
+ pub fn add_dead(&mut self, chips: i32) {
|
|
+ self.dead += chips.max(0);
|
|
+ }
|
|
+ #[inline]
|
|
+ pub fn dead(&self) -> i32 {
|
|
+ self.dead
|
|
}
|
|
/// Remaining chips behind (not yet committed).
|
|
#[inline]
|
|
@@ -422,7 +434,7 @@ impl State {
|
|
Step::Continue
|
|
}
|
|
|
|
- /// Net chip delta per seat (sum == 0). Requires a terminal state; seats `>= players` are 0.
|
|
+ /// Net chip delta per seat (sum == dead money, 0 in cash games). Requires a terminal state; seats `>= players` are 0.
|
|
pub fn payoffs(&self, deal: &Deal) -> [i32; MAX_PLAYERS] {
|
|
debug_assert!(self.is_terminal());
|
|
let n = self.n as usize;
|
|
@@ -453,7 +465,8 @@ impl State {
|
|
let Some(level) = level else { break };
|
|
let pot: i32 = (0..n)
|
|
.map(|i| self.total[i].min(level) - self.total[i].min(prev))
|
|
- .sum();
|
|
+ .sum::<i32>()
|
|
+ + if prev == 0 { self.dead } else { 0 };
|
|
let eligible = |i: usize| live >> i & 1 != 0 && self.total[i] >= level;
|
|
let best = (0..n)
|
|
.filter(|&i| eligible(i))
|
|
diff --git a/sharingan-1/search/src/solver.rs b/sharingan-1/search/src/solver.rs
|
|
index 3399cf8..891527d 100644
|
|
--- a/sharingan-1/search/src/solver.rs
|
|
+++ b/sharingan-1/search/src/solver.rs
|
|
@@ -135,6 +135,44 @@ pub struct SearchParams {
|
|
pub min_flop_players: usize,
|
|
/// Dedicated thread pool for `parallel` solves (default: rayon's global pool).
|
|
pub pool: Option<Arc<rayon::ThreadPool>>,
|
|
+ /// Tournament payoffs (pokerfreak, 30.11.): terminal values through each seat's money curve instead of
|
|
+ /// chips. `None` (default, cash) = chips, bit-identical to before.
|
|
+ pub icm: Option<Arc<Icm>>,
|
|
+}
|
|
+
|
|
+/// Money value of a seat's final stack, piecewise linear, in chip equivalents (slope ~1 at the start
|
|
+/// stack), search-game units. Seats without a table keep chips.
|
|
+#[derive(Debug, Default)]
|
|
+pub struct Icm {
|
|
+ /// Stack at the start of the hand (search units) per search seat.
|
|
+ pub start: [f64; MAX_PLAYERS],
|
|
+ /// Per search seat: (final stacks ascending, values), search units.
|
|
+ pub table: [Option<(Vec<f64>, Vec<f64>)>; MAX_PLAYERS],
|
|
+}
|
|
+
|
|
+impl Icm {
|
|
+ fn at(t: &(Vec<f64>, Vec<f64>), x: f64) -> f64 {
|
|
+ let (h, w) = t;
|
|
+ let i = h.partition_point(|y| *y <= x).clamp(1, h.len() - 1);
|
|
+ let (a, b) = (h[i - 1], h[i]);
|
|
+ w[i - 1] + (w[i] - w[i - 1]) * ((x - a) / (b - a)).clamp(0.0, 1.0)
|
|
+ }
|
|
+ /// Value of the chip delta `d` for search seat `p`, relative to the start of the hand.
|
|
+ pub fn value(&self, p: usize, d: f32) -> f32 {
|
|
+ match &self.table[p] {
|
|
+ Some(t) if t.0.len() >= 2 => (Self::at(t, self.start[p] + d as f64) - Self::at(t, self.start[p])) as f32,
|
|
+ _ => d,
|
|
+ }
|
|
+ }
|
|
+}
|
|
+
|
|
+/// Terminal value through the tournament money curve if one is set, else chips.
|
|
+#[inline]
|
|
+fn util(icm: &Option<Arc<Icm>>, p: usize, chips: i32) -> f32 {
|
|
+ match icm {
|
|
+ None => chips as f32,
|
|
+ Some(m) => m.value(p, chips as f32),
|
|
+ }
|
|
}
|
|
|
|
impl Default for SearchParams {
|
|
@@ -176,6 +214,7 @@ impl Default for SearchParams {
|
|
max_players: [6, 6, 6],
|
|
min_flop_players: 2,
|
|
pool: None,
|
|
+ icm: None,
|
|
}
|
|
}
|
|
}
|
|
@@ -330,7 +369,7 @@ pub fn solve(sg: &Subgame) -> Solution {
|
|
let root = sg.root;
|
|
let n = root.num_players();
|
|
let p = sg.params;
|
|
- if p.vector && root.street() >= p.vec_min_street && root.street() != Street::Preflop {
|
|
+ if p.vector && p.icm.is_none() && root.street() >= p.vec_min_street && root.street() != Street::Preflop {
|
|
if let Some(seats) = VecGame::live_seats(&root) {
|
|
return solve_vector(sg, seats, start);
|
|
}
|
|
@@ -708,11 +747,11 @@ impl<'a> Solver<'a> {
|
|
let mut s2 = *st;
|
|
let step = s2.apply(act);
|
|
if s2.is_folded(p) {
|
|
- return -(s2.contributed(p) as f32);
|
|
+ return util(&self.sg.params.icm, p, -s2.contributed(p));
|
|
}
|
|
let path2 = step_path(path, act);
|
|
if step == Step::Terminal {
|
|
- return s2.payoffs(&cx.deal)[p] as f32;
|
|
+ return util(&self.sg.params.icm, p, s2.payoffs(&cx.deal)[p]);
|
|
}
|
|
let mut b2 = *bph;
|
|
self.sg.bp.observe(&mut b2, st, act, st.to_act() == Some(self.sg.me));
|
|
@@ -813,7 +852,7 @@ impl<'a> Solver<'a> {
|
|
bp.observe(&mut h, &s, a, true);
|
|
s.apply(a);
|
|
}
|
|
- s.payoffs(&cx.deal)[p] as f32
|
|
+ util(&self.sg.params.icm, p, s.payoffs(&cx.deal)[p])
|
|
}
|
|
}
|
|
|
|
diff --git a/sharingan-1/serve/src/api.rs b/sharingan-1/serve/src/api.rs
|
|
index 7b55cc5..2fee063 100644
|
|
--- a/sharingan-1/serve/src/api.rs
|
|
+++ b/sharingan-1/serve/src/api.rs
|
|
@@ -82,6 +82,28 @@ pub struct ActRequest {
|
|
pub history: Vec<ActionIn>,
|
|
#[serde(default)]
|
|
pub options: Options,
|
|
+ /// Tournament (pokerfreak, 30.11.): dead money (antes) and per-seat money curves for the search's
|
|
+ /// terminal values. Absent = cash game, unchanged.
|
|
+ #[serde(default)]
|
|
+ pub icm: Option<IcmIn>,
|
|
+}
|
|
+
|
|
+#[derive(Debug, Clone, Deserialize)]
|
|
+pub struct IcmIn {
|
|
+ /// Dead money in the pot before the blinds (antes), request chips.
|
|
+ #[serde(default)]
|
|
+ pub dead: i64,
|
|
+ /// Money curves; seats without one keep chips.
|
|
+ #[serde(default)]
|
|
+ pub seats: Vec<IcmSeat>,
|
|
+}
|
|
+
|
|
+#[derive(Debug, Clone, Deserialize)]
|
|
+pub struct IcmSeat {
|
|
+ pub seat: i64,
|
|
+ /// Final stacks (request chips, ascending) and their money value in chip equivalents (request chips).
|
|
+ pub stack: Vec<f64>,
|
|
+ pub value: Vec<f64>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
diff --git a/sharingan-1/serve/src/decide.rs b/sharingan-1/serve/src/decide.rs
|
|
index 160efdd..c9a35f2 100644
|
|
--- a/sharingan-1/serve/src/decide.rs
|
|
+++ b/sharingan-1/serve/src/decide.rs
|
|
@@ -315,6 +315,9 @@ impl Core {
|
|
let cap = (budget_ms * 7 / 10).max(1);
|
|
prm.max_millis = Some(prm.max_millis.map_or(cap, |m| m.min(cap)));
|
|
prm.seed = mix(seed, 7);
|
|
+ if let Some(m) = &req.icm {
|
|
+ prm.icm = icm_params(req, m)?;
|
|
+ }
|
|
let policy = SearchPolicy::new("serve", self.blueprint.clone(), prm);
|
|
|
|
let mut hand = Hand::replay(req, Some(&policy), opts.track_seed.map_or(mix(seed, 1), |t| mix(t, 1)))?;
|
|
@@ -495,3 +498,24 @@ impl Core {
|
|
}
|
|
}
|
|
}
|
|
+
|
|
+/// Tournament money curves in search-game seats and units (pokerfreak, 30.11.): replays the hand once without a
|
|
+/// policy for the seat order and the scale. Seats without a curve (or a broken one) keep chips.
|
|
+fn icm_params(req: &ActRequest, m: &crate::api::IcmIn) -> Result<Option<std::sync::Arc<search::solver::Icm>>, ApiError> {
|
|
+ let h = Hand::replay(req, None, 0)?;
|
|
+ let mut icm = search::solver::Icm::default();
|
|
+ let stacks = h.scaled_cfg.stacks.unwrap_or([h.scaled_cfg.stack; nlhe::MAX_PLAYERS]);
|
|
+ let mut any = false;
|
|
+ for (ri, &seat) in h.order.iter().enumerate() {
|
|
+ let si = h.si(ri);
|
|
+ icm.start[si] = stacks[si] as f64;
|
|
+ if let Some(c) = m.seats.iter().find(|c| c.seat == seat as i64) {
|
|
+ let ok = c.stack.len() >= 2 && c.stack.len() == c.value.len() && c.stack.windows(2).all(|w| w[0] < w[1]) && c.value.iter().all(|x| x.is_finite());
|
|
+ if ok {
|
|
+ icm.table[si] = Some((c.stack.iter().map(|x| x * h.scale).collect(), c.value.iter().map(|x| x * h.scale).collect()));
|
|
+ any = true;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ Ok(any.then(|| std::sync::Arc::new(icm)))
|
|
+}
|
|
diff --git a/sharingan-1/serve/src/replay.rs b/sharingan-1/serve/src/replay.rs
|
|
index 47bab9d..e8d6a27 100644
|
|
--- a/sharingan-1/serve/src/replay.rs
|
|
+++ b/sharingan-1/serve/src/replay.rs
|
|
@@ -211,6 +211,12 @@ impl Hand {
|
|
stacks: Some(ss),
|
|
};
|
|
h.scaled = State::new(&h.scaled_cfg);
|
|
+ // tournament antes: dead money in both games (pokerfreak, 30.11.); cash requests have none
|
|
+ if let Some(d) = req.icm.as_ref().map(|m| m.dead).filter(|&d| d > 0) {
|
|
+ h.real.add_dead(d.min(MAX_STACK) as i32);
|
|
+ let ds = h.sc(d);
|
|
+ h.scaled.add_dead(ds);
|
|
+ }
|
|
h.player = policy.map(|p| p.player(h.hero_si, &h.scaled_cfg, seed));
|
|
for k in 0..prefold {
|
|
let nl = 2 + k;
|
|
@@ -287,7 +293,7 @@ impl Hand {
|
|
step
|
|
}
|
|
|
|
- fn si(&self, ri: usize) -> usize {
|
|
+ pub fn si(&self, ri: usize) -> usize {
|
|
if ri < 2 {
|
|
ri
|
|
} else {
|