From c84d91eff374bc10c0b62ee3f1527d1a14a6528d Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Wed, 28 Oct 2026 13:32:26 +0100 Subject: [PATCH] Response carries equity and category for external checks --- src/engine/decide.rs | 9 +++++++-- src/engine/postflop.rs | 4 ++++ src/game/decision.rs | 23 ++++++++++++++++++++++- src/wire/encode.rs | 14 +++++++++++--- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/engine/decide.rs b/src/engine/decide.rs index a439abf1..06871dfe 100644 --- a/src/engine/decide.rs +++ b/src/engine/decide.rs @@ -69,7 +69,12 @@ fn think(spot: &Spot) -> Decision { } /// Full decision for a validated spot (preflop chart or postflop equity/EV), -/// always passed through `guard::enforce::enforce`. +/// always passed through `guard::enforce::enforce`. Die Handkategorie wird nur +/// zur Nachprüfung angehängt. pub fn decide(spot: &Spot) -> Decision { - enforce(spot, think(spot)) + let decision = enforce(spot, think(spot)); + match crate::hand::showdown::best(spot.rules().hole_usage, &spot.hero_cards, &spot.board) { + Ok(strength) => decision.with_category(strength.category), + Err(_) => decision, + } } diff --git a/src/engine/postflop.rs b/src/engine/postflop.rs index 95dcb5a2..53355a3d 100644 --- a/src/engine/postflop.rs +++ b/src/engine/postflop.rs @@ -48,6 +48,10 @@ fn confidence(spot: &Spot, gap: f64) -> f64 { /// take the maximum EV. Never folds when check is legal. /// 3. `confidence` rises with the EV lead over the runner-up, relative to the pot. pub fn choose_postflop(spot: &Spot, estimate: &Estimate, thresholds: &Thresholds) -> Decision { + choose_inner(spot, estimate, thresholds).with_equity(estimate.share) +} + +fn choose_inner(spot: &Spot, estimate: &Estimate, thresholds: &Thresholds) -> Decision { let share = estimate.share; if !(share.is_finite() && (0.0..=1.0).contains(&share)) { return Decision::abstain("equity unavailable"); diff --git a/src/game/decision.rs b/src/game/decision.rs index f9114caa..9ef773d5 100644 --- a/src/game/decision.rs +++ b/src/game/decision.rs @@ -1,18 +1,39 @@ use super::{Choice, Confidence}; +use crate::hand::category::Category; #[derive(Clone, Debug, PartialEq)] pub struct Decision { pub choice: Choice, pub confidence: Confidence, pub reason: String, + /// Nur zur Nachprüfung: geschätzte Equity. Ändert keine Entscheidung. + pub equity: Option, + /// Nur zur Nachprüfung: eigene Handkategorie. + pub category: Option, } impl Decision { pub fn new(choice: Choice, confidence: f64, reason: impl Into) -> Decision { - Decision { choice, confidence: Confidence::new(confidence), reason: reason.into() } + Decision { + choice, + confidence: Confidence::new(confidence), + reason: reason.into(), + equity: None, + category: None, + } } pub fn abstain(reason: impl Into) -> Decision { Decision::new(Choice::Abstain, 0.0, reason) } + + pub fn with_equity(mut self, equity: f64) -> Decision { + self.equity = Some(equity); + self + } + + pub fn with_category(mut self, category: Category) -> Decision { + self.category = Some(category); + self + } } diff --git a/src/wire/encode.rs b/src/wire/encode.rs index f8237ea0..fa36a46f 100644 --- a/src/wire/encode.rs +++ b/src/wire/encode.rs @@ -5,15 +5,23 @@ fn three_decimals(value: f64) -> f64 { (value * 1000.0).round() / 1000.0 } -/// `{"action", "size", "confidence", "reason"}` in that key order. +/// `{"action", "size", "confidence", "reason"}` in that key order, plus the optional +/// diagnostic keys `equity` and `category` when they are known. pub fn encode_value(decision: &Decision) -> Value { let size = decision.choice.size().filter(|s| s.is_finite()).map_or(Value::Null, Value::Number); - Value::Object(vec![ + let mut felder = vec![ ("action".to_string(), Value::String(decision.choice.name().to_string())), ("size".to_string(), size), ("confidence".to_string(), Value::Number(three_decimals(decision.confidence.value()))), ("reason".to_string(), Value::String(decision.reason.clone())), - ]) + ]; + if let Some(equity) = decision.equity { + felder.push(("equity".to_string(), Value::Number(three_decimals(equity)))); + } + if let Some(category) = decision.category { + felder.push(("category".to_string(), Value::String(format!("{category:?}")))); + } + Value::Object(felder) } /// One response line (no trailing newline).