SHARINGAN-Saat auf 32 Bit (splitmix64, gefaltet) vor jeder Uebergabe an SHARINGAN (Dienst, Suche, track_seed, Turnier): seine Ziehung war mit 64-Bit-Saaten verzerrt (Open wurde zu Limp)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 14:49:17 +01:00
co-authored by Claude Opus 5.5
parent f2e8024f74
commit 66f007a5eb
2 changed files with 43 additions and 4 deletions
+42 -3
View File
@@ -76,6 +76,18 @@ pub fn rein() -> bool {
fn schalter(k: &str, w: &str) -> bool {
std::env::var(k).is_ok_and(|x| x == w)
}
/// Saat fuer SHARINGAN (03.12.): seine Ziehung ist mit grossen 64-Bit-Saaten verzerrt (unsere Anfrage-Saat ~3e18 zog in 11 von 11
/// Vorflop-Lagen call, obwohl seine Mischung 2-21 % call hatte; mit Saat 1..20 passend zur Mischung). Darum geht an ihn nur ein
/// 32-Bit-Wert, gemischt aus allen 64 Bit (splitmix64, dann obere und untere Haelfte gefaltet), damit die unteren Bits nicht korrelieren.
/// Unsere eigene Ziehung im Motor bleibt unberuehrt.
pub fn saat32(x: u64) -> u64 {
let mut z = x.wrapping_add(0x9E37_79B9_7F4A_7C15);
z = (z ^ (z >> 30)).wrapping_mul(0xBF58_476D_1CE4_E5B9);
z = (z ^ (z >> 27)).wrapping_mul(0x94D0_49BB_1331_11EB);
z ^= z >> 31;
(z ^ (z >> 32)) & 0xFFFF_FFFF
}
pub fn phm() -> bool {
static A: OnceLock<bool> = OnceLock::new();
*A.get_or_init(|| schalter("MOTOR_HYB_UEBERSETZUNG", "phm"))
@@ -330,7 +342,7 @@ impl Kontext {
}
let brett: Vec<String> = ["FLOP", "TURN", "RIVER"].iter().flat_map(|s| q["board"][*s].as_array().into_iter().flatten().filter_map(karte)).collect();
let loch: Vec<String> = q["heroCards"].as_array()?.iter().filter_map(karte).collect();
let seed = q["seed"].as_u64().unwrap_or(1);
let seed = saat32(q["seed"].as_u64().unwrap_or(1));
let mut basis = json!({"small_blind": 50, "big_blind": 100, "button_seat": if n == 2 { sb } else { (sb + n - 1) % n }, "hero_seat": pos(held)?, "hole_cards": loch,
"board": brett, "players": spieler, "history": hist, "options": {"seed": seed, "include_probs": false}});
if phm() {
@@ -339,7 +351,7 @@ impl Kontext {
for b in format!("{loch:?}{start:?}{sb}").bytes() {
f = (f ^ b as u64).wrapping_mul(0x100000001b3);
}
basis["options"]["track_seed"] = json!(f >> 1);
basis["options"]["track_seed"] = json!(saat32(f));
}
let rake_knoten = q["street"] == "PREFLOP" && rake_knoten_von(hs, erh_vor, &frei);
Some(Kontext { basis, hist, brett, zuege, flop_fremd, rake_knoten, flop_cbet })
@@ -758,7 +770,7 @@ fn such_basis(k: &Kontext) -> Value {
for x in b.to_string().bytes() {
f = (f ^ x as u64).wrapping_mul(0x100000001b3);
}
b["options"]["seed"] = json!(f >> 1);
b["options"]["seed"] = json!(saat32(f));
b
}
@@ -1048,3 +1060,30 @@ fn opfer_zug_innen(z: &Zustand, me: &Menue, h: &[Value], hand: (u8, u8), brett:
});
Some((v, false))
}
#[cfg(test)]
mod saat_spec {
use super::saat32;
#[test]
fn saat32_bleibt_in_32_bit_und_ist_fest() {
for x in [0u64, 1, 3_399_975_668_225_400_732, u64::MAX, 1 << 63, 0xFFFF_FFFF] {
assert!(saat32(x) <= u32::MAX as u64);
assert_eq!(saat32(x), saat32(x));
}
}
#[test]
fn saat32_mischt_alle_bits() {
// benachbarte Saaten und Saaten, die sich nur in den oberen 32 Bit unterscheiden, geben verschiedene, weit gestreute Werte
let a = saat32(3_399_975_668_225_400_732);
assert_ne!(a, saat32(3_399_975_668_225_400_733));
assert_ne!(saat32(5), saat32(5 | (1 << 40)));
let mut summe = 0u64;
for i in 0..1000u64 {
summe += saat32(i << 32) >> 31; // oberes Bit des Ergebnisses
}
assert!((400..600).contains(&summe), "oberes Bit nicht gleichverteilt: {summe}");
}
}
+1 -1
View File
@@ -426,7 +426,7 @@ pub fn such_anfrage(q: &Value) -> Option<Value> {
let karten = |v: &Value| v.as_array().into_iter().flatten().filter_map(crate::sharingan::karte_pub).collect::<Vec<String>>();
let brett: Vec<String> = ["FLOP", "TURN", "RIVER"].iter().flat_map(|s| karten(&q["board"][*s])).collect();
Some(json!({"small_blind": blinds.0.max(1), "big_blind": blinds.1.max(1), "button_seat": knopf, "hero_seat": pos(held)?, "hole_cards": karten(&q["heroCards"]),
"board": brett, "players": spieler, "history": hist, "options": {"seed": q["seed"].as_u64().unwrap_or(1), "include_probs": false},
"board": brett, "players": spieler, "history": hist, "options": {"seed": crate::sharingan::saat32(q["seed"].as_u64().unwrap_or(1)), "include_probs": false},
"icm": {"dead": tot, "seats": kurven}}))
}