Sim: Persona-Felder von pool-phh (raise_shove_at/semi, raise_call_margin, bluff_flop/turn/river, pool_version) aus claude/pool-nl2-echt uebernommen, nur src/sim/welt.rs; Standardwerte = bisheriges Verhalten
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"label": "pool-phh",
|
||||
"call_margin": 0.4249,
|
||||
"cbet_call": 0.044,
|
||||
"bet_at": 0.78,
|
||||
"check_raise": 0.1213,
|
||||
"size_mix_flop": [
|
||||
0.1085,
|
||||
0.6138,
|
||||
0.2079,
|
||||
0.0698
|
||||
],
|
||||
"size_mix_turn": [
|
||||
0.2709,
|
||||
0.5119,
|
||||
0.1635,
|
||||
0.0536
|
||||
],
|
||||
"size_mix_river": [
|
||||
0.3147,
|
||||
0.427,
|
||||
0.1608,
|
||||
0.0975
|
||||
],
|
||||
"raise_at": 0.87,
|
||||
"raise_bluff": 0.12,
|
||||
"call_size_exp": 0.4,
|
||||
"raise_shove_at": 0.96,
|
||||
"raise_shove_semi": 0.0,
|
||||
"raise_call_margin": 0.05,
|
||||
"_quelle": "PHH/HandHQ NL25 (Juli 2009), 2249126 Kopf-an-Kopf-Haende",
|
||||
"_verlust_eich": 112.76,
|
||||
"_pruef": "Summe z^2 251.7, 2 von 38 im Intervall"
|
||||
}
|
||||
+158
-2
@@ -113,6 +113,18 @@ pub struct Persona {
|
||||
pub call_size_exp: f64,
|
||||
/// Facing a bet with air (below `BLUFF_BELOW`): the chance to raise anyway. 0 = never.
|
||||
pub raise_bluff: f64,
|
||||
/// Facing a raise over its own bet/raise on this street: from this strength it goes all-in (instead of
|
||||
/// a sized re-raise). 0 = off (sized as before).
|
||||
pub raise_shove_at: f64,
|
||||
/// Same spot, a medium hand (`BLUFF_BELOW` .. `raise_shove_at`, draws and pairs): the chance to go
|
||||
/// all-in anyway (semi-bluff stack-off). 0 = never.
|
||||
pub raise_shove_semi: f64,
|
||||
/// Same spot: added to the call margin (positive folds more against a raise). 0 = as a bet.
|
||||
pub raise_call_margin: f64,
|
||||
/// Bluff rate per postflop street (flop, turn, river) in place of `rules.bluff` (texture and position
|
||||
/// still multiply it), from real showdowns per line (`lesen/phh_linien.py`, PHH prior + NL2). Negative =
|
||||
/// off, the street bluffs at `rules.bluff` as before.
|
||||
pub bluff_street: [f64; 3],
|
||||
}
|
||||
|
||||
/// Representative pot fraction of each `size_mix` class (inside its class even with the noise).
|
||||
@@ -164,6 +176,10 @@ impl Persona {
|
||||
size_mix: [[0.0; 4]; 3],
|
||||
call_size_exp: 0.0,
|
||||
raise_bluff: 0.0,
|
||||
raise_shove_at: 0.0,
|
||||
raise_shove_semi: 0.0,
|
||||
raise_call_margin: 0.0,
|
||||
bluff_street: [-1.0; 3],
|
||||
};
|
||||
match i {
|
||||
// Sizes up with strength, a little texture awareness.
|
||||
@@ -322,6 +338,12 @@ impl Persona {
|
||||
"check_raise" => p.check_raise = zahl()?,
|
||||
"call_size_exp" => p.call_size_exp = zahl()?,
|
||||
"raise_bluff" => p.raise_bluff = zahl()?,
|
||||
"raise_shove_at" => p.raise_shove_at = zahl()?,
|
||||
"raise_shove_semi" => p.raise_shove_semi = zahl()?,
|
||||
"raise_call_margin" => p.raise_call_margin = zahl()?,
|
||||
"bluff_flop" => p.bluff_street[0] = zahl()?,
|
||||
"bluff_turn" => p.bluff_street[1] = zahl()?,
|
||||
"bluff_river" => p.bluff_street[2] = zahl()?,
|
||||
"size_mix_flop" | "size_mix_turn" | "size_mix_river" => {
|
||||
let i = match k.as_str() {
|
||||
"size_mix_flop" => 0,
|
||||
@@ -537,17 +559,39 @@ pub fn act(p: &Persona, view: View, ctx: &Ctx, rng: Rng) -> (Act, Rng) {
|
||||
let raise_at = p.rules.raise_at + t.raise_at + ps.raise_at;
|
||||
let cbet = if ctx.facing_cbet { p.cbet_call } else { 0.0 };
|
||||
let margin = (p.rules.call_margin + t.call + ps.call + cbet).max(0.0);
|
||||
let bluff = (p.rules.bluff * t.bluff_mult * ps.bluff_mult).clamp(0.0, 0.9);
|
||||
let basis = match ctx.street {
|
||||
Street::Flop if p.bluff_street[0] >= 0.0 => p.bluff_street[0],
|
||||
Street::Turn if p.bluff_street[1] >= 0.0 => p.bluff_street[1],
|
||||
Street::River if p.bluff_street[2] >= 0.0 => p.bluff_street[2],
|
||||
_ => p.rules.bluff,
|
||||
};
|
||||
let bluff = (basis * t.bluff_mult * ps.bluff_mult).clamp(0.0, 0.9);
|
||||
let can_raise = view.min_raise_to.is_some();
|
||||
let sized = |bluff_hand: bool, rng: Rng| {
|
||||
let (frac, rng) = p.size_frac_on(Some(ctx.street), s, bluff_hand, rng);
|
||||
(Act::RaiseTo(ctx.reading.own_bet + to_call + frac * (ctx.reading.pot + to_call)), rng)
|
||||
};
|
||||
// Facing a raise over its own bet or raise on this street (postflop: own_bet > 0 and more to call).
|
||||
let facing_raise = to_call > 0.0 && ctx.reading.own_bet > 0.0;
|
||||
let mut rng = rng;
|
||||
if facing_raise && can_raise && p.raise_shove_at > 0.0 {
|
||||
let shove = Act::RaiseTo(view.max_raise_to.unwrap_or(f64::MAX));
|
||||
if s >= p.raise_shove_at {
|
||||
return (shove, rng);
|
||||
}
|
||||
if s >= BLUFF_BELOW && p.raise_shove_semi > 0.0 {
|
||||
let (u, r) = rng.unit();
|
||||
rng = r;
|
||||
if u < p.raise_shove_semi {
|
||||
return (shove, rng);
|
||||
}
|
||||
}
|
||||
}
|
||||
let margin = if facing_raise { margin + p.raise_call_margin } else { margin };
|
||||
if to_call > 0.0 {
|
||||
if can_raise && s >= raise_at {
|
||||
return sized(false, rng);
|
||||
}
|
||||
let mut rng = rng;
|
||||
if p.check_raise > 0.0 && can_raise && ctx.checked_here {
|
||||
if s >= bet_at {
|
||||
return sized(false, rng); // the trapped hand springs
|
||||
@@ -597,6 +641,53 @@ pub fn act(p: &Persona, view: View, ctx: &Ctx, rng: Rng) -> (Act, Rng) {
|
||||
(Act::Check, rng)
|
||||
}
|
||||
|
||||
/// Which pool-persona file a run measures against, pinned per output folder (plan §8, Nachfuehrung).
|
||||
///
|
||||
/// `wert` is `POOL_PERSONA`: a file (as before), or `<ordner>/<name>@aktuell`. That second form is the
|
||||
/// version the pointer `<ordner>/<name>-aktuell.txt` names (`lesen/pool_nachfuehren.py` writes it).
|
||||
/// The first run in `out` writes `out/pool.version` ("<file> <fnv64 of the text>"). A resumed run measures
|
||||
/// against exactly that file again: with `@aktuell` it keeps the pinned version after a promotion, and
|
||||
/// with a file that changed in the meantime it refuses (`Err`). Comparisons do not wander.
|
||||
/// -> (the file to read, the version line).
|
||||
pub fn pool_version(wert: &str, out: &std::path::Path) -> Result<(std::path::PathBuf, String), String> {
|
||||
use std::path::{Path, PathBuf};
|
||||
let pin = out.join("pool.version");
|
||||
let gepinnt = std::fs::read_to_string(&pin).ok().map(|z| z.trim().to_string()).filter(|z| !z.is_empty());
|
||||
let pfad: PathBuf = match wert.strip_suffix("@aktuell") {
|
||||
Some(stamm) => {
|
||||
let p = Path::new(stamm);
|
||||
let ordner = p.parent().unwrap_or(Path::new("."));
|
||||
let name = p.file_name().and_then(|n| n.to_str()).ok_or_else(|| format!("POOL_PERSONA {wert}: kein Name"))?;
|
||||
let datei = match &gepinnt {
|
||||
Some(z) => z.split_whitespace().next().unwrap_or("").to_string(),
|
||||
None => {
|
||||
let zeiger = ordner.join(format!("{name}-aktuell.txt"));
|
||||
std::fs::read_to_string(&zeiger).map_err(|e| format!("{}: {e}", zeiger.display()))?.trim().to_string()
|
||||
}
|
||||
};
|
||||
ordner.join(datei)
|
||||
}
|
||||
None => PathBuf::from(wert),
|
||||
};
|
||||
let text = std::fs::read_to_string(&pfad).map_err(|e| format!("POOL_PERSONA {}: {e}", pfad.display()))?;
|
||||
let mut h: u64 = 0xcbf2_9ce4_8422_2325;
|
||||
for b in text.replace("\r\n", "\n").bytes() {
|
||||
h = (h ^ b as u64).wrapping_mul(0x0100_0000_01b3);
|
||||
}
|
||||
let datei = pfad.file_name().and_then(|n| n.to_str()).unwrap_or("?");
|
||||
let zeile = format!("{datei} {h:016x}");
|
||||
match gepinnt {
|
||||
Some(z) if z != zeile => Err(format!("{}: gemessen gegen {z}, jetzt {zeile}; neuer Ordner fuer eine neue Version", pin.display())),
|
||||
Some(_) => Ok((pfad, zeile)),
|
||||
None => {
|
||||
std::fs::create_dir_all(out).map_err(|e| e.to_string())?;
|
||||
std::fs::write(&pin, format!("{zeile}
|
||||
")).map_err(|e| e.to_string())?;
|
||||
Ok((pfad, zeile))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -662,6 +753,71 @@ mod tests {
|
||||
assert_eq!((p.call_size_exp, p.raise_bluff), (1.2, 0.05));
|
||||
assert!(Persona::from_pool_json(r#"{"size_mix_flop":[1,2]}"#).is_err());
|
||||
assert_eq!(Persona::micro_passiv().size_mix, [[0.0; 4]; 3]);
|
||||
let q = Persona::from_pool_json(r#"{"raise_shove_at":0.8,"raise_shove_semi":0.2,"raise_call_margin":0.1}"#).unwrap();
|
||||
assert_eq!((q.raise_shove_at, q.raise_shove_semi, q.raise_call_margin), (0.8, 0.2, 0.1));
|
||||
assert_eq!(q.bluff_street, [-1.0; 3], "without the keys every street bluffs at rules.bluff");
|
||||
let b = Persona::from_pool_json(r#"{"bluff_river":0.12,"bluff_flop":0}"#).unwrap();
|
||||
assert_eq!(b.bluff_street, [0.0, -1.0, 0.12]);
|
||||
assert_eq!(Persona::micro_passiv().raise_shove_at, 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pool_version_pins_the_file_per_run() {
|
||||
let d = std::env::temp_dir().join(format!("pool_version_{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&d);
|
||||
let pool = d.join("pool");
|
||||
std::fs::create_dir_all(&pool).unwrap();
|
||||
std::fs::write(pool.join("nl2-echt-a.json"), r#"{"call_margin":0.2}"#).unwrap();
|
||||
std::fs::write(pool.join("nl2-echt-b.json"), r#"{"call_margin":0.3}"#).unwrap();
|
||||
std::fs::write(pool.join("nl2-echt-aktuell.txt"), "nl2-echt-a.json
|
||||
").unwrap();
|
||||
let wert = format!("{}/nl2-echt@aktuell", pool.display());
|
||||
let lauf = d.join("tor");
|
||||
let (p, z) = pool_version(&wert, &lauf).unwrap();
|
||||
assert!(p.ends_with("nl2-echt-a.json") && z.starts_with("nl2-echt-a.json "), "{z}");
|
||||
// promoted meanwhile: the running gate keeps a, a new gate gets b
|
||||
std::fs::write(pool.join("nl2-echt-aktuell.txt"), "nl2-echt-b.json").unwrap();
|
||||
assert!(pool_version(&wert, &lauf).unwrap().0.ends_with("nl2-echt-a.json"));
|
||||
assert!(pool_version(&wert, &d.join("tor2")).unwrap().0.ends_with("nl2-echt-b.json"));
|
||||
// a plain file as before; changed under a running gate -> refused
|
||||
let f = pool.join("nl2-echt-b.json");
|
||||
let lauf3 = d.join("tor3");
|
||||
pool_version(f.to_str().unwrap(), &lauf3).unwrap();
|
||||
std::fs::write(&f, r#"{"call_margin":0.4}"#).unwrap();
|
||||
assert!(pool_version(f.to_str().unwrap(), &lauf3).is_err());
|
||||
let _ = std::fs::remove_dir_all(&d);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raised_over_its_bet_it_shoves_strong_and_some_draws() {
|
||||
let mut p = Persona::micro_passiv();
|
||||
let ctx = |strength: f64, own_bet: f64| Ctx {
|
||||
reading: Reading { strength, pot: 20.0, own_bet, preflop: false },
|
||||
street: Street::Turn,
|
||||
texture: Texture::Dry,
|
||||
pos: Pos::Oop,
|
||||
facing_cbet: false,
|
||||
facing_three_bet: false,
|
||||
checked_here: false,
|
||||
};
|
||||
let raised = View { to_call: 6.0, min_raise_to: Some(14.0), max_raise_to: Some(90.0) };
|
||||
// off (0): the sized raise as before, never the whole stack
|
||||
let (a, _) = act(&p, raised, &ctx(0.97, 4.0), Rng::seeded(3));
|
||||
assert!(matches!(a, Act::RaiseTo(x) if x < 90.0), "{a:?}");
|
||||
p.raise_shove_at = 0.85;
|
||||
p.raise_shove_semi = 0.5;
|
||||
assert_eq!(act(&p, raised, &ctx(0.90, 4.0), Rng::seeded(3)).0, Act::RaiseTo(90.0));
|
||||
// a first bet against it (own_bet 0) is not a raise over its bet: no shove
|
||||
assert!(!matches!(act(&p, raised, &ctx(0.90, 0.0), Rng::seeded(3)).0, Act::RaiseTo(x) if x >= 90.0));
|
||||
// medium hands: about half of them
|
||||
let mut rng = Rng::seeded(11);
|
||||
let mut n = 0;
|
||||
for _ in 0..2000 {
|
||||
let (a, r) = act(&p, raised, &ctx(0.60, 4.0), rng);
|
||||
rng = r;
|
||||
n += (a == Act::RaiseTo(90.0)) as u32;
|
||||
}
|
||||
assert!((800..1200).contains(&n), "{n}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user