143 lines
5.7 KiB
Rust
143 lines
5.7 KiB
Rust
//! Preflop-Abdeckung auf echten Spots: welcher Teil entscheidet (CFR-Lösung oder Range-Regel), und
|
|
//! warum die Lösung fehlt.
|
|
//!
|
|
//! Liest `messung/preflop/spots.jsonl` (eine Zeile je echter Preflop-Anfrage, `spots_ziehen.py`),
|
|
//! schickt jede Anfrage durch den Kern (`wire::respond`, wie live) und schreibt je Zeile ein JSON:
|
|
//! `{hand, raum, cfr, klasse, aktion, grund, tiefe, sitze, pos, lage, open_bb}`.
|
|
//!
|
|
//! `klasse` ist die Spot-Klasse aus der Hand-Historie (Limp-Pot, Open + Caller, 4-Bet+ ...), damit die
|
|
//! Lücke benannt ist und nicht nur gezählt.
|
|
//!
|
|
//! cargo run --release -j 4 --bin preflop_abdeckung -- messung/preflop/spots.jsonl > aus.jsonl
|
|
//!
|
|
//! Schalter wie live: `OPEN_JAM` und `PREFLOP_VOLL` aus der Umgebung.
|
|
|
|
use rechner::game::{SeenAction, Spot, Street};
|
|
use rechner::guard::validate::check;
|
|
use rechner::json::{parse, render, Value};
|
|
use rechner::preflop::effective_stack::effective_stack_bb;
|
|
use rechner::preflop::first_raiser::{first_raiser, raise_count};
|
|
use rechner::preflop::seat_position::seat_position;
|
|
use rechner::preflop::situation_of::situation_of;
|
|
use rechner::wire::decode::decode;
|
|
use rechner::wire::respond::respond;
|
|
use std::io::{BufRead, BufReader};
|
|
|
|
fn feld<'a>(v: &'a Value, k: &str) -> Option<&'a Value> {
|
|
match v {
|
|
Value::Object(f) => f.iter().find(|(n, _)| n == k).map(|(_, w)| w),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
fn text(v: Option<&Value>) -> String {
|
|
match v {
|
|
Some(Value::String(s)) => s.clone(),
|
|
_ => String::new(),
|
|
}
|
|
}
|
|
|
|
/// Wer vor hero was tat: Limper (Calls vor dem ersten Raise), Caller nach dem ersten Raise, Raises.
|
|
struct Linie {
|
|
limper: usize,
|
|
caller: usize,
|
|
raises: usize,
|
|
hero_opener: bool,
|
|
hero_limpte: bool,
|
|
open_bb: Option<f64>,
|
|
}
|
|
|
|
fn linie(spot: &Spot) -> Linie {
|
|
let mut l = Linie { limper: 0, caller: 0, raises: 0, hero_opener: false, hero_limpte: false, open_bb: None };
|
|
for r in spot.history.iter().filter(|r| r.street == Street::Preflop) {
|
|
match r.action {
|
|
SeenAction::Call if l.raises == 0 => {
|
|
l.limper += 1;
|
|
l.hero_limpte |= r.seat == spot.hero_seat;
|
|
}
|
|
SeenAction::Call if l.raises == 1 => l.caller += 1,
|
|
SeenAction::Raise | SeenAction::AllIn => {
|
|
if l.raises == 0 {
|
|
l.open_bb = r.amount.map(|a| a / spot.big_blind);
|
|
}
|
|
l.raises += 1;
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
l.hero_opener = first_raiser(spot) == Some(spot.hero_seat);
|
|
l
|
|
}
|
|
|
|
fn tiefe_band(d: f64) -> &'static str {
|
|
if d <= 15.0 {
|
|
"<=15bb"
|
|
} else if d <= 25.0 {
|
|
"15-25bb"
|
|
} else if d <= 100.0 + 1e-9 {
|
|
"25-100bb"
|
|
} else if d <= 150.0 {
|
|
"100-150bb"
|
|
} else {
|
|
">150bb"
|
|
}
|
|
}
|
|
|
|
/// Spot-Klasse aus der Linie (unabhängig davon, ob eine Lösung antwortet).
|
|
fn klasse(spot: &Spot, l: &Linie, all_in: bool) -> String {
|
|
let pos = seat_position(spot, spot.hero_seat).label();
|
|
let k = match (l.raises, l.limper, l.caller) {
|
|
(0, 0, _) => format!("first-in {pos}"),
|
|
(0, _, _) if pos == "BB" => "Limp-Pot: BB check-option".to_string(),
|
|
(0, _, _) => "Limp-Pot: iso/overlimp".to_string(),
|
|
(1, lim, _) if lim > 0 && l.hero_limpte => "Limp-Pot: hero limpte, vs raise".to_string(),
|
|
(1, lim, _) if lim > 0 => "vs open nach Limper".to_string(),
|
|
(1, _, c) if c > 0 => "vs open + caller (squeeze/overcall)".to_string(),
|
|
(1, _, _) => format!("vs open HU-linie {pos}"),
|
|
(2, _, _) if l.hero_opener => "opener vs 3-bet".to_string(),
|
|
(2, _, _) => "kalt vs 3-bet (cold 4-bet)".to_string(),
|
|
(_, _, _) => "4-bet+".to_string(),
|
|
};
|
|
if all_in { format!("{k} [all-in]") } else { k }
|
|
}
|
|
|
|
fn main() {
|
|
let pfad = std::env::args().nth(1).unwrap_or_else(|| "messung/preflop/spots.jsonl".to_string());
|
|
let datei = std::fs::File::open(&pfad).expect("spots.jsonl");
|
|
for zeile in BufReader::new(datei).lines() {
|
|
let Ok(zeile) = zeile else { continue };
|
|
let Ok(wurzel) = parse(&zeile) else { continue };
|
|
let Some(anfrage) = feld(&wurzel, "anfrage") else { continue };
|
|
let roh = render(anfrage);
|
|
let Ok(spot) = decode(anfrage).and_then(check) else {
|
|
println!("{{\"fehler\":true}}");
|
|
continue;
|
|
};
|
|
let antwort = respond(&roh);
|
|
let Ok(ant) = parse(&antwort) else { continue };
|
|
let grund = text(feld(&ant, "reason"));
|
|
let aktion = text(feld(&ant, "action"));
|
|
let l = linie(&spot);
|
|
let lage = situation_of(&spot);
|
|
let tiefe = effective_stack_bb(&spot);
|
|
let all_in = matches!(lage, rechner::preflop::situation::Situation::FacingAllIn);
|
|
let aus = Value::Object(vec![
|
|
("hand".into(), feld(&wurzel, "hand").cloned().unwrap_or(Value::Null)),
|
|
("raum".into(), feld(&wurzel, "raum").cloned().unwrap_or(Value::Null)),
|
|
("pid".into(), feld(&wurzel, "pid").cloned().unwrap_or(Value::Null)),
|
|
("cfr".into(), Value::Bool(grund.contains("CFR"))),
|
|
("klasse".into(), Value::String(klasse(&spot, &l, all_in))),
|
|
("aktion".into(), Value::String(aktion)),
|
|
("grund".into(), Value::String(grund)),
|
|
("tiefe".into(), Value::Number(tiefe)),
|
|
("band".into(), Value::String(tiefe_band(tiefe).into())),
|
|
("sitze".into(), Value::Number(spot.seats as f64)),
|
|
("pos".into(), Value::String(seat_position(&spot, spot.hero_seat).label().into())),
|
|
("lage".into(), Value::String(lage.label().into())),
|
|
("raises".into(), Value::Number(raise_count(&spot) as f64)),
|
|
("open_bb".into(), l.open_bb.map_or(Value::Null, Value::Number)),
|
|
]);
|
|
println!("{}", render(&aus));
|
|
}
|
|
}
|