@@ -0,0 +1,120 @@
//! C-bet and stab with air (`CBET_LUFT`, off by default; live analysis 17.11.).
//!
//! Live (NL2, 5386 hands since 14.11.): as the preflop aggressor heads-up, hero c-bets 31 % and air
//! almost never. The cause is structural. A pure bluff needs `P(fold) >= PURE_BLUFF_MIN_FOLD` (0.45),
//! but its size band (`size_policy::BLUFF_BAND`, 33-50 % pot, flop x 0.8) only allows 0.26-0.40 pot,
//! where the fold model gives about 0.28 (base 0.45, `fold_chance::sized_fold`). So a flop bluff
//! passes only against a read folder. The real pool folds 33 % to our bets under 0.4 pot and 47 % to
//! 0.6-0.8 pot heads-up; the model (0.28 / 0.45) is right, and so is the EV: an air c-bet at 2/3 pot
//! wins `0.47 pot` uncalled against a check that realises about `0.2 pot`.
//!
//! The switch lifts that gate where it is a c-bet or a stab: hero bets first heads-up with nothing in
//! front, on the flop as the preflop aggressor, and with `turn` also on the turn after a flop checked
//! through. There a pure bluff needs only `min_fold` (and still its EV edge over checking,
//! `PURE_BLUFF_EDGE`), and with `gross` it may use the value sizes, so the EV picks the size.
//!
//! `beleg`: only as far as the counted read shows a villain who rarely raises against bets
//! (`glaube::evidence_weight` on the ungated `raise_to_bet`, full at 0,25, none at the anchor 0,30 or
//! without a read; needs `POSTERIOR=bluff`, which keeps the ungated profile). The least fold chance
//! slides from `PURE_BLUFF_MIN_FOLD` to `min_fold` with that weight, the value sizes need a weight
//! above 0. Gate 17.11. without it: nemesis-2 (light raiser) − 1,64 on the ladder, − 3,26 @blind.
//!
//! `CBET_LUFT=<tokens>`, comma separated: `flop` (on), `turn` (also the turn stab), `min:<x>` (least
//! fold chance, default `MIN_FOLD_DEFAULT`), `gross` (value sizes allowed), `beleg` (see above).
//! Anything unparsable: off.
use crate ::game ::{ line , Spot , Street } ;
use std ::cell ::Cell ;
/// Least P(fold) of a c-bet/stab bluff when the switch names none.
pub const MIN_FOLD_DEFAULT : f64 = 0.30 ;
#[ derive(Clone, Copy, Debug, PartialEq) ]
pub struct Mode {
pub turn : bool ,
pub min_fold : f64 ,
pub wide : bool ,
pub evidence : bool ,
}
thread_local! {
static OVERRIDE : Cell < Option < Option < Mode > > > = const { Cell ::new ( None ) } ;
}
pub fn parse ( s : & str ) -> Option < Mode > {
let mut m = Mode { turn : false , min_fold : MIN_FOLD_DEFAULT , wide : false , evidence : false } ;
let mut on = false ;
for t in s . split ( ',' ) . map ( str ::trim ) . filter ( | t | ! t . is_empty ( ) ) {
match t {
" flop " | " 1 " = > on = true ,
" turn " = > {
on = true ;
m . turn = true ;
}
" gross " = > m . wide = true ,
" beleg " = > m . evidence = true ,
_ = > {
let x = t . strip_prefix ( " min: " ) ? . parse ::< f64 > ( ) . ok ( ) . filter ( | x | ( 0. 0 ..= 1.0 ) . contains ( x ) ) ? ;
m . min_fold = x ;
}
}
}
on . then_some ( m )
}
/// The switch, `None` when off.
pub fn mode ( ) -> Option < Mode > {
use std ::sync ::OnceLock ;
static MODE : OnceLock < Option < Mode > > = OnceLock ::new ( ) ;
OVERRIDE . with ( | o | o . get ( ) ) . unwrap_or_else ( | | * MODE . get_or_init ( | | std ::env ::var ( " CBET_LUFT " ) . ok ( ) . and_then ( | s | parse ( & s ) ) ) )
}
/// Force the switch for this thread (`Some(None)` = off), `None` = back to the environment.
pub fn set_override ( mode : Option < Option < Mode > > ) {
OVERRIDE . with ( | o | o . set ( mode ) ) ;
}
/// The switch when this spot is a c-bet or stab it covers: heads-up, nothing to call, and on the flop
/// hero is the preflop aggressor with no flop bet yet, on the turn (`turn`) nobody bet the flop or
/// the turn yet.
pub fn applies ( spot : & Spot ) -> Option < Mode > {
let m = mode ( ) ? ;
if spot . to_call > 0.0 | | spot . live_villains ( ) . count ( ) ! = 1 {
return None ;
}
let quiet = | s : Street | ! spot . history . iter ( ) . any ( | r | r . street = = s & & r . action . is_aggressive ( ) ) ;
let hit = match spot . street {
Street ::Flop = > line ::cbet_spot ( & spot . history , spot . hero_seat , Street ::Flop ) ,
Street ::Turn = > m . turn & & quiet ( Street ::Flop ) & & quiet ( Street ::Turn ) ,
_ = > false ,
} ;
if ! hit {
return None ;
}
if ! m . evidence {
return Some ( m ) ;
}
let seat = spot . live_villains ( ) . next ( ) ? . seat ;
let w = super ::glaube ::raw_profile ( seat ) . as_ref ( ) . map_or ( 0.0 , super ::glaube ::evidence_weight ) ;
( w > 0.0 ) . then ( | | {
let top = super ::bluff ::PURE_BLUFF_MIN_FOLD ;
Mode { min_fold : top - w * ( top - m . min_fold . min ( top ) ) , .. m }
} )
}
#[ cfg(test) ]
mod tests {
use super ::* ;
#[ test ]
fn parses_the_tokens ( ) {
assert_eq! ( parse ( " flop " ) , Some ( Mode { turn : false , min_fold : 0.30 , wide : false , evidence : false } ) ) ;
assert_eq! ( parse ( " flop,turn,min:0.35,gross " ) , Some ( Mode { turn : true , min_fold : 0.35 , wide : true , evidence : false } ) ) ;
assert_eq! ( parse ( " turn " ) , Some ( Mode { turn : true , min_fold : 0.30 , wide : false , evidence : false } ) ) ;
assert_eq! ( parse ( " flop,gross,beleg " ) . map ( | m | m . evidence ) , Some ( true ) ) ;
assert_eq! ( parse ( " gross " ) , None ) ;
assert_eq! ( parse ( " flop,min:x " ) , None ) ;
assert_eq! ( parse ( " 0 " ) , None ) ;
assert_eq! ( parse ( " " ) , None ) ;
}
}