Files
pokerfreak/score/klassen.py
T

55 lines
1.9 KiB
Python

"""Pure classification of a recorded decision (the motor request `q`) into the strata of the spot set.
Stratum = street x pot type x decision kind, all read from the request alone:
street FLOP | TURN | RIVER
potart limp (no preflop raise) | srp | 3bet | 4bet+ (raises made preflop, blinds excluded)
art eroeffnen (nothing to call) | gegen_einsatz (one bet or raise on the street, hero faces it) | gegen_raise (two or more)
Heads-up only: exactly one villain has not folded.
"""
STREETS = ("FLOP", "TURN", "RIVER")
POTARTEN = ("limp", "srp", "3bet", "4bet+")
ARTEN = ("eroeffnen", "gegen_einsatz", "gegen_raise")
AGGRESSIVE = ("BET", "RAISE", "ALL_IN")
EPS = 1e-9
def _aggressions(history, street):
"""Number of bets/raises on `street` (an all-in counts only if it raises the highest amount so far)."""
highest, n = 0.0, 0
for h in history:
if h.get("street", "PREFLOP") != street:
continue
amount = h.get("amount") or 0.0
if h["action"] in ("POST_SB", "POST_BB"):
highest = max(highest, amount)
elif h["action"] in AGGRESSIVE:
if h["action"] != "ALL_IN" or amount > highest + EPS:
n += 1
highest = max(highest, amount)
elif h["action"] == "CALL":
highest = max(highest, amount)
return n
def potart(history):
n = _aggressions(history, "PREFLOP")
return POTARTEN[min(n, 3)]
def art(q):
if q["toCall"] <= EPS:
return "eroeffnen"
return "gegen_einsatz" if _aggressions(q["history"], q["street"]) <= 1 else "gegen_raise"
def heads_up(q):
return sum(1 for v in q["villains"] if not v["folded"]) == 1
def stratum(q):
"""`street|potart|art`, or None if the decision is not a postflop heads-up decision."""
if q.get("street") not in STREETS or not heads_up(q):
return None
return f"{q['street']}|{potart(q['history'])}|{art(q)}"