Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bd74a1caf |
@@ -112,7 +112,7 @@ fn suche(core: &Core, v: &Value) -> Value {
|
||||
Err(e) => json!({"ok": false, "error": e.to_string()}),
|
||||
Ok(mut req) => {
|
||||
req.options.search = true;
|
||||
req.options.include_probs = false;
|
||||
req.options.include_probs = v["mit_probs"] == true; // pokerfreak (04.12.): nur mit MOTOR_SHARINGAN_PI fragt der Motor so; sonst wie bisher false
|
||||
req.options.time_budget_ms = v["budget_ms"].as_u64().filter(|&b| b > 0);
|
||||
if let Some(i) = v["iters"].as_u64().filter(|&i| i > 0) {
|
||||
req.options.iters = Some(i);
|
||||
|
||||
@@ -84,6 +84,28 @@ pub fn splash() -> bool {
|
||||
*A.get_or_init(|| an() && std::env::var("MOTOR_SHARINGAN_SPLASH").is_ok_and(|x| x == "1"))
|
||||
}
|
||||
|
||||
/// MOTOR_SHARINGAN_PI=1 (04.12., Standard aus; Messweg des LBR, Tor 3): die Antwort traegt zusaetzlich `pi` = [[art, groesse_bb, p], ...]
|
||||
/// (seine ganze Mischung am Punkt, art 0 Fold, 1 Check/Call, 2 Einsatz mit Betrag in bb) und `gezogen` (Index des gespielten Eintrags).
|
||||
/// Ohne den Schalter bleibt jede Anfrage an seinen Dienst und jede Antwort Byte fuer Byte wie vorher.
|
||||
pub fn pi_an() -> bool {
|
||||
static A: OnceLock<bool> = OnceLock::new();
|
||||
*A.get_or_init(|| an() && std::env::var("MOTOR_SHARINGAN_PI").is_ok_and(|x| x == "1"))
|
||||
}
|
||||
|
||||
/// Seine Mischung (`probs`: [{type, to, p}], `to` in Chips mit BB = 100) als `pi` und der Index des gespielten Zugs (`aktion`: {type, to}).
|
||||
/// None: keine Mischung in der Antwort oder der gespielte Zug steht nicht darin.
|
||||
pub fn pi_aus(probs: &Value, aktion: &Value) -> Option<(Value, usize)> {
|
||||
let l = probs.as_array().filter(|l| !l.is_empty())?;
|
||||
let art = |k: &str| match k {
|
||||
"fold" => 0,
|
||||
"check" | "call" => 1,
|
||||
_ => 2,
|
||||
};
|
||||
let pi: Vec<Value> = l.iter().map(|x| json!([art(x["type"].as_str().unwrap_or("")), x["to"].as_f64().map_or(0.0, |t| t / 100.0), x["p"].as_f64().unwrap_or(0.0)])).collect();
|
||||
let g = l.iter().position(|x| x["type"] == aktion["type"] && x["to"] == aktion["to"])?;
|
||||
Some((json!(pi), g))
|
||||
}
|
||||
|
||||
/// Zuggrund vor dem Flop, wenn totes Geld oder ein Nachpost im Topf liegt (seine Tabellen kennen beides nicht)
|
||||
const GRUND_SPLASH: &str = " [Splash: Tabelle ohne Splash-Knoten; Topf mit totem Geld]";
|
||||
const GRUND_NACHPOST: &str = " [Nachpost: Tabelle ohne Nachpost-Knoten; Nachpost als Einsatz im Topf]";
|
||||
@@ -592,6 +614,14 @@ fn frage_roh(v: &Value) -> Option<Value> {
|
||||
pub fn zug(q: &Value, k: &Kontext) -> Option<Value> {
|
||||
let r = frage(&json!({"op": "act", "req": k.basis}))?;
|
||||
let grund = if q["street"] == "PREFLOP" { k.vorflop_grund } else { "" };
|
||||
// MOTOR_SHARINGAN_PI: der act-Weg traegt keine Mischung; dieselbe Lage nochmal als probs fragen (Blueprint, ohne Ziehen)
|
||||
if pi_an() {
|
||||
if let Some(p) = frage(&json!({"op": "probs", "req": k.basis})) {
|
||||
let mut o = r["response"].clone();
|
||||
o["probs"] = p["probs"].clone();
|
||||
return abbilden(q, &o, grund.to_string());
|
||||
}
|
||||
}
|
||||
abbilden(q, &r["response"], grund.to_string())
|
||||
}
|
||||
|
||||
@@ -623,8 +653,15 @@ fn abbilden(q: &Value, o: &Value, zusatz: String) -> Option<Value> {
|
||||
akt = if legal("CHECK") { "CHECK" } else if legal("CALL") && akt != "FOLD" { "CALL" } else { "FOLD" };
|
||||
groesse = None;
|
||||
}
|
||||
Some(json!({"action": akt, "size": groesse, "confidence": 1,
|
||||
"reason": format!("sharingan {} ({}){zusatz}", o["source"].as_str().unwrap_or("?"), o["street"].as_str().unwrap_or("?"))}))
|
||||
let mut antwort = json!({"action": akt, "size": groesse, "confidence": 1,
|
||||
"reason": format!("sharingan {} ({}){zusatz}", o["source"].as_str().unwrap_or("?"), o["street"].as_str().unwrap_or("?"))});
|
||||
if pi_an() {
|
||||
if let Some((pi, g)) = pi_aus(&o["probs"], a) {
|
||||
antwort["pi"] = pi;
|
||||
antwort["gezogen"] = json!(g);
|
||||
}
|
||||
}
|
||||
Some(antwort)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ MOTOR_SUCHE_QUELLE=sharingan (Echtzeit-Suche)
|
||||
@@ -772,6 +809,9 @@ pub fn such_zug(q: &Value, k: &Kontext) -> Option<Value> {
|
||||
// ohnehin nicht mehr nehmen; was wir nehmen, hat die volle feste Iterationszahl
|
||||
let sein_ms = (rest * 1000.0 / 0.7) as u64 + 100;
|
||||
let mut frage = json!({"op": "suche", "req": such_basis(k), "budget_ms": sein_ms});
|
||||
if pi_an() {
|
||||
frage["mit_probs"] = json!(true);
|
||||
}
|
||||
// MOTOR_SUCHE_BUDGET=1: weniger Iterationen nur, wenn die volle Zahl nicht mehr in die Frist passt
|
||||
let knapp = if budget_an() && flop_n.is_none() { knappe_iters(rest) } else { None };
|
||||
if let Some(n) = flop_n {
|
||||
@@ -1252,3 +1292,37 @@ mod splash_spec {
|
||||
assert_eq!(b.vorflop_grund, "");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod pi_spec {
|
||||
use super::pi_aus;
|
||||
use serde_json::json;
|
||||
|
||||
fn probs() -> serde_json::Value {
|
||||
json!([{"type": "raise", "to": 200, "p": 0.8}, {"type": "raise", "to": 250, "p": 0.14}, {"type": "call", "to": 100, "p": 0.06}, {"type": "fold", "p": 0.0}])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mischung_wird_pi_mit_art_betrag_und_p() {
|
||||
let (pi, g) = pi_aus(&probs(), &json!({"type": "raise", "to": 250})).unwrap();
|
||||
assert_eq!(pi, json!([[2, 2.0, 0.8], [2, 2.5, 0.14], [1, 1.0, 0.06], [0, 0.0, 0.0]]));
|
||||
assert_eq!(g, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gespielter_zug_ausserhalb_der_mischung_gibt_nichts() {
|
||||
assert!(pi_aus(&probs(), &json!({"type": "raise", "to": 999})).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ohne_mischung_nichts() {
|
||||
assert!(pi_aus(&json!(null), &json!({"type": "call", "to": 100})).is_none());
|
||||
assert!(pi_aus(&json!([]), &json!({"type": "call", "to": 100})).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fold_ohne_betrag_wird_gefunden() {
|
||||
let (_, g) = pi_aus(&probs(), &json!({"type": "fold"})).unwrap();
|
||||
assert_eq!(g, 3);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user