Compare commits

...
Author SHA1 Message Date
mmintelandClaude Opus 5.5 1023251f7d Zuggrund eindeutig: Tabelle ohne Splash-/Nachpost-Knoten, Topf mit totem Geld bzw. Nachpost als Einsatz (das tote Geld kommt an, nur die Vorflop-Tabelle kennt es nicht)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:24:39 +01:00
mmintelandClaude Opus 5.5 36dea704a2 MOTOR_REIN_ROH=1 (Standard aus, nur mit SHARINGAN rein): Arm B ohne NL2-Nachschicht, auch im Rueckfall auf den Motor und bei Straddle (Owner: weg mit den Heuristiken); Reihenfolge Suche -> seine Tabelle -> Motor roh
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:14:36 +01:00
mmintelandClaude Opus 5.5 317cb74bf7 Splash ohne passende eigene Tabelle: mit MOTOR_SHARINGAN_SPLASH spielt SHARINGAN statt ABSTAIN (Startprobe 03.12.: 150 von 180 Splash-Anfragen gingen sonst ins ABSTAIN)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:00:09 +01:00
mmintelandClaude Opus 5.5 d114259348 SHARINGAN-Splash: Herkunft, Aenderung und Diff seines Zweigs pokerfreak-splash (Apache-2.0 §4b)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 15:32:58 +01:00
mmintelandClaude Opus 5.5 d744f6b0bc SHARINGAN mit Splash, Antes und Nachpost (MOTOR_SHARINGAN_SPLASH=1, Standard aus): Splash als dead_money, Ante als players[].dead, nachgeposteter BB live als players[].live_post (Beleg: 619 Checks des Nachposters, Topf 40/40); Straddle bleibt beim Motor; Vorflop-Zuggrund nennt die Tabelle ohne totes Geld. Nur mit dem Splash-Dienst.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 15:26:01 +01:00
mmintelandClaude Opus 5.5 66f007a5eb SHARINGAN-Saat auf 32 Bit (splitmix64, gefaltet) vor jeder Uebergabe an SHARINGAN (Dienst, Suche, track_seed, Turnier): seine Ziehung war mit 64-Bit-Saaten verzerrt (Open wurde zu Limp)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 14:49:17 +01:00
6 changed files with 689 additions and 11 deletions
@@ -23,3 +23,12 @@ Schalter `MOTOR_VORFLOP_FLOP_QUELLE=sharingan` (Standard aus; Brücke `entscheid
bitgleich wie --search-threads 1); `sharingan-hybrid.rs` HYBRID_SUCHE_PLAETZE=n (n Suchen nebeneinander zu je 1 Faden, Warten
auf einen Platz statt 20-ms-Rueckfall), "iters" in op suche, HYBRID_SUCHE_MERK=1 (op vorsuche + Merkzettel, op zaehler),
HYBRID_PRIO=below (BelowNormal, EcoQoS aus). Gebaut mit `cargo build --profile serve -p sharingan-serve --bin sharingan-hybrid`.
- Splash (03.12., Owner "ich will Splash und Straddle mit reinhaben", Schalter MOTOR_SHARINGAN_SPLASH=1, Standard aus): Zweig
`pokerfreak-splash` (d5b9a6f) im Worktree D:/pokerfreak-fremd/sharingan/code-splash, Ziel D:/pokerfreak-fremd/sharingan/target-splash,
Exes `pokerbench-hybrid-live-splash.exe` und `pokerbench-hybrid-suche-splash.exe` (beide dieselbe sharingan-hybrid, sha256 e6c70321).
Aenderung (`serve-splash.diff`, Apache-2.0 §4b): Engine `GameConfig` bekommt `dead` (Antes/tote Posts je Platz, vor den Blinds aus
dem Stapel in den Topf, kein Einsatz), `house` (Splash im Haupttopf; Auszahlung nicht mehr nullsummig) und `live` (nachgeposteter
grosser Blind bis 1 bb als Einsatz, der Platz behaelt die Option); die Anfrage bekommt `dead_money`, `players[].dead`,
`players[].live_post`. Ohne diese Felder rechnet alles wie vorher. Seine Vorflop-Tabellen kennen totes Geld nicht (gleiche Knoten);
Suche und Auszahlung rechnen es mit. Straddle spielt weiter unser Motor; ein Straddle-Baum braeuchte im Trainer einen dritten
Blind als Pflichteinsatz mit eigener Option und eine Vorflop-Tabelle mit verschobener Reihenfolge (neu trainieren).
@@ -0,0 +1,452 @@
diff --git a/arena/bench/src/slumbot.rs b/arena/bench/src/slumbot.rs
index 314dc39..69a2a04 100644
--- a/arena/bench/src/slumbot.rs
+++ b/arena/bench/src/slumbot.rs
@@ -28,6 +28,7 @@ pub fn game_config() -> GameConfig {
small_blind: SMALL_BLIND,
big_blind: BIG_BLIND,
stacks: None,
+ ..GameConfig::new(2)
}
}
diff --git a/arena/openpoker/src/layout.rs b/arena/openpoker/src/layout.rs
index d16f279..19d771f 100644
--- a/arena/openpoker/src/layout.rs
+++ b/arena/openpoker/src/layout.rs
@@ -95,6 +95,7 @@ impl Layout {
small_blind: scale(sb),
big_blind: scale(bb),
stacks: Some(st),
+ ..GameConfig::new(2)
};
Ok(Layout {
n_real: n,
diff --git a/arena/server/src/hand.rs b/arena/server/src/hand.rs
index baf0d95..c36baa1 100644
--- a/arena/server/src/hand.rs
+++ b/arena/server/src/hand.rs
@@ -157,6 +157,7 @@ impl HandRunner {
small_blind: setup.cfg.small_blind as i32,
big_blind: setup.cfg.big_blind as i32,
stacks: None,
+ ..GameConfig::new(2)
}
.with_stacks(&stacks);
let st = State::new(&ecfg);
@@ -823,6 +824,7 @@ pub fn replay_parts(h: &HandHistory) -> Res<(GameConfig, Deal, Vec<usize>, Vec<A
small_blind: h.config.small_blind as i32,
big_blind: h.config.big_blind as i32,
stacks: None,
+ ..GameConfig::new(2)
}
.with_stacks(&stacks);
let deck: Vec<Card> = h
diff --git a/arena/server/src/pipe_bot.rs b/arena/server/src/pipe_bot.rs
index 5d8d603..d99b696 100644
--- a/arena/server/src/pipe_bot.rs
+++ b/arena/server/src/pipe_bot.rs
@@ -44,6 +44,7 @@ pub fn decide(house: &HouseRegistry, key: &str, data: &Value) -> Option<Value> {
small_blind: data["small_blind"].as_i64()? as i32,
big_blind: data["big_blind"].as_i64()? as i32,
stacks: None,
+ ..GameConfig::new(2)
}
.with_stacks(&stacks);
let idx = order.iter().position(|&s| s == me)?;
diff --git a/engine/nlhe/src/lib.rs b/engine/nlhe/src/lib.rs
index 1ec68af..c4e87ac 100644
--- a/engine/nlhe/src/lib.rs
+++ b/engine/nlhe/src/lib.rs
@@ -73,6 +73,14 @@ pub struct GameConfig {
pub big_blind: i32,
/// Optional per-seat starting stacks (seats `0..players`), e.g. for external sites.
pub stacks: Option<[i32; MAX_PLAYERS]>,
+ /// Dead money per seat paid before the blinds (antes, dead posts; pokerfreak 03.12.): leaves the stack, goes into the pot,
+ /// does not count as a bet of this street.
+ pub dead: [i32; MAX_PLAYERS],
+ /// Dead money from the house (splash, pokerfreak 03.12.): in the main pot, nobody paid it.
+ pub house: i32,
+ /// Extra live blind posts per seat after the blinds (reposted big blind, pokerfreak 03.12.): counts as this seat's
+ /// preflop bet; the seat still acts in turn and has the option. At most one big blind (a larger post is a straddle).
+ pub live: [i32; MAX_PLAYERS],
}
impl GameConfig {
@@ -84,6 +92,9 @@ impl GameConfig {
small_blind: 50,
big_blind: 100,
stacks: None,
+ dead: [0; MAX_PLAYERS],
+ house: 0,
+ live: [0; MAX_PLAYERS],
}
}
pub fn with_stacks(mut self, s: &[i32]) -> Self {
@@ -165,6 +176,8 @@ pub struct State {
no_raise: u8,
/// 0 = live, 1 = everyone folded to one player, 2 = showdown.
term: u8,
+ /// House money in the main pot (splash); 0 in the paper game.
+ house: i32,
}
impl State {
@@ -187,13 +200,30 @@ impl State {
pending: 0,
no_raise: 0,
term: 0,
+ house: cfg.house.max(0),
};
for i in n..MAX_PLAYERS {
s.stack[i] = 0;
}
+ for i in 0..n {
+ // dead money first (antes, dead posts): out of the stack, into the pot, not a bet of this street
+ let x = cfg.dead[i].max(0).min(s.stack[i]);
+ s.stack[i] -= x;
+ s.total[i] += x;
+ if x > 0 && s.stack[i] == 0 {
+ s.allin |= 1 << i;
+ }
+ }
s.pay(0, cfg.small_blind.min(s.stack[0]));
s.pay(1, cfg.big_blind.min(s.stack[1]));
- s.cur_bet = s.bet[0].max(s.bet[1]);
+ for i in 2..n {
+ // live extra posts (reposted big blind): a bet of this street, capped at the big blind and the stack
+ let x = cfg.live[i].max(0).min(cfg.big_blind).min(s.stack[i]);
+ if x > 0 {
+ s.pay(i, x);
+ }
+ }
+ s.cur_bet = (0..n).map(|i| s.bet[i]).max().unwrap_or(0);
if !s.open_round(if n == 2 { 0 } else { 2 }) {
s.term = 2;
s.street = Street::River as u8;
@@ -229,7 +259,7 @@ impl State {
}
#[inline]
pub fn pot(&self) -> i32 {
- self.total.iter().sum()
+ self.total.iter().sum::<i32>() + self.house
}
/// Remaining chips behind (not yet committed).
#[inline]
@@ -422,7 +452,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 == house money, 0 in the paper game). 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 +483,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.house } else { 0 }; // house money belongs to the main pot
let eligible = |i: usize| live >> i & 1 != 0 && self.total[i] >= level;
let best = (0..n)
.filter(|&i| eligible(i))
diff --git a/engine/nlhe/tests/rules.rs b/engine/nlhe/tests/rules.rs
index 2701c4f..cd1e5d9 100644
--- a/engine/nlhe/tests/rules.rs
+++ b/engine/nlhe/tests/rules.rs
@@ -217,3 +217,96 @@ fn short_blinds() {
assert!(s.is_all_in(0));
assert_eq!(s.to_act(), Some(2));
}
+
+// ---- pokerfreak 03.12.: antes/dead money, splash (house money), reposted big blind (live extra post)
+
+fn six_deal() -> Deal {
+ deal(&["2c3c", "4c5c", "6c7c", "8c9c", "TcJc", "QcKc"], "2d3d4d5d6d")
+}
+
+fn fold_to_bb(s: &mut State) {
+ for seat in [2, 3, 4, 5, 0] {
+ assert_eq!(s.to_act(), Some(seat));
+ s.apply(Action::Fold);
+ }
+ assert!(s.is_terminal());
+}
+
+#[test]
+fn antes_are_dead_money_not_bets() {
+ let mut c = cfg(6);
+ c.dead = [10; MAX_PLAYERS];
+ let mut s = State::new(&c);
+ assert_eq!(s.pot(), 150 + 60);
+ assert_eq!((s.street_bet(0), s.street_bet(1), s.street_bet(2)), (50, 100, 0));
+ assert_eq!((s.stack(0), s.stack(2)), (9940, 9990));
+ assert_eq!(s.cur_bet(), 100);
+ assert_eq!(s.legal().call_amount, 100);
+ fold_to_bb(&mut s);
+ assert_eq!(s.payoffs(&six_deal()), [-60, 100, -10, -10, -10, -10]); // BB paid 110 of the 210 pot
+}
+
+#[test]
+fn dead_money_can_put_a_seat_all_in() {
+ let mut c = cfg(3).with_stacks(&[10_000, 10_000, 10]);
+ c.dead[2] = 10;
+ let s = State::new(&c);
+ assert!(s.is_all_in(2));
+ assert_eq!(s.to_act(), Some(0)); // the all-in UTG never acts
+}
+
+#[test]
+fn splash_goes_to_the_winner_and_is_not_zero_sum() {
+ let mut c = cfg(6);
+ c.house = 30;
+ let mut s = State::new(&c);
+ assert_eq!(s.pot(), 180);
+ fold_to_bb(&mut s);
+ let p = s.payoffs(&six_deal());
+ assert_eq!(p, [-50, 80, 0, 0, 0, 0]);
+ assert_eq!(p.iter().sum::<i32>(), 30);
+}
+
+#[test]
+fn splash_belongs_to_the_main_pot() {
+ let mut c = cfg(3).with_stacks(&[1000, 2000, 3000]);
+ c.house = 30;
+ let mut s = State::new(&c);
+ s.apply(Action::RaiseTo(3000));
+ s.apply(Action::Call);
+ assert_eq!(s.apply(Action::Call), Step::Terminal);
+ // short seat 0 wins the main pot with the splash, seat 1 the side pot, seat 2 gets its uncalled 1000 back
+ let d = deal(&["AhAd", "KhKd", "QhQd"], "2c7d9hJs3c");
+ assert_eq!(s.payoffs(&d)[..3], [2030, 0, -2000]);
+}
+
+#[test]
+fn reposted_big_blind_is_live_with_the_option() {
+ let mut c = cfg(6);
+ c.live[3] = 100;
+ let mut s = State::new(&c);
+ assert_eq!(s.pot(), 250);
+ assert_eq!((s.cur_bet(), s.street_bet(3), s.stack(3)), (100, 100, 9900));
+ assert_eq!(s.to_act(), Some(2));
+ assert_eq!(s.legal().call_amount, 100);
+ s.apply(Action::Call); // UTG limps
+ assert_eq!(s.to_act(), Some(3));
+ let l = s.legal();
+ assert!(l.can_check && !l.can_fold && l.call_amount == 0 && l.can_raise);
+ assert_eq!(l.min_raise_to, 200);
+ s.apply(Action::Check);
+ s.apply(Action::Fold); // 4
+ s.apply(Action::Fold); // 5
+ s.apply(Action::Call); // SB completes
+ assert_eq!(s.to_act(), Some(1));
+ assert_eq!(s.apply(Action::Check), Step::NewStreet(Street::Flop));
+ assert_eq!(s.pot(), 400);
+}
+
+#[test]
+fn live_post_above_the_big_blind_is_capped() {
+ let mut c = cfg(6);
+ c.live[4] = 400; // a straddle is not modelled: only one big blind counts
+ let s = State::new(&c);
+ assert_eq!((s.street_bet(4), s.cur_bet()), (100, 100));
+}
diff --git a/sharingan-1/serve/src/api.rs b/sharingan-1/serve/src/api.rs
index c907610..afafdec 100644
--- a/sharingan-1/serve/src/api.rs
+++ b/sharingan-1/serve/src/api.rs
@@ -19,6 +19,13 @@ pub struct PlayerIn {
/// `false` = sitting out this hand (ignored).
#[serde(default = "yes")]
pub in_hand: bool,
+ /// pokerfreak-Zusatz (03.12.): dead money this seat paid before the blinds (ante, dead post); leaves the stack, not a bet.
+ #[serde(default)]
+ pub dead: i64,
+ /// pokerfreak-Zusatz (03.12.): live extra post after the blinds (reposted big blind, at most one big blind; not on the
+ /// blinds): counts as this seat's preflop bet, the seat acts in turn and has the option.
+ #[serde(default)]
+ pub live_post: i64,
}
#[derive(Debug, Clone, Deserialize)]
@@ -80,6 +87,9 @@ pub struct ActRequest {
#[serde(default)]
pub board: Vec<String>,
pub players: Vec<PlayerIn>,
+ /// pokerfreak-Zusatz (03.12.): dead money from the house in the main pot (splash), real chips.
+ #[serde(default)]
+ pub dead_money: i64,
/// Every action so far, in order. Leading `post_sb`/`post_bb` entries are optional.
#[serde(default)]
pub history: Vec<ActionIn>,
diff --git a/sharingan-1/serve/src/replay.rs b/sharingan-1/serve/src/replay.rs
index 47bab9d..d712949 100644
--- a/sharingan-1/serve/src/replay.rs
+++ b/sharingan-1/serve/src/replay.rs
@@ -114,6 +114,11 @@ impl Hand {
}
// ---- players
let mut dealt: Vec<(usize, i64)> = vec![];
+ // pokerfreak 03.12.: dead money (ante, dead posts) and live extra posts per seat, house money (splash)
+ let mut extra: Vec<(usize, i64, i64)> = vec![];
+ if !(0..=MAX_STACK).contains(&req.dead_money) {
+ return Err(ApiError::invalid("bad_dead_money", format!("dead_money {} must be in 0..={MAX_STACK}", req.dead_money)));
+ }
let mut seen = [false; (MAX_SEAT + 1) as usize];
for p in &req.players {
if !(0..=MAX_SEAT).contains(&p.seat) {
@@ -131,7 +136,14 @@ impl Hand {
format!("seat {}: stack_start {} must be in 1..={} (and at most {MAX_STACK_BB} big blinds)", p.seat, p.stack_start, MAX_STACK),
));
}
+ if p.dead < 0 || p.dead >= p.stack_start || p.live_post < 0 || p.live_post > bb || p.dead + p.live_post > p.stack_start {
+ return Err(ApiError::invalid(
+ "bad_dead",
+ format!("seat {}: dead {} / live_post {} must be >= 0, below the stack {} and live_post at most one big blind", p.seat, p.dead, p.live_post, p.stack_start),
+ ));
+ }
dealt.push((p.seat as usize, p.stack_start));
+ extra.push((p.seat as usize, p.dead, p.live_post));
}
dealt.sort_unstable();
let n = dealt.len();
@@ -169,15 +181,32 @@ impl Hand {
}
let stack_of = |seat: usize| dealt.iter().find(|d| d.0 == seat).map(|d| d.1).unwrap_or(0);
let hero_ri = order.iter().position(|&s| s == hero_seat).unwrap();
+ let dead_of = |seat: usize| extra.iter().find(|e| e.0 == seat).map(|e| e.1).unwrap_or(0);
+ let live_of = |seat: usize| extra.iter().find(|e| e.0 == seat).map(|e| e.2).unwrap_or(0);
+ if let Some(ri) = (0..order.len().min(2)).find(|&ri| live_of(order[ri]) > 0) {
+ return Err(ApiError::invalid("bad_dead", format!("seat {}: live_post on a blind seat", order[ri])));
+ }
// ---- engines
let scale = 100.0 / bb as f64;
let prefold = if (3..=5).contains(&n) { MAX_PLAYERS - n } else { 0 };
let si_of = |ri: usize| if ri < 2 { ri } else { ri + prefold };
let mut rs = [0i32; MAX_PLAYERS];
+ let (mut rdead, mut rlive) = ([0i32; MAX_PLAYERS], [0i32; MAX_PLAYERS]);
for (ri, &seat) in order.iter().enumerate() {
rs[ri] = stack_of(seat) as i32;
+ rdead[ri] = dead_of(seat) as i32;
+ rlive[ri] = live_of(seat) as i32;
}
- let real_cfg = GameConfig { players: n, stack: 0, small_blind: sb as i32, big_blind: bb as i32, stacks: Some(rs) };
+ let real_cfg = GameConfig {
+ players: n,
+ stack: 0,
+ small_blind: sb as i32,
+ big_blind: bb as i32,
+ stacks: Some(rs),
+ dead: rdead,
+ house: req.dead_money as i32,
+ live: rlive,
+ };
let mut h = Hand {
order,
real: State::new(&real_cfg),
@@ -197,8 +226,11 @@ impl Hand {
big_blind: bb,
};
let mut ss = [0i32; MAX_PLAYERS];
+ let (mut sdead, mut slive) = ([0i32; MAX_PLAYERS], [0i32; MAX_PLAYERS]);
for (ri, &seat) in h.order.clone().iter().enumerate() {
ss[si_of(ri)] = h.sc(stack_of(seat)).max(1);
+ sdead[si_of(ri)] = h.sc(dead_of(seat)).min(ss[si_of(ri)] - 1);
+ slive[si_of(ri)] = if live_of(seat) == bb { h.sc(bb).max(1) } else { h.sc(live_of(seat)) };
}
for k in 0..prefold {
ss[2 + k] = 100 * 100; // phantom: folds at once, size irrelevant
@@ -209,6 +241,9 @@ impl Hand {
small_blind: h.sc(sb).max(1),
big_blind: h.sc(bb).max(1),
stacks: Some(ss),
+ dead: sdead,
+ house: h.sc(req.dead_money),
+ live: slive,
};
h.scaled = State::new(&h.scaled_cfg);
h.player = policy.map(|p| p.player(h.hero_si, &h.scaled_cfg, seed));
@@ -237,7 +272,7 @@ impl Hand {
)
.with(json!({"index": idx, "expected_seat": eseat})));
}
- let want = eblind.min(stack_of(eseat));
+ let want = eblind.min(stack_of(eseat) - dead_of(eseat));
if let Some(to) = ev.to {
if to != want {
return Err(ApiError::invalid("bad_amount", format!("history[{idx}]: blind post of {to}, expected {want}")).with(json!({"index": idx, "expected_to": want})));
@@ -682,6 +717,59 @@ mod tests {
assert_eq!(back, Action::RaiseTo(60));
}
+ // ---- pokerfreak 03.12.: splash (dead_money), antes (players[].dead), reposted big blind (players[].live_post)
+
+ #[test]
+ fn splash_and_antes_reach_both_engines() {
+ // 4 players, bb 20 (scale x5); each pays an ante of 2, the house adds 10
+ let r: ActRequest = serde_json::from_value(json!({
+ "small_blind": 10, "big_blind": 20, "button_seat": 1, "hero_seat": 0, "dead_money": 10,
+ "hole_cards": ["Qh", "Qd"],
+ "players": (0..4).map(|s| json!({"seat": s, "stack_start": 2000, "dead": 2})).collect::<Vec<_>>(),
+ "history": []
+ }))
+ .unwrap();
+ let h = Hand::replay(&r, None, 1).unwrap();
+ assert!(h.desync.is_none());
+ assert_eq!(h.real.pot(), 30 + 8 + 10);
+ assert_eq!(h.scaled.pot(), 150 + 40 + 50);
+ assert_eq!(h.real.stack(h.hero_ri), 1998);
+ let l = h.legal_out();
+ assert_eq!(l.call.as_ref().unwrap().to, 20);
+ assert_eq!(l.raise.unwrap().max_to, 1998);
+ }
+
+ #[test]
+ fn reposted_big_blind_is_live_with_the_option() {
+ // button 3: order 4 (SB), 5 (BB), 0, 1, 2, 3; seat 1 reposts one big blind
+ let mut r = base();
+ r.hero_seat = 1;
+ r.players[1].live_post = 100;
+ r.history = vec![serde_json::from_value(json!({"seat": 0, "type": "call", "to": 100})).unwrap()];
+ let h = Hand::replay(&r, None, 1).unwrap();
+ assert!(h.desync.is_none());
+ assert_eq!(h.real.pot(), 50 + 100 + 100 + 100);
+ let l = h.legal_out();
+ assert!(l.check && !l.fold && l.call.is_none());
+ assert_eq!(l.raise.unwrap().min_to, 200);
+ }
+
+ #[test]
+ fn rejects_bad_dead_money() {
+ let mut r = base();
+ r.players[4].live_post = 100; // seat 4 is the small blind
+ assert_eq!(err(&r).code, "bad_dead");
+ let mut r = base();
+ r.players[1].live_post = 200; // more than one big blind is a straddle
+ assert_eq!(err(&r).code, "bad_dead");
+ let mut r = base();
+ r.players[1].dead = 10000; // the whole stack
+ assert_eq!(err(&r).code, "bad_dead");
+ let mut r = base();
+ r.dead_money = -1;
+ assert_eq!(err(&r).code, "bad_dead_money");
+ }
+
fn near_all_in_request(bb: i64, hero: usize) -> ActRequest {
let stack = 100 * bb;
let mut history = vec![json!({"seat": 2, "type": "raise", "to": stack - 1})];
diff --git a/sharingan-1/serve/tests/common/mod.rs b/sharingan-1/serve/tests/common/mod.rs
index 912dfac..58ecc45 100644
--- a/sharingan-1/serve/tests/common/mod.rs
+++ b/sharingan-1/serve/tests/common/mod.rs
@@ -172,7 +172,7 @@ pub fn gen_hand(rng: &mut Rng, o: GenOpts) -> Vec<Spot> {
for (ri, &seat) in order.iter().enumerate() {
arr[ri] = stack_of(seat) as i32;
}
- let cfg = GameConfig { players: n, stack: 0, small_blind: sb as i32, big_blind: bb as i32, stacks: Some(arr) };
+ let cfg = GameConfig { players: n, stack: 0, small_blind: sb as i32, big_blind: bb as i32, stacks: Some(arr), ..GameConfig::new(n) };
let mut st = State::new(&cfg);
let deck = rng.deck();
let hero_ri = order.iter().position(|&s| s == hero).unwrap();
+7 -2
View File
@@ -553,6 +553,9 @@ impl Motor {
}
fn nl2(&self, q: &Value, a: Value) -> Value {
if crate::sharingan::rein_roh() {
return a; // MOTOR_REIN_ROH: keine Nachschicht in Arm B
}
if self.s.turnier || self.s.n == 2 || self.s.splash > 0 || self.s.art == crate::spiel::Art::PushFold || q.get("eigen").is_some() || q.get("probeHand").is_some() || q["nackt"] == true || q["vorrechnen"] == true || q["vorrechnen_strasse"] == true {
// MOTOR_STACKOFF_SPLASH=1 (01.12.): an Splash-Tischen sonst keine NL2-Schicht, also auch keine Stack-off-Bepreisung
// (99 auf J83-4: Turn-Raise 85 bb in einer Splash-Hand, nie bepreist). Nur die Bepreisung, nicht die uebrigen Regeln.
@@ -613,9 +616,11 @@ impl Motor {
}
/// Hybrid (MOTOR_VORFLOP_FLOP_QUELLE=sharingan): nur der 6-max-Hauptmotor ohne Straddle, Splash und Antes
/// (Splash und Antes mit MOTOR_SHARINGAN_SPLASH, 03.12.; Straddle bleibt beim Motor)
fn hybrid(&self, q: &Value) -> bool {
crate::sharingan::an() && !self.s.turnier && (self.s.n == 6 || crate::sharingan::rein() && (2..=6).contains(&self.s.n)) && !self.s.straddle && self.s.splash == 0 && !self.s.ante && self.s.art != crate::spiel::Art::PushFold
&& Self::splash_tot(q) == 0.0 && Self::ante_tot(q) == 0.0 && !Self::ist_straddle(q) && q.get("eigen").is_none() && q.get("probeHand").is_none()
let tot_ok = crate::sharingan::splash();
crate::sharingan::an() && !self.s.turnier && (self.s.n == 6 || crate::sharingan::rein() && (2..=6).contains(&self.s.n)) && !self.s.straddle && (tot_ok || self.s.splash == 0 && !self.s.ante) && self.s.art != crate::spiel::Art::PushFold
&& (tot_ok || Self::splash_tot(q) == 0.0 && Self::ante_tot(q) == 0.0) && !Self::ist_straddle(q) && q.get("eigen").is_none() && q.get("probeHand").is_none()
}
/// Ersatzzug aus dem Blueprint nach einer gescheiterten Suche: Grund der Suche anhaengen (" [Suche: search_busy ...]")
+8
View File
@@ -359,6 +359,14 @@ fn main() {
r["reason"] = serde_json::json!(format!("Splash{} {}", y.0, r["reason"].as_str().unwrap_or("")));
r
}
// MOTOR_SHARINGAN_SPLASH (03.12.): ohne passende eigene Splash-Tabelle spielt SHARINGAN (totes Geld als dead_money);
// antwortet er nicht, wie bisher kein Zug (der Hauptbaum kennt kein totes Geld)
_ if crate::sharingan::splash() => {
let r = m.antworte(&q);
if r["reason"].as_str().is_some_and(|g| g.starts_with("sharingan")) { r } else {
serde_json::json!({"action": "ABSTAIN", "size": null, "confidence": 0, "reason": "motor notfall: keine Splash-Strategie, SHARINGAN ohne Antwort"})
}
}
_ => serde_json::json!({"action": "ABSTAIN", "size": null, "confidence": 0, "reason": "motor notfall: keine Splash-Strategie"}),
}
}
+212 -8
View File
@@ -73,9 +73,44 @@ pub fn rein() -> bool {
*A.get_or_init(|| an() && std::env::var("MOTOR_SHARINGAN_REIN").is_ok_and(|x| x == "1"))
}
/// MOTOR_SHARINGAN_SPLASH=1 (03.12., Owner "ich will Splash und Straddle mit reinhaben", Standard aus): Splash (Hausgeld im
/// Haupttopf), Antes und nachgepostete grosse Blinds gehen an SHARINGAN (`dead_money`, `players[].dead`, `players[].live_post`).
/// Der Nachpost ist live (Beleg schatten.jsonl 03.12.: 619 Checks des Nachposters ohne Erhoehung, Topf beim Flop 40 von 40 nur
/// mit Post als Einsatz). Nur mit dem Splash-Dienst (pokerbench-hybrid-*-splash.exe; der alte Dienst kennt die Felder nicht und
/// rechnete ohne totes Geld). Straddle (zweiter grosser Blind ueber 1 bb) spielt weiter der Motor. Vor dem Flop nimmt SHARINGAN
/// dieselben Tabellenknoten wie ohne totes Geld; der Zuggrund sagt es.
pub fn splash() -> bool {
static A: OnceLock<bool> = OnceLock::new();
*A.get_or_init(|| an() && std::env::var("MOTOR_SHARINGAN_SPLASH").is_ok_and(|x| x == "1"))
}
/// Zuggrund vor dem Flop, wenn totes Geld oder ein Nachpost im Topf liegt (seine Tabellen kennen beides nicht)
const GRUND_SPLASH: &str = " [Splash: Tabelle ohne Splash-Knoten; Topf mit totem Geld]";
const GRUND_NACHPOST: &str = " [Nachpost: Tabelle ohne Nachpost-Knoten; Nachpost als Einsatz im Topf]";
/// MOTOR_REIN_ROH=1 (03.12., Owner "weg mit den heuristiken"; nur mit MOTOR_SHARINGAN_REIN, Standard aus): keine Antwort dieses Prozesses
/// geht durch unsere NL2-Nachschicht (Abgleich, Stack-off, Bluffpreis) - auch nicht der Rueckfall auf unseren Motor und nicht Straddle.
/// Reihenfolge bleibt: seine Suche, dann seine Tabelle (Blueprint), dann unser Motor roh.
pub fn rein_roh() -> bool {
static A: OnceLock<bool> = OnceLock::new();
*A.get_or_init(|| rein() && std::env::var("MOTOR_REIN_ROH").is_ok_and(|x| x == "1"))
}
fn schalter(k: &str, w: &str) -> bool {
std::env::var(k).is_ok_and(|x| x == w)
}
/// Saat fuer SHARINGAN (03.12.): seine Ziehung ist mit grossen 64-Bit-Saaten verzerrt (unsere Anfrage-Saat ~3e18 zog in 11 von 11
/// Vorflop-Lagen call, obwohl seine Mischung 2-21 % call hatte; mit Saat 1..20 passend zur Mischung). Darum geht an ihn nur ein
/// 32-Bit-Wert, gemischt aus allen 64 Bit (splitmix64, dann obere und untere Haelfte gefaltet), damit die unteren Bits nicht korrelieren.
/// Unsere eigene Ziehung im Motor bleibt unberuehrt.
pub fn saat32(x: u64) -> u64 {
let mut z = x.wrapping_add(0x9E37_79B9_7F4A_7C15);
z = (z ^ (z >> 30)).wrapping_mul(0xBF58_476D_1CE4_E5B9);
z = (z ^ (z >> 27)).wrapping_mul(0x94D0_49BB_1331_11EB);
z ^= z >> 31;
(z ^ (z >> 32)) & 0xFFFF_FFFF
}
pub fn phm() -> bool {
static A: OnceLock<bool> = OnceLock::new();
*A.get_or_init(|| schalter("MOTOR_HYB_UEBERSETZUNG", "phm"))
@@ -150,6 +185,8 @@ pub struct Kontext {
pub rake_knoten: bool,
/// Vor dem Helden liegt am Flop eine Kopf-an-Kopf-C-Bet gegen ihn (MOTOR_HYB_ZELLE=flop_cbet)
pub flop_cbet: bool,
/// Zusatz zum Zuggrund vor dem Flop (MOTOR_SHARINGAN_SPLASH): totes Geld oder Nachpost im Topf, sonst leer
pub vorflop_grund: &'static str,
}
impl Kontext {
@@ -187,8 +224,15 @@ pub fn kontext() -> Option<Rc<Kontext>> {
impl Kontext {
/// Vertrag -> seine ActRequest (BB = 100 Chips, Sitze 0..5 in Tischreihenfolge, `to` = Einsatz dieser Strasse,
/// stack_start = Stapel jetzt + eingezahlt). Nur volle sechs Plaetze, keine Antes; sonst None (dann spielt der Motor).
/// stack_start = Stapel jetzt + eingezahlt). Nur volle sechs Plaetze (mit MOTOR_SHARINGAN_REIN 2 bis 6); Antes, Splash und
/// Nachposts nur mit MOTOR_SHARINGAN_SPLASH; sonst None (dann spielt der Motor).
pub fn aus(q: &Value) -> Option<Kontext> {
Self::aus_mit(q, splash())
}
/// `mit_tot`: Antes (`players[].dead`), Splash (`dead_money`) und nachgepostete grosse Blinds bis 1 bb (`players[].live_post`)
/// an SHARINGAN geben; ein hoeherer Nachpost (Straddle) gibt None.
pub fn aus_mit(q: &Value, mit_tot: bool) -> Option<Kontext> {
let bb = q["bigBlind"].as_f64()?;
let c = |x: f64| (x / bb * 100.0).round() as i64;
let hist_q = q["history"].as_array()?;
@@ -206,9 +250,11 @@ impl Kontext {
let pos = |s: i64| sitze.iter().position(|&x| x == s);
let sb = pos(hist_q.iter().find(|h| h["action"] == "POST_SB")?["seat"].as_i64()?)?;
let bbs = pos(hist_q.iter().find(|h| h["action"] == "POST_BB")?["seat"].as_i64()?)?;
if bbs != (sb + 1) % n || hist_q.iter().filter(|h| h["action"] == "POST_BB").count() != 1 {
if bbs != (sb + 1) % n || (hist_q.iter().filter(|h| h["action"] == "POST_BB").count() != 1 && !mit_tot) {
return None;
}
// totes Geld: Splash des Hauses, Antes je Platz, Nachposts je Platz (live; der erste POST_BB ist der grosse Blind)
let (mut haus, mut tot, mut nachpost, mut bb_gesehen) = (0i64, [0i64; 6], [0i64; 6], false);
let strasse_nr = |s: &str| ["PREFLOP", "FLOP", "TURN", "RIVER"].iter().position(|x| *x == s).map(|x| x as u8);
let (mut hist, mut zuege, mut drin) = (Vec::new(), Vec::new(), [0i64; 6]);
let (mut st, mut auf, mut hoch) = (0u8, [0i64; 6], 0i64);
@@ -231,6 +277,28 @@ impl Kontext {
if strasse != st {
(st, auf, hoch, erh_str) = (strasse, [0; 6], 0, 0);
}
if mit_tot && x == "POST_ANTE" {
let a = c(h["amount"].as_f64()?);
if h["splash"] == true {
haus += a;
} else {
tot[s] += a;
drin[s] += a;
}
continue;
}
if mit_tot && x == "POST_BB" && bb_gesehen {
let t = c(h["amount"].as_f64()?);
if t > 100 {
return None; // Straddle: spielt der Motor
}
nachpost[s] = t;
drin[s] += t - auf[s];
auf[s] = t;
hoch = hoch.max(t);
continue;
}
bb_gesehen |= x == "POST_BB";
let topf_vor: i64 = drin.iter().sum();
let (auf_vor, hoch_vor) = (auf[s], hoch);
let war_rake = strasse == 0 && rake_knoten_von(s, erh_vor, &frei);
@@ -312,7 +380,14 @@ impl Kontext {
let mut start = [0i64; 6];
for s in 0..n {
start[s] = stand[s]? + drin[s];
spieler.push(json!({"seat": s, "stack_start": start[s]}));
let mut p = json!({"seat": s, "stack_start": start[s]});
if tot[s] > 0 {
p["dead"] = json!(tot[s]);
}
if nachpost[s] > 0 {
p["live_post"] = json!(nachpost[s]);
}
spieler.push(p);
}
// die erste fremde Flop-Groesse, die nicht den ganzen Stapel setzt; ab dort spielt (mit MOTOR_HYB_FLOP_SUCHE) der Motor
let erst_fremd = fremd_kandidat.iter().find(|&&(s, d, _)| d < start[s]).map(|x| x.2);
@@ -330,7 +405,7 @@ impl Kontext {
}
let brett: Vec<String> = ["FLOP", "TURN", "RIVER"].iter().flat_map(|s| q["board"][*s].as_array().into_iter().flatten().filter_map(karte)).collect();
let loch: Vec<String> = q["heroCards"].as_array()?.iter().filter_map(karte).collect();
let seed = q["seed"].as_u64().unwrap_or(1);
let seed = saat32(q["seed"].as_u64().unwrap_or(1));
let mut basis = json!({"small_blind": 50, "big_blind": 100, "button_seat": if n == 2 { sb } else { (sb + n - 1) % n }, "hero_seat": pos(held)?, "hole_cards": loch,
"board": brett, "players": spieler, "history": hist, "options": {"seed": seed, "include_probs": false}});
if phm() {
@@ -339,10 +414,20 @@ impl Kontext {
for b in format!("{loch:?}{start:?}{sb}").bytes() {
f = (f ^ b as u64).wrapping_mul(0x100000001b3);
}
basis["options"]["track_seed"] = json!(f >> 1);
basis["options"]["track_seed"] = json!(saat32(f));
}
if haus > 0 {
basis["dead_money"] = json!(haus);
}
let vorflop_grund = if haus > 0 || tot.iter().any(|&x| x > 0) {
GRUND_SPLASH
} else if nachpost.iter().any(|&x| x > 0) {
GRUND_NACHPOST
} else {
""
};
let rake_knoten = q["street"] == "PREFLOP" && rake_knoten_von(hs, erh_vor, &frei);
Some(Kontext { basis, hist, brett, zuege, flop_fremd, rake_knoten, flop_cbet })
Some(Kontext { basis, hist, brett, zuege, flop_fremd, rake_knoten, flop_cbet, vorflop_grund })
}
}
@@ -506,7 +591,8 @@ fn frage_roh(v: &Value) -> Option<Value> {
/// Der eigene Zug von SHARINGAN, als Vertragsantwort. None: er weiss keinen (dann spielt der Motor).
pub fn zug(q: &Value, k: &Kontext) -> Option<Value> {
let r = frage(&json!({"op": "act", "req": k.basis}))?;
abbilden(q, &r["response"], String::new())
let grund = if q["street"] == "PREFLOP" { k.vorflop_grund } else { "" };
abbilden(q, &r["response"], grund.to_string())
}
/// Seine Antwort (`response`) als Vertragsantwort zum Zustand `q`; `zusatz` haengt an den Grund.
@@ -758,7 +844,7 @@ fn such_basis(k: &Kontext) -> Value {
for x in b.to_string().bytes() {
f = (f ^ x as u64).wrapping_mul(0x100000001b3);
}
b["options"]["seed"] = json!(f >> 1);
b["options"]["seed"] = json!(saat32(f));
b
}
@@ -1048,3 +1134,121 @@ fn opfer_zug_innen(z: &Zustand, me: &Menue, h: &[Value], hand: (u8, u8), brett:
});
Some((v, false))
}
#[cfg(test)]
mod saat_spec {
use super::saat32;
#[test]
fn saat32_bleibt_in_32_bit_und_ist_fest() {
for x in [0u64, 1, 3_399_975_668_225_400_732, u64::MAX, 1 << 63, 0xFFFF_FFFF] {
assert!(saat32(x) <= u32::MAX as u64);
assert_eq!(saat32(x), saat32(x));
}
}
#[test]
fn saat32_mischt_alle_bits() {
// benachbarte Saaten und Saaten, die sich nur in den oberen 32 Bit unterscheiden, geben verschiedene, weit gestreute Werte
let a = saat32(3_399_975_668_225_400_732);
assert_ne!(a, saat32(3_399_975_668_225_400_733));
assert_ne!(saat32(5), saat32(5 | (1 << 40)));
let mut summe = 0u64;
for i in 0..1000u64 {
summe += saat32(i << 32) >> 31; // oberes Bit des Ergebnisses
}
assert!((400..600).contains(&summe), "oberes Bit nicht gleichverteilt: {summe}");
}
}
#[cfg(test)]
mod splash_spec {
//! MOTOR_SHARINGAN_SPLASH (03.12.): Splash, Antes und Nachposts in seiner Anfrage; Straddle bleibt beim Motor.
use super::Kontext;
use serde_json::{json, Value};
fn karte(r: &str, f: &str) -> Value {
json!({"rank": r, "suit": f})
}
/// Sechs Plaetze 1..6, Knopf 1, SB 2, BB 3; bb 0,02; Held am Zug; alle Stapel 2,00 nach den Einsaetzen
fn frage(held: i64, hist: Value) -> Value {
let villains: Vec<Value> = (1..=6).filter(|&s| s != held).map(|s| json!({"seat": s, "stack": 2.0})).collect();
json!({"bigBlind": 0.02, "heroSeat": held, "heroStack": 2.0, "street": "PREFLOP",
"heroCards": [karte("KING", "HEARTS"), karte("FOUR", "HEARTS")], "villains": villains, "history": hist, "seed": 7})
}
fn post(seat: i64, a: &str, x: f64) -> Value {
json!({"street": "PREFLOP", "seat": seat, "action": a, "amount": x})
}
fn zug(seat: i64, a: &str) -> Value {
json!({"street": "PREFLOP", "seat": seat, "action": a})
}
fn splash_frage() -> Value {
let mut ante = post(1, "POST_ANTE", 0.04);
ante["splash"] = json!(true);
frage(1, json!([ante, post(2, "POST_SB", 0.01), post(3, "POST_BB", 0.02), zug(4, "FOLD"), zug(5, "FOLD"), zug(6, "FOLD")]))
}
fn nachpost_frage() -> Value {
let mut c = zug(4, "CALL");
c["amount"] = json!(0.02);
frage(5, json!([post(2, "POST_SB", 0.01), post(3, "POST_BB", 0.02), post(5, "POST_BB", 0.02), c]))
}
#[test]
fn splash_geht_als_hausgeld_an_ihn_und_nicht_in_den_verlauf() {
let k = Kontext::aus_mit(&splash_frage(), true).expect("Splash-Hand mit Schalter");
assert_eq!(k.basis["dead_money"], 200);
let h = k.basis["history"].as_array().unwrap();
assert_eq!(h.len(), 5); // zwei Blinds, drei Folds; der Splash steht nicht im Verlauf
assert!(h.iter().all(|e| e["type"] != "post_ante"));
// der Splash kommt nicht aus dem Stapel des Helden (Platz 1 -> sein Platz 0)
assert_eq!(k.basis["players"][0]["stack_start"], 10_000);
assert!(k.basis["players"].as_array().unwrap().iter().all(|p| p.get("dead").is_none() && p.get("live_post").is_none()));
assert_eq!(k.vorflop_grund, super::GRUND_SPLASH);
}
#[test]
fn echte_ante_ist_totes_geld_des_platzes() {
let q = frage(1, json!([post(4, "POST_ANTE", 0.01), post(2, "POST_SB", 0.01), post(3, "POST_BB", 0.02), zug(4, "FOLD"), zug(5, "FOLD"), zug(6, "FOLD")]));
let k = Kontext::aus_mit(&q, true).unwrap();
assert_eq!(k.basis["players"][3]["dead"], 50);
assert_eq!(k.basis["players"][3]["stack_start"], 10_050); // Stapel jetzt + Ante
assert!(k.basis.get("dead_money").is_none());
assert_eq!(k.vorflop_grund, super::GRUND_SPLASH);
}
#[test]
fn nachgeposteter_bb_ist_lebender_einsatz_mit_option() {
let k = Kontext::aus_mit(&nachpost_frage(), true).expect("Nachpost mit Schalter");
let p = &k.basis["players"][4]; // Platz 5
assert_eq!(p["live_post"], 100);
assert_eq!(p["stack_start"], 10_100); // Stapel jetzt + Post
let h = k.basis["history"].as_array().unwrap();
assert_eq!(h.len(), 3); // SB, BB, Call; der Nachpost steht nur in players
assert_eq!(h[2]["type"], "call");
assert!(k.basis.get("dead_money").is_none());
assert_eq!(k.vorflop_grund, super::GRUND_NACHPOST);
}
#[test]
fn straddle_bleibt_beim_motor() {
let q = frage(5, json!([post(2, "POST_SB", 0.01), post(3, "POST_BB", 0.02), post(4, "POST_BB", 0.04)]));
assert!(Kontext::aus_mit(&q, true).is_none());
}
#[test]
fn ohne_schalter_wie_bisher() {
assert!(Kontext::aus_mit(&splash_frage(), false).is_none());
assert!(Kontext::aus_mit(&nachpost_frage(), false).is_none());
// eine gewoehnliche Hand ist mit und ohne Schalter dieselbe Anfrage, ohne Zusatzfelder
let q = frage(1, json!([post(2, "POST_SB", 0.01), post(3, "POST_BB", 0.02), zug(4, "FOLD"), zug(5, "FOLD"), zug(6, "FOLD")]));
let (a, b) = (Kontext::aus_mit(&q, false).unwrap(), Kontext::aus_mit(&q, true).unwrap());
assert_eq!(a.basis, b.basis);
assert!(a.basis.get("dead_money").is_none());
assert_eq!(b.vorflop_grund, "");
}
}
+1 -1
View File
@@ -426,7 +426,7 @@ pub fn such_anfrage(q: &Value) -> Option<Value> {
let karten = |v: &Value| v.as_array().into_iter().flatten().filter_map(crate::sharingan::karte_pub).collect::<Vec<String>>();
let brett: Vec<String> = ["FLOP", "TURN", "RIVER"].iter().flat_map(|s| karten(&q["board"][*s])).collect();
Some(json!({"small_blind": blinds.0.max(1), "big_blind": blinds.1.max(1), "button_seat": knopf, "hero_seat": pos(held)?, "hole_cards": karten(&q["heroCards"]),
"board": brett, "players": spieler, "history": hist, "options": {"seed": q["seed"].as_u64().unwrap_or(1), "include_probs": false},
"board": brett, "players": spieler, "history": hist, "options": {"seed": crate::sharingan::saat32(q["seed"].as_u64().unwrap_or(1)), "include_probs": false},
"icm": {"dead": tot, "seats": kurven}}))
}