Die Welt soll nichts verraten. Woerter, die ein Gegenueber implizieren (echt vs. unecht, live, Mensch), sind aus Prosa, Kommentaren und Docstrings raus; Namen (mensch_ruhe_s, echte_chops) und der Altwert "echt" im Spielplan bleiben. Nur Kommentare und Docstrings angefasst, damit keine Einrueckung faellt.
148 lines
6.4 KiB
Python
148 lines
6.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Stichprobe je Gegner (plans/2026-10-30_gegner.md): `hands` im Profil für den Kern.
|
|
|
|
Der Client nennt keine Handzahl. Also:
|
|
* rohwerte: alle 13 Werte je Kennung als Anteil (für die Anzeige).
|
|
* stichproben: Grundwert je Kennung - 20, wenn die Werte glaubhaft sind; 3, wenn mindestens drei
|
|
der 13 Werte genau 0 oder 100 sind (so sieht eine Handvoll Hände aus).
|
|
* aus_sitzliste mit `basis` und `gesehen`: hands = Grundwert + eigene gesehene Hände der Kennung.
|
|
Ohne die beiden wie bisher (kein `hands`).
|
|
* spot_from_log zählt die Hände je Kennung mit (Sitzliste, isPlaying) und schickt `hands`.
|
|
|
|
python3 tests/gegner_spec.py -v
|
|
"""
|
|
import json
|
|
import os
|
|
import sys
|
|
import unittest
|
|
|
|
_w = os.path.dirname(os.path.abspath(__file__))
|
|
while _w != "/" and not os.path.isdir(os.path.join(_w, "lesen")):
|
|
_w = os.path.dirname(_w)
|
|
sys.path.insert(0, os.path.join(_w, "lesen"))
|
|
|
|
import profil
|
|
|
|
|
|
def esc(text):
|
|
return text.replace('"', '\\"')
|
|
|
|
|
|
HUD = esc('"api":"hud_stats","data":{"msg":{'
|
|
'"1524700":{"1":{"allin":7,"fold":45,"fta":65,"vpip":53,"pfr":20,"wtsd":50,"wsd":48,"steal":64,'
|
|
'"checkRaise":6,"threeBet":6,"foldToThreeBet":27,"cbet":50,"foldToCbet":39}},'
|
|
'"1890064":{"1":{"allin":0,"fold":0,"fta":0,"vpip":75,"pfr":0,"wtsd":25,"wsd":100,"steal":0,'
|
|
'"checkRaise":0,"threeBet":0,"foldToThreeBet":0,"cbet":0,"foldToCbet":0}}}}')
|
|
LISTE = [{"seatId": 2, "userName": "a", "userId": 1524700, "isPlaying": True},
|
|
{"seatId": 4, "userName": "b", "userId": 1890064, "isPlaying": True}]
|
|
|
|
|
|
class Rohwerte(unittest.TestCase):
|
|
def test_alle_dreizehn_als_anteil(self):
|
|
r = profil.rohwerte(HUD)["1524700"]
|
|
self.assertEqual(len(r), 13)
|
|
self.assertAlmostEqual(r["foldToCbet"], 0.39)
|
|
self.assertAlmostEqual(r["threeBet"], 0.06)
|
|
|
|
|
|
class Stichprobe(unittest.TestCase):
|
|
def test_glaubhaft_und_duenn(self):
|
|
s = profil.stichproben(HUD)
|
|
self.assertEqual(s["1524700"], profil.GLAUBHAFT)
|
|
self.assertEqual(s["1890064"], profil.DUENN)
|
|
|
|
def test_hands_aus_grundwert_und_eigenen_haenden(self):
|
|
werte = profil.statistiken(HUD)
|
|
p = profil.aus_sitzliste(LISTE, werte, basis=profil.stichproben(HUD),
|
|
gesehen={"1524700": {"h1", "h2", "h3"}})
|
|
self.assertEqual(p[2]["hands"], profil.GLAUBHAFT + 3)
|
|
self.assertEqual(p[4]["hands"], profil.DUENN)
|
|
self.assertAlmostEqual(p[2]["vpip"], 0.53)
|
|
|
|
def test_ohne_zaehlung_wie_bisher(self):
|
|
p = profil.aus_sitzliste(LISTE, profil.statistiken(HUD))
|
|
self.assertNotIn("hands", p[2])
|
|
|
|
def test_werte_der_statistik_bleiben_unberuehrt(self):
|
|
werte = profil.statistiken(HUD)
|
|
profil.aus_sitzliste(LISTE, werte, basis=profil.stichproben(HUD), gesehen={})
|
|
self.assertNotIn("hands", werte["1524700"])
|
|
|
|
|
|
class ImLog(unittest.TestCase):
|
|
"""spot_from_log zählt mit: drei Hände mit dem Gegner im Log -> hands = Grundwert + 3."""
|
|
|
|
def test_anfrage_traegt_hands(self):
|
|
import spot_from_log as S
|
|
zaehlung = {}
|
|
S.haende_zaehlen(zaehlung, {"gameHandId": "h1", "seatResponseDataList": LISTE})
|
|
S.haende_zaehlen(zaehlung, {"gameHandId": "h1", "seatResponseDataList": LISTE}) # dieselbe Hand
|
|
S.haende_zaehlen(zaehlung, {"gameHandId": "h2", "seatResponseDataList": LISTE})
|
|
aus = [dict(LISTE[0]), dict(LISTE[1], isPlaying=False)]
|
|
S.haende_zaehlen(zaehlung, {"gameHandId": "h3", "seatResponseDataList": aus})
|
|
self.assertEqual(len(zaehlung["1524700"]), 3)
|
|
self.assertEqual(len(zaehlung["1890064"]), 2)
|
|
|
|
|
|
sys.path.insert(0, os.path.join(_w, "sicht"))
|
|
|
|
|
|
class Einschaetzung(unittest.TestCase):
|
|
"""sicht/gegner.py: was der Kern über einen Gegner sagt (Antwortfeld `reads`), für Bediener."""
|
|
|
|
def test_station_mit_satz_und_vertrauen(self):
|
|
import gegner
|
|
e = gegner.einschaetzung({"seat": 2, "style": "callingStation", "foldChance": 0.18, "trust": 0.85})
|
|
self.assertEqual(e["stil"], "callingStation")
|
|
self.assertEqual(e["stil_text"], "Calling Station")
|
|
self.assertIn("bluffe nicht", e["satz"])
|
|
self.assertEqual(e["vertrauen"], 0.85)
|
|
self.assertEqual(e["vertrauen_text"], "belastbar")
|
|
self.assertEqual(e["fold_chance"], 0.18)
|
|
|
|
def test_vertrauen_stufen(self):
|
|
import gegner
|
|
self.assertEqual(gegner.vertrauen_text(0.1), "dünn")
|
|
self.assertEqual(gegner.vertrauen_text(0.45), "mittel")
|
|
self.assertEqual(gegner.vertrauen_text(0.6), "belastbar")
|
|
|
|
def test_unbekannter_stil_sagt_es(self):
|
|
import gegner
|
|
e = gegner.einschaetzung({"seat": 2, "style": "erfunden", "foldChance": 0.4, "trust": 0.5})
|
|
self.assertEqual(e["stil_text"], "unbekannt")
|
|
|
|
def test_reads_je_sitz_des_tisches(self):
|
|
"""Die Anfrage nummeriert die Sitze um (`_sitze` {neu: alt}) - zurück auf den Tischsitz."""
|
|
import gegner
|
|
schatten = [{"raum": "T", "anfrage": {"_sitze": {"2": 5, "1": 3}},
|
|
"antwort": {"reads": [{"seat": 2, "style": "nit", "foldChance": 0.7, "trust": 0.4}]}},
|
|
{"raum": "U", "anfrage": {"_sitze": {"2": 5}},
|
|
"antwort": {"reads": [{"seat": 2, "style": "regular", "foldChance": 0.45, "trust": 0.4}]}}]
|
|
r = gegner.reads_je_sitz(schatten, "T")
|
|
self.assertEqual(list(r), [5])
|
|
self.assertEqual(r[5]["stil"], "nit")
|
|
|
|
def test_neuere_entscheidung_gewinnt(self):
|
|
import gegner
|
|
alt = {"raum": "T", "anfrage": {"_sitze": {"2": 5}},
|
|
"antwort": {"reads": [{"seat": 2, "style": "nit", "foldChance": 0.7, "trust": 0.2}]}}
|
|
neu = {"raum": "T", "anfrage": {"_sitze": {"2": 5}},
|
|
"antwort": {"reads": [{"seat": 2, "style": "regular", "foldChance": 0.45, "trust": 0.6}]}}
|
|
self.assertEqual(gegner.reads_je_sitz([alt, neu], "T")[5]["stil"], "regular")
|
|
|
|
|
|
class UrteilInDerAnsicht(unittest.TestCase):
|
|
def test_tisch_traegt_sein_urteil(self):
|
|
import ansicht
|
|
import spot_from_log as S
|
|
t = S.Tisch("T")
|
|
t.namen = {1: "mmintel", 2: "a", 4: "b"}
|
|
t.profile = {2: {"vpip": 0.6, "hands": 400}, 4: {"vpip": 0.2, "hands": 400}, 1: {"vpip": 0.1, "hands": 400}}
|
|
v = ansicht._tisch_ansicht(t, 1)
|
|
self.assertEqual(v["urteil"]["urteil"], "weich")
|
|
self.assertEqual(v["urteil"]["bekannt"], 2) # wir selbst zählen nicht
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|