diff --git a/benchmarks/plo5_baseline.txt b/benchmarks/plo5_baseline.txt index 983a7d18..98e27a62 100644 --- a/benchmarks/plo5_baseline.txt +++ b/benchmarks/plo5_baseline.txt @@ -1,4 +1,4 @@ -label ea2dbb1f+lokal +label 1e4e3ff7+lokal scenario trocken deals 8 seed 104372000587777 @@ -28,4 +28,4 @@ scenario doppelbrett deals 5 seed 104372000587777 counts 5 0 0 -samples 9.886 9.010000000000002 7.681625 -2.9283374999999996 0 +samples 9.886 9.010000000000002 7.681625 0 0 diff --git a/src/engine/double_board.rs b/src/engine/double_board.rs index 29f011fe..b4919372 100644 --- a/src/engine/double_board.rs +++ b/src/engine/double_board.rs @@ -1,16 +1,18 @@ use super::decide::decide; use crate::card::Card; -use crate::game::{Choice, Decision, Spot}; +use crate::game::{ActionKind, Choice, Decision, Spot}; use crate::guard::validate::check; +use crate::odds::break_even::break_even; -/// Double board (`boardDouble`): the same spot is decided once per board and the -/// better judgement wins - the decision with the higher equity, on a tie the first board. +/// Double board (`boardDouble`): the same spot is decided once per board. /// -/// **Approximation, on purpose:** the pot is split between the boards, so the exact pot -/// share is the mean of both equities. Taking the better board is optimistic: a hand -/// that is strong on one board only is played as if it were strong for the whole pot. -/// Both boards are also judged independently (the opponent's range is not required to -/// be one hand on both boards). +/// **The pot is split between the boards**, so hero's real pot share is the *mean* of both +/// board equities, not the better one. The call/fold decision is gated on that split share: +/// when the mean clears the price (`odds::break_even`), the better board carries the +/// continuing action and its reasoning is reported; when the mean falls short, the hand +/// folds - a hand that is strong on one board only no longer overcalls the whole pot. +/// Both boards are judged independently (the opponent's range is not required to be one +/// hand on both boards). /// /// Anything unclear is refused instead of guessed: a second board of another length, /// a card twice, or a board that cannot be judged gives `ABSTAIN`. @@ -37,6 +39,26 @@ pub fn decide_double(spot: &Spot, second: &[Card]) -> Decision { first.reason, second.reason )); } + // Pott geteilt: Heros echter Anteil ist das Mittel beider Brett-Equities. Schlaegt das + // Mittel den Preis nicht, waere das Mitgehen am besseren Brett ein Uebercall -> Fold. + if let (Some(a), Some(b)) = (first.equity, second.equity) { + let mean = 0.5 * (a + b); + let price = break_even(spot.pot, spot.to_call); + if mean < price && spot.is_legal(ActionKind::Fold) { + let (chosen, number) = if b > a { (&second, 2) } else { (&first, 1) }; + return Decision { + choice: Choice::Fold, + reason: format!( + "double board: split equity {mean:.2} below price {price:.2} (board 1 {a:.2}, \ + board 2 {b:.2}); pot split halves each board, board {number} strong alone is \ + not enough - {}", + chosen.reason + ), + equity: Some(mean), + ..chosen.clone() + }; + } + } let (chosen, number, other_equity) = match (first.equity, second.equity) { (Some(a), Some(b)) if b > a => (second, 2, Some(a)), (_, b) => (first, 1, b), diff --git a/tests/double_board_split.rs b/tests/double_board_split.rs new file mode 100644 index 00000000..1196cf67 --- /dev/null +++ b/tests/double_board_split.rs @@ -0,0 +1,53 @@ +//! Doppelbrett-Split durch `wire::respond::respond` (PLO5-Bomb-Pot, zwei Bretter). +//! +//! Bei zwei Brettern wird der Pot haelftig je Brett vergeben: Heros echter Pot-Anteil ist +//! das MITTEL beider Brett-Equities, nicht das bessere Brett. Eine Hand, die nur auf EINEM +//! Brett stark ist, gewinnt real nur die halbe Equity -- ein Call darf sich daran messen, +//! nicht am optimistischen besseren Brett. + +mod support; + +use rechner::wire::respond::respond; +use support::{action, board_json, cards_json, short}; + +/// Ein PLO5-Doppelbrett-Spot als Vertrags-JSON: fuenf Lochkarten, fertiges Brett (River), +/// zweites Brett `board2`, Hero zahlt `to_call` in einen Pot von `pot`, gegen einen Gegner. +fn request(hero: &str, board: &str, board2: &str, pot: f64, to_call: f64) -> String { + format!( + r#"{{"variant":"PLO5","bigBlind":1.0,"seats":6,"heroSeat":6,"buttonSeat":1,"heroCards":{},"board":{},"street":"RIVER","pot":{pot},"toCall":{to_call},"heroStack":1000.0,"legalActions":["FOLD","CALL"],"seed":4919,"villains":[{{"seat":1,"stack":1000.0,"folded":false}}],"boardDouble":{}}}"#, + cards_json(&short(hero)), + board_json(&short(board)), + board_json(&short(board2)), + ) +} + +#[test] +fn nut_on_one_board_dead_on_the_other_folds_to_the_overbet() { + // Nut-Flush auf Brett 1 (die Nuss), nur die Brett-Strasse (tot) auf Brett 2. Der Pot wird + // je Brett geteilt, Heros echter Anteil ist das Mittel beider Equities -- und das liegt + // unter dem Ueberbet-Preis (16 in 10 => 61,5 %). Ein starkes Brett allein reicht nicht. + let out = respond(&request("Ah Kh Qh Jd Tc", "9h 5h 2h 3s 4c", "8d 7c 6s 5s 4h", 10.0, 16.0)); + assert_eq!(action(&out), "FOLD", "Split-Equity unter dem Preis muss folden: {out}"); +} + +#[test] +fn a_monster_on_both_boards_still_calls() { + // Set Asse voll auf Brett 1, Top-Zwei-Paar/Set auf Brett 2: das Mittel bleibt klar ueber + // dem Preis (10 in 10 => 50 %). Ein Monster auf beiden Brettern callt weiter. + let out = respond(&request("As Ah Ks Kh 2c", "Ac Kd 7s 7d 2h", "Ad 9c 6h Jd 3s", 10.0, 10.0)); + assert_eq!(action(&out), "CALL", "Monster auf beiden Brettern muss callen: {out}"); +} + +#[test] +fn a_second_board_of_the_wrong_length_abstains() { + // Drei Karten gegen fuenf: das zweite Brett ist nicht wertbar -> ABSTAIN bleibt. + let out = respond(&request("Ah Kh Qh Jd Tc", "9h 5h 2h 3s 4c", "8d 7c 6s", 10.0, 16.0)); + assert_eq!(action(&out), "ABSTAIN", "falsche Brettlaenge muss aussetzen: {out}"); +} + +#[test] +fn a_second_board_that_repeats_a_card_abstains() { + // Das zweite Brett wiederholt Heros Ass-Herz: doppelte Karte ist nicht wertbar -> ABSTAIN. + let out = respond(&request("Ah Kh Qh Jd Tc", "9h 5h 2h 3s 4c", "Ah 7c 6s 5s 4d", 10.0, 16.0)); + assert_eq!(action(&out), "ABSTAIN", "doppelte Karte muss aussetzen: {out}"); +}