- lesen/profil.py mit_zaehlung: HUD-Raten bleiben, hands = max(bisher, gezaehlt), Aggression und Strassen-Reads aus der Zaehlung; kein Populations-Prior. - Schalter GEGNER_ZAEHLUNG=1 (runner -> spot_from_log.ZAEHLUNG), GEGNER_SHOWDOWN=1 dazu fuer riverBluffShare/-Shown; beide aus, live bitgleich. - zaehler: riverBluffShown aus game.reveal_cards + ganzem Board (Luft = Equity < 0,4). - Kern: decode_villain liest riverBluffShare/-Shown; sim::memory WireRead (LESEN_DRAHT) fuer die Leiter, engine_lbr LBR_PROFIL. - messung_zaehlung/replay.py: 1345 echte Zuege, live -> gezaehlt 3 anders (0,2 %), Stil-Read anders in 238/516 Nach-Flop-Spots. Leiter + LBR eingereiht, ausstehend. - STAND §10 + PLAN D1b. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
215 lines
9.8 KiB
Python
215 lines
9.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Spezifikation des Gegnerprofils - geschrieben VOR dem Code.
|
|
|
|
Der Client liefert Gegnerstatistiken je Nutzerkennung, und die Sitzliste führt
|
|
Sitz, Name und Kennung zusammen. Daraus entsteht ein Profil je Sitz.
|
|
|
|
Geprüft wird: Werte werden auf 0..1 normiert, fehlende Felder fliegen raus,
|
|
spätere Angaben schlagen frühere, fremde Kennungen tauchen nicht auf.
|
|
|
|
python3 tests/profil_spec.py -v
|
|
"""
|
|
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)
|
|
for _u in ("lesen",):
|
|
_q = os.path.join(_w, _u)
|
|
if os.path.isdir(_q):
|
|
sys.path.append(_q)
|
|
|
|
import profil
|
|
|
|
|
|
def esc(text):
|
|
"""Wie im Client-Log: innere Anführungszeichen sind maskiert."""
|
|
return text.replace('"', '\\"')
|
|
|
|
|
|
SITZE = esc('"seatResponseDataList":['
|
|
'{"seatId":2,"userName":"SneS77","userId":1662615,"userChips":9.8},'
|
|
'{"seatId":4,"userName":"Chicago111","userId":1701711,"userChips":10.6},'
|
|
'{"seatId":5,"userName":"mmintel","userId":1671088,"userChips":9.0}]')
|
|
|
|
KOMPLETT = esc('"api":"hud_stats","data":{"msg":{'
|
|
'"1662615":{"1":{"fold":73,"fta":65,"vpip":29,"pfr":20,"threeBet":9}},'
|
|
'"1701711":{"1":{"fold":76,"fta":62,"vpip":26,"pfr":15}},'
|
|
'"999999":{"1":{"fold":50,"fta":40,"vpip":11,"pfr":3}}}}')
|
|
|
|
OHNE_FTA = esc('"api":"hud_stats","data":{"msg":{"1701711":{"1":{"fold":76,"vpip":26,"pfr":15}}}}')
|
|
|
|
KAPUTT = esc('"api":"hud_stats","data":{"msg":{"1701711":{"1":{"mkdir":1,"vpip":120,"pfr":-5}}}}')
|
|
|
|
# Der Client liefert je Gegner rund dreizehn Zahlen; bis Phase E nutzte der Kern nur vpip/pfr/fta.
|
|
# Diese Vorlage trägt die volle HUD-Zeile, damit die bisher brachen Felder geprüft sind.
|
|
HUD_VOLL = esc('"api":"hud_stats","data":{"msg":{"1662615":{"1":{'
|
|
'"vpip":29,"pfr":20,"fta":65,"fold":73,'
|
|
'"cbet":58,"foldToCbet":34,"threeBet":9,"foldToThreeBet":62,'
|
|
'"steal":41,"checkRaise":7,"wtsd":28,"wsd":54}}}}')
|
|
|
|
|
|
class Werte(unittest.TestCase):
|
|
def test_prozent_wird_zu_anteil(self):
|
|
s = profil.statistiken(SITZE + KOMPLETT)
|
|
self.assertAlmostEqual(s["1662615"]["vpip"], 0.29, places=4)
|
|
self.assertAlmostEqual(s["1662615"]["pfr"], 0.20, places=4)
|
|
|
|
def test_foldtobet_aus_dem_feld_fuer_druck(self):
|
|
s = profil.statistiken(SITZE + KOMPLETT)
|
|
self.assertAlmostEqual(s["1662615"]["foldToBet"], 0.65, places=4)
|
|
|
|
def test_ohne_druck_feld_zaehlt_das_gesamte_folden(self):
|
|
s = profil.statistiken(SITZE + OHNE_FTA)
|
|
self.assertAlmostEqual(s["1701711"]["foldToBet"], 0.76, places=4)
|
|
|
|
def test_werte_bleiben_zwischen_null_und_eins(self):
|
|
s = profil.statistiken(KAPUTT)
|
|
self.assertLessEqual(s["1701711"]["vpip"], 1.0)
|
|
self.assertGreaterEqual(s["1701711"]["pfr"], 0.0)
|
|
|
|
def test_unbekannte_felder_stoeren_nicht(self):
|
|
s = profil.statistiken(KAPUTT)
|
|
self.assertIn("vpip", s["1701711"])
|
|
|
|
def test_leerer_text_ergibt_leere_abbildung(self):
|
|
self.assertEqual(profil.statistiken(""), {})
|
|
|
|
|
|
class HudFelder(unittest.TestCase):
|
|
"""Phase E: die schon abgerufenen, bisher brachen HUD-Felder landen im Profil je Sitz."""
|
|
|
|
NEU = ("cbet", "foldToCbet", "threeBet", "foldToThreeBet", "steal", "checkRaise", "wtsd", "wsd")
|
|
ERWARTET = {"cbet": 0.58, "foldToCbet": 0.34, "threeBet": 0.09, "foldToThreeBet": 0.62,
|
|
"steal": 0.41, "checkRaise": 0.07, "wtsd": 0.28, "wsd": 0.54}
|
|
|
|
def test_alle_neuen_felder_als_anteil(self):
|
|
s = profil.statistiken(HUD_VOLL)["1662615"]
|
|
for feld, wert in self.ERWARTET.items():
|
|
self.assertAlmostEqual(s[feld], wert, places=4, msg=feld)
|
|
|
|
def test_vpip_pfr_foldtobet_bleiben_erhalten(self):
|
|
s = profil.statistiken(HUD_VOLL)["1662615"]
|
|
self.assertAlmostEqual(s["vpip"], 0.29, places=4)
|
|
self.assertAlmostEqual(s["pfr"], 0.20, places=4)
|
|
self.assertAlmostEqual(s["foldToBet"], 0.65, places=4)
|
|
|
|
def test_fehlende_neue_felder_fliegen_raus(self):
|
|
s = profil.statistiken(OHNE_FTA)["1701711"]
|
|
for feld in self.NEU:
|
|
self.assertNotIn(feld, s)
|
|
|
|
def test_felder_haengen_am_sitz_und_an_der_sitzliste(self):
|
|
werte = profil.statistiken(HUD_VOLL)
|
|
liste = [{"seatId": 2, "userName": "SneS77", "userId": 1662615}]
|
|
p = profil.aus_sitzliste(liste, werte)
|
|
self.assertAlmostEqual(p[2]["foldToCbet"], 0.34, places=4)
|
|
self.assertAlmostEqual(p[2]["threeBet"], 0.09, places=4)
|
|
|
|
|
|
class Sitze(unittest.TestCase):
|
|
def test_profil_haengt_am_sitz(self):
|
|
p = profil.profile_je_sitz(SITZE + KOMPLETT)
|
|
self.assertEqual(sorted(p), [2, 4])
|
|
self.assertAlmostEqual(p[2]["vpip"], 0.29, places=4)
|
|
|
|
def test_sitz_ohne_statistik_fehlt(self):
|
|
p = profil.profile_je_sitz(SITZE + OHNE_FTA)
|
|
self.assertNotIn(2, p)
|
|
self.assertIn(4, p)
|
|
|
|
def test_ohne_sitzliste_leer(self):
|
|
self.assertEqual(profil.profile_je_sitz(KOMPLETT), {})
|
|
|
|
|
|
class Reihenfolge(unittest.TestCase):
|
|
def test_spaetere_angabe_schlaegt_fruehere(self):
|
|
alt = esc('"api":"hud_stats","data":{"msg":{"1701711":{"1":{"vpip":10,"pfr":5}}}}')
|
|
neu = esc('"api":"hud_stats","data":{"msg":{"1701711":{"1":{"vpip":40,"pfr":30}}}}')
|
|
s = profil.statistiken(alt + " ... " + neu)
|
|
self.assertAlmostEqual(s["1701711"]["vpip"], 0.40, places=4)
|
|
|
|
|
|
class AusSitzliste(unittest.TestCase):
|
|
""" 30.10. (main.6): zwei Tische, an beiden ein Platz 2 - einmal du, einmal Thoughtknox.
|
|
Ein Profil je Sitz für das ganze Log gab beiden dieselben Werte. Das Profil kommt aus der
|
|
Sitzliste des Raums (lesen/spot_from_log.py ruft es je Bohne)."""
|
|
|
|
def test_platz_nach_der_sitzliste_des_raums(self):
|
|
werte = profil.statistiken(KOMPLETT)
|
|
a = [{"seatId": 2, "userName": "SneS77", "userId": 1662615}]
|
|
b = [{"seatId": 2, "userName": "Chicago111", "userId": 1701711}, {"seatId": 3, "userId": 5}]
|
|
self.assertAlmostEqual(profil.aus_sitzliste(a, werte)[2]["vpip"], 0.29, places=4)
|
|
self.assertAlmostEqual(profil.aus_sitzliste(b, werte)[2]["vpip"], 0.26, places=4)
|
|
self.assertNotIn(3, profil.aus_sitzliste(b, werte)) # ohne Statistik kein Profil
|
|
self.assertEqual(profil.aus_sitzliste(None, werte), {})
|
|
|
|
|
|
class MitZaehlung(unittest.TestCase):
|
|
"""14.11.: live trug jedes Profil `hands` ~23 (geraten) und eine Aggression aus ~2 Zuegen; die
|
|
Vertrauensrampen des Kerns blieben am ungelesenen Standard (7 von 2060 Entscheidungen hingen am
|
|
Profil). Die gezaehlten Reads (lesen/zaehler.py) bringen die echte Stichprobe."""
|
|
|
|
HUD = {"vpip": 0.30, "pfr": 0.18, "foldToBet": 0.60, "cbet": 0.5, "hands": 23,
|
|
"aggression": 1.0, "aggressionActions": 2}
|
|
ZAEHLUNG = {"vpip": [180, 50], "pfr": [180, 30], "aggression": [90, 27],
|
|
"turnAggression": [20, 4], "riverFoldToBet": [12, 7], "flopFoldToBet": [30, 15],
|
|
"turnFoldToBet": [10, 5]}
|
|
|
|
def test_hud_raten_bleiben_stichprobe_wird_echt(self):
|
|
p = profil.mit_zaehlung(self.HUD, self.ZAEHLUNG)
|
|
self.assertEqual(p["vpip"], 0.30) # HUD zaehlt unsere Haende mit: Rate bleibt
|
|
self.assertEqual(p["foldToBet"], 0.60)
|
|
self.assertEqual(p["hands"], 180) # gezaehlte Haende = Untergrenze der HUD-Stichprobe
|
|
self.assertAlmostEqual(p["aggression"], 0.30) # 27 von 90 statt 2 von 2
|
|
self.assertEqual(p["aggressionActions"], 90)
|
|
self.assertAlmostEqual(p["turnAggression"], 0.20)
|
|
self.assertEqual(p["turnAggressionActions"], 20)
|
|
self.assertAlmostEqual(p["riverFoldToBet"], 7 / 12)
|
|
self.assertEqual(p["riverFacingBet"], 12)
|
|
self.assertEqual(self.HUD["hands"], 23) # das alte Profil bleibt unveraendert
|
|
|
|
def test_duenne_zaehlung_ersetzt_keine_dickere_sitzung(self):
|
|
p = profil.mit_zaehlung({"vpip": 0.3, "hands": 40, "aggression": 0.5, "aggressionActions": 8},
|
|
{"vpip": [10, 3], "aggression": [5, 1]})
|
|
self.assertEqual(p["hands"], 40)
|
|
self.assertEqual(p["aggression"], 0.5)
|
|
self.assertEqual(p["aggressionActions"], 8)
|
|
|
|
def test_ohne_hud_aus_der_zaehlung_allein(self):
|
|
p = profil.mit_zaehlung(None, self.ZAEHLUNG)
|
|
self.assertAlmostEqual(p["vpip"], 50 / 180)
|
|
self.assertAlmostEqual(p["pfr"], 30 / 180)
|
|
self.assertAlmostEqual(p["foldToBet"], 27 / 52) # alle Strassen gepoolt
|
|
self.assertEqual(p["hands"], 180)
|
|
|
|
def test_kein_prior_fuer_fehlende_reads(self):
|
|
p = profil.mit_zaehlung({"vpip": 0.3, "hands": 20}, {"vpip": [50, 15]})
|
|
self.assertNotIn("aggression", p)
|
|
self.assertNotIn("foldToBet", p)
|
|
self.assertEqual(profil.mit_zaehlung(None, {}), {})
|
|
|
|
def test_je_sitz_ueber_die_kennung(self):
|
|
profile = {2: dict(self.HUD), 4: {"vpip": 0.2, "hands": 20}}
|
|
neu = profil.profile_mit_zaehlung(profile, {2: "111", 4: "222", 5: None},
|
|
{"111": self.ZAEHLUNG, "_gezaehlt": ["1"]})
|
|
self.assertEqual(neu[2]["hands"], 180)
|
|
self.assertEqual(neu[4], {"vpip": 0.2, "hands": 20}) # ohne Zaehlung unveraendert
|
|
self.assertEqual(profile[2]["hands"], 23)
|
|
self.assertEqual(profil.profile_mit_zaehlung(profile, {}, None), profile)
|
|
|
|
def test_showdown_nur_mit_schalter(self):
|
|
z = dict(self.ZAEHLUNG, riverBluffShown=[8, 2])
|
|
self.assertNotIn("riverBluffShare", profil.mit_zaehlung(self.HUD, z))
|
|
p = profil.mit_zaehlung(self.HUD, z, showdown=True)
|
|
self.assertAlmostEqual(p["riverBluffShare"], 0.25)
|
|
self.assertEqual(p["riverBluffShown"], 8)
|
|
neu = profil.profile_mit_zaehlung({2: dict(self.HUD)}, {2: "111"}, {"111": z}, showdown=True)
|
|
self.assertEqual(neu[2]["riverBluffShown"], 8)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(verbosity=2)
|