diff --git a/src/engine/decide.rs b/src/engine/decide.rs index 0a488192..c0224d78 100644 --- a/src/engine/decide.rs +++ b/src/engine/decide.rs @@ -60,6 +60,7 @@ fn postflop(spot: &Spot, thresholds: &Thresholds) -> Decision { match estimate(&query, Rng::seeded(spot.seed)) { Ok((equity, _)) => { choose_postflop_with(spot, &equity, &called_equity(spot), thresholds, &hand_read) + .with_equity(equity.share) } Err(fault) => Decision::abstain(format!("equity unavailable: {fault}")), } @@ -75,7 +76,12 @@ fn think(spot: &Spot) -> Decision { } /// Full decision for a validated spot (preflop chart or postflop read/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/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).