diff --git a/src/engine/glaube.rs b/src/engine/glaube.rs index c6c36f60..18415868 100644 --- a/src/engine/glaube.rs +++ b/src/engine/glaube.rs @@ -55,6 +55,10 @@ pub struct Mode { pub board_weight: f64, /// `nurfold`: the board term only in the fold branch, the called branch keeps `call_floor`. pub fold_only_branch: bool, + /// `anteil`: the read is the fold RATE within the class (below / above the floor) instead of a + /// logit level, `P(fold) = m_board * f / m_ref` (see `class_fold`). Never above the mass below + /// the floor unless the read folds more than that mass on average. + pub class_rate: bool, } thread_local! { @@ -70,12 +74,14 @@ pub fn mode() -> Option { } fn parse(s: &str) -> Option { - let mut m = Mode { fold: false, board_weight: 1.0, fold_only_branch: false }; + let mut m = Mode { fold: false, board_weight: 1.0, fold_only_branch: false, class_rate: false }; for t in s.split(',').map(str::trim) { if t == "fold" { m.fold = true; } else if t == "nurfold" { m.fold_only_branch = true; + } else if t == "anteil" { + m.class_rate = true; } else if let Some(w) = t.strip_prefix("fold:").and_then(|w| w.parse::().ok()).filter(|w| w.is_finite()) { m.fold = true; m.board_weight = w; @@ -195,11 +201,32 @@ pub fn fold(spot: &Spot, villain: &Villain, ratio: f64, facing_raise: bool, read let reference = reference(&rules, spot.variant, lo, hi, spot.board.len(), made, draws); let _ = facing_raise; match (board, reference) { + (Some(b), Some(r)) if m.class_rate => { + let b = r + m.board_weight * (b - r); + class_fold(read_fold, b.clamp(0.0, 1.0), r).clamp(0.0, MAX_FOLD) + } (Some(b), Some(r)) => sigmoid(logit(read_fold) + m.board_weight * (logit(b) - logit(r))).clamp(0.0, MAX_FOLD), _ => read_fold, } } +/// The read as a rate within the classes: on the average board a share `m_ref` lies below the floor, +/// the villain folds `f` in all. If `f <= m_ref` he folds `f / m_ref` of his hands below the floor and +/// nothing above it; else all below and `(f - m_ref) / (1 - m_ref)` of those above. On this board +/// (`m_board` below) the same rates give the fold chance; `m_board = m_ref` returns `f`. +fn class_fold(f: f64, m_board: f64, m_ref: f64) -> f64 { + if m_ref <= 0.0 { + return f; + } + if f <= m_ref { + m_board * f / m_ref + } else if m_ref >= 1.0 { + f + } else { + m_board + (1.0 - m_board) * (f - m_ref) / (1.0 - m_ref) + } +} + /// The read's fold chance as `table_fold` prices it (street read, c-bet read on a c-bet), then S1. pub fn table_fold_of(spot: &Spot, villain: &Villain, ratio: f64, facing_raise: bool) -> f64 { let p = villain.profile.as_ref(); @@ -217,9 +244,9 @@ mod tests { #[test] fn parses_the_stages() { - assert_eq!(parse("fold"), Some(Mode { fold: true, board_weight: 1.0, fold_only_branch: false })); - assert_eq!(parse("fold:0.5,bluff"), Some(Mode { fold: true, board_weight: 0.5, fold_only_branch: false })); - assert_eq!(parse("fold:0,nurfold"), Some(Mode { fold: true, board_weight: 0.0, fold_only_branch: true })); + assert_eq!(parse("fold"), Some(Mode { fold: true, board_weight: 1.0, fold_only_branch: false, class_rate: false })); + assert_eq!(parse("fold:0.5,bluff"), Some(Mode { fold: true, board_weight: 0.5, fold_only_branch: false, class_rate: false })); + assert_eq!(parse("fold:0,nurfold"), Some(Mode { fold: true, board_weight: 0.0, fold_only_branch: true, class_rate: false })); assert_eq!(parse("0"), None); assert_eq!(parse(""), None); } @@ -227,5 +254,16 @@ mod tests { #[test] fn an_average_board_keeps_the_read() { assert!((sigmoid(logit(0.45)) - 0.45).abs() < 1e-12); + assert!((class_fold(0.2, 0.55, 0.55) - 0.2).abs() < 1e-12); + assert!((class_fold(0.7, 0.55, 0.55) - 0.7).abs() < 1e-12); + } + + #[test] + fn a_rarely_folding_villain_folds_little_on_a_dry_board() { + // Maniac: folds 0.20 on average, 0.55 below the floor on average, 0.80 on this board. + let f = class_fold(0.2, 0.8, 0.55); + assert!((f - 0.2 * 0.8 / 0.55).abs() < 1e-12); + assert!(f < sigmoid(logit(0.2) + logit(0.8) - logit(0.55))); + assert_eq!(parse("fold,anteil").map(|m| m.class_rate), Some(true)); } }