Files
pokerfreak/src/engine/check_falle.rs
T

148 lines
6.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! Messschalter `CHECK_FALLE=oop|alle`: Check-Falle mit gemachter Hand gegen Stabber (Auftrag 17.11. nachts,
//! Owner-Frage: „checken, obwohl man was hat, damit der Gegner denkt, wir haben nichts“).
//!
//! Live (eigene NL2-Hände seit 14.11., erste Flop-Aktion ohne Einsatz): starke Hände checken 26-mal (−89 BB) und setzen
//! 57-mal (+449 BB); die Checks sind EV-Argmax-Checks, keine Fallen. Unsere Check-Range ist fast nur Luft und schwache
//! Paare, der Stab dagegen kostet den Gegner nichts.
//!
//! Wo die Engine mit Wert setzen würde (Gewinner ist ein Value-Raise ohne offenen Einsatz), checkt sie stattdessen,
//! wenn heads-up auf Flop oder Turn der Gegner als aggressiv gelesen ist (Nach-Flop-Aggression ≥ `CHECK_FALLE_AGGR`,
//! Vorgabe 0,45, Lese-Vertrauen ≥ `CHECK_FALLE_VERTRAUEN`, Vorgabe 0,5) und die Hand stark ist (Anteil gegen die Range
//! ≥ `CHECK_FALLE_EQ`, Vorgabe 0,80). Auf den Stab antwortet die normale Logik (Value-Raise oder Call).
//! `oop`: nur als Erster auf der Straße (Check-Raise-Linie); `alle`: auch nach Check des Gegners (Check zurück).
//! Der Read kommt aus dem UNGEGATETEN Spot (`merke_roh`, gesetzt in `engine::decide`): `read_gate` laesst einen
//! aggressiven Gegner (Regular, LAG) blind, genau den, gegen den die Falle zielt.
//! Ungesetzt: aus, bitgleich.
use crate::exploit::profile::Profile;
use crate::game::{ActionKind, SeenAction, Spot, Street};
thread_local! {
/// The ungated profiles (seat, read) of the decision being made (`merke_roh`).
static ROH: std::cell::RefCell<Vec<(u8, Option<Profile>)>> = const { std::cell::RefCell::new(Vec::new()) };
}
/// Set per postflop decision (`engine::decide`): the villains' reads before `read_gate`.
pub fn merke_roh(raw: &Spot) {
if art().is_none() {
return;
}
ROH.with(|r| *r.borrow_mut() = raw.villains.iter().map(|v| (v.seat, v.profile)).collect());
}
fn roh_von(seat: u8) -> Option<Profile> {
ROH.with(|r| r.borrow().iter().find(|(s, _)| *s == seat).and_then(|(_, p)| *p))
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Art {
Oop,
Alle,
}
fn art() -> Option<Art> {
use std::sync::OnceLock;
static A: OnceLock<Option<Art>> = OnceLock::new();
*A.get_or_init(|| match std::env::var("CHECK_FALLE").as_deref() {
Ok("oop") => Some(Art::Oop),
Ok("alle") => Some(Art::Alle),
_ => None,
})
}
fn zahl(name: &str, vorgabe: f64) -> f64 {
std::env::var(name).ok().and_then(|s| s.parse().ok()).filter(|x: &f64| x.is_finite()).unwrap_or(vorgabe)
}
fn schwellen() -> (f64, f64, f64) {
use std::sync::OnceLock;
static S: OnceLock<(f64, f64, f64)> = OnceLock::new();
*S.get_or_init(|| (zahl("CHECK_FALLE_AGGR", 0.45), zahl("CHECK_FALLE_VERTRAUEN", 0.5), zahl("CHECK_FALLE_EQ", 0.80)))
}
/// Check instead of the value bet the engine chose? `share`: hero's share against the villain's range.
pub fn falle(spot: &Spot, share: f64) -> bool {
let Some(art) = art() else { return false };
falle_mit(spot, share, art, schwellen(), roh_von)
}
fn falle_mit(
spot: &Spot,
share: f64,
art: Art,
(aggr, vertrauen, eq): (f64, f64, f64),
roh: impl Fn(u8) -> Option<Profile>,
) -> bool {
if spot.to_call > 0.0 || !spot.is_legal(ActionKind::Check) || !matches!(spot.street, Street::Flop | Street::Turn) {
return false;
}
let mut lebend = spot.live_villains();
let (Some(v), None) = (lebend.next(), lebend.next()) else { return false };
let gegner_hier: Vec<SeenAction> =
spot.history.iter().filter(|r| r.street == spot.street && r.seat == v.seat).map(|r| r.action).collect();
let lage = match art {
Art::Oop => gegner_hier.is_empty(),
Art::Alle => gegner_hier.iter().all(|a| *a == SeenAction::Check),
};
let Some(p) = roh(v.seat).or(v.profile) else { return false };
lage && share >= eq
&& p.aggression.is_some_and(|a| a >= aggr)
&& p.bluff_read_confidence().unwrap_or(0.0) >= vertrauen
}
#[cfg(test)]
mod tests {
use super::*;
use crate::game::{ActionRecord, Villain};
fn spot(history: Vec<ActionRecord>, aggression: f64) -> Spot {
Spot {
variant: crate::variant::Variant::Nlhe,
big_blind: 1.0,
seats: 2,
hero_seat: 2,
button_seat: Some(1),
hero_cards: crate::card::Card::parse_list("Ah Ad").unwrap(),
board: crate::card::Card::parse_list("As 7c 2d").unwrap(),
street: Street::Flop,
pot: 6.0,
to_call: 0.0,
hero_stack: 97.0,
min_raise_to: Some(1.0),
max_raise_to: Some(97.0),
legal: vec![ActionKind::Check, ActionKind::Raise],
allowed_sizes: None,
villains: vec![Villain {
seat: 1,
stack: 97.0,
folded: false,
profile: Some(Profile { aggression: Some(aggression), confidence: Some(0.8), ..Profile::default() }),
}],
seed: 1,
history,
}
}
const S: (f64, f64, f64) = (0.45, 0.5, 0.8);
fn gated(_: u8) -> Option<Profile> {
None
}
#[test]
fn traps_only_strong_hands_against_aggressive_reads() {
let first = spot(vec![], 0.6);
assert!(falle_mit(&first, 0.9, Art::Oop, S, gated));
assert!(!falle_mit(&first, 0.7, Art::Oop, S, gated));
assert!(!falle_mit(&spot(vec![], 0.3), 0.9, Art::Oop, S, gated));
let checked = spot(vec![ActionRecord { street: Street::Flop, seat: 1, action: SeenAction::Check, amount: None }], 0.6);
assert!(!falle_mit(&checked, 0.9, Art::Oop, S, gated));
assert!(falle_mit(&checked, 0.9, Art::Alle, S, gated));
// The gate dropped the aggressive read: the raw read still counts.
let mut blind = spot(vec![], 0.6);
blind.villains[0].profile = None;
assert!(!falle_mit(&blind, 0.9, Art::Oop, S, gated));
let roh = |_: u8| Some(Profile { aggression: Some(0.6), confidence: Some(0.8), ..Profile::default() });
assert!(falle_mit(&blind, 0.9, Art::Oop, S, roh));
}
}