Welt ohne fremden Namen: Pruefordner vollstaendig mitkopieren, Engine nur im eigenen Baum
Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
This commit is contained in:
Generated
+1
-1
@@ -3,5 +3,5 @@
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "pokerfreak"
|
||||
name = "rechner"
|
||||
version = "0.1.0"
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "pokerfreak"
|
||||
name = "rechner"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
description = "Pure, functional poker decision core. JSON lines in, JSON lines out."
|
||||
|
||||
@@ -30,8 +30,8 @@ Chrome an und bleibt gruen. Bei sechs roten Kettenspezifikationen mit `Lobby gel
|
||||
|
||||
## Die Cockpit-App traegt ihren Repo-Pfad in der Info.plist (31.10.)
|
||||
|
||||
`mac/Sources/Cockpit/Orte.swift` liest die Wurzel in dieser Reihenfolge: `POKERFREAK_SHELL`,
|
||||
**`Bundle.main` Schluessel `PokerfreakShell`** (beim Bauen eingetragen), sonst der Quellbaum aus
|
||||
`mac/Sources/Cockpit/Orte.swift` liest die Wurzel in dieser Reihenfolge: `SHELL`,
|
||||
**`Bundle.main` Schluessel `Quellbaum`** (beim Bauen eingetragen), sonst der Quellbaum aus
|
||||
`#filePath`. Die installierte App hat also den Pfad **gebrannt**, der beim Bauen galt.
|
||||
|
||||
Wurde das Repo danach umbenannt oder verschoben, laeuft der von der App gestartete Server ins
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ def protokoll_text(pfad):
|
||||
|
||||
|
||||
SEITE = """<!doctype html>
|
||||
<html lang="de"><head><meta charset="utf-8"><title>Pokerfreak Buehne</title>
|
||||
<html lang="de"><head><meta charset="utf-8"><title>Buehne</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style>
|
||||
:root{color-scheme:dark;--bg:#101418;--fg:#e8edf2;--dim:#8a96a3;--ak:#4fd18b;--rot:#ef6b6b;--rand:#27303a}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"""Invarianten: Regeln, die ab dem ersten Eintrag des Schattenlogs und durchgehend gelten.
|
||||
|
||||
Der Läufer (betrieb/runner.py) gibt jeden Eintrag, den er schreibt, an einen `Pruefer`; im
|
||||
strengen Betrieb (Standard, POKERFREAK_INVARIANTEN=melden schaltet auf nur melden) bricht die
|
||||
strengen Betrieb (Standard, INVARIANTEN=melden schaltet auf nur melden) bricht die
|
||||
erste Verletzung den Lauf ab (`Invariantenbruch`). Dieselbe Prüfung läuft im Chaos-Lauf von
|
||||
aussen über die Datei (`datei_pruefen`). Spezifikation: tests/invarianten_spec.py.
|
||||
|
||||
|
||||
+23
-23
@@ -39,7 +39,7 @@ Wiederaufnahme: beim Start liest er, wo wir schon sitzen und welche Stellen geme
|
||||
|
||||
Ergebnis (lesen/ergebnis.py): jede fertige eigene Hand steht einmal im Schattenlog (gewonnen/
|
||||
verloren, Betrag, Showdown) und in der Statistik (betrieb/statistik.py, archiv// oder
|
||||
POKERFREAK_STATS_DIR) samt Sitzungen und Sitouts; STATS.md schreibt er beim Beenden neu.
|
||||
STATS_DIR) samt Sitzungen und Sitouts; STATS.md schreibt er beim Beenden neu.
|
||||
|
||||
Ein aktiver Raum (betrieb/tischzustand.py): welcher Raum aktiv ist, ob ein Dialog offen ist und
|
||||
was wir am Tisch geöffnet haben (+, Find Seat, Nachkauf, Warteliste, Claim), hält EINE
|
||||
@@ -50,7 +50,7 @@ er nicht, solange wir sitzen - welches unseres ist, wäre geraten (Vorfall Fenst
|
||||
|
||||
Invarianten (betrieb/invarianten.py): jeder Eintrag des Schattenlogs geht durch den Prüfer; die
|
||||
erste Verletzung bricht den Lauf ab (Ereignis "abbruch", kein Klick mehr, Rückgabe 2) -
|
||||
POKERFREAK_INVARIANTEN=melden meldet nur. Höchstens ein Läufer (betrieb/sperre.py): Sperrdatei mit
|
||||
INVARIANTEN=melden meldet nur. Höchstens ein Läufer (betrieb/sperre.py): Sperrdatei mit
|
||||
PID, ein zweiter startet nicht (Rückgabe 3), die Sperre eines toten übernimmt er.
|
||||
|
||||
Logrotation (electron-log: main.log -> main.old.log): ist das Log kürzer als das Lesefenster,
|
||||
@@ -60,7 +60,7 @@ Geld (lesen/geld.py): Kaufhöhe je Modus (coinType), Tischzahl nach der Fünftel
|
||||
Guthaben aus reserve_Seat (minus eigener Käufe), Nachkauf gegen dasselbe Guthaben. Aufstehen
|
||||
(Sitout, Kreuz) unter 20 BB ohne Nachkauf, am Verlustdeckel je Tisch und je Sitzung
|
||||
(geld.stopp_grund - nach dem Sitzungsdeckel setzt er sich nicht mehr) und, eingeschaltet mit
|
||||
POKERFREAK_RATHOLING=1, nach grossem Gewinn. Zwei Fenster auf denselben Raum: das zweite schliesst.
|
||||
RATHOLING=1, nach grossem Gewinn. Zwei Fenster auf denselben Raum: das zweite schliesst.
|
||||
"""
|
||||
import os as _os, sys as _sys
|
||||
_w = _os.path.dirname(_os.path.abspath(__file__))
|
||||
@@ -117,24 +117,24 @@ import zeitplan
|
||||
|
||||
BASE = os.path.dirname(os.path.abspath(__file__))
|
||||
LOG = umgebung.log() # CLIENT=1: Log des Klons, siehe client/umgebung.py
|
||||
SCRATCH = os.environ.get("POKERFREAK_SCRATCH") or os.path.join(BASE, "scratch") # Kette/Chaos: eigener Ordner
|
||||
SCRATCH = os.environ.get("SCRATCH") or os.path.join(BASE, "scratch") # Kette/Chaos: eigener Ordner
|
||||
SHADOW = os.path.join(SCRATCH, "shadow.jsonl")
|
||||
ZUSTAND = os.path.join(SCRATCH, "zustand.json") # Wiederaufnahme nach Absturz
|
||||
SPIELPLAN = os.path.join(SCRATCH, "spielplan.json") # Übung oder Cash und Tischzahl - setzt das Cockpit (betrieb/spielplan.py)
|
||||
# Du hast Maus/Tastatur benutzt: das Cockpit (mac/) legt die Datei an - nur bei Eingaben, nie
|
||||
# bei Klicks eines Programms (macOS nennt den Absender). Du hast Vorrang, der Läufer wartet.
|
||||
# Deine Eingaben meldet das Cockpit. Kette/Chaos (POKERFREAK_SCRATCH) haben ihren eigenen Ordner -
|
||||
# Deine Eingaben meldet das Cockpit. Kette/Chaos (SCRATCH) haben ihren eigenen Ordner -
|
||||
# sonst pausierte deine Maus am Mac den Klon-Läufer (30.10., chaos-1)
|
||||
EINGRIFF = (os.path.join(os.environ["POKERFREAK_SCRATCH"], "eingriff") if os.environ.get("POKERFREAK_SCRATCH")
|
||||
EINGRIFF = (os.path.join(os.environ["SCRATCH"], "eingriff") if os.environ.get("SCRATCH")
|
||||
else os.path.join(umgebung.treffpunkt(), "eingriff")) # Naht: das Cockpit liest das
|
||||
EINGRIFF_PAUSE = 4.0 # Sekunden nach deiner letzten Eingabe, bis der Läufer wieder setzt
|
||||
SPERRE = os.environ.get("POKERFREAK_SPERRE") or os.path.join(SCRATCH, "laeufer.pid")
|
||||
SPERRE = os.environ.get("SPERRE") or os.path.join(SCRATCH, "laeufer.pid")
|
||||
ROTATION_BYTES = 20_000_000
|
||||
ZURUECK_VERSUCHE = 3 # so oft "zurück" nach Sitout, dann geht er
|
||||
# In der PAUSE sitzen bleiben (nur aussetzen): ein Bediener steht fuer eine Zigarettenpause nicht
|
||||
# jedes Mal auf, und jedes Aufstehen/NeuSetzen ist ein Klickweg mehr, der schiefgehen kann.
|
||||
# POKERFREAK_PAUSE_RAEUMT=1 raeumt auch in der Pause (wie frueher).
|
||||
PAUSE_RAEUMT = _os.environ.get("POKERFREAK_PAUSE_RAEUMT", "0") == "1"
|
||||
# PAUSE_RAEUMT=1 raeumt auch in der Pause (wie frueher).
|
||||
PAUSE_RAEUMT = _os.environ.get("PAUSE_RAEUMT", "0") == "1"
|
||||
|
||||
AUSLAUF_FRIST = 120.0 # Sekunden: so lange spielt er nach dem Sitout die laufende Hand zu Ende
|
||||
ERGEBNIS_TAKT = 3.0 # Sekunden: so oft liest er fertige Hände nach
|
||||
@@ -193,7 +193,7 @@ def schreiben(eintrag):
|
||||
_rotieren()
|
||||
with open(SHADOW, "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps(eintrag, ensure_ascii=False) + "\n")
|
||||
strom.mitschreiben(eintrag, SHADOW) # Ereignisstrom der Buehne: schluckt jeden Fehler, aus mit POKERFREAK_STROM=0
|
||||
strom.mitschreiben(eintrag, SHADOW) # Ereignisstrom der Buehne: schluckt jeden Fehler, aus mit STROM=0
|
||||
if PRUEFER is not None:
|
||||
for v in PRUEFER.pruefen(eintrag) if not PRUEFER.streng else ():
|
||||
print(f"{time.strftime('%H:%M:%S')} INVARIANTE {v.regel}: {v.text}")
|
||||
@@ -211,7 +211,7 @@ def ereignis(art, **daten):
|
||||
grund=daten.get("grund") or art)
|
||||
|
||||
|
||||
ZEIGER = None # hand/zeiger.Lauf, wenn POKERFREAK_ZEIGER=1 (Klon ohne Mac)
|
||||
ZEIGER = None # hand/zeiger.Lauf, wenn ZEIGER=1 (Klon ohne Mac)
|
||||
WACHE = dialog.Wache() # offene Dialoge je Raum (Profil: bad_beat_counter im Log)
|
||||
NOCH_ZEIT = 1.5 # Sekunden: so viel Uhr muss für einen zweiten Klick noch übrig sein
|
||||
KLICK_PUFFER = 3.0 # Sekunden: Fenster prüfen, Dialog schliessen, Mausweg, Beleg - nach der Denkzeit
|
||||
@@ -385,7 +385,7 @@ def zeiger_pflegen(raum=None):
|
||||
"""Startet den Zeiger-Lauf auf der Tischseite, sobald es eine gibt. Ohne Wirkung auf den
|
||||
Spielweg: jeder Fehler bleibt hier, der Lauf ist ein eigener Faden."""
|
||||
global ZEIGER
|
||||
if os.environ.get("POKERFREAK_ZEIGER") != "1":
|
||||
if os.environ.get("ZEIGER") != "1":
|
||||
return _zeiger_mac()
|
||||
if ZEIGER is not None:
|
||||
return
|
||||
@@ -399,7 +399,7 @@ def zeiger_pflegen(raum=None):
|
||||
return
|
||||
schirm = klonmaus.Bildschirm() # ein Zeiger über allen Tischfenstern
|
||||
ZEIGER = zeiger.Lauf(schirm.bewegen, schirm.position, schirm.grenzen, stellen=regie.STELLEN,
|
||||
spur=os.environ.get("POKERFREAK_ZEIGER_SPUR"),
|
||||
spur=os.environ.get("ZEIGER_SPUR"),
|
||||
stelle_zu=schirm.stelle, zum_schirm=schirm.schirm,
|
||||
meiden=schirm.schilder).starten()
|
||||
print(f"{time.strftime('%H:%M:%S')} ZEIGER lebt über {len(schirm.liste)} Fenster(n), "
|
||||
@@ -412,7 +412,7 @@ def _zeiger_mac():
|
||||
"""Am Mac: der lebende Zeiger nach dem Schalter im Spielplan (spielplan.zeiger_lebt) - an,
|
||||
sobald eingeschaltet und ein Tisch offen; aus, sobald ausgeschaltet."""
|
||||
global ZEIGER
|
||||
if fenster.klon(): # Klon: dort lebt der Zeiger nur mit POKERFREAK_ZEIGER=1
|
||||
if fenster.klon(): # Klon: dort lebt der Zeiger nur mit ZEIGER=1
|
||||
return
|
||||
soll = spielplan.zeiger_lebt(spielplan.lesen(SPIELPLAN)) and not act.gestoppt()
|
||||
if ZEIGER is not None and not soll:
|
||||
@@ -640,8 +640,8 @@ RUHEZEIT_GEMELDET = False
|
||||
|
||||
# Die Wahl aus der API (lesen/raumliste.py) statt aus der Lobby: die Lobby verliert ihre Liste
|
||||
# gern, die Quelle tut das nicht. Die REGELN der Wahl bleiben dieselben (lobby/auswahl.py).
|
||||
# POKERFREAK_AUSWAHL_AUS_API=0 schaltet es ab - dann waehlt wieder die Lobby.
|
||||
AUSWAHL_AUS_API = _os.environ.get("POKERFREAK_AUSWAHL_AUS_API", "1") != "0"
|
||||
# AUSWAHL_AUS_API=0 schaltet es ab - dann waehlt wieder die Lobby.
|
||||
AUSWAHL_AUS_API = _os.environ.get("AUSWAHL_AUS_API", "1") != "0"
|
||||
|
||||
|
||||
_RAUMLISTE = {"stand": 0.0, "ids": set()}
|
||||
@@ -941,8 +941,8 @@ class Sitzer:
|
||||
self.phase = None # Zeitplan (betrieb/zeitplan.py): Spielen | Pause | Ausserhalb | Fertig
|
||||
self.abbau = {} # Raum -> Zeit des Sitout beim Abbauen (Pause, Fenster zu, fertig)
|
||||
self.find_seat = {} # voller Raum -> (Zeit, aktive Räume davor): nach Find Seat schliessen
|
||||
self.zufall = random.Random(os.environ.get("POKERFREAK_SEED")) # Seeds für den Zeitplan
|
||||
self.rathole = os.environ.get("POKERFREAK_RATHOLING") == "1" or geld.RATHOLING
|
||||
self.zufall = random.Random(os.environ.get("SEED")) # Seeds für den Zeitplan
|
||||
self.rathole = os.environ.get("RATHOLING") == "1" or geld.RATHOLING
|
||||
self.auslauf = None # beim Beenden: {"bis", "grund"} - Sitout geklickt, Hand läuft aus
|
||||
self.ausgesetzt = set() # Räume, in denen wir beim Beenden Sitout geklickt haben
|
||||
self.gesichert = None # zuletzt gesicherter Stand (Merkzettel nur bei Änderung schreiben)
|
||||
@@ -1700,14 +1700,14 @@ def live(klicken=False):
|
||||
def _live(klicken, vorgaenger):
|
||||
global PRUEFER, MASCHINE
|
||||
print("beobachte am Tisch" + (" und klicke" if klicken else " (Schatten)") + " ...")
|
||||
profil = denkzeit.profil() # POKERFREAK_TEMPO: normal (Vorgabe), schnell, blitz
|
||||
# POKERFREAK_SEED macht die Gedenkzeiten nachrechenbar (Kettentest), sonst Zufall
|
||||
zufall = random.Random(os.environ.get("POKERFREAK_SEED"))
|
||||
profil = denkzeit.profil() # TEMPO: normal (Vorgabe), schnell, blitz
|
||||
# SEED macht die Gedenkzeiten nachrechenbar (Kettentest), sonst Zufall
|
||||
zufall = random.Random(os.environ.get("SEED"))
|
||||
print(f"Denkzeit-Profil: Median {profil['median_ms']:.0f} ms, "
|
||||
f"Untergrenze {profil['min_ms']:.0f} ms")
|
||||
global BUCH
|
||||
BUCH = statistik.Statistik()
|
||||
PRUEFER = invarianten.Pruefer(streng=os.environ.get("POKERFREAK_INVARIANTEN", "streng") != "melden")
|
||||
PRUEFER = invarianten.Pruefer(streng=os.environ.get("INVARIANTEN", "streng") != "melden")
|
||||
sitzer = Sitzer(klicken)
|
||||
MASCHINE = sitzer.maschine
|
||||
stopp_beim_start = act.gestoppt()
|
||||
@@ -1719,7 +1719,7 @@ def _live(klicken, vorgaenger):
|
||||
signal.signal(getattr(signal, name), _signal)
|
||||
kreis = {}
|
||||
try:
|
||||
ereignis("start", klicken=bool(klicken), seed=os.environ.get("POKERFREAK_SEED"),
|
||||
ereignis("start", klicken=bool(klicken), seed=os.environ.get("SEED"),
|
||||
**({"uebernommen_von": vorgaenger} if vorgaenger else {}))
|
||||
konto_melden() # erst nach "start": die Invarianten kennen den neuen Läufer sonst nicht
|
||||
grund = _kreislauf(klicken, profil, zufall, sitzer, stopp_beim_start, kreis)
|
||||
|
||||
@@ -5,7 +5,7 @@ Reine Rechnung oben (`rate`, `bb_pro_100`, `kennzahlen_aus`), darunter der Speic
|
||||
Spezifikation: tests/statistik_spec.py. Die Haende kommen aus lesen/ergebnis.py (aus den Logzeilen); der Laeufer ruft `Statistik.aufnehmen(logtext)` bzw. `ereignis(...)`.
|
||||
|
||||
from statistik import Statistik, rate, bb_pro_100
|
||||
st = Statistik() # archiv// (oder POKERFREAK_STATS_DIR)
|
||||
st = Statistik() # archiv// (oder STATS_DIR)
|
||||
st.aufnehmen(logtext) # fertige eigene Haende, doppelt = nur einmal
|
||||
st.ereignis("sitzung_start", raum="Big Ben 1664572")
|
||||
st.ereignis("auszeit", raum=..., grund="timeout", dauer=300)
|
||||
@@ -36,7 +36,7 @@ import os
|
||||
import ergebnis
|
||||
|
||||
STANDARD = os.path.join(WURZEL, "archiv", "lauf")
|
||||
UMGEBUNG = "POKERFREAK_STATS_DIR"
|
||||
UMGEBUNG = "STATS_DIR"
|
||||
AUSZEIT_ARTEN = ("auszeit", "sitout")
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@ Ereignisarten (`art`):
|
||||
zeiger Zeigerzustand (Eintrag mit Feld "zeiger"; folgt mit hand/zeiger.py)
|
||||
sonstiges alles andere, mit den Feldnamen als Text
|
||||
|
||||
Abschalten: Umgebungsvariable POKERFREAK_STROM=0.
|
||||
Abschalten: Umgebungsvariable STROM=0.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
@@ -28,7 +28,7 @@ import re
|
||||
import threading
|
||||
import time
|
||||
|
||||
UMGEBUNG = "POKERFREAK_STROM"
|
||||
UMGEBUNG = "STROM"
|
||||
DATEI = "strom.jsonl"
|
||||
ROTATION_BYTES = 20_000_000
|
||||
PRUEFTAKT = 100 # so viele Anhaenge zwischen zwei Groessenpruefungen
|
||||
@@ -349,7 +349,7 @@ def strom_pfad(schatten_pfad):
|
||||
|
||||
def mitschreiben(eintrag, schatten_pfad):
|
||||
"""Die eine Zeile in runner.schreiben: Schatteneintrag -> Strom neben dem Schattenlog.
|
||||
Ohne Wirkung auf den Spielweg: schluckt jede Ausnahme, abschaltbar mit POKERFREAK_STROM=0."""
|
||||
Ohne Wirkung auf den Spielweg: schluckt jede Ausnahme, abschaltbar mit STROM=0."""
|
||||
try:
|
||||
if not eingeschaltet():
|
||||
return
|
||||
|
||||
@@ -24,7 +24,7 @@ import spot_from_log
|
||||
import umgebung
|
||||
import zuschauer
|
||||
|
||||
SCRATCH = os.environ.get("POKERFREAK_SCRATCH") or os.path.join(BASE, "scratch")
|
||||
SCRATCH = os.environ.get("SCRATCH") or os.path.join(BASE, "scratch")
|
||||
ZIEL = os.path.join(SCRATCH, "zuschauer.jsonl")
|
||||
PID = os.path.join(SCRATCH, "zuschauer.pid") # die Zuschauersteuerung liest sie: auch ein Lauf aus dem Terminal zählt
|
||||
TAIL = 400_000
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import os
|
||||
import socket
|
||||
import struct
|
||||
|
||||
TMP = os.environ.get("POKERFREAK_PIPE_TMP") or "/tmp" # Klon und Spec koennen woanders horchen
|
||||
TMP = os.environ.get("PIPE_TMP") or "/tmp" # Klon und Spec koennen woanders horchen
|
||||
LOBBY = "lobby-pipe"
|
||||
FRIST_S = 1.5
|
||||
|
||||
|
||||
+4
-6
@@ -22,7 +22,7 @@ STREFFPUNKT_DATEIEN = ("shadow.jsonl", "strom.jsonl", "spielplan.json", "ausweic
|
||||
def treffpunkt():
|
||||
"""Wo Welt und Engine sich treffen. Vorgabe: betrieb/scratch - und ohne betrieb/ das eigene
|
||||
scratch/ (so heisst es dort, wo es keinen betrieb-Ordner gibt)."""
|
||||
ausdruecklich = os.environ.get("POKERFREAK_SCRATCH")
|
||||
ausdruecklich = os.environ.get("SCRATCH")
|
||||
if ausdruecklich:
|
||||
return ausdruecklich
|
||||
if os.path.isdir(os.path.join(_WURZEL, "betrieb")):
|
||||
@@ -37,13 +37,11 @@ KLON_LOG = os.path.join(tempfile.gettempdir(), "coinpoker-klon.log")
|
||||
|
||||
|
||||
def engine():
|
||||
"""Das Kommando der Engine: ausdruecklich (POKERFREAK_ENGINE), sonst dieser Baum, sonst der Nachbar."""
|
||||
ausdruecklich = os.environ.get("POKERFREAK_ENGINE")
|
||||
"""Das Kommando der Engine: ausdruecklich (ENGINE), sonst hier im Baum."""
|
||||
ausdruecklich = os.environ.get("ENGINE")
|
||||
if ausdruecklich:
|
||||
return ausdruecklich
|
||||
eigen = os.path.join(_WURZEL, "betrieb", "runner.py")
|
||||
nachbar = os.path.join(os.path.dirname(_WURZEL), "pokerfreak", "betrieb", "runner.py")
|
||||
ziel = eigen if os.path.exists(eigen) else nachbar
|
||||
ziel = os.path.join(_WURZEL, "betrieb", "runner.py")
|
||||
return f"{os.environ.get('PYTHON', 'python3')} {ziel}"
|
||||
|
||||
|
||||
|
||||
+22
-25
@@ -1,36 +1,33 @@
|
||||
# Schnittstelle: wie die Welt eine Engine andockt
|
||||
# Schnittstelle: wie App und Engine zusammenhaengen
|
||||
|
||||
`pokersim` ist die Welt: ein **Klon** des Clients (mit Log, Debug-Port, zwei `/tmp`-Sockets und den
|
||||
Fenstertiteln des Clients) und die **Cockpit-App**. Die **Engine** (`pokerfreak`: Rechner, Leser,
|
||||
Hand, Lauf) dockt an. Beide koennen getrennt stehen: die Welt laeuft ohne Engine (die App hat einen
|
||||
eigenen Zustand "nichts laeuft"), die Engine laeuft ohne App.
|
||||
Dieser Baum ist der **Klon** des Clients (Log, Debug-Port, zwei `/tmp`-Sockets und die
|
||||
Fenstertitel des Clients), die **Cockpit-App** (`mac/`) - und die **Engine**: `hand/` klickt und
|
||||
tippt, `betrieb/` fuehrt den Lauf, `src/` rechnet, `lesen/` liest mit. Beide Seiten koennen
|
||||
getrennt stehen: die App laeuft ohne Engine (sie hat einen eigenen Zustand "nichts laeuft"), die
|
||||
Engine laeuft ohne App.
|
||||
|
||||
Eingefroren durch `tests/schnittstelle_spec.py`. Wer eine der fuenf Beruehrungen aendert, aendert
|
||||
zuerst diese Datei und den Fall.
|
||||
|
||||
## Die fuenf Beruehrungen (mehr kreuzt nicht)
|
||||
|
||||
1. **Die Adresse des Clients.** Die Welt stellt einen Client hin: Log, Chrome-Debug-Port, je Tisch
|
||||
ein Unix-Socket `<tmp>/<Raumname>` und `<tmp>/lobby-pipe`, Tischfenster heissen `CoinPoker`.
|
||||
Uebersteuerbar: `COINPOKER_LOG`, `CDP_PORT`, `POKERFREAK_PIPE_TMP`.
|
||||
Vorgabe der Engine ist **die Welt** (`CLIENT` leer = Klon); `CLIENT=0` zeigt auf
|
||||
den Client daneben.
|
||||
2. **Der Treffpunkt.** Ein Verzeichnis, `POKERFREAK_SCRATCH` (Vorgabe: `betrieb/scratch`). Hier
|
||||
treffen sich beide Seiten; ausserhalb kreuzt kein Pfad.
|
||||
3. **Der Protokollstand** darin - die Engine schreibt, die Welt liest:
|
||||
1. **Die Adresse.** Der Klon traegt sie: Logpfad, Chrome-Debug-Port, je Tisch ein Unix-Socket
|
||||
`<tmp>/<Raumname>` und `<tmp>/lobby-pipe`, Tischfenster heissen `CoinPoker`. Uebersteuerbar:
|
||||
`COINPOKER_LOG`, `CDP_PORT`, `PIPE_TMP`.
|
||||
2. **Der Treffpunkt.** Ein Verzeichnis, `TREFFPUNKT` (Vorgabe: `betrieb/scratch`). Hier treffen
|
||||
sich beide Seiten; ausserhalb kreuzt kein Pfad.
|
||||
3. **Der Protokollstand** darin - die Engine schreibt, die App liest:
|
||||
`shadow.jsonl` (Entscheidungen, Setzen, Ereignisse, Ergebnisse) und `strom.jsonl` (Ereignisstrom).
|
||||
4. **Die Steuerdateien** darin - beide lesen und schreiben:
|
||||
`spielplan.json` (die Welt setzt ihn, die Engine liest ihn), `ausweichen` und `cockpit.json`
|
||||
(der Vertrag mit dem Panel: die Engine legt `ausweichen` an, das Panel tritt zur Seite),
|
||||
`stop` (Not-Aus), `eigene_taste` (die Leiste ignoriert dann ESC).
|
||||
5. **Ein Befehl.** Die Welt startet und stoppt die Engine ueber `POKERFREAK_ENGINE` (eine
|
||||
Kommandozeile; Vorgabe: `python3 <wurzel>/betrieb/runner.py`). Gestartet wird mit `--act`
|
||||
(klicken) und mit gesetztem `POKERFREAK_SCRATCH`; gestoppt wird an ihre Prozessgruppe.
|
||||
4. **Die Steuerdateien** darin - beide lesen und schreiben: `spielplan.json` (die App setzt ihn,
|
||||
die Engine liest ihn), `ausweichen` und `cockpit.json` (der Vertrag mit dem Panel), `stop`
|
||||
(Not-Aus), `eigene_taste`.
|
||||
5. **Ein Befehl.** Die App startet und stoppt die Engine ueber `ENGINE` (eine Kommandozeile;
|
||||
Vorgabe: `python3 <wurzel>/betrieb/runner.py`), gestartet mit `--act` und gesetztem `TREFFPUNKT`.
|
||||
|
||||
## Regeln
|
||||
|
||||
* Die Welt **importiert** die Engine nicht, die Engine importiert die Welt nicht. Geteilt wird nur,
|
||||
was die Sprache des Clients ist (das Log lesen, die Adresse kennen).
|
||||
* Die Welt ist die Vorgabe. Wer den Client daneben will, sagt es ausdruecklich.
|
||||
* Nichts in der Engine kennt einen Namen aus der App, nichts in der App einen Namen aus der Engine -
|
||||
nur die fuenf Beruehrungen oben.
|
||||
* Die App **importiert** die Engine nicht, die Engine die App nicht. Geteilt wird nur, was die
|
||||
Sprache des Clients ist (das Log lesen, die Adresse kennen).
|
||||
* Vorgabe ist der Klon. Wer den Client meint, sagt es ausdruecklich (`CLIENT=0`).
|
||||
* Nichts in der App kennt einen Namen aus der Engine, nichts in der Engine einen Namen aus der App
|
||||
- nur die fuenf Beruehrungen oben.
|
||||
|
||||
@@ -390,7 +390,7 @@ Die Bubble callt nie eine Hand, die Cash foldet. Öffnen und Shoven verschiebt d
|
||||
- Verlustdeckel: 100 BB je Tisch, 250 BB je Sitzung.
|
||||
- Die Stakes-Leiter steigt bei 2× Bezug auf und bei 0,5× ab, höchstens um eine Stufe.
|
||||
- Beim Beenden setzt die Hülle erst aus (Sitout), dann steht sie auf. Ergebnis und Statistik werden je Hand gebucht.
|
||||
- Ratholing (`POKERFREAK_RATHOLING=1`) ist aus. Über 280 NL-Folgen des Bestands senkt es den mittleren Stack am Tisch von 235,9 auf 114,4 BB und löst 490-mal aus. Ein Netto-Effekt lässt sich aus dem Bestand nicht beziffern: Gewinne sind nicht gedeckelt, und die Gegnerstacks sind unbekannt.
|
||||
- Ratholing (`RATHOLING=1`) ist aus. Über 280 NL-Folgen des Bestands senkt es den mittleren Stack am Tisch von 235,9 auf 114,4 BB und löst 490-mal aus. Ein Netto-Effekt lässt sich aus dem Bestand nicht beziffern: Gewinne sind nicht gedeckelt, und die Gegnerstacks sind unbekannt.
|
||||
- Im Turnier gelten keine Cash-Geldregeln.
|
||||
|
||||
**Lücken:**
|
||||
|
||||
@@ -26,7 +26,7 @@ cargo build --release
|
||||
```
|
||||
|
||||
```bash
|
||||
./target/release/pokerfreak < anfragen.jsonl
|
||||
./target/release/rechner < anfragen.jsonl
|
||||
```
|
||||
|
||||
Das Programm liest bis zum Ende von stdin. Leere Zeilen werden übersprungen. Auf stdout steht nichts außer den Antwortzeilen. Eine Entscheidung dauert im Release-Build rund 20 ms.
|
||||
@@ -116,7 +116,7 @@ Hier steckt **kein Spielverstand**. Der liegt im Rust-Kern (`src/`) und wird
|
||||
allein über zwei Dinge berührt:
|
||||
|
||||
* den **Vertrag** – Kopie in `docs/VERTRAG.md`, eingefroren
|
||||
* das gebaute Programm, standardmässig `target/release/pokerfreak`,
|
||||
* das gebaute Programm, standardmässig `target/release/rechner`,
|
||||
überschreibbar über `COINPOKER_KERN` (Quellordner: `COINPOKER_KERN_QUELLE`)
|
||||
|
||||
Der Kern bleibt rein: keine Abhängigkeiten, keine Clientkenntnis, kein Zeitgefühl. Beide liegen im selben Repo,
|
||||
@@ -156,7 +156,7 @@ touch scratch/stop # Not-Aus fürs Klicken
|
||||
Fensters; namenlose Fenster werden an Räume gebunden), ob ein Dialog offen ist, was wir am Tisch
|
||||
geöffnet haben - reine Funktion `schritt(zustand, ereignis)`, der Läufer führt nur aus.
|
||||
* **Invarianten** (`betrieb/invarianten.py`): jeder Eintrag des Schattenlogs geht durch den Prüfer,
|
||||
die erste Verletzung bricht den Läufer ab (Rückgabe 2; `POKERFREAK_INVARIANTEN=melden` nur melden).
|
||||
die erste Verletzung bricht den Läufer ab (Rückgabe 2; `INVARIANTEN=melden` nur melden).
|
||||
`python3 betrieb/invarianten.py <shadow.jsonl>` zählt von aussen.
|
||||
* **Ein Läufer** (`betrieb/sperre.py`): Sperrdatei mit PID, ein zweiter startet nicht (Rückgabe 3).
|
||||
* **Treue-Katalog** (`archiv/mitschrieb/KATALOG.md`): je gesehenem Phänomen ein Klon-Hebel und
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Schickt Anfragen an den Entscheidungskern (pokerfreak) und liest Antworten.
|
||||
"""Schickt Anfragen an den Entscheidungskern (Rust, src/) und liest Antworten.
|
||||
|
||||
from decide import entscheide
|
||||
"""
|
||||
@@ -18,7 +18,7 @@ import sys
|
||||
import subprocess
|
||||
|
||||
BASE = os.path.dirname(os.path.abspath(__file__))
|
||||
BINARY = os.environ.get("COINPOKER_KERN", os.path.join(BASE, "..", "target", "release", "pokerfreak"))
|
||||
BINARY = os.environ.get("COINPOKER_KERN", os.path.join(BASE, "..", "target", "release", "rechner"))
|
||||
QUELLE = os.environ.get("COINPOKER_KERN_QUELLE", os.path.join(BASE, ".."))
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ def entscheide(anfragen, timeout=30):
|
||||
r = subprocess.run([BINARY], input="\n".join(anfragen) + "\n",
|
||||
capture_output=True, text=True, timeout=timeout)
|
||||
if r.returncode != 0:
|
||||
raise RuntimeError(f"pokerfreak scheiterte: {r.stderr.strip()[:300]}")
|
||||
raise RuntimeError(f"der Kern scheiterte: {r.stderr.strip()[:300]}")
|
||||
antworten = []
|
||||
for zeile in r.stdout.strip().split("\n"):
|
||||
if not zeile.strip():
|
||||
|
||||
+1
-1
@@ -110,7 +110,7 @@ FOKUS_ZURUECK = click.FOKUS_ZURUECK # Vorgabe an (hand/click.py)
|
||||
def _klicken(px, py, f, halb, rng=None):
|
||||
"""Ein Klick mit der Maus, und der Zeiger (hand/zeiger.py) ruht so lange - ohne Lauf ohne Wirkung.
|
||||
|
||||
Mit POKERFREAK_FOKUS_ZURUECK=1 holt er danach die vorher vordere App zurueck: der Client reisst
|
||||
Mit FOKUS_ZURUECK=1 holt er danach die vorher vordere App zurueck: der Client reisst
|
||||
sein Fenster bei jeder Aktivierung nach vorn (window, gemessen 20x in 20 s), sonst bleibt
|
||||
es nach unserem Klick vorn und man arbeitet in einem anderen Fenster weiter.
|
||||
"""
|
||||
|
||||
+5
-5
@@ -112,13 +112,13 @@ def nach_vorn(fenster):
|
||||
|
||||
# Nach jedem Anheben die vorher vordere App zurueckholen. Der Client reisst sein Fenster bei
|
||||
# JEDER Aktivierung hoch (20x in 20 s) - ohne Rueckholen arbeitet man dauerhaft in ihm.
|
||||
# POKERFREAK_FOKUS_ZURUECK=0 schaltet es ab.
|
||||
FOKUS_ZURUECK = _os.environ.get("POKERFREAK_FOKUS_ZURUECK", "1") != "0"
|
||||
# FOKUS_ZURUECK=0 schaltet es ab.
|
||||
FOKUS_ZURUECK = _os.environ.get("FOKUS_ZURUECK", "1") != "0"
|
||||
|
||||
# Klick an den Prozess statt global: kein Vordergrund noetig, kein Hochreissen des Fensters.
|
||||
# Am Unity-Tisch wirkt das (gemessen); Chrome (Klon) nimmt es nicht an - dort bleibt es global.
|
||||
# POKERFREAK_KLICK_AN_PID=0 schaltet es ab.
|
||||
AN_PID = _os.environ.get("POKERFREAK_KLICK_AN_PID", "1") != "0"
|
||||
# KLICK_AN_PID=0 schaltet es ab.
|
||||
AN_PID = _os.environ.get("KLICK_AN_PID", "1") != "0"
|
||||
|
||||
|
||||
def klickweg(fenster, an_pid=None):
|
||||
@@ -194,7 +194,7 @@ def _merken(ziel_pid):
|
||||
|
||||
|
||||
def nach_vorn_app(pid):
|
||||
"""Eine fremde App wieder nach vorn holen (nach unserem Klick, siehe POKERFREAK_FOKUS_ZURUECK)."""
|
||||
"""Eine fremde App wieder nach vorn holen (nach unserem Klick, siehe FOKUS_ZURUECK)."""
|
||||
if not pid:
|
||||
return
|
||||
try:
|
||||
|
||||
+3
-3
@@ -48,7 +48,7 @@ MENSCH = {"min_ms": 1200.0, "median_ms": 2600.0, "spread_ms": 3000.0,
|
||||
|
||||
# Tempo ist eine Wahl, kein Zwang. Gegner spielen im Median 3 s - bei einem Tisch die gute
|
||||
# Mischung, bei vielen zu langsam (12 Tische brauchen eine Aktion alle zwei Sekunden).
|
||||
# POKERFREAK_TEMPO: normal (Vorgabe, wie Gegner), schnell, blitz. Die Streuung bleibt, damit
|
||||
# TEMPO: normal (Vorgabe, wie Gegner), schnell, blitz. Die Streuung bleibt, damit
|
||||
# die Zeiten nicht takten.
|
||||
TEMPO = {"normal": MENSCH,
|
||||
"schnell": {"min_ms": 700.0, "median_ms": 1400.0, "spread_ms": 1200.0,
|
||||
@@ -58,8 +58,8 @@ TEMPO = {"normal": MENSCH,
|
||||
|
||||
|
||||
def profil(tempo=None):
|
||||
"""Profil zur Tempo-Wahl (POKERFREAK_TEMPO, Vorgabe normal). Unbekanntes fuehrt zur Vorgabe."""
|
||||
name = (tempo or os.environ.get("POKERFREAK_TEMPO") or "normal").strip().lower()
|
||||
"""Profil zur Tempo-Wahl (TEMPO, Vorgabe normal). Unbekanntes fuehrt zur Vorgabe."""
|
||||
name = (tempo or os.environ.get("TEMPO") or "normal").strip().lower()
|
||||
return dict(TEMPO.get(name, MENSCH))
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -253,7 +253,7 @@ def bild_lesen(pfad, breite=LESEBREITE):
|
||||
"""PNG-Datei gelesen, vorher auf `breite` verkleinert (macOS sips); ohne sips in voller Größe."""
|
||||
if sys.platform == "darwin":
|
||||
import subprocess
|
||||
klein = os.path.join(tempfile.gettempdir(), f"pokerfreak-klein-{os.getpid()}.png")
|
||||
klein = os.path.join(tempfile.gettempdir(), f"cockpit-klein-{os.getpid()}.png")
|
||||
try:
|
||||
r = subprocess.run(["sips", "-Z", str(breite), pfad, "--out", klein],
|
||||
capture_output=True, timeout=10)
|
||||
@@ -277,7 +277,7 @@ def aufnahme(f, raum=None):
|
||||
if sys.platform != "darwin":
|
||||
return None
|
||||
import foto
|
||||
pfad = os.path.join(tempfile.gettempdir(), f"pokerfreak-dialog-{os.getpid()}.png")
|
||||
pfad = os.path.join(tempfile.gettempdir(), f"cockpit-dialog-{os.getpid()}.png")
|
||||
if not foto.foto(pfad, raum):
|
||||
return None
|
||||
return bild_lesen(pfad)
|
||||
|
||||
+2
-2
@@ -284,8 +284,8 @@ def vergessen():
|
||||
# So lange gilt eine gelesene Fensterliste. Wichtig nicht nur wegen der 2 s pro Abfrage: JEDE
|
||||
# System-Events-Abfrage holt den Client nach vorn (seine Window-Lib reisst das Fenster bei jeder
|
||||
# Aktivierung hoch). Die Sicht fragt im Sekundentakt - mit 0,5 s kam jeder Aufruf durch und der
|
||||
# Client stand permanent vorn (30.10.). Ueber POKERFREAK_FENSTER_FRIST einstellbar.
|
||||
FENSTER_FRIST_S = float(os.environ.get("POKERFREAK_FENSTER_FRIST") or 10.0)
|
||||
# Client stand permanent vorn (30.10.). Ueber FENSTER_FRIST einstellbar.
|
||||
FENSTER_FRIST_S = float(os.environ.get("FENSTER_FRIST") or 10.0)
|
||||
_liste = {"stand": 0.0, "da": None}
|
||||
|
||||
|
||||
|
||||
+6
-6
@@ -12,9 +12,9 @@ while _w != "/" and not os.path.isdir(os.path.join(_w, "lesen")):
|
||||
_w = os.path.dirname(_w)
|
||||
WURZEL = _w
|
||||
|
||||
# POKERFREAK_STOPP_ORDNER: eigener Ordner (tests/lauf.py) - Tests sehen den Not-Aus dieses Rechners
|
||||
# STOPP_ORDNER: eigener Ordner (tests/lauf.py) - Tests sehen den Not-Aus dieses Rechners
|
||||
# nicht und setzen oder löschen ihn nie.
|
||||
_ORDNER = os.environ.get("POKERFREAK_STOPP_ORDNER")
|
||||
_ORDNER = os.environ.get("STOPP_ORDNER")
|
||||
PFADE = [os.path.join(_ORDNER, "stop")] if _ORDNER else [
|
||||
os.path.join(WURZEL, "scratch", "stop"),
|
||||
os.path.join(WURZEL, "hand", "scratch", "stop"),
|
||||
@@ -30,10 +30,10 @@ def aktiv():
|
||||
# Der Tastenwaegter ist die Cockpit-App selbst (`Tasten`); nur sie faengt
|
||||
# ein ESC. Der Server daneben schreibt nur eine Instanz-Datei - die kann veralten, der
|
||||
# laufende Prozess nicht.
|
||||
COCKPIT = "Pokerfreak Cockpit.app/Contents/MacOS/Cockpit"
|
||||
COCKPIT = "Cockpit.app/Contents/MacOS/Cockpit"
|
||||
|
||||
ESC_HINWEIS = ("NOT-AUS TAUB: ESC wird nicht gefangen - das Cockpit laeuft nicht. "
|
||||
"Vor dem Klicken starten: die Cockpit-App (open .../Pokerfreak Cockpit.app)")
|
||||
"Vor dem Klicken starten: die Cockpit-App (open .../Cockpit.app)")
|
||||
|
||||
|
||||
def esc_waechter(prozesse=None):
|
||||
@@ -47,9 +47,9 @@ def esc_waechter(prozesse=None):
|
||||
return None
|
||||
|
||||
|
||||
# POKERFREAK_ESC_STRENG: ohne lebenden ESC-Waechter geht kein Klick raus. Vorgabe aus, damit ein
|
||||
# ESC_STRENG: ohne lebenden ESC-Waechter geht kein Klick raus. Vorgabe aus, damit ein
|
||||
# Start ohne Cockpit nicht stillschweigend nichts tut - streng eingeschaltet ist es der Riegel.
|
||||
STRENG = os.environ.get("POKERFREAK_ESC_STRENG", "") not in ("", "0")
|
||||
STRENG = os.environ.get("ESC_STRENG", "") not in ("", "0")
|
||||
|
||||
|
||||
def darf_klicken(prozesse=None):
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ PLUS = {1: (0.497, 0.787), 2: (0.107, 0.61), 3: (0.140, 0.235),
|
||||
# Nachkauf: ein Klick auf den eigenen Platz trifft den Avatar (30.10.: table_avatar_click, Profil
|
||||
# statt Dialog). Die Stelle ist nicht gemessen - bis dahin klickt er nicht. Im Klon gibt es den Knopf.
|
||||
NACHKAUF_GEMESSEN = (os.environ.get("CLIENT") != "1"
|
||||
or os.environ.get("POKERFREAK_NACHKAUF", "") not in ("", "0"))
|
||||
or os.environ.get("NACHKAUF", "") not in ("", "0"))
|
||||
ABGELEITET = frozenset() # 30.10.: am leeren Tisch 1678304 alle sechs beobachtet
|
||||
# (mock/vorlage/tisch-geometrie.md) - keine Ableitung mehr
|
||||
VERMESSEN_FUER = 6 # die Stellen gelten für den 6er-Tisch
|
||||
|
||||
+1
-1
@@ -160,7 +160,7 @@ def stakes_leiter(guthaben, bezug, stufe, stufen):
|
||||
return stufe, bezug
|
||||
|
||||
|
||||
RATHOLING = False # Vorgabe aus - einschalten mit POKERFREAK_RATHOLING=1
|
||||
RATHOLING = False # Vorgabe aus - einschalten mit RATHOLING=1
|
||||
RATHOLE_AB_MAX = 2.0 # Stack ab dem Doppelten der Obergrenze: Gewinn vom Tisch nehmen
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Tischurteil vor dem Setzen: weich, mittel oder hart - aus den Gegnerprofilen eines offenen Tisches.
|
||||
|
||||
Die Werte kommen, sobald der Tisch offen ist (hud_stats für jeden Spieler), also bevor der Laeufer
|
||||
Platz nimmt. Dünne Werte werden wie im Kern zur Grundgesamtheit gezogen (pokerfreak
|
||||
Platz nimmt. Dünne Werte werden wie im Kern zur Grundgesamtheit gezogen (
|
||||
src/exploit/sample.rs: w = hands / (hands + 30), vpip-Grundwert 0.28) - ein Gegner mit 70 % über
|
||||
zwei Hände macht keinen Tisch weich. Regeln und Grenzen: plans/2026-10-30_gegner.md,
|
||||
Spezifikation: tests/tischurteil_spec.py.
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ async function seite() {
|
||||
// Ein Klick, zwei Wege (hand/eingabe.py): im Klon die Ereignisse in der Seite; sonst mit der Maus
|
||||
// nur die Bildschirmlage des Knopfs ("MAUS {x, y, text}") - den
|
||||
// Klick macht Python. Alle Klicks dieser Datei und mcp/lobby_adapter.KLICK_ZEILE gehen hierüber.
|
||||
const MAUS = process.env.POKERFREAK_EINGABE === "maus";
|
||||
const MAUS = process.env.EINGABE === "maus";
|
||||
const VORSPANN = `window.__pfMaus = ${MAUS};
|
||||
window.__pfKlick = (ziel) => {
|
||||
// Was nicht im Bild steht, trifft kein Mausklick: der Reiterstreifen scrollt waagerecht
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import PackageDescription
|
||||
let cltFrameworks = "/Library/Developer/CommandLineTools/Library/Developer/Frameworks"
|
||||
|
||||
let package = Package(
|
||||
name: "PokerfreakCockpit",
|
||||
name: "Cockpit",
|
||||
defaultLocalization: "de",
|
||||
platforms: [.macOS(.v26)],
|
||||
targets: [
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
# Pokerfreak Cockpit für macOS
|
||||
# Cockpit für macOS
|
||||
|
||||
Native Oberfläche (SwiftUI/AppKit) über der Datenschicht in `sicht/`. Die App enthält keinen
|
||||
Spielverstand und liest keine Protokolle: Sie startet `python3 sicht/start.py` als
|
||||
@@ -13,7 +13,7 @@ Selbstheilen.
|
||||
**Ohne Xcode.** Gebaut wird nur mit den Command Line Tools:
|
||||
|
||||
```bash
|
||||
./mac/bauen.sh # baut mac/build/Pokerfreak Cockpit.app
|
||||
./mac/bauen.sh # baut mac/build/Cockpit.app
|
||||
./mac/bauen.sh --installieren # und legt sie nach ~/Applications
|
||||
./mac/bauen.sh --pruefen # vorher die Prüfungen des Kerns
|
||||
cd mac && swift run Pruefung # nur die Prüfungen
|
||||
@@ -102,8 +102,8 @@ App oder `sicht/start.py` im Terminal: Es läuft höchstens eines. Die Sperre h
|
||||
Server und Läufer, die die App startet, laufen unter ihrer Verantwortung. macOS fragt also die
|
||||
Freigaben der **App** ab, nicht die des Terminals:
|
||||
|
||||
* **Bedienungshilfen** für „Pokerfreak Cockpit“: Fenster lesen (`hand/fenster.py`), Klicken, ESC
|
||||
* **Automation → System Events** für „Pokerfreak Cockpit“
|
||||
* **Bedienungshilfen** für „Cockpit“: Fenster lesen (`hand/fenster.py`), Klicken, ESC
|
||||
* **Automation → System Events** für „Cockpit“
|
||||
|
||||
Fehlt eine davon, meldet die Fensterabfrage still **null Fenster**. Das Cockpit sagt dann
|
||||
„noch kein Tisch“, und ein Läufer von hier bricht mit `raum_ohne_fenster` ab (29.10. 20:09 und
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import CockpitKern
|
||||
import SwiftUI
|
||||
|
||||
/// Farbe und Kürzel eines Stils, wie der Kern ihn sieht (pokerfreak exploit/style.rs).
|
||||
/// Farbe und Kürzel eines Stils, wie der Kern ihn sieht (src/exploit/style.rs).
|
||||
enum GegnerStil {
|
||||
static func farbe(_ stil: String?) -> Color {
|
||||
switch stil {
|
||||
|
||||
@@ -3,18 +3,18 @@ import Foundation
|
||||
/// Wo die Huelle liegt und welche Dateien der Vertrag mit dem Laeufer sind
|
||||
/// (der Treffpunkt: betrieb/scratch, docs/SCHNITTSTELLE.md).
|
||||
enum Orte {
|
||||
/// Reihenfolge: POKERFREAK_SHELL, der beim Bauen eingetragene Pfad (Info.plist), sonst der
|
||||
/// Reihenfolge: SHELL, der beim Bauen eingetragene Pfad (Info.plist), sonst der
|
||||
/// Quellbaum, aus dem diese Datei kompiliert wurde (swift run).
|
||||
static let shell: URL = {
|
||||
if let p = ProcessInfo.processInfo.environment["POKERFREAK_SHELL"], !p.isEmpty {
|
||||
if let p = ProcessInfo.processInfo.environment["SHELL"], !p.isEmpty {
|
||||
return URL(filePath: p, directoryHint: .isDirectory)
|
||||
}
|
||||
if let p = Bundle.main.object(forInfoDictionaryKey: "PokerfreakShell") as? String, !p.isEmpty {
|
||||
if let p = Bundle.main.object(forInfoDictionaryKey: "Quellbaum") as? String, !p.isEmpty {
|
||||
return URL(filePath: p, directoryHint: .isDirectory)
|
||||
}
|
||||
return URL(filePath: #filePath).deletingLastPathComponent() // Sources/Cockpit
|
||||
.deletingLastPathComponent().deletingLastPathComponent() // mac
|
||||
.deletingLastPathComponent() // pokerfreak
|
||||
.deletingLastPathComponent() // der Quellbaum
|
||||
}()
|
||||
|
||||
// Der Treffpunkt: betrieb/scratch, und ohne betrieb/ das eigene scratch/ (dieselbe Regel wie in
|
||||
|
||||
@@ -255,10 +255,10 @@ struct FreigabeHinweis: View {
|
||||
let f = cockpit.freigabe
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
Label("Cockpit sieht keine Tische", systemImage: "eye.slash.fill").font(.callout.weight(.semibold))
|
||||
Text("macOS lässt „Pokerfreak Cockpit“ die Tischfenster nicht lesen. Ein Läufer von hier wäre blind - darum startet der Hauptknopf keinen.")
|
||||
Text("macOS lässt „Cockpit“ die Tischfenster nicht lesen. Ein Läufer von hier wäre blind - darum startet der Hauptknopf keinen.")
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
if !f.bedienungshilfen { Text("• Bedienungshilfen: „Pokerfreak Cockpit“ einschalten").font(.caption) }
|
||||
if f.systemEvents == .verboten { Text("• Automation: „System Events“ für „Pokerfreak Cockpit“ erlauben").font(.caption) }
|
||||
if !f.bedienungshilfen { Text("• Bedienungshilfen: „Cockpit“ einschalten").font(.caption) }
|
||||
if f.systemEvents == .verboten { Text("• Automation: „System Events“ für „Cockpit“ erlauben").font(.caption) }
|
||||
Button("Freigeben …") { Freigabe.erbitten(f) }
|
||||
.buttonStyle(.borderedProminent).tint(.red).controlSize(.small)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import AppKit
|
||||
import CockpitKern
|
||||
|
||||
/// Pokerfreak Cockpit: native Oberflaeche ueber der Datenschicht in sicht/ (Python).
|
||||
/// Cockpit: native Oberflaeche ueber der Datenschicht in sicht/ (Python).
|
||||
@MainActor
|
||||
final class App: NSObject, NSApplicationDelegate {
|
||||
private let cockpit = Cockpit()
|
||||
@@ -12,7 +12,7 @@ final class App: NSObject, NSApplicationDelegate {
|
||||
private let tasten = Tasten()
|
||||
private var signale: [DispatchSourceSignal] = []
|
||||
|
||||
private static let zeigenNachricht = Notification.Name("de.pokerfreak.cockpit.zeigen")
|
||||
private static let zeigenNachricht = Notification.Name("de.cockpit.zeigen")
|
||||
|
||||
/// Laeuft die App schon (gleiche Bundle-ID), zeigt die erste ihr Panel und diese geht.
|
||||
/// Ein Cockpit aus dem Terminal faengt die Sperre im Server ab (sicht/instanz.py).
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
#!/bin/zsh
|
||||
# Baut "Pokerfreak Cockpit.app" - ohne Xcode, nur mit den Command Line Tools.
|
||||
# Baut "Cockpit.app" - ohne Xcode, nur mit den Command Line Tools.
|
||||
#
|
||||
# ./mac/bauen.sh baut nach mac/build/
|
||||
# ./mac/bauen.sh --installieren und kopiert nach ~/Applications (dort ein fester Ort fuers Anmeldeobjekt)
|
||||
@@ -8,7 +8,7 @@ set -euo pipefail
|
||||
|
||||
HIER=${0:A:h}
|
||||
SHELL_PFAD=${HIER:h}
|
||||
NAME="Pokerfreak Cockpit"
|
||||
NAME="Cockpit"
|
||||
APP="$HIER/build/$NAME.app"
|
||||
cd "$HIER"
|
||||
|
||||
@@ -37,7 +37,7 @@ cat > "$APP/Contents/Info.plist" <<PLIST
|
||||
<dict>
|
||||
<key>CFBundleName</key><string>$NAME</string>
|
||||
<key>CFBundleDisplayName</key><string>$NAME</string>
|
||||
<key>CFBundleIdentifier</key><string>de.pokerfreak.cockpit</string>
|
||||
<key>CFBundleIdentifier</key><string>de.cockpit</string>
|
||||
<key>CFBundleExecutable</key><string>Cockpit</string>
|
||||
<key>CFBundleIconFile</key><string>Cockpit</string>
|
||||
<key>CFBundlePackageType</key><string>APPL</string>
|
||||
@@ -47,7 +47,7 @@ cat > "$APP/Contents/Info.plist" <<PLIST
|
||||
<key>LSMinimumSystemVersion</key><string>26.0</string>
|
||||
<key>LSUIElement</key><true/>
|
||||
<key>NSHighResolutionCapable</key><true/>
|
||||
<key>PokerfreakShell</key><string>$SHELL_PFAD</string>
|
||||
<key>Quellbaum</key><string>$SHELL_PFAD</string>
|
||||
<key>NSAppleEventsUsageDescription</key><string>Das Cockpit und der Läufer lesen über System Events, welche Tischfenster offen sind und wo sie liegen.</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -58,10 +58,10 @@ PLIST
|
||||
# braeuchte jede neue Fassung die Freigaben neu - und ohne Freigabe sieht das Cockpit keine Tische.
|
||||
SIGNATUR=${COCKPIT_SIGNATUR:-$(security find-identity -v -p codesigning | sed -n 's/.*"\(Developer ID Application: [^"]*\)".*/\1/p' | head -1)}
|
||||
if [[ -n "$SIGNATUR" ]]; then
|
||||
codesign --force --sign "$SIGNATUR" --identifier de.pokerfreak.cockpit "$APP"
|
||||
codesign --force --sign "$SIGNATUR" --identifier de.cockpit "$APP"
|
||||
echo "signiert: $SIGNATUR"
|
||||
else
|
||||
codesign --force --sign - --identifier de.pokerfreak.cockpit "$APP"
|
||||
codesign --force --sign - --identifier de.cockpit "$APP"
|
||||
echo "WARNUNG: nur ad-hoc signiert - nach jedem Neubau die Freigaben neu erteilen"
|
||||
fi
|
||||
|
||||
|
||||
@@ -151,10 +151,10 @@ KLICK_ZEILE = """(() => {
|
||||
def _eingabeart():
|
||||
"""Wie die Lobby geklickt wird: IN der Seite. Der Mausklick blieb dort still
|
||||
wirkungslos (31.10. bei Reiter UND Zeile: "geklickt" gemeldet, nichts passierte),
|
||||
waehrend ein Klick im DOM sofort wirkte. POKERFREAK_LOBBYMAUS=1 schaltet auf die Maus zurueck.
|
||||
waehrend ein Klick im DOM sofort wirkte. LOBBYMAUS=1 schaltet auf die Maus zurueck.
|
||||
Der Tisch (Unity) behaelt ohnehin die Maus - dort laeuft kein cdp."""
|
||||
import eingabe
|
||||
return "maus" if os.environ.get("POKERFREAK_LOBBYMAUS", "") not in ("", "0") else eingabe.OHNE
|
||||
return "maus" if os.environ.get("LOBBYMAUS", "") not in ("", "0") else eingabe.OHNE
|
||||
|
||||
|
||||
def cdp_ausfuehren(args):
|
||||
@@ -165,7 +165,7 @@ def cdp_ausfuehren(args):
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=8,
|
||||
env=dict(os.environ, POKERFREAK_EINGABE=_eingabeart()),
|
||||
env=dict(os.environ, EINGABE=_eingabeart()),
|
||||
)
|
||||
out = (r.stdout or "").strip()
|
||||
err = (r.stderr or "").strip()
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
"""MCP-Server für CoinPoker / pokerfreak.
|
||||
"""MCP-Server für CoinPoker: Tische, Sitze, Lauf.
|
||||
|
||||
Dünne Hülle um bestehende Module: spot_from_log, decide, denkzeit, act, fenster, korpus, cdp.mjs.
|
||||
Wirkende Werkzeuge (act) sind strikt von lesenden getrennt.
|
||||
@@ -426,7 +426,7 @@ def history(limit: int = 5) -> str:
|
||||
def stats() -> str:
|
||||
"""Kennzahlen der eigenen Haende (Haende, bb/100 je Stake und Spielart, VPIP/PFR, Showdown,
|
||||
Aktionsverteilung, Sitzungen, Auszeiten) als JSON aus dem Speicher (archiv// oder
|
||||
POKERFREAK_STATS_DIR). Leere Grundmengen stehen als null, nicht als 0."""
|
||||
STATS_DIR). Leere Grundmengen stehen als null, nicht als 0."""
|
||||
try:
|
||||
return mit_debug(json.dumps(statistik_modul.Statistik().kennzahlen(), ensure_ascii=False))
|
||||
except Exception as exc:
|
||||
|
||||
+1
-1
@@ -160,7 +160,7 @@ class Bruecke:
|
||||
"""Beide Kanaele des Klons. `auf_befehl(raum, cmd, daten)` fuehrt Serverbefehle aus."""
|
||||
|
||||
def __init__(self, tmp=None, schreibe=None, auf_befehl=None):
|
||||
self.tmp = tmp or os.environ.get("POKERFREAK_PIPE_TMP") or pipe.TMP
|
||||
self.tmp = tmp or os.environ.get("PIPE_TMP") or pipe.TMP
|
||||
self.schreibe = schreibe or (lambda *_: None)
|
||||
self.auf_befehl = auf_befehl or (lambda *_: None)
|
||||
self.wege = {} # pfad -> Kanal
|
||||
|
||||
@@ -107,7 +107,7 @@ Aus den Bildern gemessen, für den Fensterrahmen gerechnet:
|
||||
Token, VPN-Regel und Sitzungsschlüssel, Antworten in der Form des Bestands (`send_to_table`
|
||||
mit `api` und `data.msg.<userId>.<miniGameTypeId>`, aus `main.1.log.gz`) und Ausführung der
|
||||
Serverbefehle (`game.user_action`, `game.sitout`, `game.take_Seat`, `game.leave_Seat`,
|
||||
`game.quit_table` …). Eigener `/tmp` per `POKERFREAK_PIPE_TMP`. Die Feldnamen in `BeanData`
|
||||
`game.quit_table` …). Eigener `/tmp` per `PIPE_TMP`. Die Feldnamen in `BeanData`
|
||||
sind ANNAHME - der Klon schreibt jede Zeile mit, damit sofort auffällt, wenn sie anders
|
||||
heissen (die *Palette* dagegen ist gemessen, `TableEventHandlers.AddOnHandler`).
|
||||
- **Tasten** (`tests/tasten_kette_spec.py`): die Seite meldet die KeyCodes, die der Client in
|
||||
|
||||
+1
-1
@@ -934,7 +934,7 @@ def _geldregeln(q=None):
|
||||
"stop_tisch_bb": m.tisch_verlust_bb,
|
||||
"stop_sitzung_bb": sv.wert if sv is not None and sv.einheit == "bb" else None,
|
||||
"anteil_je_tisch": g.ANTEIL_JE_TISCH, "hoechstens_tische": g.HOECHSTENS_TISCHE,
|
||||
"ratholing": bool(g.RATHOLING or os.environ.get("POKERFREAK_RATHOLING") == "1"),
|
||||
"ratholing": bool(g.RATHOLING or os.environ.get("RATHOLING") == "1"),
|
||||
"modell": m.modell, "stakes_bb": m.stakes_bb, "kauf": m.kauf, "stops": stops}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
"""Was der Laeufer über einen Gegner denkt - für die Ansicht (plans/2026-10-30_gegner.md).
|
||||
|
||||
Quelle ist der Kern selbst: seine Antwort trägt `reads` ({seat, style, foldChance, trust}, siehe
|
||||
pokerfreak src/wire/reads.rs). Die Sätze sagen, was der Kern je Stil tut (exploit/style_shift.rs),
|
||||
src/wire/reads.rs). Die Sätze sagen, was der Kern je Stil tut (exploit/style_shift.rs),
|
||||
nicht was man vermuten könnte. Rein: liest nichts selbst, wirft nie.
|
||||
"""
|
||||
|
||||
|
||||
+3
-3
@@ -4,7 +4,7 @@
|
||||
schatten betrieb/scratch/shadow.jsonl Entscheidungen, Setzen, Ereignisse, Ergebnisse
|
||||
strom betrieb/scratch/strom.jsonl Ereignisstrom der Bühne (Ticker)
|
||||
zustand betrieb/scratch/zustand.json Wiederaufnahme: eigene Stellen, Gedächtnis je Raum
|
||||
haende Statistik (POKERFREAK_STATS_DIR oder archiv/): haende.jsonl, ereignisse.jsonl
|
||||
haende Statistik (STATS_DIR oder archiv/): haende.jsonl, ereignisse.jsonl
|
||||
log Schwanz des Client-Logs (client/umgebung.log: CLIENT=1 -> Klon)
|
||||
gestoppt Not-Aus-Datei (mcp/stopp.py)
|
||||
fenster Tischfenster (nur lesend, gedrosselt; Fehler -> None)
|
||||
@@ -47,7 +47,7 @@ SPIELPLAN = os.path.join(SCRATCH, "spielplan.json") # sicht/
|
||||
NULLPUNKTE = os.path.join(WURZEL, "sicht", "scratch", "statistik.json") # je Modus: ab wann die Statistik zählt
|
||||
STROM = os.path.join(SCRATCH, "strom.jsonl")
|
||||
ZUSTAND = os.path.join(SCRATCH, "zustand.json")
|
||||
STATS = os.environ.get("POKERFREAK_STATS_DIR") or os.path.join(WURZEL, "archiv", "live")
|
||||
STATS = os.environ.get("STATS_DIR") or os.path.join(WURZEL, "archiv", "live")
|
||||
|
||||
ZUSCHAUER = os.path.join(SCRATCH, "zuschauer.jsonl")
|
||||
SCHWANZ = {"zuschauer": 1_000_000, "schatten": 3_000_000, "strom": 1_000_000, "haende": 2_000_000,
|
||||
@@ -205,7 +205,7 @@ class Leser:
|
||||
Blockiert nie: fehlt die Ablage, startet die Rechnung im Hintergrund und `haende` ist
|
||||
bis dahin leer (`rechnet`: True). Eine veraltete Ablage gilt weiter, bis die neue da ist."""
|
||||
ordner, ziel = ordner or BESTAND_ARCHIV, ziel or BESTAND_DATEI
|
||||
if os.environ.get("POKERFREAK_SICHT_BESTAND") == "0":
|
||||
if os.environ.get("SICHT_BESTAND") == "0":
|
||||
return None
|
||||
marke = self._bestand_marke(ordner)
|
||||
if not marke:
|
||||
|
||||
+2
-2
@@ -36,7 +36,7 @@ ENGINE = umgebung.engine()
|
||||
|
||||
|
||||
def engine_befehl():
|
||||
return (os.environ.get("POKERFREAK_ENGINE") or ENGINE).split() + ["--act"]
|
||||
return (os.environ.get("ENGINE") or ENGINE).split() + ["--act"]
|
||||
SCRATCH = os.path.join(HIER, "scratch")
|
||||
PID_DATEI = os.path.join(SCRATCH, "laeufer.pid")
|
||||
LAEUFER_LOG = os.path.join(SCRATCH, "laeufer.txt")
|
||||
@@ -176,7 +176,7 @@ def laeufer_starten():
|
||||
# eigene Prozessgruppe: Strg-C im Cockpit und ein Absturz des Cockpits treffen den
|
||||
# Läufer nicht; Strg-Pause an seine Gruppe (laeufer_stoppen) erreicht ihn trotzdem
|
||||
_kind = subprocess.Popen(befehl, cwd=WURZEL,
|
||||
env=dict(os.environ, POKERFREAK_SCRATCH=treffpunkt()),
|
||||
env=dict(os.environ, SCRATCH=treffpunkt()),
|
||||
stdin=subprocess.DEVNULL,
|
||||
stdout=log, stderr=subprocess.STDOUT, **kw)
|
||||
finally:
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
//! cargo run --release --bin benchmark -- --save # the current engine becomes the baseline
|
||||
//! ```
|
||||
|
||||
use pokerfreak::sim::benchmark::{parse, render, run_all, verdict_of_run, Report};
|
||||
use pokerfreak::sim::paired::{Comparison, Verdict};
|
||||
use rechner::sim::benchmark::{parse, render, run_all, verdict_of_run, Report};
|
||||
use rechner::sim::paired::{Comparison, Verdict};
|
||||
use std::process::{exit, Command};
|
||||
use std::time::Instant;
|
||||
use std::{env, fs};
|
||||
|
||||
+218
-218
@@ -1,218 +1,218 @@
|
||||
//! Chart generator: the only place of the CFR work that touches the outside world.
|
||||
//!
|
||||
//! ```text
|
||||
//! cargo run --release --bin chartgen -- equity > src/cfr/generated_equity.rs
|
||||
//! cargo run --release --bin chartgen -- charts > src/preflop/generated_charts.rs
|
||||
//! cargo run --release --bin chartgen -- equity --deck short > src/cfr/generated_equity_short.rs
|
||||
//! cargo run --release --bin chartgen -- charts --deck short > src/preflop/generated_charts_short.rs
|
||||
//! cargo run --release --bin chartgen -- multi > src/preflop/generated_charts_multi.rs
|
||||
//! ```
|
||||
//!
|
||||
//! Options: `--threads N` (default: all cores; the result never depends on it), `--deck full|short`,
|
||||
//! `equity --samples N --seed S`, `charts --push-iterations N --open-iterations N` (override the
|
||||
//! plan of `cfr::run_plan` for every seat), `multi --iterations N --check N` (one to four
|
||||
//! defenders, `cfr::multi_solve`; `multi-spot --seat EP --defenders 4 --depth 100` solves one spot
|
||||
//! and prints its metrics). Source text goes to stdout, progress to stderr.
|
||||
//! `charts` reads the frozen equity table of its deck, so regenerate the equity first.
|
||||
|
||||
use pokerfreak::cfr::chart_deck::ChartDeck;
|
||||
use pokerfreak::cfr::environment::Environment;
|
||||
use pokerfreak::cfr::equity_matrix::TRIANGLE_LEN;
|
||||
use pokerfreak::cfr::equity_run::triangle_slice;
|
||||
use pokerfreak::cfr::frozen_spot::{OpenSpot, PushFoldSpot};
|
||||
use pokerfreak::cfr::render_charts::render_charts;
|
||||
use pokerfreak::cfr::render_equity::render_equity;
|
||||
use pokerfreak::cfr::run_plan::{
|
||||
open_iterations as open_iterations_for, open_plan, push_fold_iterations, push_fold_plan, EQUITY_SAMPLES,
|
||||
EQUITY_SEED,
|
||||
};
|
||||
use pokerfreak::cfr::spot_solver::{solve_open_spot_for, solve_push_fold_spot_for};
|
||||
use pokerfreak::cfr::frozen_strategy::binary_row;
|
||||
use pokerfreak::cfr::multi_solve::{solve_multi, width};
|
||||
use pokerfreak::cfr::open_game::open_tree;
|
||||
use pokerfreak::cfr::render_multi::{multi_plan, record, render_multi, BaselineRecord};
|
||||
use pokerfreak::cfr::run_plan::{CFR_SEED, OPEN_ITERATIONS};
|
||||
use pokerfreak::cfr::solve::solve;
|
||||
use pokerfreak::preflop::generated_charts::OPEN;
|
||||
use pokerfreak::rng::Rng;
|
||||
use pokerfreak::cfr::run_plan::{MULTI_CHECK_SAMPLES, MULTI_ITERATIONS};
|
||||
use pokerfreak::cfr::seat::Seat;
|
||||
use pokerfreak::fault::Fault;
|
||||
use pokerfreak::variant::rules;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Mutex;
|
||||
use std::time::Instant;
|
||||
|
||||
/// `f(0..count)` on `threads` workers; the result order is the index order.
|
||||
fn parallel_map<T: Send>(count: usize, threads: usize, f: impl Fn(usize) -> T + Sync) -> Vec<T> {
|
||||
let next = AtomicUsize::new(0);
|
||||
let slots: Mutex<Vec<Option<T>>> = Mutex::new((0..count).map(|_| None).collect());
|
||||
std::thread::scope(|scope| {
|
||||
for _ in 0..threads.max(1) {
|
||||
scope.spawn(|| loop {
|
||||
let index = next.fetch_add(1, Ordering::SeqCst);
|
||||
if index >= count {
|
||||
break;
|
||||
}
|
||||
let value = f(index);
|
||||
if let Ok(mut guard) = slots.lock() {
|
||||
guard[index] = Some(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
slots.into_inner().unwrap_or_default().into_iter().flatten().collect()
|
||||
}
|
||||
|
||||
fn option<T: std::str::FromStr>(args: &[String], name: &str) -> Option<T> {
|
||||
args.iter().position(|a| a == name).and_then(|i| args.get(i + 1)).and_then(|v| v.parse().ok())
|
||||
}
|
||||
|
||||
fn threads(args: &[String]) -> usize {
|
||||
option(args, "--threads")
|
||||
.unwrap_or_else(|| std::thread::available_parallelism().map_or(1, |n| n.get()))
|
||||
}
|
||||
|
||||
fn deck(args: &[String]) -> ChartDeck {
|
||||
match option::<String>(args, "--deck").as_deref() {
|
||||
Some("short") => ChartDeck::Short,
|
||||
_ => ChartDeck::Full,
|
||||
}
|
||||
}
|
||||
|
||||
fn equity(args: &[String]) -> Result<String, Fault> {
|
||||
let deck = deck(args);
|
||||
let rules = rules(deck.variant());
|
||||
let seed: u64 = option(args, "--seed").unwrap_or(EQUITY_SEED);
|
||||
let samples: u32 = option(args, "--samples").unwrap_or(EQUITY_SAMPLES);
|
||||
let chunk = 64;
|
||||
let chunks = TRIANGLE_LEN.div_ceil(chunk);
|
||||
let started = Instant::now();
|
||||
eprintln!("equity: {TRIANGLE_LEN} class pairs x {samples} samples on {} threads", threads(args));
|
||||
let parts = parallel_map(chunks, threads(args), |k| {
|
||||
triangle_slice(&rules, seed, samples, k * chunk..(k + 1) * chunk)
|
||||
});
|
||||
let triangle: Vec<u16> = parts.into_iter().collect::<Result<Vec<_>, _>>()?.concat();
|
||||
eprintln!("equity: done in {:.1} s", started.elapsed().as_secs_f64());
|
||||
Ok(render_equity(deck, seed, samples, &triangle))
|
||||
}
|
||||
|
||||
fn charts(args: &[String]) -> Result<String, Fault> {
|
||||
let deck = deck(args);
|
||||
let env = Environment::frozen_for(deck);
|
||||
let push_iterations: Option<u32> = option(args, "--push-iterations");
|
||||
let open_iterations: Option<u32> = option(args, "--open-iterations");
|
||||
let (push_plan, open_plan) = (push_fold_plan(), open_plan());
|
||||
let started = Instant::now();
|
||||
eprintln!(
|
||||
"charts: {} push/fold + {} open spots on {} threads",
|
||||
push_plan.len(),
|
||||
open_plan.len(),
|
||||
threads(args)
|
||||
);
|
||||
let push: Vec<Result<PushFoldSpot, Fault>> = parallel_map(push_plan.len(), threads(args), |k| {
|
||||
let (seat, depth) = push_plan[k];
|
||||
solve_push_fold_spot_for(&env, seat, depth, push_iterations.unwrap_or(push_fold_iterations(seat)))
|
||||
});
|
||||
eprintln!("charts: push/fold done at {:.1} s", started.elapsed().as_secs_f64());
|
||||
let open: Vec<Result<OpenSpot, Fault>> = parallel_map(open_plan.len(), threads(args), |k| {
|
||||
let (seat, depth) = open_plan[k];
|
||||
solve_open_spot_for(&env, seat, depth, open_iterations.unwrap_or(open_iterations_for(seat)))
|
||||
});
|
||||
eprintln!("charts: all done in {:.1} s", started.elapsed().as_secs_f64());
|
||||
let push = push.into_iter().collect::<Result<Vec<_>, _>>()?;
|
||||
let open = open.into_iter().collect::<Result<Vec<_>, _>>()?;
|
||||
Ok(render_charts(deck, &push, &open))
|
||||
}
|
||||
|
||||
fn seat(args: &[String]) -> Result<Seat, Fault> {
|
||||
let label: String = option(args, "--seat").unwrap_or_else(|| "EP".into());
|
||||
Seat::ALL
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|s| s.label() == label)
|
||||
.ok_or_else(|| Fault::Invalid { field: "--seat".into(), detail: format!("unknown seat {label}") })
|
||||
}
|
||||
|
||||
/// One multi-defender spot, metrics only (for tuning the plan).
|
||||
fn multi_spot(args: &[String]) -> Result<String, Fault> {
|
||||
let env = Environment::frozen_for(deck(args));
|
||||
let (seat, defenders, depth) = (seat(args)?, option(args, "--defenders").unwrap_or(2), option(args, "--depth").unwrap_or(100));
|
||||
let iterations = option(args, "--iterations").unwrap_or(MULTI_ITERATIONS);
|
||||
let samples = option(args, "--check").unwrap_or(MULTI_CHECK_SAMPLES);
|
||||
let started = Instant::now();
|
||||
let solved = solve_multi(&env, seat, defenders, depth, iterations, samples)?;
|
||||
let open = solved.rows.iter().find(|r| r.0 == "open").map(|r| r.2.clone()).unwrap_or_default();
|
||||
Ok(format!(
|
||||
"{} k={} {}bb: {} it, {:.1} s, width {:.4}, drift {} permille, check in-sample {:.6} holdout {:.6} exact {:?}
|
||||
",
|
||||
seat.label(),
|
||||
defenders,
|
||||
depth,
|
||||
iterations,
|
||||
started.elapsed().as_secs_f64(),
|
||||
width(&env, &open),
|
||||
solved.open_drift_permille,
|
||||
solved.check.in_sample_total(),
|
||||
solved.check.holdout_total(),
|
||||
solved.exact
|
||||
))
|
||||
}
|
||||
|
||||
/// One-defender baselines and every multi-defender spot; the most expensive spots start first.
|
||||
fn multi(args: &[String]) -> Result<String, Fault> {
|
||||
let env = Environment::frozen();
|
||||
let iterations = option(args, "--iterations").unwrap_or(MULTI_ITERATIONS);
|
||||
let samples = option(args, "--check").unwrap_or(MULTI_CHECK_SAMPLES);
|
||||
let started = Instant::now();
|
||||
let base_plan: Vec<(Seat, u8)> = open_plan();
|
||||
eprintln!("multi: {} one-defender baselines on {} threads", base_plan.len(), threads(args));
|
||||
let baselines = parallel_map(base_plan.len(), threads(args), |k| {
|
||||
let (seat, depth) = base_plan[k];
|
||||
let tree = open_tree(&env, seat, depth as f64)?;
|
||||
let solved = solve(&tree, OPEN_ITERATIONS, Rng::seeded(CFR_SEED));
|
||||
Ok::<_, Fault>(BaselineRecord {
|
||||
seat,
|
||||
depth_bb: depth,
|
||||
iterations: OPEN_ITERATIONS,
|
||||
open: binary_row(&tree, &solved.strategy, "open")?.to_vec(),
|
||||
})
|
||||
});
|
||||
let baselines = baselines.into_iter().collect::<Result<Vec<_>, _>>()?;
|
||||
let plan = multi_plan();
|
||||
let mut order: Vec<usize> = (0..plan.len()).collect();
|
||||
order.sort_by_key(|i| std::cmp::Reverse(plan[*i].1));
|
||||
eprintln!("multi: baselines at {:.1} s; {} spots, {iterations} iterations", started.elapsed().as_secs_f64(), plan.len());
|
||||
let solved = parallel_map(order.len(), threads(args), |k| {
|
||||
let (seat, defenders, depth) = plan[order[k]];
|
||||
let result = solve_multi(&env, seat, defenders, depth, iterations, samples).map(|s| record(&s));
|
||||
eprintln!("multi: {} k={defenders} {depth} bb done at {:.0} s", seat.label(), started.elapsed().as_secs_f64());
|
||||
(order[k], result)
|
||||
});
|
||||
let mut solved = solved;
|
||||
solved.sort_by_key(|(i, _)| *i);
|
||||
let spots = solved.into_iter().map(|(_, r)| r).collect::<Result<Vec<_>, _>>()?;
|
||||
let reference: Vec<(Seat, u8, Vec<u16>)> = OPEN.iter().map(|s| (s.seat, s.depth_bb, s.open.to_vec())).collect();
|
||||
Ok(render_multi(&env, &spots, &baselines, &reference))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
let result = match args.first().map(String::as_str) {
|
||||
Some("equity") => equity(&args[1..]),
|
||||
Some("charts") => charts(&args[1..]),
|
||||
Some("multi-spot") => multi_spot(&args[1..]),
|
||||
Some("multi") => multi(&args[1..]),
|
||||
_ => {
|
||||
eprintln!("usage: chartgen equity|charts|multi|multi-spot [--threads N] [options] (source goes to stdout)");
|
||||
std::process::exit(2);
|
||||
}
|
||||
};
|
||||
match result {
|
||||
Ok(source) => print!("{source}"),
|
||||
Err(fault) => {
|
||||
eprintln!("chartgen: {fault}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
//! Chart generator: the only place of the CFR work that touches the outside world.
|
||||
//!
|
||||
//! ```text
|
||||
//! cargo run --release --bin chartgen -- equity > src/cfr/generated_equity.rs
|
||||
//! cargo run --release --bin chartgen -- charts > src/preflop/generated_charts.rs
|
||||
//! cargo run --release --bin chartgen -- equity --deck short > src/cfr/generated_equity_short.rs
|
||||
//! cargo run --release --bin chartgen -- charts --deck short > src/preflop/generated_charts_short.rs
|
||||
//! cargo run --release --bin chartgen -- multi > src/preflop/generated_charts_multi.rs
|
||||
//! ```
|
||||
//!
|
||||
//! Options: `--threads N` (default: all cores; the result never depends on it), `--deck full|short`,
|
||||
//! `equity --samples N --seed S`, `charts --push-iterations N --open-iterations N` (override the
|
||||
//! plan of `cfr::run_plan` for every seat), `multi --iterations N --check N` (one to four
|
||||
//! defenders, `cfr::multi_solve`; `multi-spot --seat EP --defenders 4 --depth 100` solves one spot
|
||||
//! and prints its metrics). Source text goes to stdout, progress to stderr.
|
||||
//! `charts` reads the frozen equity table of its deck, so regenerate the equity first.
|
||||
|
||||
use rechner::cfr::chart_deck::ChartDeck;
|
||||
use rechner::cfr::environment::Environment;
|
||||
use rechner::cfr::equity_matrix::TRIANGLE_LEN;
|
||||
use rechner::cfr::equity_run::triangle_slice;
|
||||
use rechner::cfr::frozen_spot::{OpenSpot, PushFoldSpot};
|
||||
use rechner::cfr::render_charts::render_charts;
|
||||
use rechner::cfr::render_equity::render_equity;
|
||||
use rechner::cfr::run_plan::{
|
||||
open_iterations as open_iterations_for, open_plan, push_fold_iterations, push_fold_plan, EQUITY_SAMPLES,
|
||||
EQUITY_SEED,
|
||||
};
|
||||
use rechner::cfr::spot_solver::{solve_open_spot_for, solve_push_fold_spot_for};
|
||||
use rechner::cfr::frozen_strategy::binary_row;
|
||||
use rechner::cfr::multi_solve::{solve_multi, width};
|
||||
use rechner::cfr::open_game::open_tree;
|
||||
use rechner::cfr::render_multi::{multi_plan, record, render_multi, BaselineRecord};
|
||||
use rechner::cfr::run_plan::{CFR_SEED, OPEN_ITERATIONS};
|
||||
use rechner::cfr::solve::solve;
|
||||
use rechner::preflop::generated_charts::OPEN;
|
||||
use rechner::rng::Rng;
|
||||
use rechner::cfr::run_plan::{MULTI_CHECK_SAMPLES, MULTI_ITERATIONS};
|
||||
use rechner::cfr::seat::Seat;
|
||||
use rechner::fault::Fault;
|
||||
use rechner::variant::rules;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Mutex;
|
||||
use std::time::Instant;
|
||||
|
||||
/// `f(0..count)` on `threads` workers; the result order is the index order.
|
||||
fn parallel_map<T: Send>(count: usize, threads: usize, f: impl Fn(usize) -> T + Sync) -> Vec<T> {
|
||||
let next = AtomicUsize::new(0);
|
||||
let slots: Mutex<Vec<Option<T>>> = Mutex::new((0..count).map(|_| None).collect());
|
||||
std::thread::scope(|scope| {
|
||||
for _ in 0..threads.max(1) {
|
||||
scope.spawn(|| loop {
|
||||
let index = next.fetch_add(1, Ordering::SeqCst);
|
||||
if index >= count {
|
||||
break;
|
||||
}
|
||||
let value = f(index);
|
||||
if let Ok(mut guard) = slots.lock() {
|
||||
guard[index] = Some(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
slots.into_inner().unwrap_or_default().into_iter().flatten().collect()
|
||||
}
|
||||
|
||||
fn option<T: std::str::FromStr>(args: &[String], name: &str) -> Option<T> {
|
||||
args.iter().position(|a| a == name).and_then(|i| args.get(i + 1)).and_then(|v| v.parse().ok())
|
||||
}
|
||||
|
||||
fn threads(args: &[String]) -> usize {
|
||||
option(args, "--threads")
|
||||
.unwrap_or_else(|| std::thread::available_parallelism().map_or(1, |n| n.get()))
|
||||
}
|
||||
|
||||
fn deck(args: &[String]) -> ChartDeck {
|
||||
match option::<String>(args, "--deck").as_deref() {
|
||||
Some("short") => ChartDeck::Short,
|
||||
_ => ChartDeck::Full,
|
||||
}
|
||||
}
|
||||
|
||||
fn equity(args: &[String]) -> Result<String, Fault> {
|
||||
let deck = deck(args);
|
||||
let rules = rules(deck.variant());
|
||||
let seed: u64 = option(args, "--seed").unwrap_or(EQUITY_SEED);
|
||||
let samples: u32 = option(args, "--samples").unwrap_or(EQUITY_SAMPLES);
|
||||
let chunk = 64;
|
||||
let chunks = TRIANGLE_LEN.div_ceil(chunk);
|
||||
let started = Instant::now();
|
||||
eprintln!("equity: {TRIANGLE_LEN} class pairs x {samples} samples on {} threads", threads(args));
|
||||
let parts = parallel_map(chunks, threads(args), |k| {
|
||||
triangle_slice(&rules, seed, samples, k * chunk..(k + 1) * chunk)
|
||||
});
|
||||
let triangle: Vec<u16> = parts.into_iter().collect::<Result<Vec<_>, _>>()?.concat();
|
||||
eprintln!("equity: done in {:.1} s", started.elapsed().as_secs_f64());
|
||||
Ok(render_equity(deck, seed, samples, &triangle))
|
||||
}
|
||||
|
||||
fn charts(args: &[String]) -> Result<String, Fault> {
|
||||
let deck = deck(args);
|
||||
let env = Environment::frozen_for(deck);
|
||||
let push_iterations: Option<u32> = option(args, "--push-iterations");
|
||||
let open_iterations: Option<u32> = option(args, "--open-iterations");
|
||||
let (push_plan, open_plan) = (push_fold_plan(), open_plan());
|
||||
let started = Instant::now();
|
||||
eprintln!(
|
||||
"charts: {} push/fold + {} open spots on {} threads",
|
||||
push_plan.len(),
|
||||
open_plan.len(),
|
||||
threads(args)
|
||||
);
|
||||
let push: Vec<Result<PushFoldSpot, Fault>> = parallel_map(push_plan.len(), threads(args), |k| {
|
||||
let (seat, depth) = push_plan[k];
|
||||
solve_push_fold_spot_for(&env, seat, depth, push_iterations.unwrap_or(push_fold_iterations(seat)))
|
||||
});
|
||||
eprintln!("charts: push/fold done at {:.1} s", started.elapsed().as_secs_f64());
|
||||
let open: Vec<Result<OpenSpot, Fault>> = parallel_map(open_plan.len(), threads(args), |k| {
|
||||
let (seat, depth) = open_plan[k];
|
||||
solve_open_spot_for(&env, seat, depth, open_iterations.unwrap_or(open_iterations_for(seat)))
|
||||
});
|
||||
eprintln!("charts: all done in {:.1} s", started.elapsed().as_secs_f64());
|
||||
let push = push.into_iter().collect::<Result<Vec<_>, _>>()?;
|
||||
let open = open.into_iter().collect::<Result<Vec<_>, _>>()?;
|
||||
Ok(render_charts(deck, &push, &open))
|
||||
}
|
||||
|
||||
fn seat(args: &[String]) -> Result<Seat, Fault> {
|
||||
let label: String = option(args, "--seat").unwrap_or_else(|| "EP".into());
|
||||
Seat::ALL
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|s| s.label() == label)
|
||||
.ok_or_else(|| Fault::Invalid { field: "--seat".into(), detail: format!("unknown seat {label}") })
|
||||
}
|
||||
|
||||
/// One multi-defender spot, metrics only (for tuning the plan).
|
||||
fn multi_spot(args: &[String]) -> Result<String, Fault> {
|
||||
let env = Environment::frozen_for(deck(args));
|
||||
let (seat, defenders, depth) = (seat(args)?, option(args, "--defenders").unwrap_or(2), option(args, "--depth").unwrap_or(100));
|
||||
let iterations = option(args, "--iterations").unwrap_or(MULTI_ITERATIONS);
|
||||
let samples = option(args, "--check").unwrap_or(MULTI_CHECK_SAMPLES);
|
||||
let started = Instant::now();
|
||||
let solved = solve_multi(&env, seat, defenders, depth, iterations, samples)?;
|
||||
let open = solved.rows.iter().find(|r| r.0 == "open").map(|r| r.2.clone()).unwrap_or_default();
|
||||
Ok(format!(
|
||||
"{} k={} {}bb: {} it, {:.1} s, width {:.4}, drift {} permille, check in-sample {:.6} holdout {:.6} exact {:?}
|
||||
",
|
||||
seat.label(),
|
||||
defenders,
|
||||
depth,
|
||||
iterations,
|
||||
started.elapsed().as_secs_f64(),
|
||||
width(&env, &open),
|
||||
solved.open_drift_permille,
|
||||
solved.check.in_sample_total(),
|
||||
solved.check.holdout_total(),
|
||||
solved.exact
|
||||
))
|
||||
}
|
||||
|
||||
/// One-defender baselines and every multi-defender spot; the most expensive spots start first.
|
||||
fn multi(args: &[String]) -> Result<String, Fault> {
|
||||
let env = Environment::frozen();
|
||||
let iterations = option(args, "--iterations").unwrap_or(MULTI_ITERATIONS);
|
||||
let samples = option(args, "--check").unwrap_or(MULTI_CHECK_SAMPLES);
|
||||
let started = Instant::now();
|
||||
let base_plan: Vec<(Seat, u8)> = open_plan();
|
||||
eprintln!("multi: {} one-defender baselines on {} threads", base_plan.len(), threads(args));
|
||||
let baselines = parallel_map(base_plan.len(), threads(args), |k| {
|
||||
let (seat, depth) = base_plan[k];
|
||||
let tree = open_tree(&env, seat, depth as f64)?;
|
||||
let solved = solve(&tree, OPEN_ITERATIONS, Rng::seeded(CFR_SEED));
|
||||
Ok::<_, Fault>(BaselineRecord {
|
||||
seat,
|
||||
depth_bb: depth,
|
||||
iterations: OPEN_ITERATIONS,
|
||||
open: binary_row(&tree, &solved.strategy, "open")?.to_vec(),
|
||||
})
|
||||
});
|
||||
let baselines = baselines.into_iter().collect::<Result<Vec<_>, _>>()?;
|
||||
let plan = multi_plan();
|
||||
let mut order: Vec<usize> = (0..plan.len()).collect();
|
||||
order.sort_by_key(|i| std::cmp::Reverse(plan[*i].1));
|
||||
eprintln!("multi: baselines at {:.1} s; {} spots, {iterations} iterations", started.elapsed().as_secs_f64(), plan.len());
|
||||
let solved = parallel_map(order.len(), threads(args), |k| {
|
||||
let (seat, defenders, depth) = plan[order[k]];
|
||||
let result = solve_multi(&env, seat, defenders, depth, iterations, samples).map(|s| record(&s));
|
||||
eprintln!("multi: {} k={defenders} {depth} bb done at {:.0} s", seat.label(), started.elapsed().as_secs_f64());
|
||||
(order[k], result)
|
||||
});
|
||||
let mut solved = solved;
|
||||
solved.sort_by_key(|(i, _)| *i);
|
||||
let spots = solved.into_iter().map(|(_, r)| r).collect::<Result<Vec<_>, _>>()?;
|
||||
let reference: Vec<(Seat, u8, Vec<u16>)> = OPEN.iter().map(|s| (s.seat, s.depth_bb, s.open.to_vec())).collect();
|
||||
Ok(render_multi(&env, &spots, &baselines, &reference))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
let result = match args.first().map(String::as_str) {
|
||||
Some("equity") => equity(&args[1..]),
|
||||
Some("charts") => charts(&args[1..]),
|
||||
Some("multi-spot") => multi_spot(&args[1..]),
|
||||
Some("multi") => multi(&args[1..]),
|
||||
_ => {
|
||||
eprintln!("usage: chartgen equity|charts|multi|multi-spot [--threads N] [options] (source goes to stdout)");
|
||||
std::process::exit(2);
|
||||
}
|
||||
};
|
||||
match result {
|
||||
Ok(source) => print!("{source}"),
|
||||
Err(fault) => {
|
||||
eprintln!("chartgen: {fault}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
//! The only impure part: read lines from stdin, write lines to stdout.
|
||||
|
||||
use pokerfreak::game::Decision;
|
||||
use pokerfreak::wire::encode::encode;
|
||||
use pokerfreak::wire::respond::respond;
|
||||
use rechner::game::Decision;
|
||||
use rechner::wire::encode::encode;
|
||||
use rechner::wire::respond::respond;
|
||||
use std::io::{self, BufRead, Write};
|
||||
use std::panic::{catch_unwind, set_hook, AssertUnwindSafe};
|
||||
|
||||
|
||||
@@ -226,12 +226,12 @@ fn lineup(spot: &Spot, attacker: u8) -> Option<(Seat, Lineup)> {
|
||||
}
|
||||
}
|
||||
let k = present.len().min(max_defenders(seat));
|
||||
if std::env::var("POKERFREAK_DEBUG").is_ok() {
|
||||
if std::env::var("DEBUG").is_ok() {
|
||||
eprintln!("[pf] seat={seat:?} present={present:?} k={k} after={after:?}");
|
||||
}
|
||||
let lineup = Lineup::new(seat, k).ok()?;
|
||||
let passt = lineup.defenders.iter().all(|d| present.contains(d));
|
||||
if std::env::var("POKERFREAK_DEBUG").is_ok() {
|
||||
if std::env::var("DEBUG").is_ok() {
|
||||
eprintln!("[pf] defenders={:?} passt={passt}", lineup.defenders);
|
||||
}
|
||||
passt.then_some((seat, lineup))
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
//! times 0.7 when the opponent already bet (they are being raised), capped at 0.95.
|
||||
//! foldToBet is measured against a typical two-thirds-pot bet, so at that size p = f.
|
||||
|
||||
use pokerfreak::exploit::fold_chance::{
|
||||
use rechner::exploit::fold_chance::{
|
||||
fold_base, fold_chance, DEFAULT_FOLD_TO_BET, MAX_FOLD, RAISE_RESISTANCE, REFERENCE_RATIO,
|
||||
};
|
||||
use pokerfreak::exploit::profile::Profile;
|
||||
use pokerfreak::exploit::table_fold::pressure_ratio;
|
||||
use rechner::exploit::profile::Profile;
|
||||
use rechner::exploit::table_fold::pressure_ratio;
|
||||
|
||||
fn folds(f: f64) -> Profile {
|
||||
Profile { fold_to_bet: Some(f), ..Profile::default() }
|
||||
|
||||
+14
-14
@@ -8,20 +8,20 @@
|
||||
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::engine::bluff::{branches, NEVER_FOLDS, PURE_BLUFF_MIN_FOLD};
|
||||
use pokerfreak::engine::called::Called;
|
||||
use pokerfreak::engine::effective::effective;
|
||||
use pokerfreak::engine::multiway::realized_share;
|
||||
use pokerfreak::engine::options::passive_ev;
|
||||
use pokerfreak::engine::postflop::choose_postflop_with;
|
||||
use pokerfreak::exploit::profile::Profile;
|
||||
use pokerfreak::exploit::table_fold::table_fold;
|
||||
use pokerfreak::exploit::thresholds::Thresholds;
|
||||
use pokerfreak::game::{ActionKind, Choice, Spot, Street, Villain};
|
||||
use pokerfreak::read::draw::Draw;
|
||||
use pokerfreak::read::made::Made;
|
||||
use pokerfreak::read::suit_pattern::SuitPattern;
|
||||
use pokerfreak::rng::Rng;
|
||||
use rechner::engine::bluff::{branches, NEVER_FOLDS, PURE_BLUFF_MIN_FOLD};
|
||||
use rechner::engine::called::Called;
|
||||
use rechner::engine::effective::effective;
|
||||
use rechner::engine::multiway::realized_share;
|
||||
use rechner::engine::options::passive_ev;
|
||||
use rechner::engine::postflop::choose_postflop_with;
|
||||
use rechner::exploit::profile::Profile;
|
||||
use rechner::exploit::table_fold::table_fold;
|
||||
use rechner::exploit::thresholds::Thresholds;
|
||||
use rechner::game::{ActionKind, Choice, Spot, Street, Villain};
|
||||
use rechner::read::draw::Draw;
|
||||
use rechner::read::made::Made;
|
||||
use rechner::read::suit_pattern::SuitPattern;
|
||||
use rechner::rng::Rng;
|
||||
use spot_fixture::*;
|
||||
|
||||
const MADES: [Made; 8] = [
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::card::{deck, Card};
|
||||
use pokerfreak::engine::range_filter::range_filter;
|
||||
use pokerfreak::exploit::range_spec::{Continuation, RangeSpec};
|
||||
use pokerfreak::read::glance::glance;
|
||||
use pokerfreak::read::made::Made;
|
||||
use pokerfreak::variant::{rules, Variant};
|
||||
use rechner::card::{deck, Card};
|
||||
use rechner::engine::range_filter::range_filter;
|
||||
use rechner::exploit::range_spec::{Continuation, RangeSpec};
|
||||
use rechner::read::glance::glance;
|
||||
use rechner::read::made::Made;
|
||||
use rechner::variant::{rules, Variant};
|
||||
use spot_fixture::cards;
|
||||
|
||||
fn spec(bluff_share: f64) -> RangeSpec {
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
//! (share of postflop actions that are bets or raises) overrides it as `aggression / 0.45`,
|
||||
//! clamped to [0, 2]. Capped at 0.6.
|
||||
|
||||
use pokerfreak::exploit::bluff_share::{bluff_share, MAX_BLUFF_SHARE, NEUTRAL_RATIO};
|
||||
use pokerfreak::exploit::profile::Profile;
|
||||
use pokerfreak::game::Street;
|
||||
use rechner::exploit::bluff_share::{bluff_share, MAX_BLUFF_SHARE, NEUTRAL_RATIO};
|
||||
use rechner::exploit::profile::Profile;
|
||||
use rechner::game::Street;
|
||||
|
||||
fn close(a: f64, b: f64) -> bool {
|
||||
(a - b).abs() < 1e-9
|
||||
|
||||
@@ -22,7 +22,7 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
# Eigener /tmp: der Client laesst seine Sockets liegen, sonst ist nicht klar, wer gruesst.
|
||||
TMP = tempfile.mkdtemp(prefix="pf-bruecke-kette-")
|
||||
os.environ["POKERFREAK_PIPE_TMP"] = TMP
|
||||
os.environ["PIPE_TMP"] = TMP
|
||||
|
||||
from klonlauf import Klonlauf, warte # noqa: E402
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ for p in (WURZEL, os.path.join(WURZEL, "hand"), os.path.join(WURZEL, "mock")):
|
||||
# Ein eigener /tmp fuer diese Spec (der Client laesst seine Sockets liegen) - noch vor dem
|
||||
# Import, weil `pipe.TMP` daraus gelesen wird. `kanal`/`pipe` finden den Klon dann ohne Zutun.
|
||||
TMP = tempfile.mkdtemp(prefix="pf-bruecke-")
|
||||
os.environ["POKERFREAK_PIPE_TMP"] = TMP
|
||||
os.environ["PIPE_TMP"] = TMP
|
||||
|
||||
import kanal
|
||||
import pipe
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use pokerfreak::card::{deck, Card, Rank, Suit};
|
||||
use pokerfreak::rng::Rng;
|
||||
use pokerfreak::variant::{rules, ActionShape, HoleUsage, SizingRule, Variant};
|
||||
use rechner::card::{deck, Card, Rank, Suit};
|
||||
use rechner::rng::Rng;
|
||||
use rechner::variant::{rules, ActionShape, HoleUsage, SizingRule, Variant};
|
||||
|
||||
#[test]
|
||||
fn ranks_parse_contract_names_and_symbols() {
|
||||
|
||||
+10
-10
@@ -6,13 +6,13 @@
|
||||
mod cfr_support;
|
||||
|
||||
use cfr_support::id;
|
||||
use pokerfreak::cfr::chance_table::chance_table;
|
||||
use pokerfreak::cfr::equity_matrix::{triangle_pairs, EquityMatrix, TRIANGLE_LEN};
|
||||
use pokerfreak::cfr::equity_pair::pair_equity;
|
||||
use pokerfreak::cfr::frozen_equity::frozen_equity;
|
||||
use pokerfreak::cfr::generated_equity as frozen;
|
||||
use pokerfreak::cfr::hand_class::CLASS_COUNT;
|
||||
use pokerfreak::variant::{rules, DeckRule, Rules, Variant};
|
||||
use rechner::cfr::chance_table::chance_table;
|
||||
use rechner::cfr::equity_matrix::{triangle_pairs, EquityMatrix, TRIANGLE_LEN};
|
||||
use rechner::cfr::equity_pair::pair_equity;
|
||||
use rechner::cfr::frozen_equity::frozen_equity;
|
||||
use rechner::cfr::generated_equity as frozen;
|
||||
use rechner::cfr::hand_class::CLASS_COUNT;
|
||||
use rechner::variant::{rules, DeckRule, Rules, Variant};
|
||||
|
||||
fn nlhe() -> Rules {
|
||||
rules(Variant::Nlhe)
|
||||
@@ -113,9 +113,9 @@ fn frozen_short_deck_table_has_the_reference_values_and_only_deck_classes() {
|
||||
// Exact-enumeration references for short deck (36 cards, flush beats full house):
|
||||
// AA vs KK 74.26 %, AKs vs QQ 54.28 %, AKo vs JTs 49.35 %. The frozen table is Monte Carlo
|
||||
// (60 000 samples per pair, standard error about 0.2 %) and lands within about one point.
|
||||
use pokerfreak::cfr::chart_deck::ChartDeck;
|
||||
use pokerfreak::cfr::frozen_equity::frozen_equity_for;
|
||||
use pokerfreak::cfr::hand_class::class_exists;
|
||||
use rechner::cfr::chart_deck::ChartDeck;
|
||||
use rechner::cfr::frozen_equity::frozen_equity_for;
|
||||
use rechner::cfr::hand_class::class_exists;
|
||||
let m = frozen_equity_for(ChartDeck::Short);
|
||||
assert!((m.get(id("AA"), id("KK")) - 0.7426).abs() < 0.012, "{}", m.get(id("AA"), id("KK")));
|
||||
assert!((m.get(id("AKs"), id("QQ")) - 0.5428).abs() < 0.012, "{}", m.get(id("AKs"), id("QQ")));
|
||||
|
||||
+14
-14
@@ -6,22 +6,22 @@
|
||||
//! "always fold" is -0.5 (the small blind already posted).
|
||||
mod cfr_support;
|
||||
|
||||
use pokerfreak::cfr::environment::Environment;
|
||||
use pokerfreak::cfr::exploitability::game_value;
|
||||
use pokerfreak::cfr::open_game::open_tree;
|
||||
use pokerfreak::cfr::push_fold_game::push_fold_tree;
|
||||
use pokerfreak::cfr::seat::Seat;
|
||||
use pokerfreak::cfr::spot_params::{OPEN_SIZE, THREE_BET_SIZE, WAKE_FRACTION};
|
||||
use pokerfreak::cfr::strategy::Strategy;
|
||||
use pokerfreak::cfr::tree::Node;
|
||||
use pokerfreak::cfr::wake_range::top_membership;
|
||||
use pokerfreak::variant::{rules, Variant};
|
||||
use rechner::cfr::environment::Environment;
|
||||
use rechner::cfr::exploitability::game_value;
|
||||
use rechner::cfr::open_game::open_tree;
|
||||
use rechner::cfr::push_fold_game::push_fold_tree;
|
||||
use rechner::cfr::seat::Seat;
|
||||
use rechner::cfr::spot_params::{OPEN_SIZE, THREE_BET_SIZE, WAKE_FRACTION};
|
||||
use rechner::cfr::strategy::Strategy;
|
||||
use rechner::cfr::tree::Node;
|
||||
use rechner::cfr::wake_range::top_membership;
|
||||
use rechner::variant::{rules, Variant};
|
||||
|
||||
fn env() -> Environment {
|
||||
Environment::frozen_free_table()
|
||||
}
|
||||
|
||||
fn names(tree: &pokerfreak::cfr::tree::Tree) -> Vec<&'static str> {
|
||||
fn names(tree: &rechner::cfr::tree::Tree) -> Vec<&'static str> {
|
||||
tree.nodes
|
||||
.iter()
|
||||
.filter_map(|n| match n {
|
||||
@@ -78,7 +78,7 @@ fn bad_stack_depths_are_faults_not_panics() {
|
||||
|
||||
#[test]
|
||||
fn environment_rejects_rules_that_are_not_two_card_hold_em() {
|
||||
let equity = pokerfreak::cfr::frozen_equity::frozen_equity();
|
||||
let equity = rechner::cfr::frozen_equity::frozen_equity();
|
||||
assert!(Environment::new(&rules(Variant::Plo5), equity.clone()).is_err());
|
||||
assert!(Environment::new(&rules(Variant::Nlhe), equity.clone()).is_ok());
|
||||
assert!(Environment::new(&rules(Variant::Aof), equity).is_ok());
|
||||
@@ -113,7 +113,7 @@ fn small_blind_open_identities_are_exact() {
|
||||
assert!((game_value(&tree, &strat(1, 2)) + OPEN_SIZE_SB).abs() < 1e-9);
|
||||
}
|
||||
|
||||
const OPEN_SIZE_SB: f64 = pokerfreak::cfr::spot_params::SMALL_BLIND_OPEN_SIZE;
|
||||
const OPEN_SIZE_SB: f64 = rechner::cfr::spot_params::SMALL_BLIND_OPEN_SIZE;
|
||||
|
||||
#[test]
|
||||
fn players_behind_cost_the_opener_money_when_they_wake_up() {
|
||||
@@ -136,7 +136,7 @@ fn wake_range_membership_covers_exactly_the_requested_share_of_combos() {
|
||||
let e = env();
|
||||
let membership = top_membership(&e, WAKE_FRACTION);
|
||||
let combos: f64 = (0..169)
|
||||
.map(|c| membership[c] * pokerfreak::cfr::hand_class::class_combos(c).len() as f64)
|
||||
.map(|c| membership[c] * rechner::cfr::hand_class::class_combos(c).len() as f64)
|
||||
.sum();
|
||||
assert!((combos / 1326.0 - WAKE_FRACTION).abs() < 1e-9);
|
||||
assert!(membership.iter().all(|m| (0.0..=1.0).contains(m)));
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
mod cfr_support;
|
||||
|
||||
use cfr_support::id;
|
||||
use pokerfreak::card::{Card, Rank};
|
||||
use pokerfreak::cfr::chance_table::chance_table;
|
||||
use pokerfreak::cfr::hand_class::{
|
||||
use rechner::card::{Card, Rank};
|
||||
use rechner::cfr::chance_table::chance_table;
|
||||
use rechner::cfr::hand_class::{
|
||||
class_combos, class_exists, class_name, class_of, class_parse, classes_in, CLASS_COUNT,
|
||||
};
|
||||
use pokerfreak::variant::DeckRule;
|
||||
use rechner::variant::DeckRule;
|
||||
use std::collections::HashSet;
|
||||
|
||||
fn card(text: &str) -> Card {
|
||||
|
||||
+7
-7
@@ -5,13 +5,13 @@
|
||||
//! the first player bets J with probability a in [0, 1/3], K with 3a, checks Q always, and after
|
||||
//! check-bet calls with Q at 1/3 + a, K always, J never. The second player facing a bet calls
|
||||
//! with K always, Q at 1/3, J never; after a check bets J at 1/3, K always, Q never.
|
||||
use pokerfreak::cfr::exploitability::{best_response_gain, exploitability, game_value};
|
||||
use pokerfreak::cfr::iterate::iterate;
|
||||
use pokerfreak::cfr::solve::solve;
|
||||
use pokerfreak::cfr::solver_state::SolverState;
|
||||
use pokerfreak::cfr::strategy::{average_strategy, Strategy};
|
||||
use pokerfreak::cfr::tree::{Node, Payoff, Tree};
|
||||
use pokerfreak::rng::Rng;
|
||||
use rechner::cfr::exploitability::{best_response_gain, exploitability, game_value};
|
||||
use rechner::cfr::iterate::iterate;
|
||||
use rechner::cfr::solve::solve;
|
||||
use rechner::cfr::solver_state::SolverState;
|
||||
use rechner::cfr::strategy::{average_strategy, Strategy};
|
||||
use rechner::cfr::tree::{Node, Payoff, Tree};
|
||||
use rechner::rng::Rng;
|
||||
|
||||
const J: usize = 0;
|
||||
const Q: usize = 1;
|
||||
|
||||
+26
-26
@@ -19,29 +19,29 @@
|
||||
//! `generated_charts::OPEN` (`SAME_GAME`). With more defenders the open ranges get narrower.
|
||||
mod cfr_support;
|
||||
|
||||
use pokerfreak::cfr::defenders::{behind, max_defenders, Lineup, Place, MAX_DEFENDERS};
|
||||
use pokerfreak::cfr::environment::Environment;
|
||||
use pokerfreak::cfr::exploitability::{exploitability, game_value};
|
||||
use pokerfreak::cfr::frozen_multi::{multi_strategy, open_row, permille_rows};
|
||||
use pokerfreak::cfr::frozen_strategy::binary_row;
|
||||
use pokerfreak::cfr::game::Game;
|
||||
use pokerfreak::cfr::multi_shares::multi_shares;
|
||||
use pokerfreak::cfr::multi_solve::{exact_exploitability, exact_name, mean_abs_difference, width, CHECK_SEED};
|
||||
use pokerfreak::cfr::multi_tree::{multi_open_tree, MultiNode, MultiOutcome, MultiTree};
|
||||
use pokerfreak::cfr::multi_walk::{sampled_exploitability, sampled_values, MultiStrategy};
|
||||
use pokerfreak::cfr::open3_game::open3_tree;
|
||||
use pokerfreak::cfr::open_game::open_tree;
|
||||
use pokerfreak::cfr::payoffs::share;
|
||||
use pokerfreak::cfr::render_multi::{baseline_records, evidence, multi_plan, records, render_multi};
|
||||
use pokerfreak::cfr::run_plan::{CFR_SEED, OPEN_ITERATIONS};
|
||||
use pokerfreak::cfr::seat::Seat;
|
||||
use pokerfreak::cfr::solve::solve;
|
||||
use pokerfreak::cfr::strategy::Strategy;
|
||||
use pokerfreak::cfr::three_way::three_way_shares;
|
||||
use pokerfreak::cfr::walk3::game_value3;
|
||||
use pokerfreak::preflop::generated_charts::OPEN;
|
||||
use pokerfreak::preflop::generated_charts_multi::{BASELINE, MULTI};
|
||||
use pokerfreak::rng::Rng;
|
||||
use rechner::cfr::defenders::{behind, max_defenders, Lineup, Place, MAX_DEFENDERS};
|
||||
use rechner::cfr::environment::Environment;
|
||||
use rechner::cfr::exploitability::{exploitability, game_value};
|
||||
use rechner::cfr::frozen_multi::{multi_strategy, open_row, permille_rows};
|
||||
use rechner::cfr::frozen_strategy::binary_row;
|
||||
use rechner::cfr::game::Game;
|
||||
use rechner::cfr::multi_shares::multi_shares;
|
||||
use rechner::cfr::multi_solve::{exact_exploitability, exact_name, mean_abs_difference, width, CHECK_SEED};
|
||||
use rechner::cfr::multi_tree::{multi_open_tree, MultiNode, MultiOutcome, MultiTree};
|
||||
use rechner::cfr::multi_walk::{sampled_exploitability, sampled_values, MultiStrategy};
|
||||
use rechner::cfr::open3_game::open3_tree;
|
||||
use rechner::cfr::open_game::open_tree;
|
||||
use rechner::cfr::payoffs::share;
|
||||
use rechner::cfr::render_multi::{baseline_records, evidence, multi_plan, records, render_multi};
|
||||
use rechner::cfr::run_plan::{CFR_SEED, OPEN_ITERATIONS};
|
||||
use rechner::cfr::seat::Seat;
|
||||
use rechner::cfr::solve::solve;
|
||||
use rechner::cfr::strategy::Strategy;
|
||||
use rechner::cfr::three_way::three_way_shares;
|
||||
use rechner::cfr::walk3::game_value3;
|
||||
use rechner::preflop::generated_charts::OPEN;
|
||||
use rechner::preflop::generated_charts_multi::{BASELINE, MULTI};
|
||||
use rechner::rng::Rng;
|
||||
|
||||
/// Exploitability bound of every frozen multi-defender spot (bb per deal), as for the exact
|
||||
/// tables (`tests/cfr_nash.rs`).
|
||||
@@ -263,13 +263,13 @@ fn the_baseline_is_the_one_defender_game_solved_full_width() {
|
||||
let env = env();
|
||||
let sb = BASELINE.iter().find(|b| b.seat == Seat::SmallBlind && b.depth_bb == 100).expect("spot");
|
||||
let table = OPEN.iter().find(|s| s.seat == Seat::SmallBlind && s.depth_bb == 100).expect("spot");
|
||||
let frozen = pokerfreak::cfr::frozen_multi::decode(sb.open).expect("decode");
|
||||
let frozen = rechner::cfr::frozen_multi::decode(sb.open).expect("decode");
|
||||
assert_eq!(frozen, table.open.to_vec(), "the small blind's one-defender game is the shipped table");
|
||||
let tree = open_tree(&env, Seat::Button, 100.0).expect("tree");
|
||||
let solved = solve(&tree, OPEN_ITERATIONS, Rng::seeded(CFR_SEED));
|
||||
let btn = BASELINE.iter().find(|b| b.seat == Seat::Button && b.depth_bb == 100).expect("spot");
|
||||
let rebuilt = binary_row(&tree, &solved.strategy, "open").expect("row").to_vec();
|
||||
assert_eq!(pokerfreak::cfr::frozen_multi::decode(btn.open).expect("decode"), rebuilt);
|
||||
assert_eq!(rechner::cfr::frozen_multi::decode(btn.open).expect("decode"), rebuilt);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -336,7 +336,7 @@ fn more_defenders_narrow_the_open() {
|
||||
.collect();
|
||||
assert!(widths.windows(2).all(|w| w[1] <= w[0] + 0.005), "{seat:?} {depth}: {widths:?}");
|
||||
let base = BASELINE.iter().find(|b| b.seat == seat && b.depth_bb == depth).expect("baseline");
|
||||
let base = pokerfreak::cfr::frozen_multi::decode(base.open).expect("decode");
|
||||
let base = rechner::cfr::frozen_multi::decode(base.open).expect("decode");
|
||||
let last = MULTI.iter().rev().find(|s| s.seat == seat && s.depth_bb == depth).expect("spot");
|
||||
let diff = mean_abs_difference(&env, &open_row(last.rows).expect("open"), &base);
|
||||
if max_defenders(seat) >= 2 {
|
||||
|
||||
+14
-14
@@ -20,20 +20,20 @@
|
||||
//!
|
||||
//! Units: big blinds per deal of the spot (the expected result of the whole spot for the player
|
||||
//! who is first to act, so `0.01` bb is `10` milli-bb per hand dealt).
|
||||
use pokerfreak::cfr::chart_deck::ChartDeck;
|
||||
use pokerfreak::cfr::deviation::{deviations, Deviation};
|
||||
use pokerfreak::cfr::environment::Environment;
|
||||
use pokerfreak::cfr::exploitability::exploitability;
|
||||
use pokerfreak::cfr::frozen_spot::{OpenSpot, PushFoldSpot};
|
||||
use pokerfreak::cfr::frozen_strategy::{open3_strategy, open_strategy, push_fold3_strategy, push_fold_strategy};
|
||||
use pokerfreak::cfr::open3_game::open3_tree;
|
||||
use pokerfreak::cfr::open_game::open_tree;
|
||||
use pokerfreak::cfr::push_fold3_game::push_fold3_tree;
|
||||
use pokerfreak::cfr::push_fold_game::push_fold_tree;
|
||||
use pokerfreak::cfr::seat::Seat;
|
||||
use pokerfreak::cfr::walk3::{deviations3, exploitability3};
|
||||
use pokerfreak::preflop::generated_charts::{AOF_PUSH_FOLD, OPEN, PUSH_FOLD};
|
||||
use pokerfreak::preflop::generated_charts_short as short;
|
||||
use rechner::cfr::chart_deck::ChartDeck;
|
||||
use rechner::cfr::deviation::{deviations, Deviation};
|
||||
use rechner::cfr::environment::Environment;
|
||||
use rechner::cfr::exploitability::exploitability;
|
||||
use rechner::cfr::frozen_spot::{OpenSpot, PushFoldSpot};
|
||||
use rechner::cfr::frozen_strategy::{open3_strategy, open_strategy, push_fold3_strategy, push_fold_strategy};
|
||||
use rechner::cfr::open3_game::open3_tree;
|
||||
use rechner::cfr::open_game::open_tree;
|
||||
use rechner::cfr::push_fold3_game::push_fold3_tree;
|
||||
use rechner::cfr::push_fold_game::push_fold_tree;
|
||||
use rechner::cfr::seat::Seat;
|
||||
use rechner::cfr::walk3::{deviations3, exploitability3};
|
||||
use rechner::preflop::generated_charts::{AOF_PUSH_FOLD, OPEN, PUSH_FOLD};
|
||||
use rechner::preflop::generated_charts_short as short;
|
||||
|
||||
const EPSILON: f64 = 0.02;
|
||||
const EPSILON_SUPPORT: f64 = 0.05;
|
||||
|
||||
+17
-17
@@ -1,21 +1,21 @@
|
||||
//! Die Chart-Spiele mit Rake: wer was trägt, was ein Fold kostet, und dass die Grenzen enger werden.
|
||||
|
||||
use pokerfreak::cfr::environment::Environment;
|
||||
use pokerfreak::cfr::exploitability::game_value;
|
||||
use pokerfreak::cfr::multi_solve::width;
|
||||
use pokerfreak::cfr::payoffs::{postflop, share};
|
||||
use pokerfreak::cfr::multi_tree::{multi_open_tree, MultiNode, MultiOutcome};
|
||||
use pokerfreak::cfr::open_game::open_tree;
|
||||
use pokerfreak::cfr::push_fold3_game::push_fold3_tree;
|
||||
use pokerfreak::cfr::push_fold_game::push_fold_tree;
|
||||
use pokerfreak::cfr::seat::Seat;
|
||||
use pokerfreak::cfr::solve::solve;
|
||||
use pokerfreak::cfr::strategy::Strategy;
|
||||
use pokerfreak::cfr::terminal_value::terminal_value;
|
||||
use pokerfreak::cfr::tree::Payoff;
|
||||
use pokerfreak::cfr::walk3::game_value3;
|
||||
use pokerfreak::rake::ChartRake;
|
||||
use pokerfreak::rng::Rng;
|
||||
use rechner::cfr::environment::Environment;
|
||||
use rechner::cfr::exploitability::game_value;
|
||||
use rechner::cfr::multi_solve::width;
|
||||
use rechner::cfr::payoffs::{postflop, share};
|
||||
use rechner::cfr::multi_tree::{multi_open_tree, MultiNode, MultiOutcome};
|
||||
use rechner::cfr::open_game::open_tree;
|
||||
use rechner::cfr::push_fold3_game::push_fold3_tree;
|
||||
use rechner::cfr::push_fold_game::push_fold_tree;
|
||||
use rechner::cfr::seat::Seat;
|
||||
use rechner::cfr::solve::solve;
|
||||
use rechner::cfr::strategy::Strategy;
|
||||
use rechner::cfr::terminal_value::terminal_value;
|
||||
use rechner::cfr::tree::Payoff;
|
||||
use rechner::cfr::walk3::game_value3;
|
||||
use rechner::rake::ChartRake;
|
||||
use rechner::rng::Rng;
|
||||
|
||||
fn raked() -> Environment {
|
||||
Environment::frozen()
|
||||
@@ -23,7 +23,7 @@ fn raked() -> Environment {
|
||||
|
||||
#[test]
|
||||
fn the_tables_of_the_full_deck_carry_the_rake_and_short_deck_does_not() {
|
||||
use pokerfreak::cfr::chart_deck::ChartDeck;
|
||||
use rechner::cfr::chart_deck::ChartDeck;
|
||||
assert_eq!(raked().rake, ChartRake::Measured);
|
||||
assert!((raked().antes - 0.96).abs() < 1e-12);
|
||||
assert_eq!(Environment::frozen_for(ChartDeck::Short).antes, 0.0);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
use pokerfreak::cfr::hand_class::{class_combos, class_parse, CLASS_COUNT};
|
||||
use rechner::cfr::hand_class::{class_combos, class_parse, CLASS_COUNT};
|
||||
|
||||
/// Class id for a name like `"AKs"`; panics only inside tests.
|
||||
pub fn id(name: &str) -> usize {
|
||||
|
||||
+16
-16
@@ -16,21 +16,21 @@
|
||||
//! Largest error 0.136 (dominated hands: AKs over AQo and KQo), root mean square 0.058. The
|
||||
//! product of the pairwise equities (0.129 / 0.068) and other means were not better. The
|
||||
//! favourite is kept where it is clear (a lead of 0.1 or more); near-even triples may swap.
|
||||
use pokerfreak::card::Card;
|
||||
use pokerfreak::cfr::environment::Environment;
|
||||
use pokerfreak::cfr::hand_class::{class_of, CLASS_COUNT};
|
||||
use pokerfreak::cfr::open3_game::open3_tree;
|
||||
use pokerfreak::cfr::push_fold3_game::push_fold3_tree;
|
||||
use pokerfreak::cfr::seat::Seat;
|
||||
use pokerfreak::cfr::strategy::Strategy;
|
||||
use pokerfreak::cfr::three_way::three_way_shares;
|
||||
use pokerfreak::cfr::tree3::Node3;
|
||||
use pokerfreak::cfr::walk3::{exploitability3, game_value3};
|
||||
use pokerfreak::equity::monte_carlo::estimate;
|
||||
use pokerfreak::equity::query::Query;
|
||||
use pokerfreak::equity::villain_range::VillainRange;
|
||||
use pokerfreak::rng::Rng;
|
||||
use pokerfreak::variant::{rules, Variant};
|
||||
use rechner::card::Card;
|
||||
use rechner::cfr::environment::Environment;
|
||||
use rechner::cfr::hand_class::{class_of, CLASS_COUNT};
|
||||
use rechner::cfr::open3_game::open3_tree;
|
||||
use rechner::cfr::push_fold3_game::push_fold3_tree;
|
||||
use rechner::cfr::seat::Seat;
|
||||
use rechner::cfr::strategy::Strategy;
|
||||
use rechner::cfr::three_way::three_way_shares;
|
||||
use rechner::cfr::tree3::Node3;
|
||||
use rechner::cfr::walk3::{exploitability3, game_value3};
|
||||
use rechner::equity::monte_carlo::estimate;
|
||||
use rechner::equity::query::Query;
|
||||
use rechner::equity::villain_range::VillainRange;
|
||||
use rechner::rng::Rng;
|
||||
use rechner::variant::{rules, Variant};
|
||||
|
||||
const SHARE_TOLERANCE: f64 = 0.14;
|
||||
|
||||
@@ -127,7 +127,7 @@ fn triple_deal_weights_are_a_symmetric_distribution_close_to_the_pairwise_one()
|
||||
}
|
||||
}
|
||||
|
||||
fn pure(tree: &pokerfreak::cfr::tree3::Tree3, aggressive: bool) -> Strategy {
|
||||
fn pure(tree: &rechner::cfr::tree3::Tree3, aggressive: bool) -> Strategy {
|
||||
Strategy::pure(tree, |_, _| if aggressive { 1 } else { 0 })
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ Am Ende stehen die Zähler aus dem Auftrag, die null sein müssen (unbestätigte
|
||||
Züge, Raumwechsel, Doppelaktionen, Aussetzer ohne Grund), und das Guthaben des Klons ist gegen das
|
||||
Schattenlog gerechnet: jeder Kauf im Klon ist ein geklickter Kauf des Läufers.
|
||||
|
||||
Wiederholbar: gleicher Startwert, gleicher Plan, gleiche Gedenkzeiten (POKERFREAK_SEED).
|
||||
Wiederholbar: gleicher Startwert, gleicher Plan, gleiche Gedenkzeiten (SEED).
|
||||
|
||||
python3 tests/chaos_spec.py -v # Startwert chaos-1, 240 s
|
||||
CHAOS_SEED=chaos-7 CHAOS_DAUER=600 python3 tests/chaos_spec.py -v
|
||||
|
||||
@@ -222,14 +222,14 @@ class Vermessung(unittest.TestCase):
|
||||
|
||||
|
||||
class Tempo(unittest.TestCase):
|
||||
"""POKERFREAK_TEMPO waehlt das Profil: normal wie Gegner, schneller fuer viele Tische."""
|
||||
"""TEMPO waehlt das Profil: normal wie Gegner, schneller fuer viele Tische."""
|
||||
|
||||
def test_vorgabe_wie_echte_gegner(self):
|
||||
alt = _os.environ.pop("POKERFREAK_TEMPO", None)
|
||||
alt = _os.environ.pop("TEMPO", None)
|
||||
try:
|
||||
self.assertEqual(denkzeit.profil()["median_ms"], denkzeit.MENSCH["median_ms"])
|
||||
finally:
|
||||
if alt: _os.environ["POKERFREAK_TEMPO"] = alt
|
||||
if alt: _os.environ["TEMPO"] = alt
|
||||
|
||||
def test_schneller_ist_schneller_und_bleibt_gestreut(self):
|
||||
schnell = denkzeit.profil("schnell")
|
||||
|
||||
@@ -15,7 +15,7 @@ for _u in ("hand", "client", "lesen", "betrieb"):
|
||||
import tempfile # noqa: E402
|
||||
# Eigener Scratch für den Läufer, den einige Fälle laden: sonst landeten ihre Ereignisse im
|
||||
# Protokoll (30.10.: dialog_offen/dialog_zu an Big Ben 1664086 bei jedem Suite-Lauf)
|
||||
os.environ["POKERFREAK_SCRATCH"] = tempfile.mkdtemp(prefix="dialog-")
|
||||
os.environ["SCRATCH"] = tempfile.mkdtemp(prefix="dialog-")
|
||||
import dialog
|
||||
import sitzen
|
||||
import zeiger
|
||||
|
||||
+140
-140
@@ -1,140 +1,140 @@
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::engine::postflop::choose_postflop;
|
||||
use pokerfreak::exploit::thresholds::Thresholds;
|
||||
use pokerfreak::game::{ActionKind, Choice, Spot};
|
||||
use pokerfreak::sizing::candidates::candidates;
|
||||
use spot_fixture::*;
|
||||
|
||||
const BASE: Thresholds = Thresholds::BASE;
|
||||
|
||||
// round_flop: pot 10, 5 to call -> break-even exactly 1/3.
|
||||
|
||||
#[test]
|
||||
fn clear_call_when_equity_beats_the_price() {
|
||||
let d = choose_postflop(&round_flop(), &estimate(0.45, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Call);
|
||||
assert!(d.reason.contains("equity 0.45"), "{}", d.reason);
|
||||
assert!(d.reason.contains("break-even 0.33"), "{}", d.reason);
|
||||
assert!(d.reason.contains("EV"), "{}", d.reason);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clear_fold_when_equity_is_far_below_the_price() {
|
||||
let d = choose_postflop(&round_flop(), &estimate(0.15, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Fold);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn abstains_near_the_breakpoint() {
|
||||
let d = choose_postflop(&round_flop(), &estimate(0.34, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Abstain);
|
||||
assert!(d.confidence.value() > 0.0 && d.confidence.value() <= 0.3, "{d:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn abstain_band_widens_with_the_standard_error() {
|
||||
// call breakpoint = 1/3 + call_margin 0.02 = 0.3533
|
||||
let noisy = choose_postflop(&round_flop(), &estimate(0.38, 0.02), &BASE, &neutral_read());
|
||||
assert_eq!(noisy.choice, Choice::Abstain);
|
||||
let tight = choose_postflop(&round_flop(), &estimate(0.38, 0.001), &BASE, &neutral_read());
|
||||
assert_eq!(tight.choice, Choice::Call);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_margin_is_required_above_break_even() {
|
||||
let thresholds = Thresholds { abstain_band: 0.0, call_margin: 0.05, ..BASE };
|
||||
// 0.36 is above break-even (0.333) but below break-even + margin (0.383)
|
||||
let d = choose_postflop(&round_flop(), &estimate(0.36, 0.0), &thresholds, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Fold);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn value_raise_when_equity_is_high() {
|
||||
let spot = round_flop();
|
||||
let d = choose_postflop(&spot, &estimate(0.80, 0.005), &BASE, &neutral_read());
|
||||
match d.choice {
|
||||
Choice::Raise { to } => assert!(candidates(&spot).contains(&to), "{to}"),
|
||||
other => panic!("expected a raise, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_raise_below_the_value_threshold() {
|
||||
let d = choose_postflop(&round_flop(), &estimate(0.50, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Call);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn value_threshold_comes_from_the_thresholds() {
|
||||
let eager = Thresholds { value_raise: 0.45, ..BASE };
|
||||
let d = choose_postflop(&round_flop(), &estimate(0.50, 0.005), &eager, &neutral_read());
|
||||
assert!(matches!(d.choice, Choice::Raise { .. }), "{d:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checks_when_free_and_weak() {
|
||||
let spot = Spot { to_call: 0.0, legal: vec![ActionKind::Check, ActionKind::Raise], ..round_flop() };
|
||||
let d = choose_postflop(&spot, &estimate(0.30, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Check);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raises_when_free_and_strong() {
|
||||
let spot = Spot { to_call: 0.0, legal: vec![ActionKind::Check, ActionKind::Raise], ..round_flop() };
|
||||
let d = choose_postflop(&spot, &estimate(0.90, 0.005), &BASE, &neutral_read());
|
||||
assert!(matches!(d.choice, Choice::Raise { .. }), "{d:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn never_folds_when_check_is_legal() {
|
||||
let spot = Spot {
|
||||
to_call: 0.0,
|
||||
legal: vec![ActionKind::Fold, ActionKind::Check],
|
||||
..round_flop()
|
||||
};
|
||||
for share in [0.0, 0.05, 0.3, 0.9] {
|
||||
let d = choose_postflop(&spot, &estimate(share, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Check, "share {share}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_when_fold_and_check_are_not_available() {
|
||||
let spot = Spot { legal: vec![ActionKind::Call], ..round_flop() };
|
||||
let d = choose_postflop(&spot, &estimate(0.10, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Call);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raises_come_from_allowed_sizes_verbatim() {
|
||||
let spot = Spot { allowed_sizes: Some(vec![20.0, 40.0]), ..round_flop() };
|
||||
let d = choose_postflop(&spot, &estimate(0.85, 0.005), &BASE, &neutral_read());
|
||||
match d.choice {
|
||||
Choice::Raise { to } => assert!(to == 20.0 || to == 40.0, "{to}"),
|
||||
other => panic!("expected a raise, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raise_without_candidates_falls_back_to_the_passive_line() {
|
||||
let spot = Spot { allowed_sizes: Some(vec![500.0]), ..round_flop() };
|
||||
let d = choose_postflop(&spot, &estimate(0.85, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Call);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_finite_equity_abstains() {
|
||||
let d = choose_postflop(&round_flop(), &estimate(f64::NAN, 0.0), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Abstain);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn confidence_grows_with_distance_from_the_breakpoint() {
|
||||
let near = choose_postflop(&round_flop(), &estimate(0.40, 0.001), &BASE, &neutral_read());
|
||||
let far = choose_postflop(&round_flop(), &estimate(0.55, 0.001), &BASE, &neutral_read());
|
||||
assert_eq!(near.choice, Choice::Call);
|
||||
assert_eq!(far.choice, Choice::Call);
|
||||
assert!(far.confidence > near.confidence);
|
||||
assert!(far.confidence.value() <= 1.0 && near.confidence.value() > 0.0);
|
||||
}
|
||||
mod spot_fixture;
|
||||
|
||||
use rechner::engine::postflop::choose_postflop;
|
||||
use rechner::exploit::thresholds::Thresholds;
|
||||
use rechner::game::{ActionKind, Choice, Spot};
|
||||
use rechner::sizing::candidates::candidates;
|
||||
use spot_fixture::*;
|
||||
|
||||
const BASE: Thresholds = Thresholds::BASE;
|
||||
|
||||
// round_flop: pot 10, 5 to call -> break-even exactly 1/3.
|
||||
|
||||
#[test]
|
||||
fn clear_call_when_equity_beats_the_price() {
|
||||
let d = choose_postflop(&round_flop(), &estimate(0.45, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Call);
|
||||
assert!(d.reason.contains("equity 0.45"), "{}", d.reason);
|
||||
assert!(d.reason.contains("break-even 0.33"), "{}", d.reason);
|
||||
assert!(d.reason.contains("EV"), "{}", d.reason);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clear_fold_when_equity_is_far_below_the_price() {
|
||||
let d = choose_postflop(&round_flop(), &estimate(0.15, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Fold);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn abstains_near_the_breakpoint() {
|
||||
let d = choose_postflop(&round_flop(), &estimate(0.34, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Abstain);
|
||||
assert!(d.confidence.value() > 0.0 && d.confidence.value() <= 0.3, "{d:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn abstain_band_widens_with_the_standard_error() {
|
||||
// call breakpoint = 1/3 + call_margin 0.02 = 0.3533
|
||||
let noisy = choose_postflop(&round_flop(), &estimate(0.38, 0.02), &BASE, &neutral_read());
|
||||
assert_eq!(noisy.choice, Choice::Abstain);
|
||||
let tight = choose_postflop(&round_flop(), &estimate(0.38, 0.001), &BASE, &neutral_read());
|
||||
assert_eq!(tight.choice, Choice::Call);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_margin_is_required_above_break_even() {
|
||||
let thresholds = Thresholds { abstain_band: 0.0, call_margin: 0.05, ..BASE };
|
||||
// 0.36 is above break-even (0.333) but below break-even + margin (0.383)
|
||||
let d = choose_postflop(&round_flop(), &estimate(0.36, 0.0), &thresholds, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Fold);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn value_raise_when_equity_is_high() {
|
||||
let spot = round_flop();
|
||||
let d = choose_postflop(&spot, &estimate(0.80, 0.005), &BASE, &neutral_read());
|
||||
match d.choice {
|
||||
Choice::Raise { to } => assert!(candidates(&spot).contains(&to), "{to}"),
|
||||
other => panic!("expected a raise, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_raise_below_the_value_threshold() {
|
||||
let d = choose_postflop(&round_flop(), &estimate(0.50, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Call);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn value_threshold_comes_from_the_thresholds() {
|
||||
let eager = Thresholds { value_raise: 0.45, ..BASE };
|
||||
let d = choose_postflop(&round_flop(), &estimate(0.50, 0.005), &eager, &neutral_read());
|
||||
assert!(matches!(d.choice, Choice::Raise { .. }), "{d:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checks_when_free_and_weak() {
|
||||
let spot = Spot { to_call: 0.0, legal: vec![ActionKind::Check, ActionKind::Raise], ..round_flop() };
|
||||
let d = choose_postflop(&spot, &estimate(0.30, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Check);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raises_when_free_and_strong() {
|
||||
let spot = Spot { to_call: 0.0, legal: vec![ActionKind::Check, ActionKind::Raise], ..round_flop() };
|
||||
let d = choose_postflop(&spot, &estimate(0.90, 0.005), &BASE, &neutral_read());
|
||||
assert!(matches!(d.choice, Choice::Raise { .. }), "{d:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn never_folds_when_check_is_legal() {
|
||||
let spot = Spot {
|
||||
to_call: 0.0,
|
||||
legal: vec![ActionKind::Fold, ActionKind::Check],
|
||||
..round_flop()
|
||||
};
|
||||
for share in [0.0, 0.05, 0.3, 0.9] {
|
||||
let d = choose_postflop(&spot, &estimate(share, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Check, "share {share}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_when_fold_and_check_are_not_available() {
|
||||
let spot = Spot { legal: vec![ActionKind::Call], ..round_flop() };
|
||||
let d = choose_postflop(&spot, &estimate(0.10, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Call);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raises_come_from_allowed_sizes_verbatim() {
|
||||
let spot = Spot { allowed_sizes: Some(vec![20.0, 40.0]), ..round_flop() };
|
||||
let d = choose_postflop(&spot, &estimate(0.85, 0.005), &BASE, &neutral_read());
|
||||
match d.choice {
|
||||
Choice::Raise { to } => assert!(to == 20.0 || to == 40.0, "{to}"),
|
||||
other => panic!("expected a raise, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raise_without_candidates_falls_back_to_the_passive_line() {
|
||||
let spot = Spot { allowed_sizes: Some(vec![500.0]), ..round_flop() };
|
||||
let d = choose_postflop(&spot, &estimate(0.85, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Call);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_finite_equity_abstains() {
|
||||
let d = choose_postflop(&round_flop(), &estimate(f64::NAN, 0.0), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Abstain);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn confidence_grows_with_distance_from_the_breakpoint() {
|
||||
let near = choose_postflop(&round_flop(), &estimate(0.40, 0.001), &BASE, &neutral_read());
|
||||
let far = choose_postflop(&round_flop(), &estimate(0.55, 0.001), &BASE, &neutral_read());
|
||||
assert_eq!(near.choice, Choice::Call);
|
||||
assert_eq!(far.choice, Choice::Call);
|
||||
assert!(far.confidence > near.confidence);
|
||||
assert!(far.confidence.value() <= 1.0 && near.confidence.value() > 0.0);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::engine::from_plan::from_plan;
|
||||
use pokerfreak::game::{ActionKind, Choice, Spot};
|
||||
use pokerfreak::preflop::plan::ChartAction;
|
||||
use rechner::engine::from_plan::from_plan;
|
||||
use rechner::game::{ActionKind, Choice, Spot};
|
||||
use rechner::preflop::plan::ChartAction;
|
||||
use spot_fixture::*;
|
||||
|
||||
fn free_spot() -> Spot {
|
||||
|
||||
+116
-116
@@ -1,116 +1,116 @@
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::engine::effective::effective;
|
||||
use pokerfreak::engine::multiway::{
|
||||
extra_call_margin, extra_value_raise, realized_share, semibluff_allowed,
|
||||
};
|
||||
use pokerfreak::engine::postflop::choose_postflop;
|
||||
use pokerfreak::exploit::thresholds::Thresholds;
|
||||
use pokerfreak::game::Choice;
|
||||
use pokerfreak::read::draw::Draw;
|
||||
use pokerfreak::read::made::Made;
|
||||
use pokerfreak::read::suit_pattern::SuitPattern;
|
||||
use spot_fixture::*;
|
||||
|
||||
const BASE: Thresholds = Thresholds::BASE;
|
||||
|
||||
fn close(a: f64, b: f64) -> bool {
|
||||
(a - b).abs() < 1e-9
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn heads_up_changes_nothing() {
|
||||
assert_eq!(realized_share(0.5, 1), 0.5);
|
||||
assert_eq!(extra_call_margin(1), 0.0);
|
||||
assert_eq!(extra_value_raise(1), 0.0);
|
||||
assert_eq!(realized_share(0.5, 0), 0.5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_extra_villain_discounts_equity_and_raises_the_bars() {
|
||||
assert!(close(realized_share(0.5, 4), 0.5 * 0.97f64.powi(3)));
|
||||
assert!(close(extra_call_margin(3), 0.02));
|
||||
assert!(close(extra_value_raise(3), 0.10));
|
||||
assert!(realized_share(0.5, 5) < realized_share(0.5, 4));
|
||||
assert!(extra_value_raise(5) > extra_value_raise(4));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn semibluffs_need_at_most_two_villains() {
|
||||
assert!(semibluff_allowed(0) && semibluff_allowed(1) && semibluff_allowed(2));
|
||||
assert!(!semibluff_allowed(3) && !semibluff_allowed(5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn effective_thresholds_combine_texture_and_player_count() {
|
||||
// Medium hand, dry board (wetness 0.1): texture gives margin 0.034, value 0.652.
|
||||
let read = read_of(Made::MiddlePair, Draw::None, 0, SuitPattern::Rainbow, 0.1);
|
||||
let spot = with_villains(round_flop(), 3);
|
||||
let e = effective(&spot, 0.5, &BASE, &read);
|
||||
assert_eq!(e.villains, 3);
|
||||
assert!(close(e.share, 0.5 * 0.97 * 0.97), "{e:?}");
|
||||
assert!(close(e.call_margin, 0.034 + 0.02), "{e:?}");
|
||||
assert!(close(e.value_raise, 0.652 + 0.10), "{e:?}");
|
||||
assert!(e.value_ok && e.raise_ok && !e.semibluff_ok);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn folded_villains_do_not_count() {
|
||||
let mut spot = with_villains(round_flop(), 4);
|
||||
spot.villains[0].folded = true;
|
||||
spot.villains[1].folded = true;
|
||||
let e = effective(&spot, 0.5, &BASE, &neutral_read());
|
||||
assert_eq!(e.villains, 2);
|
||||
assert!(e.semibluff_ok);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_live_villain_counts_as_one() {
|
||||
let e = effective(&with_villains(round_flop(), 0), 0.5, &BASE, &neutral_read());
|
||||
assert_eq!(e.villains, 1);
|
||||
assert_eq!(e.share, 0.5);
|
||||
}
|
||||
|
||||
// round_flop: pot 10, 5 to call, break-even 1/3.
|
||||
|
||||
#[test]
|
||||
fn a_share_that_calls_heads_up_folds_four_way() {
|
||||
let share = estimate(0.38, 0.002);
|
||||
let heads_up = choose_postflop(&with_villains(round_flop(), 1), &share, &BASE, &neutral_read());
|
||||
assert_eq!(heads_up.choice, Choice::Call, "{heads_up:?}");
|
||||
let four_way = choose_postflop(&with_villains(round_flop(), 4), &share, &BASE, &neutral_read());
|
||||
assert_eq!(four_way.choice, Choice::Fold, "{four_way:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_share_that_value_raises_heads_up_only_calls_three_way() {
|
||||
let share = estimate(0.64, 0.002);
|
||||
let heads_up = choose_postflop(&with_villains(round_flop(), 1), &share, &BASE, &neutral_read());
|
||||
assert!(matches!(heads_up.choice, Choice::Raise { .. }), "{heads_up:?}");
|
||||
let three_way = choose_postflop(&with_villains(round_flop(), 3), &share, &BASE, &neutral_read());
|
||||
assert_eq!(three_way.choice, Choice::Call, "{three_way:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn semibluff_works_two_way_but_not_three_way() {
|
||||
// Folds are independent per villain (`exploit::table_fold`), so two-way fold equity
|
||||
// is the square of one villain's. With foldy villains (scale 1.6: 0.67 each to a pot
|
||||
// raise) the semibluff pays two-way; three-way it is not allowed at all.
|
||||
let share = estimate(0.45, 0.005);
|
||||
let foldy = Thresholds { fold_equity_scale: 1.6, ..BASE };
|
||||
let two = choose_postflop(&with_villains(round_flop(), 2), &share, &foldy, &flush_draw_read());
|
||||
assert!(matches!(two.choice, Choice::Raise { .. }), "{two:?}");
|
||||
let three = choose_postflop(&with_villains(round_flop(), 3), &share, &foldy, &flush_draw_read());
|
||||
assert_eq!(three.choice, Choice::Call, "{three:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_reason_names_the_player_count_when_multiway() {
|
||||
let d = choose_postflop(
|
||||
&with_villains(round_flop(), 3),
|
||||
&estimate(0.45, 0.002),
|
||||
&BASE,
|
||||
&neutral_read(),
|
||||
);
|
||||
assert!(d.reason.contains("3-way"), "{}", d.reason);
|
||||
}
|
||||
mod spot_fixture;
|
||||
|
||||
use rechner::engine::effective::effective;
|
||||
use rechner::engine::multiway::{
|
||||
extra_call_margin, extra_value_raise, realized_share, semibluff_allowed,
|
||||
};
|
||||
use rechner::engine::postflop::choose_postflop;
|
||||
use rechner::exploit::thresholds::Thresholds;
|
||||
use rechner::game::Choice;
|
||||
use rechner::read::draw::Draw;
|
||||
use rechner::read::made::Made;
|
||||
use rechner::read::suit_pattern::SuitPattern;
|
||||
use spot_fixture::*;
|
||||
|
||||
const BASE: Thresholds = Thresholds::BASE;
|
||||
|
||||
fn close(a: f64, b: f64) -> bool {
|
||||
(a - b).abs() < 1e-9
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn heads_up_changes_nothing() {
|
||||
assert_eq!(realized_share(0.5, 1), 0.5);
|
||||
assert_eq!(extra_call_margin(1), 0.0);
|
||||
assert_eq!(extra_value_raise(1), 0.0);
|
||||
assert_eq!(realized_share(0.5, 0), 0.5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_extra_villain_discounts_equity_and_raises_the_bars() {
|
||||
assert!(close(realized_share(0.5, 4), 0.5 * 0.97f64.powi(3)));
|
||||
assert!(close(extra_call_margin(3), 0.02));
|
||||
assert!(close(extra_value_raise(3), 0.10));
|
||||
assert!(realized_share(0.5, 5) < realized_share(0.5, 4));
|
||||
assert!(extra_value_raise(5) > extra_value_raise(4));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn semibluffs_need_at_most_two_villains() {
|
||||
assert!(semibluff_allowed(0) && semibluff_allowed(1) && semibluff_allowed(2));
|
||||
assert!(!semibluff_allowed(3) && !semibluff_allowed(5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn effective_thresholds_combine_texture_and_player_count() {
|
||||
// Medium hand, dry board (wetness 0.1): texture gives margin 0.034, value 0.652.
|
||||
let read = read_of(Made::MiddlePair, Draw::None, 0, SuitPattern::Rainbow, 0.1);
|
||||
let spot = with_villains(round_flop(), 3);
|
||||
let e = effective(&spot, 0.5, &BASE, &read);
|
||||
assert_eq!(e.villains, 3);
|
||||
assert!(close(e.share, 0.5 * 0.97 * 0.97), "{e:?}");
|
||||
assert!(close(e.call_margin, 0.034 + 0.02), "{e:?}");
|
||||
assert!(close(e.value_raise, 0.652 + 0.10), "{e:?}");
|
||||
assert!(e.value_ok && e.raise_ok && !e.semibluff_ok);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn folded_villains_do_not_count() {
|
||||
let mut spot = with_villains(round_flop(), 4);
|
||||
spot.villains[0].folded = true;
|
||||
spot.villains[1].folded = true;
|
||||
let e = effective(&spot, 0.5, &BASE, &neutral_read());
|
||||
assert_eq!(e.villains, 2);
|
||||
assert!(e.semibluff_ok);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_live_villain_counts_as_one() {
|
||||
let e = effective(&with_villains(round_flop(), 0), 0.5, &BASE, &neutral_read());
|
||||
assert_eq!(e.villains, 1);
|
||||
assert_eq!(e.share, 0.5);
|
||||
}
|
||||
|
||||
// round_flop: pot 10, 5 to call, break-even 1/3.
|
||||
|
||||
#[test]
|
||||
fn a_share_that_calls_heads_up_folds_four_way() {
|
||||
let share = estimate(0.38, 0.002);
|
||||
let heads_up = choose_postflop(&with_villains(round_flop(), 1), &share, &BASE, &neutral_read());
|
||||
assert_eq!(heads_up.choice, Choice::Call, "{heads_up:?}");
|
||||
let four_way = choose_postflop(&with_villains(round_flop(), 4), &share, &BASE, &neutral_read());
|
||||
assert_eq!(four_way.choice, Choice::Fold, "{four_way:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_share_that_value_raises_heads_up_only_calls_three_way() {
|
||||
let share = estimate(0.64, 0.002);
|
||||
let heads_up = choose_postflop(&with_villains(round_flop(), 1), &share, &BASE, &neutral_read());
|
||||
assert!(matches!(heads_up.choice, Choice::Raise { .. }), "{heads_up:?}");
|
||||
let three_way = choose_postflop(&with_villains(round_flop(), 3), &share, &BASE, &neutral_read());
|
||||
assert_eq!(three_way.choice, Choice::Call, "{three_way:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn semibluff_works_two_way_but_not_three_way() {
|
||||
// Folds are independent per villain (`exploit::table_fold`), so two-way fold equity
|
||||
// is the square of one villain's. With foldy villains (scale 1.6: 0.67 each to a pot
|
||||
// raise) the semibluff pays two-way; three-way it is not allowed at all.
|
||||
let share = estimate(0.45, 0.005);
|
||||
let foldy = Thresholds { fold_equity_scale: 1.6, ..BASE };
|
||||
let two = choose_postflop(&with_villains(round_flop(), 2), &share, &foldy, &flush_draw_read());
|
||||
assert!(matches!(two.choice, Choice::Raise { .. }), "{two:?}");
|
||||
let three = choose_postflop(&with_villains(round_flop(), 3), &share, &foldy, &flush_draw_read());
|
||||
assert_eq!(three.choice, Choice::Call, "{three:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_reason_names_the_player_count_when_multiway() {
|
||||
let d = choose_postflop(
|
||||
&with_villains(round_flop(), 3),
|
||||
&estimate(0.45, 0.002),
|
||||
&BASE,
|
||||
&neutral_read(),
|
||||
);
|
||||
assert!(d.reason.contains("3-way"), "{}", d.reason);
|
||||
}
|
||||
|
||||
+287
-287
@@ -1,287 +1,287 @@
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::card::deck;
|
||||
use pokerfreak::engine::from_plan::from_plan;
|
||||
use pokerfreak::engine::postflop::choose_postflop;
|
||||
use pokerfreak::equity::estimate::Estimate;
|
||||
use pokerfreak::exploit::thresholds::Thresholds;
|
||||
use pokerfreak::game::{ActionKind, Choice, Decision, Spot, Street, Villain};
|
||||
use pokerfreak::guard::enforce::enforce;
|
||||
use pokerfreak::guard::settle::settle;
|
||||
use pokerfreak::preflop::plan::{ChartAction, PreflopPlan};
|
||||
use pokerfreak::read::draw::Draw;
|
||||
use pokerfreak::read::hand_read::HandRead;
|
||||
use pokerfreak::read::made::Made;
|
||||
use pokerfreak::read::suit_pattern::SuitPattern;
|
||||
use pokerfreak::rng::Rng;
|
||||
use pokerfreak::variant::{ActionShape, Variant};
|
||||
|
||||
const CASES: usize = 3000;
|
||||
const POSTFLOP_CASES: usize = 4000;
|
||||
|
||||
/// Tiny generator monad over the seeded Rng: each draw returns the value and the next Rng.
|
||||
fn unit(rng: Rng) -> (f64, Rng) {
|
||||
rng.unit()
|
||||
}
|
||||
|
||||
fn below(rng: Rng, bound: u64) -> (u64, Rng) {
|
||||
rng.below(bound)
|
||||
}
|
||||
|
||||
fn chips(rng: Rng, scale: f64) -> (f64, Rng) {
|
||||
let (kind, rng) = below(rng, 12);
|
||||
let (x, rng) = unit(rng);
|
||||
let value = match kind {
|
||||
0 => 0.0,
|
||||
1 => 0.01 * x,
|
||||
_ => (x * scale * 100.0).round() / 100.0,
|
||||
};
|
||||
(value, rng)
|
||||
}
|
||||
|
||||
fn subset_of_legal(rng: Rng) -> (Vec<ActionKind>, Rng) {
|
||||
let (mask, rng) = below(rng, 15);
|
||||
let kinds: Vec<ActionKind> = ActionKind::ALL
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(i, _)| (mask + 1) >> i & 1 == 1)
|
||||
.map(|(_, k)| *k)
|
||||
.collect();
|
||||
(kinds, rng)
|
||||
}
|
||||
|
||||
fn allowed_list(rng: Rng) -> (Option<Vec<f64>>, Rng) {
|
||||
let (on, rng) = below(rng, 2);
|
||||
if on == 0 {
|
||||
return (None, rng);
|
||||
}
|
||||
let (n, rng) = below(rng, 5);
|
||||
let (values, rng) = (0..n).fold((vec![], rng), |(mut acc, rng), _| {
|
||||
let (v, rng) = chips(rng, 6.0);
|
||||
acc.push(v);
|
||||
(acc, rng)
|
||||
});
|
||||
(Some(values), rng)
|
||||
}
|
||||
|
||||
fn random_spot(rng: Rng) -> (Spot, Rng) {
|
||||
let (v, rng) = below(rng, Variant::ALL.len() as u64);
|
||||
let variant = Variant::ALL[v as usize];
|
||||
let (s, rng) = below(rng, 4);
|
||||
let street = Street::ALL[s as usize];
|
||||
let (hole, rng) = (spot_fixture::cards("Ah 5h"), rng);
|
||||
let (pot, rng) = chips(rng, 20.0);
|
||||
let (to_call, rng) = chips(rng, 5.0);
|
||||
let (stack, rng) = chips(rng, 10.0);
|
||||
let (min_on, rng) = below(rng, 2);
|
||||
let (min, rng) = chips(rng, 2.0);
|
||||
let (max_on, rng) = below(rng, 2);
|
||||
let (max, rng) = chips(rng, 15.0);
|
||||
let (legal, rng) = subset_of_legal(rng);
|
||||
let (allowed, rng) = allowed_list(rng);
|
||||
let (nv, rng) = below(rng, 6);
|
||||
let (folded_mask, rng) = below(rng, 64);
|
||||
let spot = Spot {
|
||||
variant,
|
||||
street,
|
||||
board: deck::full().into_iter().skip(10).take(street.board_len()).collect(),
|
||||
hero_cards: hole,
|
||||
pot,
|
||||
to_call,
|
||||
hero_stack: stack,
|
||||
min_raise_to: (min_on == 1).then_some(min),
|
||||
max_raise_to: (max_on == 1).then_some(max),
|
||||
legal,
|
||||
allowed_sizes: allowed,
|
||||
villains: (0..nv)
|
||||
.map(|i| Villain { seat: i as u8, folded: i < 5 && folded_mask >> i & 1 == 1 && folded_mask % 3 == 0, ..spot_fixture::villain(0) })
|
||||
.collect(),
|
||||
..spot_fixture::flop()
|
||||
};
|
||||
(spot, rng)
|
||||
}
|
||||
|
||||
fn random_estimate(rng: Rng) -> (Estimate, Rng) {
|
||||
let (share, rng) = unit(rng);
|
||||
let (se, rng) = unit(rng);
|
||||
(spot_fixture::estimate(share, se * 0.05), rng)
|
||||
}
|
||||
|
||||
const MADES: [Made; 16] = [
|
||||
Made::Air, Made::BoardOnly, Made::Underpair, Made::BottomPair, Made::MiddlePair,
|
||||
Made::TopPairWeakKicker, Made::TopPairGoodKicker, Made::Overpair, Made::TwoPair, Made::Set,
|
||||
Made::Trips, Made::Straight, Made::Flush, Made::FullHouse, Made::Quads, Made::StraightFlush,
|
||||
];
|
||||
const DRAWS: [Draw; 6] = [Draw::None, Draw::Backdoor, Draw::Gutshot, Draw::OpenEnded, Draw::Flush, Draw::Combo];
|
||||
const SUITS: [SuitPattern; 4] =
|
||||
[SuitPattern::Rainbow, SuitPattern::TwoTone, SuitPattern::Monotone, SuitPattern::FourFlush];
|
||||
|
||||
fn random_read(rng: Rng) -> (HandRead, Rng) {
|
||||
let (m, rng) = below(rng, MADES.len() as u64);
|
||||
let (d, rng) = below(rng, DRAWS.len() as u64);
|
||||
let (outs, rng) = below(rng, 16);
|
||||
let (s, rng) = below(rng, SUITS.len() as u64);
|
||||
let (wet, rng) = unit(rng);
|
||||
let (odd, rng) = below(rng, 20);
|
||||
let wetness = if odd == 0 { f64::NAN } else { wet };
|
||||
(
|
||||
spot_fixture::read_of(MADES[m as usize], DRAWS[d as usize], outs as u8, SUITS[s as usize], wetness),
|
||||
rng,
|
||||
)
|
||||
}
|
||||
|
||||
fn random_plan(rng: Rng) -> (PreflopPlan, Rng) {
|
||||
let (a, rng) = below(rng, 4);
|
||||
let (certainty, rng) = unit(rng);
|
||||
let action = [ChartAction::Fold, ChartAction::Call, ChartAction::Raise, ChartAction::Jam][a as usize];
|
||||
(spot_fixture::plan(action, certainty), rng)
|
||||
}
|
||||
|
||||
fn random_thresholds(rng: Rng) -> (Thresholds, Rng) {
|
||||
let (a, rng) = unit(rng);
|
||||
let (b, rng) = unit(rng);
|
||||
let (c, rng) = unit(rng);
|
||||
let (d, rng) = unit(rng);
|
||||
(
|
||||
Thresholds {
|
||||
call_margin: a * 0.1,
|
||||
value_raise: 0.4 + b * 0.5,
|
||||
abstain_band: c * 0.05,
|
||||
fold_equity_scale: d * 2.0,
|
||||
range_width_scale: 1.0,
|
||||
},
|
||||
rng,
|
||||
)
|
||||
}
|
||||
|
||||
fn assert_sound(spot: &Spot, decision: &Decision, label: &str) {
|
||||
let ctx = format!("{label}: {spot:?} -> {decision:?}");
|
||||
if let Some(kind) = decision.choice.kind() {
|
||||
assert!(spot.is_legal(kind), "illegal kind. {ctx}");
|
||||
if kind == ActionKind::Fold {
|
||||
assert!(!spot.is_legal(ActionKind::Check), "fold with check legal. {ctx}");
|
||||
}
|
||||
}
|
||||
assert!((0.0..=1.0).contains(&decision.confidence.value()), "{ctx}");
|
||||
if let Choice::Raise { to } = decision.choice {
|
||||
assert!(to.is_finite() && to > 0.0, "{ctx}");
|
||||
assert!(to <= spot.hero_stack, "unaffordable. {ctx}");
|
||||
if let Some(allowed) = &spot.allowed_sizes {
|
||||
assert!(allowed.contains(&to), "not from allowedSizes. {ctx}");
|
||||
}
|
||||
if let Some(min) = spot.min_raise_to {
|
||||
assert!(to >= min || to == spot.hero_stack, "below min and not all-in. {ctx}");
|
||||
}
|
||||
if let Some(max) = spot.max_raise_to {
|
||||
assert!(to <= max, "above max. {ctx}");
|
||||
}
|
||||
if spot.rules().shape == ActionShape::Binary {
|
||||
assert!(to == spot.hero_stack || Some(to) == spot.max_raise_to || spot.allowed_sizes.is_some(), "{ctx}");
|
||||
}
|
||||
}
|
||||
let after = settle(spot, decision.choice);
|
||||
assert!(after.stack >= 0.0, "negative stack. {ctx}");
|
||||
assert!(
|
||||
(after.stack + after.pot - (spot.hero_stack + spot.pot)).abs() < 1e-9,
|
||||
"chips not conserved. {ctx}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn postflop_choices_survive_enforcement_on_random_spots() {
|
||||
let rng = Rng::seeded(0xD1CE);
|
||||
let _ = (0..POSTFLOP_CASES).fold(rng, |rng, _| {
|
||||
let (spot, rng) = random_spot(rng);
|
||||
let (est, rng) = random_estimate(rng);
|
||||
let (th, rng) = random_thresholds(rng);
|
||||
let (read, rng) = random_read(rng);
|
||||
let raw = choose_postflop(&spot, &est, &th, &read);
|
||||
let enforced = enforce(&spot, raw);
|
||||
assert_sound(&spot, &enforced, "postflop");
|
||||
if enforced.choice == Choice::Abstain {
|
||||
assert!(enforced.confidence.value() <= 0.3, "abstain too confident: {enforced:?}");
|
||||
}
|
||||
rng
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preflop_plans_survive_enforcement_on_random_spots() {
|
||||
let rng = Rng::seeded(0xBEEF);
|
||||
let _ = (0..CASES).fold(rng, |rng, _| {
|
||||
let (spot, rng) = random_spot(rng);
|
||||
let (plan, rng) = random_plan(rng);
|
||||
let raw = from_plan(&spot, &plan);
|
||||
assert_sound(&spot, &enforce(&spot, raw), "from_plan");
|
||||
rng
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enforce_is_sound_for_arbitrary_decisions() {
|
||||
let rng = Rng::seeded(0xFACE);
|
||||
let _ = (0..CASES).fold(rng, |rng, _| {
|
||||
let (spot, rng) = random_spot(rng);
|
||||
let (k, rng) = below(rng, 6);
|
||||
let (size, rng) = chips(rng, 30.0);
|
||||
let choice = match k {
|
||||
0 => Choice::Fold,
|
||||
1 => Choice::Check,
|
||||
2 => Choice::Call,
|
||||
3 => Choice::Raise { to: size },
|
||||
4 => Choice::Raise { to: f64::NAN },
|
||||
_ => Choice::Abstain,
|
||||
};
|
||||
assert_sound(&spot, &enforce(&spot, Decision::new(choice, 0.5, "arbitrary")), "enforce");
|
||||
rng
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enforce_is_idempotent() {
|
||||
let rng = Rng::seeded(0xABCD);
|
||||
let _ = (0..CASES).fold(rng, |rng, _| {
|
||||
let (spot, rng) = random_spot(rng);
|
||||
let (est, rng) = random_estimate(rng);
|
||||
let (read, rng) = random_read(rng);
|
||||
let once = enforce(&spot, choose_postflop(&spot, &est, &Thresholds::BASE, &read));
|
||||
let twice = enforce(&spot, once.clone());
|
||||
assert_eq!(once.choice, twice.choice, "{spot:?}");
|
||||
rng
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn postflop_raise_sizes_come_from_the_menu_and_confidence_is_bounded_before_enforcement() {
|
||||
let rng = Rng::seeded(0x5EED);
|
||||
let _ = (0..POSTFLOP_CASES).fold(rng, |rng, _| {
|
||||
let (spot, rng) = random_spot(rng);
|
||||
let (est, rng) = random_estimate(rng);
|
||||
let (th, rng) = random_thresholds(rng);
|
||||
let (read, rng) = random_read(rng);
|
||||
let raw = choose_postflop(&spot, &est, &th, &read);
|
||||
assert!((0.0..=1.0).contains(&raw.confidence.value()), "{raw:?}");
|
||||
if raw.choice == Choice::Abstain {
|
||||
assert!(raw.confidence.value() <= 0.3, "{raw:?}");
|
||||
}
|
||||
if let (Choice::Raise { to }, Some(menu)) = (raw.choice, &spot.allowed_sizes) {
|
||||
assert!(menu.contains(&to), "raw raise {to} not in {menu:?}");
|
||||
}
|
||||
rng
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nothing_beats_nothing_never_raises_on_the_board_alone() {
|
||||
let rng = Rng::seeded(0xB0A2D);
|
||||
let _ = (0..CASES).fold(rng, |rng, _| {
|
||||
let (spot, rng) = random_spot(rng);
|
||||
let (est, rng) = random_estimate(rng);
|
||||
let (th, rng) = random_thresholds(rng);
|
||||
let (read, rng) = random_read(rng);
|
||||
let read = HandRead { made: Made::BoardOnly, ..read };
|
||||
let raw = choose_postflop(&spot, &est, &th, &read);
|
||||
assert!(!matches!(raw.choice, Choice::Raise { .. }), "{spot:?} {raw:?}");
|
||||
rng
|
||||
});
|
||||
}
|
||||
mod spot_fixture;
|
||||
|
||||
use rechner::card::deck;
|
||||
use rechner::engine::from_plan::from_plan;
|
||||
use rechner::engine::postflop::choose_postflop;
|
||||
use rechner::equity::estimate::Estimate;
|
||||
use rechner::exploit::thresholds::Thresholds;
|
||||
use rechner::game::{ActionKind, Choice, Decision, Spot, Street, Villain};
|
||||
use rechner::guard::enforce::enforce;
|
||||
use rechner::guard::settle::settle;
|
||||
use rechner::preflop::plan::{ChartAction, PreflopPlan};
|
||||
use rechner::read::draw::Draw;
|
||||
use rechner::read::hand_read::HandRead;
|
||||
use rechner::read::made::Made;
|
||||
use rechner::read::suit_pattern::SuitPattern;
|
||||
use rechner::rng::Rng;
|
||||
use rechner::variant::{ActionShape, Variant};
|
||||
|
||||
const CASES: usize = 3000;
|
||||
const POSTFLOP_CASES: usize = 4000;
|
||||
|
||||
/// Tiny generator monad over the seeded Rng: each draw returns the value and the next Rng.
|
||||
fn unit(rng: Rng) -> (f64, Rng) {
|
||||
rng.unit()
|
||||
}
|
||||
|
||||
fn below(rng: Rng, bound: u64) -> (u64, Rng) {
|
||||
rng.below(bound)
|
||||
}
|
||||
|
||||
fn chips(rng: Rng, scale: f64) -> (f64, Rng) {
|
||||
let (kind, rng) = below(rng, 12);
|
||||
let (x, rng) = unit(rng);
|
||||
let value = match kind {
|
||||
0 => 0.0,
|
||||
1 => 0.01 * x,
|
||||
_ => (x * scale * 100.0).round() / 100.0,
|
||||
};
|
||||
(value, rng)
|
||||
}
|
||||
|
||||
fn subset_of_legal(rng: Rng) -> (Vec<ActionKind>, Rng) {
|
||||
let (mask, rng) = below(rng, 15);
|
||||
let kinds: Vec<ActionKind> = ActionKind::ALL
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(i, _)| (mask + 1) >> i & 1 == 1)
|
||||
.map(|(_, k)| *k)
|
||||
.collect();
|
||||
(kinds, rng)
|
||||
}
|
||||
|
||||
fn allowed_list(rng: Rng) -> (Option<Vec<f64>>, Rng) {
|
||||
let (on, rng) = below(rng, 2);
|
||||
if on == 0 {
|
||||
return (None, rng);
|
||||
}
|
||||
let (n, rng) = below(rng, 5);
|
||||
let (values, rng) = (0..n).fold((vec![], rng), |(mut acc, rng), _| {
|
||||
let (v, rng) = chips(rng, 6.0);
|
||||
acc.push(v);
|
||||
(acc, rng)
|
||||
});
|
||||
(Some(values), rng)
|
||||
}
|
||||
|
||||
fn random_spot(rng: Rng) -> (Spot, Rng) {
|
||||
let (v, rng) = below(rng, Variant::ALL.len() as u64);
|
||||
let variant = Variant::ALL[v as usize];
|
||||
let (s, rng) = below(rng, 4);
|
||||
let street = Street::ALL[s as usize];
|
||||
let (hole, rng) = (spot_fixture::cards("Ah 5h"), rng);
|
||||
let (pot, rng) = chips(rng, 20.0);
|
||||
let (to_call, rng) = chips(rng, 5.0);
|
||||
let (stack, rng) = chips(rng, 10.0);
|
||||
let (min_on, rng) = below(rng, 2);
|
||||
let (min, rng) = chips(rng, 2.0);
|
||||
let (max_on, rng) = below(rng, 2);
|
||||
let (max, rng) = chips(rng, 15.0);
|
||||
let (legal, rng) = subset_of_legal(rng);
|
||||
let (allowed, rng) = allowed_list(rng);
|
||||
let (nv, rng) = below(rng, 6);
|
||||
let (folded_mask, rng) = below(rng, 64);
|
||||
let spot = Spot {
|
||||
variant,
|
||||
street,
|
||||
board: deck::full().into_iter().skip(10).take(street.board_len()).collect(),
|
||||
hero_cards: hole,
|
||||
pot,
|
||||
to_call,
|
||||
hero_stack: stack,
|
||||
min_raise_to: (min_on == 1).then_some(min),
|
||||
max_raise_to: (max_on == 1).then_some(max),
|
||||
legal,
|
||||
allowed_sizes: allowed,
|
||||
villains: (0..nv)
|
||||
.map(|i| Villain { seat: i as u8, folded: i < 5 && folded_mask >> i & 1 == 1 && folded_mask % 3 == 0, ..spot_fixture::villain(0) })
|
||||
.collect(),
|
||||
..spot_fixture::flop()
|
||||
};
|
||||
(spot, rng)
|
||||
}
|
||||
|
||||
fn random_estimate(rng: Rng) -> (Estimate, Rng) {
|
||||
let (share, rng) = unit(rng);
|
||||
let (se, rng) = unit(rng);
|
||||
(spot_fixture::estimate(share, se * 0.05), rng)
|
||||
}
|
||||
|
||||
const MADES: [Made; 16] = [
|
||||
Made::Air, Made::BoardOnly, Made::Underpair, Made::BottomPair, Made::MiddlePair,
|
||||
Made::TopPairWeakKicker, Made::TopPairGoodKicker, Made::Overpair, Made::TwoPair, Made::Set,
|
||||
Made::Trips, Made::Straight, Made::Flush, Made::FullHouse, Made::Quads, Made::StraightFlush,
|
||||
];
|
||||
const DRAWS: [Draw; 6] = [Draw::None, Draw::Backdoor, Draw::Gutshot, Draw::OpenEnded, Draw::Flush, Draw::Combo];
|
||||
const SUITS: [SuitPattern; 4] =
|
||||
[SuitPattern::Rainbow, SuitPattern::TwoTone, SuitPattern::Monotone, SuitPattern::FourFlush];
|
||||
|
||||
fn random_read(rng: Rng) -> (HandRead, Rng) {
|
||||
let (m, rng) = below(rng, MADES.len() as u64);
|
||||
let (d, rng) = below(rng, DRAWS.len() as u64);
|
||||
let (outs, rng) = below(rng, 16);
|
||||
let (s, rng) = below(rng, SUITS.len() as u64);
|
||||
let (wet, rng) = unit(rng);
|
||||
let (odd, rng) = below(rng, 20);
|
||||
let wetness = if odd == 0 { f64::NAN } else { wet };
|
||||
(
|
||||
spot_fixture::read_of(MADES[m as usize], DRAWS[d as usize], outs as u8, SUITS[s as usize], wetness),
|
||||
rng,
|
||||
)
|
||||
}
|
||||
|
||||
fn random_plan(rng: Rng) -> (PreflopPlan, Rng) {
|
||||
let (a, rng) = below(rng, 4);
|
||||
let (certainty, rng) = unit(rng);
|
||||
let action = [ChartAction::Fold, ChartAction::Call, ChartAction::Raise, ChartAction::Jam][a as usize];
|
||||
(spot_fixture::plan(action, certainty), rng)
|
||||
}
|
||||
|
||||
fn random_thresholds(rng: Rng) -> (Thresholds, Rng) {
|
||||
let (a, rng) = unit(rng);
|
||||
let (b, rng) = unit(rng);
|
||||
let (c, rng) = unit(rng);
|
||||
let (d, rng) = unit(rng);
|
||||
(
|
||||
Thresholds {
|
||||
call_margin: a * 0.1,
|
||||
value_raise: 0.4 + b * 0.5,
|
||||
abstain_band: c * 0.05,
|
||||
fold_equity_scale: d * 2.0,
|
||||
range_width_scale: 1.0,
|
||||
},
|
||||
rng,
|
||||
)
|
||||
}
|
||||
|
||||
fn assert_sound(spot: &Spot, decision: &Decision, label: &str) {
|
||||
let ctx = format!("{label}: {spot:?} -> {decision:?}");
|
||||
if let Some(kind) = decision.choice.kind() {
|
||||
assert!(spot.is_legal(kind), "illegal kind. {ctx}");
|
||||
if kind == ActionKind::Fold {
|
||||
assert!(!spot.is_legal(ActionKind::Check), "fold with check legal. {ctx}");
|
||||
}
|
||||
}
|
||||
assert!((0.0..=1.0).contains(&decision.confidence.value()), "{ctx}");
|
||||
if let Choice::Raise { to } = decision.choice {
|
||||
assert!(to.is_finite() && to > 0.0, "{ctx}");
|
||||
assert!(to <= spot.hero_stack, "unaffordable. {ctx}");
|
||||
if let Some(allowed) = &spot.allowed_sizes {
|
||||
assert!(allowed.contains(&to), "not from allowedSizes. {ctx}");
|
||||
}
|
||||
if let Some(min) = spot.min_raise_to {
|
||||
assert!(to >= min || to == spot.hero_stack, "below min and not all-in. {ctx}");
|
||||
}
|
||||
if let Some(max) = spot.max_raise_to {
|
||||
assert!(to <= max, "above max. {ctx}");
|
||||
}
|
||||
if spot.rules().shape == ActionShape::Binary {
|
||||
assert!(to == spot.hero_stack || Some(to) == spot.max_raise_to || spot.allowed_sizes.is_some(), "{ctx}");
|
||||
}
|
||||
}
|
||||
let after = settle(spot, decision.choice);
|
||||
assert!(after.stack >= 0.0, "negative stack. {ctx}");
|
||||
assert!(
|
||||
(after.stack + after.pot - (spot.hero_stack + spot.pot)).abs() < 1e-9,
|
||||
"chips not conserved. {ctx}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn postflop_choices_survive_enforcement_on_random_spots() {
|
||||
let rng = Rng::seeded(0xD1CE);
|
||||
let _ = (0..POSTFLOP_CASES).fold(rng, |rng, _| {
|
||||
let (spot, rng) = random_spot(rng);
|
||||
let (est, rng) = random_estimate(rng);
|
||||
let (th, rng) = random_thresholds(rng);
|
||||
let (read, rng) = random_read(rng);
|
||||
let raw = choose_postflop(&spot, &est, &th, &read);
|
||||
let enforced = enforce(&spot, raw);
|
||||
assert_sound(&spot, &enforced, "postflop");
|
||||
if enforced.choice == Choice::Abstain {
|
||||
assert!(enforced.confidence.value() <= 0.3, "abstain too confident: {enforced:?}");
|
||||
}
|
||||
rng
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preflop_plans_survive_enforcement_on_random_spots() {
|
||||
let rng = Rng::seeded(0xBEEF);
|
||||
let _ = (0..CASES).fold(rng, |rng, _| {
|
||||
let (spot, rng) = random_spot(rng);
|
||||
let (plan, rng) = random_plan(rng);
|
||||
let raw = from_plan(&spot, &plan);
|
||||
assert_sound(&spot, &enforce(&spot, raw), "from_plan");
|
||||
rng
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enforce_is_sound_for_arbitrary_decisions() {
|
||||
let rng = Rng::seeded(0xFACE);
|
||||
let _ = (0..CASES).fold(rng, |rng, _| {
|
||||
let (spot, rng) = random_spot(rng);
|
||||
let (k, rng) = below(rng, 6);
|
||||
let (size, rng) = chips(rng, 30.0);
|
||||
let choice = match k {
|
||||
0 => Choice::Fold,
|
||||
1 => Choice::Check,
|
||||
2 => Choice::Call,
|
||||
3 => Choice::Raise { to: size },
|
||||
4 => Choice::Raise { to: f64::NAN },
|
||||
_ => Choice::Abstain,
|
||||
};
|
||||
assert_sound(&spot, &enforce(&spot, Decision::new(choice, 0.5, "arbitrary")), "enforce");
|
||||
rng
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enforce_is_idempotent() {
|
||||
let rng = Rng::seeded(0xABCD);
|
||||
let _ = (0..CASES).fold(rng, |rng, _| {
|
||||
let (spot, rng) = random_spot(rng);
|
||||
let (est, rng) = random_estimate(rng);
|
||||
let (read, rng) = random_read(rng);
|
||||
let once = enforce(&spot, choose_postflop(&spot, &est, &Thresholds::BASE, &read));
|
||||
let twice = enforce(&spot, once.clone());
|
||||
assert_eq!(once.choice, twice.choice, "{spot:?}");
|
||||
rng
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn postflop_raise_sizes_come_from_the_menu_and_confidence_is_bounded_before_enforcement() {
|
||||
let rng = Rng::seeded(0x5EED);
|
||||
let _ = (0..POSTFLOP_CASES).fold(rng, |rng, _| {
|
||||
let (spot, rng) = random_spot(rng);
|
||||
let (est, rng) = random_estimate(rng);
|
||||
let (th, rng) = random_thresholds(rng);
|
||||
let (read, rng) = random_read(rng);
|
||||
let raw = choose_postflop(&spot, &est, &th, &read);
|
||||
assert!((0.0..=1.0).contains(&raw.confidence.value()), "{raw:?}");
|
||||
if raw.choice == Choice::Abstain {
|
||||
assert!(raw.confidence.value() <= 0.3, "{raw:?}");
|
||||
}
|
||||
if let (Choice::Raise { to }, Some(menu)) = (raw.choice, &spot.allowed_sizes) {
|
||||
assert!(menu.contains(&to), "raw raise {to} not in {menu:?}");
|
||||
}
|
||||
rng
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nothing_beats_nothing_never_raises_on_the_board_alone() {
|
||||
let rng = Rng::seeded(0xB0A2D);
|
||||
let _ = (0..CASES).fold(rng, |rng, _| {
|
||||
let (spot, rng) = random_spot(rng);
|
||||
let (est, rng) = random_estimate(rng);
|
||||
let (th, rng) = random_thresholds(rng);
|
||||
let (read, rng) = random_read(rng);
|
||||
let read = HandRead { made: Made::BoardOnly, ..read };
|
||||
let raw = choose_postflop(&spot, &est, &th, &read);
|
||||
assert!(!matches!(raw.choice, Choice::Raise { .. }), "{spot:?} {raw:?}");
|
||||
rng
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::engine::range_filter::range_filter;
|
||||
use pokerfreak::exploit::range_spec::RangeSpec;
|
||||
use pokerfreak::preflop::hand_percentile::percentile;
|
||||
use pokerfreak::variant::{rules, Variant};
|
||||
use rechner::engine::range_filter::range_filter;
|
||||
use rechner::exploit::range_spec::RangeSpec;
|
||||
use rechner::preflop::hand_percentile::percentile;
|
||||
use rechner::variant::{rules, Variant};
|
||||
use spot_fixture::cards;
|
||||
|
||||
// Only specs without continuations are tested here: continuations call `read::glance`,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::engine::postflop::choose_postflop;
|
||||
use pokerfreak::engine::read_label::describe;
|
||||
use pokerfreak::exploit::thresholds::Thresholds;
|
||||
use pokerfreak::read::draw::Draw;
|
||||
use pokerfreak::read::made::Made;
|
||||
use pokerfreak::read::suit_pattern::SuitPattern;
|
||||
use rechner::engine::postflop::choose_postflop;
|
||||
use rechner::engine::read_label::describe;
|
||||
use rechner::exploit::thresholds::Thresholds;
|
||||
use rechner::read::draw::Draw;
|
||||
use rechner::read::made::Made;
|
||||
use rechner::read::suit_pattern::SuitPattern;
|
||||
use spot_fixture::*;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::engine::postflop::choose_postflop;
|
||||
use pokerfreak::engine::semibluff::has_real_draw;
|
||||
use pokerfreak::exploit::thresholds::Thresholds;
|
||||
use pokerfreak::game::{Choice, Spot, Street};
|
||||
use pokerfreak::read::draw::Draw;
|
||||
use pokerfreak::read::made::Made;
|
||||
use pokerfreak::read::suit_pattern::SuitPattern;
|
||||
use rechner::engine::postflop::choose_postflop;
|
||||
use rechner::engine::semibluff::has_real_draw;
|
||||
use rechner::exploit::thresholds::Thresholds;
|
||||
use rechner::game::{Choice, Spot, Street};
|
||||
use rechner::read::draw::Draw;
|
||||
use rechner::read::made::Made;
|
||||
use rechner::read::suit_pattern::SuitPattern;
|
||||
use spot_fixture::*;
|
||||
|
||||
const BASE: Thresholds = Thresholds::BASE;
|
||||
@@ -81,7 +81,7 @@ fn a_semibluff_is_also_possible_when_the_raise_is_the_only_way_to_continue_cheap
|
||||
// Free to act: check is the passive option (EV share * pot = 4.0 at 0.40).
|
||||
let spot = Spot {
|
||||
to_call: 0.0,
|
||||
legal: vec![pokerfreak::game::ActionKind::Check, pokerfreak::game::ActionKind::Raise],
|
||||
legal: vec![rechner::game::ActionKind::Check, rechner::game::ActionKind::Raise],
|
||||
..round_flop()
|
||||
};
|
||||
let d = choose_postflop(&spot, &estimate(0.40, 0.005), &BASE, &flush_draw_read());
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::engine::bluff::RaiseKind;
|
||||
use pokerfreak::engine::size_policy::{ladder_fraction, ladder_streets, sizes, spr};
|
||||
use pokerfreak::game::{ActionKind, Spot};
|
||||
use pokerfreak::read::draw::Draw;
|
||||
use pokerfreak::read::made::Made;
|
||||
use pokerfreak::read::suit_pattern::SuitPattern;
|
||||
use rechner::engine::bluff::RaiseKind;
|
||||
use rechner::engine::size_policy::{ladder_fraction, ladder_streets, sizes, spr};
|
||||
use rechner::game::{ActionKind, Spot};
|
||||
use rechner::read::draw::Draw;
|
||||
use rechner::read::made::Made;
|
||||
use rechner::read::suit_pattern::SuitPattern;
|
||||
use spot_fixture::*;
|
||||
|
||||
/// Free to act on the flop, pot 10, big blind 0.1, the sizes 1/3, 1/2, 2/3, 1 pot and the stack.
|
||||
@@ -18,13 +18,13 @@ fn bet_spot(stack: f64) -> Spot {
|
||||
max_raise_to: Some(stack),
|
||||
allowed_sizes: Some(vec![3.33, 5.0, 6.67, 10.0, stack]),
|
||||
legal: vec![ActionKind::Check, ActionKind::Raise],
|
||||
villains: vec![pokerfreak::game::Villain { seat: 2, stack, folded: false, profile: None }],
|
||||
villains: vec![rechner::game::Villain { seat: 2, stack, folded: false, profile: None }],
|
||||
big_blind: 0.1,
|
||||
..round_flop()
|
||||
}
|
||||
}
|
||||
|
||||
fn strong() -> pokerfreak::read::hand_read::HandRead {
|
||||
fn strong() -> rechner::read::hand_read::HandRead {
|
||||
read_of(Made::Overpair, Draw::None, 0, SuitPattern::Rainbow, 0.4)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::engine::texture_stance::texture_stance;
|
||||
use pokerfreak::exploit::thresholds::Thresholds;
|
||||
use pokerfreak::read::draw::Draw;
|
||||
use pokerfreak::read::made::Made;
|
||||
use pokerfreak::read::suit_pattern::SuitPattern;
|
||||
use rechner::engine::texture_stance::texture_stance;
|
||||
use rechner::exploit::thresholds::Thresholds;
|
||||
use rechner::read::draw::Draw;
|
||||
use rechner::read::made::Made;
|
||||
use rechner::read::suit_pattern::SuitPattern;
|
||||
use spot_fixture::read_of;
|
||||
|
||||
const BASE: Thresholds = Thresholds::BASE; // call_margin 0.02, value_raise 0.58
|
||||
|
||||
+93
-93
@@ -1,93 +1,93 @@
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::engine::postflop::choose_postflop;
|
||||
use pokerfreak::engine::uncertainty::{abstain_confidence, MAX_UNCERTAIN_CONFIDENCE, MIN_UNCERTAIN_CONFIDENCE};
|
||||
use pokerfreak::exploit::thresholds::Thresholds;
|
||||
use pokerfreak::game::Choice;
|
||||
use pokerfreak::read::draw::Draw;
|
||||
use pokerfreak::read::made::Made;
|
||||
use pokerfreak::read::suit_pattern::SuitPattern;
|
||||
use spot_fixture::*;
|
||||
|
||||
const BASE: Thresholds = Thresholds::BASE;
|
||||
|
||||
fn close(a: f64, b: f64) -> bool {
|
||||
(a - b).abs() < 1e-9
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn confidence_rises_linearly_from_the_edge_to_the_rim_of_the_band() {
|
||||
assert!(close(abstain_confidence(0.0, 0.04), 0.05));
|
||||
assert!(close(abstain_confidence(0.02, 0.04), 0.175));
|
||||
assert!(close(abstain_confidence(0.04, 0.04), 0.30));
|
||||
assert_eq!(MIN_UNCERTAIN_CONFIDENCE, 0.05);
|
||||
assert_eq!(MAX_UNCERTAIN_CONFIDENCE, 0.30);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn confidence_never_leaves_its_range() {
|
||||
for (d, w) in [(1.0, 0.04), (-1.0, 0.04), (0.01, 0.0), (f64::NAN, 0.1), (0.1, f64::NAN), (f64::INFINITY, 1.0)] {
|
||||
let c = abstain_confidence(d, w);
|
||||
assert!((0.05..=0.30).contains(&c), "{d} {w} -> {c}");
|
||||
}
|
||||
}
|
||||
|
||||
// round_flop: break-even 1/3, plain call margin 0.02 -> call breakpoint 0.3533.
|
||||
|
||||
#[test]
|
||||
fn abstain_near_the_effective_breakpoint_carries_small_confidence() {
|
||||
let d = choose_postflop(&round_flop(), &estimate(0.34, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Abstain);
|
||||
let c = d.confidence.value();
|
||||
assert!((0.05..=0.30).contains(&c), "{c}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closer_to_the_edge_means_less_confidence() {
|
||||
let near = choose_postflop(&round_flop(), &estimate(0.352, 0.005), &BASE, &neutral_read());
|
||||
let rim = choose_postflop(&round_flop(), &estimate(0.335, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!((near.choice, rim.choice), (Choice::Abstain, Choice::Abstain));
|
||||
assert!(near.confidence < rim.confidence, "{near:?} {rim:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_band_applies_to_the_texture_adjusted_breakpoint() {
|
||||
// Medium pair on a dry board: margin 0.02 + 0.01 + 0.004 = 0.034 -> breakpoint 0.3673.
|
||||
// Share 0.38 is outside the band around the plain 0.3533 but inside the one around 0.3673.
|
||||
let medium = read_of(Made::MiddlePair, Draw::None, 0, SuitPattern::Rainbow, 0.1);
|
||||
let plain = choose_postflop(&round_flop(), &estimate(0.38, 0.001), &BASE, &neutral_read());
|
||||
let shifted = choose_postflop(&round_flop(), &estimate(0.38, 0.001), &BASE, &medium);
|
||||
assert_eq!(plain.choice, Choice::Call);
|
||||
assert_eq!(shifted.choice, Choice::Abstain, "{shifted:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_band_applies_to_the_multiway_adjusted_breakpoint() {
|
||||
// Three-way: realized 0.38 * 0.9409 = 0.3575, breakpoint 0.3333 + 0.04 = 0.3733.
|
||||
let spot = with_villains(round_flop(), 3);
|
||||
let d = choose_postflop(&spot, &estimate(0.38, 0.001), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Abstain, "{d:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marginal_raise_versus_call_abstains_with_small_confidence() {
|
||||
// Flush draw, share 0.40, fold-equity scale 0.85: P(fold) to a raise to 20 is
|
||||
// 0.595 * 0.7 * 0.85 = 0.354, worth 3.54 - 0.646 * 2 = 2.25 against the call's 1.0.
|
||||
// EV standard error = std_error * final pot (45): 2.25 noisy, 0.9 tight.
|
||||
let th = Thresholds { fold_equity_scale: 0.85, ..BASE };
|
||||
let noisy = choose_postflop(&round_flop(), &estimate(0.40, 0.05), &th, &flush_draw_read());
|
||||
assert_eq!(noisy.choice, Choice::Abstain, "{noisy:?}");
|
||||
let c = noisy.confidence.value();
|
||||
assert!((0.05..=0.30).contains(&c), "{c}");
|
||||
let tight = choose_postflop(&round_flop(), &estimate(0.40, 0.02), &th, &flush_draw_read());
|
||||
assert!(matches!(tight.choice, Choice::Raise { .. }), "{tight:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_equity_stays_at_zero_confidence() {
|
||||
for share in [f64::NAN, -0.1, 1.5] {
|
||||
let d = choose_postflop(&round_flop(), &estimate(share, 0.01), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Abstain);
|
||||
assert_eq!(d.confidence.value(), 0.0);
|
||||
}
|
||||
}
|
||||
mod spot_fixture;
|
||||
|
||||
use rechner::engine::postflop::choose_postflop;
|
||||
use rechner::engine::uncertainty::{abstain_confidence, MAX_UNCERTAIN_CONFIDENCE, MIN_UNCERTAIN_CONFIDENCE};
|
||||
use rechner::exploit::thresholds::Thresholds;
|
||||
use rechner::game::Choice;
|
||||
use rechner::read::draw::Draw;
|
||||
use rechner::read::made::Made;
|
||||
use rechner::read::suit_pattern::SuitPattern;
|
||||
use spot_fixture::*;
|
||||
|
||||
const BASE: Thresholds = Thresholds::BASE;
|
||||
|
||||
fn close(a: f64, b: f64) -> bool {
|
||||
(a - b).abs() < 1e-9
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn confidence_rises_linearly_from_the_edge_to_the_rim_of_the_band() {
|
||||
assert!(close(abstain_confidence(0.0, 0.04), 0.05));
|
||||
assert!(close(abstain_confidence(0.02, 0.04), 0.175));
|
||||
assert!(close(abstain_confidence(0.04, 0.04), 0.30));
|
||||
assert_eq!(MIN_UNCERTAIN_CONFIDENCE, 0.05);
|
||||
assert_eq!(MAX_UNCERTAIN_CONFIDENCE, 0.30);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn confidence_never_leaves_its_range() {
|
||||
for (d, w) in [(1.0, 0.04), (-1.0, 0.04), (0.01, 0.0), (f64::NAN, 0.1), (0.1, f64::NAN), (f64::INFINITY, 1.0)] {
|
||||
let c = abstain_confidence(d, w);
|
||||
assert!((0.05..=0.30).contains(&c), "{d} {w} -> {c}");
|
||||
}
|
||||
}
|
||||
|
||||
// round_flop: break-even 1/3, plain call margin 0.02 -> call breakpoint 0.3533.
|
||||
|
||||
#[test]
|
||||
fn abstain_near_the_effective_breakpoint_carries_small_confidence() {
|
||||
let d = choose_postflop(&round_flop(), &estimate(0.34, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Abstain);
|
||||
let c = d.confidence.value();
|
||||
assert!((0.05..=0.30).contains(&c), "{c}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closer_to_the_edge_means_less_confidence() {
|
||||
let near = choose_postflop(&round_flop(), &estimate(0.352, 0.005), &BASE, &neutral_read());
|
||||
let rim = choose_postflop(&round_flop(), &estimate(0.335, 0.005), &BASE, &neutral_read());
|
||||
assert_eq!((near.choice, rim.choice), (Choice::Abstain, Choice::Abstain));
|
||||
assert!(near.confidence < rim.confidence, "{near:?} {rim:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_band_applies_to_the_texture_adjusted_breakpoint() {
|
||||
// Medium pair on a dry board: margin 0.02 + 0.01 + 0.004 = 0.034 -> breakpoint 0.3673.
|
||||
// Share 0.38 is outside the band around the plain 0.3533 but inside the one around 0.3673.
|
||||
let medium = read_of(Made::MiddlePair, Draw::None, 0, SuitPattern::Rainbow, 0.1);
|
||||
let plain = choose_postflop(&round_flop(), &estimate(0.38, 0.001), &BASE, &neutral_read());
|
||||
let shifted = choose_postflop(&round_flop(), &estimate(0.38, 0.001), &BASE, &medium);
|
||||
assert_eq!(plain.choice, Choice::Call);
|
||||
assert_eq!(shifted.choice, Choice::Abstain, "{shifted:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_band_applies_to_the_multiway_adjusted_breakpoint() {
|
||||
// Three-way: realized 0.38 * 0.9409 = 0.3575, breakpoint 0.3333 + 0.04 = 0.3733.
|
||||
let spot = with_villains(round_flop(), 3);
|
||||
let d = choose_postflop(&spot, &estimate(0.38, 0.001), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Abstain, "{d:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marginal_raise_versus_call_abstains_with_small_confidence() {
|
||||
// Flush draw, share 0.40, fold-equity scale 0.85: P(fold) to a raise to 20 is
|
||||
// 0.595 * 0.7 * 0.85 = 0.354, worth 3.54 - 0.646 * 2 = 2.25 against the call's 1.0.
|
||||
// EV standard error = std_error * final pot (45): 2.25 noisy, 0.9 tight.
|
||||
let th = Thresholds { fold_equity_scale: 0.85, ..BASE };
|
||||
let noisy = choose_postflop(&round_flop(), &estimate(0.40, 0.05), &th, &flush_draw_read());
|
||||
assert_eq!(noisy.choice, Choice::Abstain, "{noisy:?}");
|
||||
let c = noisy.confidence.value();
|
||||
assert!((0.05..=0.30).contains(&c), "{c}");
|
||||
let tight = choose_postflop(&round_flop(), &estimate(0.40, 0.02), &th, &flush_draw_read());
|
||||
assert!(matches!(tight.choice, Choice::Raise { .. }), "{tight:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_equity_stays_at_zero_confidence() {
|
||||
for share in [f64::NAN, -0.1, 1.5] {
|
||||
let d = choose_postflop(&round_flop(), &estimate(share, 0.01), &BASE, &neutral_read());
|
||||
assert_eq!(d.choice, Choice::Abstain);
|
||||
assert_eq!(d.confidence.value(), 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//! Invalid queries are faults, never panics.
|
||||
use pokerfreak::card::Card;
|
||||
use pokerfreak::equity::monte_carlo::estimate;
|
||||
use pokerfreak::equity::query::Query;
|
||||
use pokerfreak::equity::villain_range::VillainRange;
|
||||
use pokerfreak::fault::Fault;
|
||||
use pokerfreak::rng::Rng;
|
||||
use pokerfreak::variant::{rules, Variant};
|
||||
use rechner::card::Card;
|
||||
use rechner::equity::monte_carlo::estimate;
|
||||
use rechner::equity::query::Query;
|
||||
use rechner::equity::villain_range::VillainRange;
|
||||
use rechner::fault::Fault;
|
||||
use rechner::rng::Rng;
|
||||
use rechner::variant::{rules, Variant};
|
||||
|
||||
fn cs(text: &str) -> Vec<Card> {
|
||||
Card::parse_list(text).expect("cards")
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//! Determinism, invariants of the estimate and range filtering.
|
||||
use std::cell::Cell;
|
||||
|
||||
use pokerfreak::card::{Card, Rank};
|
||||
use pokerfreak::equity::estimate::Estimate;
|
||||
use pokerfreak::equity::monte_carlo::estimate;
|
||||
use pokerfreak::equity::query::Query;
|
||||
use pokerfreak::equity::villain_range::VillainRange;
|
||||
use pokerfreak::rng::Rng;
|
||||
use pokerfreak::variant::{rules, Variant};
|
||||
use rechner::card::{Card, Rank};
|
||||
use rechner::equity::estimate::Estimate;
|
||||
use rechner::equity::monte_carlo::estimate;
|
||||
use rechner::equity::query::Query;
|
||||
use rechner::equity::villain_range::VillainRange;
|
||||
use rechner::rng::Rng;
|
||||
use rechner::variant::{rules, Variant};
|
||||
|
||||
fn cs(text: &str) -> Vec<Card> {
|
||||
Card::parse_list(text).expect("cards")
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
//! AKo vs QQ ~ 43 / 57, AKs vs 22 ~ 50 / 50, AA vs 3 random hands ~ 64.2 %.
|
||||
//! - Flush draw: "rule of 4 and 2" (9 outs, two cards to come: 1 - 38/47 * 37/46 = 35.0 %).
|
||||
//! - Exact spots: complete enumeration with `hand::showdown::best` (independent of the sampler).
|
||||
use pokerfreak::card::{deck, Card};
|
||||
use pokerfreak::equity::estimate::Estimate;
|
||||
use pokerfreak::equity::monte_carlo::estimate;
|
||||
use pokerfreak::equity::query::Query;
|
||||
use pokerfreak::equity::villain_range::VillainRange;
|
||||
use pokerfreak::hand::showdown::best;
|
||||
use pokerfreak::rng::Rng;
|
||||
use pokerfreak::variant::{rules, HoleUsage, Variant};
|
||||
use rechner::card::{deck, Card};
|
||||
use rechner::equity::estimate::Estimate;
|
||||
use rechner::equity::monte_carlo::estimate;
|
||||
use rechner::equity::query::Query;
|
||||
use rechner::equity::villain_range::VillainRange;
|
||||
use rechner::hand::showdown::best;
|
||||
use rechner::rng::Rng;
|
||||
use rechner::variant::{rules, HoleUsage, Variant};
|
||||
|
||||
fn cs(text: &str) -> Vec<Card> {
|
||||
Card::parse_list(text).expect("cards")
|
||||
|
||||
+130
-130
@@ -1,130 +1,130 @@
|
||||
use pokerfreak::exploit::adjust::adjust;
|
||||
use pokerfreak::exploit::profile::Profile;
|
||||
use pokerfreak::exploit::thresholds::Thresholds;
|
||||
|
||||
const BASE: Thresholds = Thresholds::BASE;
|
||||
|
||||
fn profile(vpip: Option<f64>, pfr: Option<f64>, fold_to_bet: Option<f64>) -> Profile {
|
||||
Profile {
|
||||
vpip,
|
||||
pfr,
|
||||
fold_to_bet,
|
||||
aggression: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn station() -> Profile {
|
||||
profile(Some(0.50), Some(0.05), Some(0.20))
|
||||
}
|
||||
|
||||
fn nit() -> Profile {
|
||||
profile(Some(0.10), Some(0.07), Some(0.75))
|
||||
}
|
||||
|
||||
fn maniac() -> Profile {
|
||||
profile(Some(0.60), Some(0.40), Some(0.40))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_information_changes_nothing() {
|
||||
assert_eq!(adjust(BASE, &[]), BASE);
|
||||
assert_eq!(adjust(BASE, &[Profile::default()]), BASE);
|
||||
assert_eq!(
|
||||
adjust(BASE, &[Profile::default(), Profile::default()]),
|
||||
BASE
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calling_stations_are_value_bet_thinner_and_not_bluffed() {
|
||||
let t = adjust(BASE, &[station()]);
|
||||
// Fold equity is per opponent now (`exploit::fold_chance`), not a shared threshold.
|
||||
assert_eq!(t.fold_equity_scale, BASE.fold_equity_scale, "{t:?}");
|
||||
assert!(t.value_raise < BASE.value_raise);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nits_fold_more_and_bet_strong() {
|
||||
let t = adjust(BASE, &[nit()]);
|
||||
assert_eq!(t.fold_equity_scale, BASE.fold_equity_scale);
|
||||
assert!(t.call_margin > BASE.call_margin);
|
||||
assert!(t.range_width_scale < BASE.range_width_scale);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn aggressive_players_are_called_wider() {
|
||||
let t = adjust(BASE, &[maniac()]);
|
||||
assert!(t.call_margin < BASE.call_margin);
|
||||
assert!(t.range_width_scale > BASE.range_width_scale);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fold_to_bet_no_longer_moves_the_shared_scale() {
|
||||
// foldToBet enters per opponent through `fold_chance`; counting it here too would
|
||||
// count it twice.
|
||||
for i in 0..=20 {
|
||||
let t = adjust(BASE, &[profile(Some(0.3), Some(0.1), Some(i as f64 / 20.0))]);
|
||||
assert_eq!(t.fold_equity_scale, BASE.fold_equity_scale);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn several_profiles_combine_conservatively() {
|
||||
let (s, n) = (adjust(BASE, &[station()]), adjust(BASE, &[nit()]));
|
||||
let both = adjust(BASE, &[station(), nit()]);
|
||||
assert_eq!(both.call_margin, s.call_margin.max(n.call_margin));
|
||||
assert_eq!(
|
||||
both.fold_equity_scale,
|
||||
s.fold_equity_scale.min(n.fold_equity_scale)
|
||||
);
|
||||
assert_eq!(both.value_raise, s.value_raise.max(n.value_raise));
|
||||
assert_eq!(
|
||||
both.range_width_scale,
|
||||
s.range_width_scale.min(n.range_width_scale)
|
||||
);
|
||||
// order does not matter, unknowns are ignored
|
||||
assert_eq!(adjust(BASE, &[nit(), Profile::default(), station()]), both);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outputs_stay_in_sane_ranges_for_any_input() {
|
||||
let grid = [
|
||||
None,
|
||||
Some(-1.0),
|
||||
Some(0.0),
|
||||
Some(0.3),
|
||||
Some(1.0),
|
||||
Some(9.0),
|
||||
Some(f64::NAN),
|
||||
Some(f64::INFINITY),
|
||||
];
|
||||
for vpip in grid {
|
||||
for pfr in grid {
|
||||
for ftb in grid {
|
||||
let t = adjust(BASE, &[profile(vpip, pfr, ftb)]);
|
||||
assert!((0.0..=0.15).contains(&t.call_margin), "{t:?}");
|
||||
assert!((0.52..=0.85).contains(&t.value_raise), "{t:?}");
|
||||
assert!((0.0..=0.05).contains(&t.abstain_band), "{t:?}");
|
||||
assert!((0.3..=1.6).contains(&t.fold_equity_scale), "{t:?}");
|
||||
assert!((0.6..=1.4).contains(&t.range_width_scale), "{t:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn adjust_is_pure() {
|
||||
let ps = [station(), maniac()];
|
||||
assert_eq!(adjust(BASE, &ps), adjust(BASE, &ps));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn adjustments_compose_with_a_non_default_base() {
|
||||
let tight = Thresholds {
|
||||
fold_equity_scale: 0.8,
|
||||
..BASE
|
||||
};
|
||||
// The shared fold-equity scale passes through untouched (profiles act per opponent).
|
||||
assert_eq!(adjust(tight, &[nit()]).fold_equity_scale, 0.8);
|
||||
assert_eq!(adjust(tight, &[station()]).fold_equity_scale, 0.8);
|
||||
}
|
||||
use rechner::exploit::adjust::adjust;
|
||||
use rechner::exploit::profile::Profile;
|
||||
use rechner::exploit::thresholds::Thresholds;
|
||||
|
||||
const BASE: Thresholds = Thresholds::BASE;
|
||||
|
||||
fn profile(vpip: Option<f64>, pfr: Option<f64>, fold_to_bet: Option<f64>) -> Profile {
|
||||
Profile {
|
||||
vpip,
|
||||
pfr,
|
||||
fold_to_bet,
|
||||
aggression: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn station() -> Profile {
|
||||
profile(Some(0.50), Some(0.05), Some(0.20))
|
||||
}
|
||||
|
||||
fn nit() -> Profile {
|
||||
profile(Some(0.10), Some(0.07), Some(0.75))
|
||||
}
|
||||
|
||||
fn maniac() -> Profile {
|
||||
profile(Some(0.60), Some(0.40), Some(0.40))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_information_changes_nothing() {
|
||||
assert_eq!(adjust(BASE, &[]), BASE);
|
||||
assert_eq!(adjust(BASE, &[Profile::default()]), BASE);
|
||||
assert_eq!(
|
||||
adjust(BASE, &[Profile::default(), Profile::default()]),
|
||||
BASE
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calling_stations_are_value_bet_thinner_and_not_bluffed() {
|
||||
let t = adjust(BASE, &[station()]);
|
||||
// Fold equity is per opponent now (`exploit::fold_chance`), not a shared threshold.
|
||||
assert_eq!(t.fold_equity_scale, BASE.fold_equity_scale, "{t:?}");
|
||||
assert!(t.value_raise < BASE.value_raise);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nits_fold_more_and_bet_strong() {
|
||||
let t = adjust(BASE, &[nit()]);
|
||||
assert_eq!(t.fold_equity_scale, BASE.fold_equity_scale);
|
||||
assert!(t.call_margin > BASE.call_margin);
|
||||
assert!(t.range_width_scale < BASE.range_width_scale);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn aggressive_players_are_called_wider() {
|
||||
let t = adjust(BASE, &[maniac()]);
|
||||
assert!(t.call_margin < BASE.call_margin);
|
||||
assert!(t.range_width_scale > BASE.range_width_scale);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fold_to_bet_no_longer_moves_the_shared_scale() {
|
||||
// foldToBet enters per opponent through `fold_chance`; counting it here too would
|
||||
// count it twice.
|
||||
for i in 0..=20 {
|
||||
let t = adjust(BASE, &[profile(Some(0.3), Some(0.1), Some(i as f64 / 20.0))]);
|
||||
assert_eq!(t.fold_equity_scale, BASE.fold_equity_scale);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn several_profiles_combine_conservatively() {
|
||||
let (s, n) = (adjust(BASE, &[station()]), adjust(BASE, &[nit()]));
|
||||
let both = adjust(BASE, &[station(), nit()]);
|
||||
assert_eq!(both.call_margin, s.call_margin.max(n.call_margin));
|
||||
assert_eq!(
|
||||
both.fold_equity_scale,
|
||||
s.fold_equity_scale.min(n.fold_equity_scale)
|
||||
);
|
||||
assert_eq!(both.value_raise, s.value_raise.max(n.value_raise));
|
||||
assert_eq!(
|
||||
both.range_width_scale,
|
||||
s.range_width_scale.min(n.range_width_scale)
|
||||
);
|
||||
// order does not matter, unknowns are ignored
|
||||
assert_eq!(adjust(BASE, &[nit(), Profile::default(), station()]), both);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outputs_stay_in_sane_ranges_for_any_input() {
|
||||
let grid = [
|
||||
None,
|
||||
Some(-1.0),
|
||||
Some(0.0),
|
||||
Some(0.3),
|
||||
Some(1.0),
|
||||
Some(9.0),
|
||||
Some(f64::NAN),
|
||||
Some(f64::INFINITY),
|
||||
];
|
||||
for vpip in grid {
|
||||
for pfr in grid {
|
||||
for ftb in grid {
|
||||
let t = adjust(BASE, &[profile(vpip, pfr, ftb)]);
|
||||
assert!((0.0..=0.15).contains(&t.call_margin), "{t:?}");
|
||||
assert!((0.52..=0.85).contains(&t.value_raise), "{t:?}");
|
||||
assert!((0.0..=0.05).contains(&t.abstain_band), "{t:?}");
|
||||
assert!((0.3..=1.6).contains(&t.fold_equity_scale), "{t:?}");
|
||||
assert!((0.6..=1.4).contains(&t.range_width_scale), "{t:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn adjust_is_pure() {
|
||||
let ps = [station(), maniac()];
|
||||
assert_eq!(adjust(BASE, &ps), adjust(BASE, &ps));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn adjustments_compose_with_a_non_default_base() {
|
||||
let tight = Thresholds {
|
||||
fold_equity_scale: 0.8,
|
||||
..BASE
|
||||
};
|
||||
// The shared fold-equity scale passes through untouched (profiles act per opponent).
|
||||
assert_eq!(adjust(tight, &[nit()]).fold_equity_scale, 0.8);
|
||||
assert_eq!(adjust(tight, &[station()]).fold_equity_scale, 0.8);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use pokerfreak::exploit::profile::Profile;
|
||||
use pokerfreak::exploit::range_guess::top_fraction;
|
||||
use pokerfreak::game::{ActionKind, Spot, Street, Villain};
|
||||
use pokerfreak::variant::Variant;
|
||||
use rechner::exploit::profile::Profile;
|
||||
use rechner::exploit::range_guess::top_fraction;
|
||||
use rechner::game::{ActionKind, Spot, Street, Villain};
|
||||
use rechner::variant::Variant;
|
||||
|
||||
fn villain(profile: Option<Profile>) -> Villain {
|
||||
Villain {
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
//! * The response carries `reads`: per villain with a profile `{seat, style, foldChance, trust}`;
|
||||
//! none without profiles.
|
||||
|
||||
use pokerfreak::exploit::profile::Profile;
|
||||
use pokerfreak::exploit::sample::{shrink, trust, PRIOR_HANDS, PRIOR};
|
||||
use pokerfreak::wire::respond::respond;
|
||||
use rechner::exploit::profile::Profile;
|
||||
use rechner::exploit::sample::{shrink, trust, PRIOR_HANDS, PRIOR};
|
||||
use rechner::wire::respond::respond;
|
||||
|
||||
fn station() -> Profile {
|
||||
Profile { vpip: Some(0.60), pfr: Some(0.05), fold_to_bet: Some(0.15), aggression: Some(0.20) }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use pokerfreak::exploit::profile::Profile;
|
||||
use pokerfreak::exploit::style::{classify, Style};
|
||||
use rechner::exploit::profile::Profile;
|
||||
use rechner::exploit::style::{classify, Style};
|
||||
|
||||
fn profile(vpip: Option<f64>, pfr: Option<f64>, fold_to_bet: Option<f64>) -> Profile {
|
||||
Profile {
|
||||
|
||||
@@ -200,16 +200,16 @@ class FokusRuhe(unittest.TestCase):
|
||||
|
||||
def test_frist_ist_einstellbar(self):
|
||||
import importlib, os
|
||||
alt = os.environ.get("POKERFREAK_FENSTER_FRIST")
|
||||
alt = os.environ.get("FENSTER_FRIST")
|
||||
try:
|
||||
os.environ["POKERFREAK_FENSTER_FRIST"] = "9"
|
||||
os.environ["FENSTER_FRIST"] = "9"
|
||||
importlib.reload(fenster)
|
||||
self.assertEqual(fenster.FENSTER_FRIST_S, 9.0)
|
||||
finally:
|
||||
if alt is None:
|
||||
os.environ.pop("POKERFREAK_FENSTER_FRIST", None)
|
||||
os.environ.pop("FENSTER_FRIST", None)
|
||||
else:
|
||||
os.environ["POKERFREAK_FENSTER_FRIST"] = alt
|
||||
os.environ["FENSTER_FRIST"] = alt
|
||||
importlib.reload(fenster)
|
||||
|
||||
def test_vorgabe_bremst_die_sicht(self):
|
||||
|
||||
+206
-206
@@ -1,206 +1,206 @@
|
||||
//! Pure lookup over the frozen charts: grid points, interpolation, clamping, refusals.
|
||||
//!
|
||||
//! Depth rule (documented in `generated_lookup.rs`): linear interpolation of the frequencies
|
||||
//! between the two neighbouring grid depths; outside the grid the nearest table is used
|
||||
//! (clamping). Non-finite or non-positive depths are refused (`None`).
|
||||
mod cfr_support;
|
||||
|
||||
use cfr_support::id;
|
||||
use pokerfreak::card::Card;
|
||||
use pokerfreak::cfr::hand_class::{class_of, CLASS_COUNT};
|
||||
use pokerfreak::cfr::seat::Seat;
|
||||
use pokerfreak::preflop::generated_charts::{OPEN, PUSH_FOLD};
|
||||
use pokerfreak::preflop::generated_charts_short as short;
|
||||
use pokerfreak::preflop::generated_lookup::{
|
||||
bb_overcall_vs_push, bb_vs_open_and_call, call_vs_push, has_charts, open_depth_range, open_frequency,
|
||||
push_depth_range, push_frequency, sb_call_vs_push, sb_vs_open, seat_of, vs_jam, vs_open,
|
||||
vs_sb_three_bet, vs_three_bet, Frequencies,
|
||||
};
|
||||
use pokerfreak::preflop::position::Position;
|
||||
use pokerfreak::variant::Variant;
|
||||
|
||||
fn close(a: f64, b: f64) -> bool {
|
||||
(a - b).abs() < 1e-9
|
||||
}
|
||||
|
||||
fn sums_to_one(f: Frequencies) -> bool {
|
||||
close(f.fold + f.call + f.raise, 1.0)
|
||||
&& [f.fold, f.call, f.raise].iter().all(|x| (0.0..=1.0).contains(x))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn grid_depths_return_the_table_entry_exactly() {
|
||||
let spot = PUSH_FOLD.iter().find(|s| s.seat == Seat::Button && s.depth_bb == 10).expect("spot");
|
||||
for c in [id("AA"), id("A5s"), id("72o"), id("98s"), id("QJo")] {
|
||||
let f = push_frequency(Variant::Nlhe, Seat::Button, 10.0, c).expect("lookup");
|
||||
assert!(close(f.raise, spot.push[c] as f64 / 1000.0));
|
||||
assert!(close(f.fold, 1.0 - spot.push[c] as f64 / 1000.0));
|
||||
assert_eq!(f.call, 0.0);
|
||||
let g = call_vs_push(Variant::Nlhe, Seat::Button, 10.0, c).expect("lookup");
|
||||
assert!(close(g.call, spot.call[c] as f64 / 1000.0));
|
||||
assert!(sums_to_one(f) && sums_to_one(g));
|
||||
}
|
||||
let open = OPEN.iter().find(|s| s.seat == Seat::Cutoff && s.depth_bb == 40).expect("spot");
|
||||
let c = id("KJs");
|
||||
let f = open_frequency(Variant::Nlhe, Seat::Cutoff, 40.0, c).expect("lookup");
|
||||
assert!(close(f.raise, open.open[c] as f64 / 1000.0));
|
||||
let d = vs_open(Variant::Nlhe, Seat::Cutoff, 40.0, c).expect("lookup");
|
||||
assert!(close(d.call, open.defend[c][0] as f64 / 1000.0));
|
||||
assert!(close(d.raise, open.defend[c][1] as f64 / 1000.0));
|
||||
let t = vs_three_bet(Variant::Nlhe, Seat::Cutoff, 40.0, c).expect("lookup");
|
||||
assert!(close(t.call, open.vs_three_bet[c][0] as f64 / 1000.0));
|
||||
assert!(close(t.raise, open.vs_three_bet[c][1] as f64 / 1000.0));
|
||||
let j = vs_jam(Variant::Nlhe, Seat::Cutoff, 40.0, c).expect("lookup");
|
||||
assert!(close(j.call, open.vs_jam[c] as f64 / 1000.0));
|
||||
assert!([d, t, j].into_iter().all(sums_to_one));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn between_grid_depths_the_frequencies_are_linearly_interpolated() {
|
||||
for c in 0..CLASS_COUNT {
|
||||
let lo = push_frequency(Variant::Nlhe, Seat::Cutoff, 8.0, c).expect("lookup").raise;
|
||||
let hi = push_frequency(Variant::Nlhe, Seat::Cutoff, 10.0, c).expect("lookup").raise;
|
||||
let mid = push_frequency(Variant::Nlhe, Seat::Cutoff, 9.0, c).expect("lookup");
|
||||
assert!(close(mid.raise, (lo + hi) / 2.0), "class {c}");
|
||||
assert!(sums_to_one(mid));
|
||||
let quarter = push_frequency(Variant::Nlhe, Seat::Cutoff, 8.5, c).expect("lookup").raise;
|
||||
assert!(close(quarter, lo * 0.75 + hi * 0.25));
|
||||
}
|
||||
let a = open_frequency(Variant::Nlhe, Seat::Button, 20.0, id("K9o")).expect("lookup").raise;
|
||||
let b = open_frequency(Variant::Nlhe, Seat::Button, 40.0, id("K9o")).expect("lookup").raise;
|
||||
let m = open_frequency(Variant::Nlhe, Seat::Button, 30.0, id("K9o")).expect("lookup").raise;
|
||||
assert!(close(m, (a + b) / 2.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outside_the_grid_the_nearest_table_is_used() {
|
||||
let (lo, hi) = push_depth_range();
|
||||
assert_eq!((lo, hi), (5.0, 25.0));
|
||||
for c in [id("A2o"), id("T8s"), id("54s")] {
|
||||
let at_lo = push_frequency(Variant::Nlhe, Seat::Early, lo, c).expect("lookup");
|
||||
let below = push_frequency(Variant::Nlhe, Seat::Early, 1.0, c).expect("lookup");
|
||||
let at_hi = push_frequency(Variant::Nlhe, Seat::Early, hi, c).expect("lookup");
|
||||
let above = push_frequency(Variant::Nlhe, Seat::Early, 80.0, c).expect("lookup");
|
||||
assert_eq!(at_lo, below);
|
||||
assert_eq!(at_hi, above);
|
||||
}
|
||||
assert_eq!(open_depth_range(), (20.0, 100.0));
|
||||
assert_eq!(
|
||||
open_frequency(Variant::Nlhe, Seat::Early, 500.0, id("JTs")),
|
||||
open_frequency(Variant::Nlhe, Seat::Early, 100.0, id("JTs"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nonsense_inputs_are_refused_not_panicked_on() {
|
||||
for depth in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY, 0.0, -3.0] {
|
||||
assert!(push_frequency(Variant::Nlhe, Seat::Button, depth, 0).is_none(), "{depth}");
|
||||
assert!(call_vs_push(Variant::Nlhe, Seat::Button, depth, 0).is_none());
|
||||
assert!(open_frequency(Variant::Nlhe, Seat::Button, depth, 0).is_none());
|
||||
assert!(vs_open(Variant::Nlhe, Seat::Button, depth, 0).is_none());
|
||||
assert!(vs_three_bet(Variant::Nlhe, Seat::Button, depth, 0).is_none());
|
||||
assert!(vs_jam(Variant::Nlhe, Seat::Button, depth, 0).is_none());
|
||||
}
|
||||
assert!(push_frequency(Variant::Nlhe, Seat::Button, 10.0, CLASS_COUNT).is_none());
|
||||
assert!(open_frequency(Variant::Nlhe, Seat::Button, 40.0, usize::MAX).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsupported_variants_have_no_chart() {
|
||||
for v in [Variant::Plo5, Variant::KPoker] {
|
||||
assert!(!has_charts(v));
|
||||
assert!(push_frequency(v, Seat::Button, 10.0, 0).is_none(), "{v:?}");
|
||||
assert!(call_vs_push(v, Seat::Button, 10.0, 0).is_none());
|
||||
assert!(open_frequency(v, Seat::Button, 40.0, 0).is_none());
|
||||
}
|
||||
// All-in-or-fold has no open tables.
|
||||
assert!(open_frequency(Variant::Aof, Seat::Button, 40.0, 0).is_none());
|
||||
assert!([Variant::Nlhe, Variant::Aof, Variant::ShortDeck].into_iter().all(has_charts));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_tables_for_both_blinds_are_read_from_their_own_rows() {
|
||||
let push = PUSH_FOLD.iter().find(|s| s.seat == Seat::Cutoff && s.depth_bb == 12).expect("spot");
|
||||
let open = OPEN.iter().find(|s| s.seat == Seat::Middle && s.depth_bb == 40).expect("spot");
|
||||
for c in [id("AA"), id("AJo"), id("77"), id("KTs"), id("72o")] {
|
||||
let sb = sb_call_vs_push(Variant::Nlhe, Seat::Cutoff, 12.0, c).expect("lookup");
|
||||
assert!(close(sb.call, push.sb_call[c] as f64 / 1000.0) && sb.raise == 0.0);
|
||||
let over = bb_overcall_vs_push(Variant::Nlhe, Seat::Cutoff, 12.0, c).expect("lookup");
|
||||
assert!(close(over.call, push.bb_overcall[c] as f64 / 1000.0));
|
||||
let d = sb_vs_open(Variant::Nlhe, Seat::Middle, 40.0, c).expect("lookup");
|
||||
assert!(close(d.call, open.sb_defend[c][0] as f64 / 1000.0));
|
||||
assert!(close(d.raise, open.sb_defend[c][1] as f64 / 1000.0));
|
||||
let o = bb_vs_open_and_call(Variant::Nlhe, Seat::Middle, 40.0, c).expect("lookup");
|
||||
assert!(close(o.call, open.bb_overcall[c] as f64 / 1000.0) && o.raise == 0.0);
|
||||
let t = vs_sb_three_bet(Variant::Nlhe, Seat::Middle, 40.0, c).expect("lookup");
|
||||
assert!(close(t.call, open.vs_sb_three_bet[c][0] as f64 / 1000.0));
|
||||
assert!(close(t.raise, open.vs_sb_three_bet[c][1] as f64 / 1000.0));
|
||||
assert!([sb, over, d, o, t].into_iter().all(sums_to_one));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_small_blind_as_first_actor_has_no_small_blind_or_overcall_rows() {
|
||||
for v in [Variant::Nlhe, Variant::ShortDeck] {
|
||||
assert!(sb_call_vs_push(v, Seat::SmallBlind, 10.0, id("AA")).is_none());
|
||||
assert!(bb_overcall_vs_push(v, Seat::SmallBlind, 10.0, id("AA")).is_none());
|
||||
assert!(sb_vs_open(v, Seat::SmallBlind, 40.0, id("AA")).is_none());
|
||||
assert!(bb_vs_open_and_call(v, Seat::SmallBlind, 40.0, id("AA")).is_none());
|
||||
assert!(vs_sb_three_bet(v, Seat::SmallBlind, 40.0, id("AA")).is_none());
|
||||
// The big blind's tables against the small blind exist.
|
||||
assert!(call_vs_push(v, Seat::SmallBlind, 10.0, id("AA")).is_some());
|
||||
assert!(vs_open(v, Seat::SmallBlind, 40.0, id("AA")).is_some());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn short_deck_reads_its_own_tables() {
|
||||
let spot = short::PUSH_FOLD.iter().find(|s| s.seat == Seat::Button && s.depth_bb == 10).expect("spot");
|
||||
let open = short::OPEN.iter().find(|s| s.seat == Seat::Early && s.depth_bb == 100).expect("spot");
|
||||
for c in [id("AA"), id("A6s"), id("T9o"), id("66")] {
|
||||
let f = push_frequency(Variant::ShortDeck, Seat::Button, 10.0, c).expect("lookup");
|
||||
assert!(close(f.raise, spot.push[c] as f64 / 1000.0));
|
||||
let o = open_frequency(Variant::ShortDeck, Seat::Early, 100.0, c).expect("lookup");
|
||||
assert!(close(o.raise, open.open[c] as f64 / 1000.0));
|
||||
}
|
||||
// A class that is not in the short deck reads as a fold.
|
||||
let deuces = push_frequency(Variant::ShortDeck, Seat::Button, 10.0, id("22")).expect("lookup");
|
||||
assert_eq!(deuces.raise, 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_in_or_fold_answers_exactly_like_push_fold() {
|
||||
for c in 0..CLASS_COUNT {
|
||||
for depth in [5.0, 9.3, 17.0, 25.0] {
|
||||
assert_eq!(
|
||||
push_frequency(Variant::Aof, Seat::SmallBlind, depth, c),
|
||||
push_frequency(Variant::Nlhe, Seat::SmallBlind, depth, c)
|
||||
);
|
||||
assert_eq!(
|
||||
call_vs_push(Variant::Aof, Seat::Early, depth, c),
|
||||
call_vs_push(Variant::Nlhe, Seat::Early, depth, c)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn positions_map_to_chart_seats() {
|
||||
assert_eq!(seat_of(Position::Early), Some(Seat::Early));
|
||||
assert_eq!(seat_of(Position::Middle), Some(Seat::Middle));
|
||||
assert_eq!(seat_of(Position::Cutoff), Some(Seat::Cutoff));
|
||||
assert_eq!(seat_of(Position::Button), Some(Seat::Button));
|
||||
assert_eq!(seat_of(Position::SmallBlind), Some(Seat::SmallBlind));
|
||||
assert_eq!(seat_of(Position::HeadsUpButton), Some(Seat::SmallBlind), "heads-up button is the small blind");
|
||||
assert_eq!(seat_of(Position::Unknown), Some(Seat::Early), "unknown position uses the tightest row");
|
||||
assert_eq!(seat_of(Position::BigBlind), None, "the big blind never opens or jams first");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classes_come_from_cards() {
|
||||
let ace = Card::parse_short("Ah").expect("card");
|
||||
let king = Card::parse_short("Kh").expect("card");
|
||||
let c = class_of(ace, king).expect("class");
|
||||
let f = push_frequency(Variant::Nlhe, Seat::Button, 8.0, c).expect("lookup");
|
||||
assert!(f.raise > 0.9, "AKs jams the button at 8 bb");
|
||||
}
|
||||
//! Pure lookup over the frozen charts: grid points, interpolation, clamping, refusals.
|
||||
//!
|
||||
//! Depth rule (documented in `generated_lookup.rs`): linear interpolation of the frequencies
|
||||
//! between the two neighbouring grid depths; outside the grid the nearest table is used
|
||||
//! (clamping). Non-finite or non-positive depths are refused (`None`).
|
||||
mod cfr_support;
|
||||
|
||||
use cfr_support::id;
|
||||
use rechner::card::Card;
|
||||
use rechner::cfr::hand_class::{class_of, CLASS_COUNT};
|
||||
use rechner::cfr::seat::Seat;
|
||||
use rechner::preflop::generated_charts::{OPEN, PUSH_FOLD};
|
||||
use rechner::preflop::generated_charts_short as short;
|
||||
use rechner::preflop::generated_lookup::{
|
||||
bb_overcall_vs_push, bb_vs_open_and_call, call_vs_push, has_charts, open_depth_range, open_frequency,
|
||||
push_depth_range, push_frequency, sb_call_vs_push, sb_vs_open, seat_of, vs_jam, vs_open,
|
||||
vs_sb_three_bet, vs_three_bet, Frequencies,
|
||||
};
|
||||
use rechner::preflop::position::Position;
|
||||
use rechner::variant::Variant;
|
||||
|
||||
fn close(a: f64, b: f64) -> bool {
|
||||
(a - b).abs() < 1e-9
|
||||
}
|
||||
|
||||
fn sums_to_one(f: Frequencies) -> bool {
|
||||
close(f.fold + f.call + f.raise, 1.0)
|
||||
&& [f.fold, f.call, f.raise].iter().all(|x| (0.0..=1.0).contains(x))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn grid_depths_return_the_table_entry_exactly() {
|
||||
let spot = PUSH_FOLD.iter().find(|s| s.seat == Seat::Button && s.depth_bb == 10).expect("spot");
|
||||
for c in [id("AA"), id("A5s"), id("72o"), id("98s"), id("QJo")] {
|
||||
let f = push_frequency(Variant::Nlhe, Seat::Button, 10.0, c).expect("lookup");
|
||||
assert!(close(f.raise, spot.push[c] as f64 / 1000.0));
|
||||
assert!(close(f.fold, 1.0 - spot.push[c] as f64 / 1000.0));
|
||||
assert_eq!(f.call, 0.0);
|
||||
let g = call_vs_push(Variant::Nlhe, Seat::Button, 10.0, c).expect("lookup");
|
||||
assert!(close(g.call, spot.call[c] as f64 / 1000.0));
|
||||
assert!(sums_to_one(f) && sums_to_one(g));
|
||||
}
|
||||
let open = OPEN.iter().find(|s| s.seat == Seat::Cutoff && s.depth_bb == 40).expect("spot");
|
||||
let c = id("KJs");
|
||||
let f = open_frequency(Variant::Nlhe, Seat::Cutoff, 40.0, c).expect("lookup");
|
||||
assert!(close(f.raise, open.open[c] as f64 / 1000.0));
|
||||
let d = vs_open(Variant::Nlhe, Seat::Cutoff, 40.0, c).expect("lookup");
|
||||
assert!(close(d.call, open.defend[c][0] as f64 / 1000.0));
|
||||
assert!(close(d.raise, open.defend[c][1] as f64 / 1000.0));
|
||||
let t = vs_three_bet(Variant::Nlhe, Seat::Cutoff, 40.0, c).expect("lookup");
|
||||
assert!(close(t.call, open.vs_three_bet[c][0] as f64 / 1000.0));
|
||||
assert!(close(t.raise, open.vs_three_bet[c][1] as f64 / 1000.0));
|
||||
let j = vs_jam(Variant::Nlhe, Seat::Cutoff, 40.0, c).expect("lookup");
|
||||
assert!(close(j.call, open.vs_jam[c] as f64 / 1000.0));
|
||||
assert!([d, t, j].into_iter().all(sums_to_one));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn between_grid_depths_the_frequencies_are_linearly_interpolated() {
|
||||
for c in 0..CLASS_COUNT {
|
||||
let lo = push_frequency(Variant::Nlhe, Seat::Cutoff, 8.0, c).expect("lookup").raise;
|
||||
let hi = push_frequency(Variant::Nlhe, Seat::Cutoff, 10.0, c).expect("lookup").raise;
|
||||
let mid = push_frequency(Variant::Nlhe, Seat::Cutoff, 9.0, c).expect("lookup");
|
||||
assert!(close(mid.raise, (lo + hi) / 2.0), "class {c}");
|
||||
assert!(sums_to_one(mid));
|
||||
let quarter = push_frequency(Variant::Nlhe, Seat::Cutoff, 8.5, c).expect("lookup").raise;
|
||||
assert!(close(quarter, lo * 0.75 + hi * 0.25));
|
||||
}
|
||||
let a = open_frequency(Variant::Nlhe, Seat::Button, 20.0, id("K9o")).expect("lookup").raise;
|
||||
let b = open_frequency(Variant::Nlhe, Seat::Button, 40.0, id("K9o")).expect("lookup").raise;
|
||||
let m = open_frequency(Variant::Nlhe, Seat::Button, 30.0, id("K9o")).expect("lookup").raise;
|
||||
assert!(close(m, (a + b) / 2.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outside_the_grid_the_nearest_table_is_used() {
|
||||
let (lo, hi) = push_depth_range();
|
||||
assert_eq!((lo, hi), (5.0, 25.0));
|
||||
for c in [id("A2o"), id("T8s"), id("54s")] {
|
||||
let at_lo = push_frequency(Variant::Nlhe, Seat::Early, lo, c).expect("lookup");
|
||||
let below = push_frequency(Variant::Nlhe, Seat::Early, 1.0, c).expect("lookup");
|
||||
let at_hi = push_frequency(Variant::Nlhe, Seat::Early, hi, c).expect("lookup");
|
||||
let above = push_frequency(Variant::Nlhe, Seat::Early, 80.0, c).expect("lookup");
|
||||
assert_eq!(at_lo, below);
|
||||
assert_eq!(at_hi, above);
|
||||
}
|
||||
assert_eq!(open_depth_range(), (20.0, 100.0));
|
||||
assert_eq!(
|
||||
open_frequency(Variant::Nlhe, Seat::Early, 500.0, id("JTs")),
|
||||
open_frequency(Variant::Nlhe, Seat::Early, 100.0, id("JTs"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nonsense_inputs_are_refused_not_panicked_on() {
|
||||
for depth in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY, 0.0, -3.0] {
|
||||
assert!(push_frequency(Variant::Nlhe, Seat::Button, depth, 0).is_none(), "{depth}");
|
||||
assert!(call_vs_push(Variant::Nlhe, Seat::Button, depth, 0).is_none());
|
||||
assert!(open_frequency(Variant::Nlhe, Seat::Button, depth, 0).is_none());
|
||||
assert!(vs_open(Variant::Nlhe, Seat::Button, depth, 0).is_none());
|
||||
assert!(vs_three_bet(Variant::Nlhe, Seat::Button, depth, 0).is_none());
|
||||
assert!(vs_jam(Variant::Nlhe, Seat::Button, depth, 0).is_none());
|
||||
}
|
||||
assert!(push_frequency(Variant::Nlhe, Seat::Button, 10.0, CLASS_COUNT).is_none());
|
||||
assert!(open_frequency(Variant::Nlhe, Seat::Button, 40.0, usize::MAX).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsupported_variants_have_no_chart() {
|
||||
for v in [Variant::Plo5, Variant::KPoker] {
|
||||
assert!(!has_charts(v));
|
||||
assert!(push_frequency(v, Seat::Button, 10.0, 0).is_none(), "{v:?}");
|
||||
assert!(call_vs_push(v, Seat::Button, 10.0, 0).is_none());
|
||||
assert!(open_frequency(v, Seat::Button, 40.0, 0).is_none());
|
||||
}
|
||||
// All-in-or-fold has no open tables.
|
||||
assert!(open_frequency(Variant::Aof, Seat::Button, 40.0, 0).is_none());
|
||||
assert!([Variant::Nlhe, Variant::Aof, Variant::ShortDeck].into_iter().all(has_charts));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_tables_for_both_blinds_are_read_from_their_own_rows() {
|
||||
let push = PUSH_FOLD.iter().find(|s| s.seat == Seat::Cutoff && s.depth_bb == 12).expect("spot");
|
||||
let open = OPEN.iter().find(|s| s.seat == Seat::Middle && s.depth_bb == 40).expect("spot");
|
||||
for c in [id("AA"), id("AJo"), id("77"), id("KTs"), id("72o")] {
|
||||
let sb = sb_call_vs_push(Variant::Nlhe, Seat::Cutoff, 12.0, c).expect("lookup");
|
||||
assert!(close(sb.call, push.sb_call[c] as f64 / 1000.0) && sb.raise == 0.0);
|
||||
let over = bb_overcall_vs_push(Variant::Nlhe, Seat::Cutoff, 12.0, c).expect("lookup");
|
||||
assert!(close(over.call, push.bb_overcall[c] as f64 / 1000.0));
|
||||
let d = sb_vs_open(Variant::Nlhe, Seat::Middle, 40.0, c).expect("lookup");
|
||||
assert!(close(d.call, open.sb_defend[c][0] as f64 / 1000.0));
|
||||
assert!(close(d.raise, open.sb_defend[c][1] as f64 / 1000.0));
|
||||
let o = bb_vs_open_and_call(Variant::Nlhe, Seat::Middle, 40.0, c).expect("lookup");
|
||||
assert!(close(o.call, open.bb_overcall[c] as f64 / 1000.0) && o.raise == 0.0);
|
||||
let t = vs_sb_three_bet(Variant::Nlhe, Seat::Middle, 40.0, c).expect("lookup");
|
||||
assert!(close(t.call, open.vs_sb_three_bet[c][0] as f64 / 1000.0));
|
||||
assert!(close(t.raise, open.vs_sb_three_bet[c][1] as f64 / 1000.0));
|
||||
assert!([sb, over, d, o, t].into_iter().all(sums_to_one));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_small_blind_as_first_actor_has_no_small_blind_or_overcall_rows() {
|
||||
for v in [Variant::Nlhe, Variant::ShortDeck] {
|
||||
assert!(sb_call_vs_push(v, Seat::SmallBlind, 10.0, id("AA")).is_none());
|
||||
assert!(bb_overcall_vs_push(v, Seat::SmallBlind, 10.0, id("AA")).is_none());
|
||||
assert!(sb_vs_open(v, Seat::SmallBlind, 40.0, id("AA")).is_none());
|
||||
assert!(bb_vs_open_and_call(v, Seat::SmallBlind, 40.0, id("AA")).is_none());
|
||||
assert!(vs_sb_three_bet(v, Seat::SmallBlind, 40.0, id("AA")).is_none());
|
||||
// The big blind's tables against the small blind exist.
|
||||
assert!(call_vs_push(v, Seat::SmallBlind, 10.0, id("AA")).is_some());
|
||||
assert!(vs_open(v, Seat::SmallBlind, 40.0, id("AA")).is_some());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn short_deck_reads_its_own_tables() {
|
||||
let spot = short::PUSH_FOLD.iter().find(|s| s.seat == Seat::Button && s.depth_bb == 10).expect("spot");
|
||||
let open = short::OPEN.iter().find(|s| s.seat == Seat::Early && s.depth_bb == 100).expect("spot");
|
||||
for c in [id("AA"), id("A6s"), id("T9o"), id("66")] {
|
||||
let f = push_frequency(Variant::ShortDeck, Seat::Button, 10.0, c).expect("lookup");
|
||||
assert!(close(f.raise, spot.push[c] as f64 / 1000.0));
|
||||
let o = open_frequency(Variant::ShortDeck, Seat::Early, 100.0, c).expect("lookup");
|
||||
assert!(close(o.raise, open.open[c] as f64 / 1000.0));
|
||||
}
|
||||
// A class that is not in the short deck reads as a fold.
|
||||
let deuces = push_frequency(Variant::ShortDeck, Seat::Button, 10.0, id("22")).expect("lookup");
|
||||
assert_eq!(deuces.raise, 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_in_or_fold_answers_exactly_like_push_fold() {
|
||||
for c in 0..CLASS_COUNT {
|
||||
for depth in [5.0, 9.3, 17.0, 25.0] {
|
||||
assert_eq!(
|
||||
push_frequency(Variant::Aof, Seat::SmallBlind, depth, c),
|
||||
push_frequency(Variant::Nlhe, Seat::SmallBlind, depth, c)
|
||||
);
|
||||
assert_eq!(
|
||||
call_vs_push(Variant::Aof, Seat::Early, depth, c),
|
||||
call_vs_push(Variant::Nlhe, Seat::Early, depth, c)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn positions_map_to_chart_seats() {
|
||||
assert_eq!(seat_of(Position::Early), Some(Seat::Early));
|
||||
assert_eq!(seat_of(Position::Middle), Some(Seat::Middle));
|
||||
assert_eq!(seat_of(Position::Cutoff), Some(Seat::Cutoff));
|
||||
assert_eq!(seat_of(Position::Button), Some(Seat::Button));
|
||||
assert_eq!(seat_of(Position::SmallBlind), Some(Seat::SmallBlind));
|
||||
assert_eq!(seat_of(Position::HeadsUpButton), Some(Seat::SmallBlind), "heads-up button is the small blind");
|
||||
assert_eq!(seat_of(Position::Unknown), Some(Seat::Early), "unknown position uses the tightest row");
|
||||
assert_eq!(seat_of(Position::BigBlind), None, "the big blind never opens or jams first");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classes_come_from_cards() {
|
||||
let ace = Card::parse_short("Ah").expect("card");
|
||||
let king = Card::parse_short("Kh").expect("card");
|
||||
let c = class_of(ace, king).expect("class");
|
||||
let f = push_frequency(Variant::Nlhe, Seat::Button, 8.0, c).expect("lookup");
|
||||
assert!(f.raise > 0.9, "AKs jams the button at 8 bb");
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
mod cfr_support;
|
||||
|
||||
use cfr_support::{id, width, width_column};
|
||||
use pokerfreak::cfr::hand_class::CLASS_COUNT;
|
||||
use pokerfreak::cfr::seat::Seat;
|
||||
use pokerfreak::preflop::generated_charts::{
|
||||
use rechner::cfr::hand_class::CLASS_COUNT;
|
||||
use rechner::cfr::seat::Seat;
|
||||
use rechner::preflop::generated_charts::{
|
||||
AOF_PUSH_FOLD, OPEN, OPEN_DEPTHS, PUSH_FOLD, PUSH_FOLD_DEPTHS,
|
||||
};
|
||||
|
||||
@@ -28,11 +28,11 @@ const SLACK: f64 = 0.05;
|
||||
const WIDTH_SLACK: f64 = 0.01;
|
||||
const DEPTH_DRIFT: f64 = 0.06;
|
||||
|
||||
fn push_spot(seat: Seat, depth: u8) -> &'static pokerfreak::cfr::frozen_spot::PushFoldSpot {
|
||||
fn push_spot(seat: Seat, depth: u8) -> &'static rechner::cfr::frozen_spot::PushFoldSpot {
|
||||
PUSH_FOLD.iter().find(|s| s.seat == seat && s.depth_bb == depth).expect("push spot")
|
||||
}
|
||||
|
||||
fn open_spot(seat: Seat, depth: u8) -> &'static pokerfreak::cfr::frozen_spot::OpenSpot {
|
||||
fn open_spot(seat: Seat, depth: u8) -> &'static rechner::cfr::frozen_spot::OpenSpot {
|
||||
OPEN.iter().find(|s| s.seat == seat && s.depth_bb == depth).expect("open spot")
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ fn tight_seats_defend_less_than_they_open_wide_and_big_blind_defends_widest_agai
|
||||
for depth in OPEN_DEPTHS {
|
||||
let vs_ep = open_spot(Seat::Early, depth);
|
||||
let vs_btn = open_spot(Seat::Button, depth);
|
||||
let cont = |s: &pokerfreak::cfr::frozen_spot::OpenSpot| {
|
||||
let cont = |s: &rechner::cfr::frozen_spot::OpenSpot| {
|
||||
width_column(&s.defend, 0) + width_column(&s.defend, 1)
|
||||
};
|
||||
assert!(cont(vs_ep) <= cont(vs_btn) + WIDTH_SLACK, "{depth}bb");
|
||||
@@ -302,9 +302,9 @@ fn both_blinds_play_and_the_overcall_is_tighter_than_the_call() {
|
||||
|
||||
#[test]
|
||||
fn short_deck_tables_hold_only_deck_classes_and_look_like_poker() {
|
||||
use pokerfreak::cfr::hand_class::class_exists;
|
||||
use pokerfreak::preflop::generated_charts_short as short;
|
||||
use pokerfreak::variant::{rules, Variant};
|
||||
use rechner::cfr::hand_class::class_exists;
|
||||
use rechner::preflop::generated_charts_short as short;
|
||||
use rechner::variant::{rules, Variant};
|
||||
let deck = rules(Variant::ShortDeck).deck;
|
||||
let missing: Vec<usize> = (0..CLASS_COUNT).filter(|c| !class_exists(deck, *c)).collect();
|
||||
assert_eq!(missing.len(), 169 - 81);
|
||||
|
||||
@@ -8,23 +8,23 @@
|
||||
//! sampled `stable_since` check covers the push/fold spots of both decks and the open spots of
|
||||
//! the small blind (two players); the three-player open solver is the same generic `solve` and
|
||||
//! is covered through the three-player push/fold spots and the Nash test.
|
||||
use pokerfreak::cfr::chart_deck::ChartDeck;
|
||||
use pokerfreak::cfr::chart_signature::signature;
|
||||
use pokerfreak::cfr::environment::Environment;
|
||||
use pokerfreak::cfr::frozen_spot::PushFoldSpot;
|
||||
use pokerfreak::cfr::frozen_strategy::{open_strategy, push_fold3_strategy, push_fold_strategy};
|
||||
use pokerfreak::cfr::open_game::open_tree;
|
||||
use pokerfreak::cfr::push_fold3_game::push_fold3_tree;
|
||||
use pokerfreak::cfr::push_fold_game::push_fold_tree;
|
||||
use pokerfreak::cfr::render_charts::render_charts;
|
||||
use pokerfreak::cfr::run_plan::{open_iterations, push_fold_iterations, CFR_SEED};
|
||||
use pokerfreak::cfr::seat::Seat;
|
||||
use pokerfreak::cfr::solve::solve;
|
||||
use pokerfreak::cfr::spot_solver::{solve_open_spot, solve_push_fold_spot};
|
||||
use pokerfreak::preflop::generated_charts::{AOF_PUSH_FOLD, OPEN, PUSH_FOLD};
|
||||
use pokerfreak::preflop::generated_charts_short as short;
|
||||
use pokerfreak::rng::Rng;
|
||||
use pokerfreak::variant::{rules, Variant};
|
||||
use rechner::cfr::chart_deck::ChartDeck;
|
||||
use rechner::cfr::chart_signature::signature;
|
||||
use rechner::cfr::environment::Environment;
|
||||
use rechner::cfr::frozen_spot::PushFoldSpot;
|
||||
use rechner::cfr::frozen_strategy::{open_strategy, push_fold3_strategy, push_fold_strategy};
|
||||
use rechner::cfr::open_game::open_tree;
|
||||
use rechner::cfr::push_fold3_game::push_fold3_tree;
|
||||
use rechner::cfr::push_fold_game::push_fold_tree;
|
||||
use rechner::cfr::render_charts::render_charts;
|
||||
use rechner::cfr::run_plan::{open_iterations, push_fold_iterations, CFR_SEED};
|
||||
use rechner::cfr::seat::Seat;
|
||||
use rechner::cfr::solve::solve;
|
||||
use rechner::cfr::spot_solver::{solve_open_spot, solve_push_fold_spot};
|
||||
use rechner::preflop::generated_charts::{AOF_PUSH_FOLD, OPEN, PUSH_FOLD};
|
||||
use rechner::preflop::generated_charts_short as short;
|
||||
use rechner::rng::Rng;
|
||||
use rechner::variant::{rules, Variant};
|
||||
|
||||
/// How many spots of each kind are re-run up to `stable_since`.
|
||||
const SAMPLE: u64 = 3;
|
||||
@@ -69,7 +69,7 @@ fn an_open_spot_is_reproduced_bit_for_bit() {
|
||||
fn the_all_in_or_fold_rules_generate_the_same_push_fold_tables() {
|
||||
// Generic over rules: the AOF rule set (binary action shape) yields the identical spot.
|
||||
let nlhe = Environment::frozen();
|
||||
let aof = Environment::new(&rules(Variant::Aof), pokerfreak::cfr::frozen_equity::frozen_equity())
|
||||
let aof = Environment::new(&rules(Variant::Aof), rechner::cfr::frozen_equity::frozen_equity())
|
||||
.expect("environment");
|
||||
let aof = Environment { rake: nlhe.rake, antes: nlhe.antes, ..aof };
|
||||
let a = solve_push_fold_spot(&aof, Seat::Middle, 12).expect("spot");
|
||||
@@ -156,14 +156,14 @@ fn the_frozen_chart_file_is_exactly_what_the_generator_prints() {
|
||||
|
||||
#[test]
|
||||
fn the_frozen_equity_file_is_exactly_what_the_generator_prints() {
|
||||
use pokerfreak::cfr::generated_equity as frozen;
|
||||
use pokerfreak::cfr::render_equity::render_equity;
|
||||
use rechner::cfr::generated_equity as frozen;
|
||||
use rechner::cfr::render_equity::render_equity;
|
||||
let committed = unix(include_str!("../src/cfr/generated_equity.rs"));
|
||||
assert!(
|
||||
committed == render_equity(pokerfreak::cfr::chart_deck::ChartDeck::Full, frozen::SEED, frozen::SAMPLES, &frozen::TRIANGLE),
|
||||
committed == render_equity(rechner::cfr::chart_deck::ChartDeck::Full, frozen::SEED, frozen::SAMPLES, &frozen::TRIANGLE),
|
||||
"generated_equity.rs differs from the renderer output"
|
||||
);
|
||||
use pokerfreak::cfr::generated_equity_short as short_equity;
|
||||
use rechner::cfr::generated_equity_short as short_equity;
|
||||
let committed = unix(include_str!("../src/cfr/generated_equity_short.rs"));
|
||||
assert!(
|
||||
committed == render_equity(ChartDeck::Short, short_equity::SEED, short_equity::SAMPLES, &short_equity::TRIANGLE),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::game::{ActionKind, Choice, Decision, Spot};
|
||||
use pokerfreak::guard::enforce::enforce;
|
||||
use pokerfreak::variant::Variant;
|
||||
use rechner::game::{ActionKind, Choice, Decision, Spot};
|
||||
use rechner::guard::enforce::enforce;
|
||||
use rechner::variant::Variant;
|
||||
use spot_fixture::*;
|
||||
|
||||
fn choose(spot: &Spot, choice: Choice) -> Choice {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::game::{Choice, Spot};
|
||||
use pokerfreak::guard::settle::settle;
|
||||
use rechner::game::{Choice, Spot};
|
||||
use rechner::guard::settle::settle;
|
||||
use spot_fixture::*;
|
||||
|
||||
fn close(a: f64, b: f64) -> bool {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
mod spot_fixture;
|
||||
|
||||
use pokerfreak::fault::Fault;
|
||||
use pokerfreak::game::{ActionKind, Spot, Street};
|
||||
use pokerfreak::guard::validate::check;
|
||||
use pokerfreak::variant::Variant;
|
||||
use rechner::fault::Fault;
|
||||
use rechner::game::{ActionKind, Spot, Street};
|
||||
use rechner::guard::validate::check;
|
||||
use rechner::variant::Variant;
|
||||
use spot_fixture::*;
|
||||
|
||||
fn fault_text(spot: Spot) -> String {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! Five-card evaluation: categories, kickers, wheel, ordering.
|
||||
//! Category ranking order: standard poker hand ranking (Wikipedia "List of poker hands").
|
||||
use pokerfreak::card::Card;
|
||||
use pokerfreak::hand::category::Category;
|
||||
use pokerfreak::hand::five::evaluate;
|
||||
use pokerfreak::hand::strength::Strength;
|
||||
use rechner::card::Card;
|
||||
use rechner::hand::category::Category;
|
||||
use rechner::hand::five::evaluate;
|
||||
use rechner::hand::strength::Strength;
|
||||
|
||||
fn s(text: &str) -> Strength {
|
||||
let cards = Card::parse_list(text).expect("cards");
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
//! Best-hand selection per variant family and its failure modes.
|
||||
//! Omaha rule (exactly 2 hole + exactly 3 board): standard Omaha rules, Wikipedia "Omaha hold 'em".
|
||||
use pokerfreak::card::Card;
|
||||
use pokerfreak::fault::Fault;
|
||||
use pokerfreak::hand::category::Category;
|
||||
use pokerfreak::hand::showdown::best;
|
||||
use pokerfreak::hand::strength::Strength;
|
||||
use pokerfreak::variant::HoleUsage;
|
||||
use pokerfreak::variant::HoleUsage::{BestFiveOfAll as Holdem, ExactlyTwoHole as Omaha};
|
||||
use rechner::card::Card;
|
||||
use rechner::fault::Fault;
|
||||
use rechner::hand::category::Category;
|
||||
use rechner::hand::showdown::best;
|
||||
use rechner::hand::strength::Strength;
|
||||
use rechner::variant::HoleUsage;
|
||||
use rechner::variant::HoleUsage::{BestFiveOfAll as Holdem, ExactlyTwoHole as Omaha};
|
||||
|
||||
fn cs(text: &str) -> Vec<Card> {
|
||||
Card::parse_list(text).expect("cards")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use pokerfreak::fault::Fault;
|
||||
use pokerfreak::game::{ActionRecord, SeenAction, Spot, Street};
|
||||
use pokerfreak::json::parse;
|
||||
use pokerfreak::wire::decode::decode;
|
||||
use rechner::fault::Fault;
|
||||
use rechner::game::{ActionRecord, SeenAction, Spot, Street};
|
||||
use rechner::json::parse;
|
||||
use rechner::wire::decode::decode;
|
||||
|
||||
const EXAMPLE: &str = r#"{
|
||||
"variant": "NLHE",
|
||||
|
||||
+7
-7
@@ -1,12 +1,12 @@
|
||||
//! ICM-lite: harville equities and the bubble. Same spots, cash against bubble.
|
||||
|
||||
use pokerfreak::card::Card;
|
||||
use pokerfreak::engine::decide::{decide, decide_with};
|
||||
use pokerfreak::game::{ActionKind, ActionRecord, Choice, SeenAction, Spot, Street, Villain};
|
||||
use pokerfreak::icm::harville::equities;
|
||||
use pokerfreak::icm::lage::Turnierlage;
|
||||
use pokerfreak::icm::risk::{call_premium, required_equity};
|
||||
use pokerfreak::variant::Variant;
|
||||
use rechner::card::Card;
|
||||
use rechner::engine::decide::{decide, decide_with};
|
||||
use rechner::game::{ActionKind, ActionRecord, Choice, SeenAction, Spot, Street, Villain};
|
||||
use rechner::icm::harville::equities;
|
||||
use rechner::icm::lage::Turnierlage;
|
||||
use rechner::icm::risk::{call_premium, required_equity};
|
||||
use rechner::variant::Variant;
|
||||
|
||||
const RANKS: &str = "AKQJT98765432";
|
||||
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
use pokerfreak::fault::Fault;
|
||||
use pokerfreak::json::field::{
|
||||
use rechner::fault::Fault;
|
||||
use rechner::json::field::{
|
||||
at, flag, items, join, number, optional, required, text, whole_u64, whole_u8,
|
||||
};
|
||||
use pokerfreak::json::parse;
|
||||
use rechner::json::parse;
|
||||
|
||||
fn invalid_field(f: Fault) -> String {
|
||||
match f {
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
use pokerfreak::fault::Fault;
|
||||
use pokerfreak::json::{parse, Value};
|
||||
use rechner::fault::Fault;
|
||||
use rechner::json::{parse, Value};
|
||||
|
||||
fn ok(text: &str) -> Value {
|
||||
parse(text).unwrap_or_else(|f| panic!("{text:?} should parse, got {f}"))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use pokerfreak::json::{parse, render, Value};
|
||||
use rechner::json::{parse, render, Value};
|
||||
|
||||
#[test]
|
||||
fn scalars() {
|
||||
|
||||
+7
-7
@@ -25,8 +25,8 @@ import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
WURZEL = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
# Liegt die Engine daneben (POKERFREAK_ENGINE nennt ihr Kommando), holen wir ihre Ordner dazu:
|
||||
_eng = os.environ.get("POKERFREAK_ENGINE")
|
||||
# Liegt die Engine daneben (ENGINE nennt ihr Kommando), holen wir ihre Ordner dazu:
|
||||
_eng = os.environ.get("ENGINE")
|
||||
if _eng:
|
||||
_er = os.path.dirname(os.path.dirname(os.path.abspath(_eng.split()[-1])))
|
||||
for _u in ("betrieb", "mcp", "hand", "lobby"):
|
||||
@@ -113,11 +113,11 @@ class Klonlauf:
|
||||
|
||||
def umgebung(self, **mehr):
|
||||
umg = {k: v for k, v in os.environ.items()
|
||||
if k not in ("COINPOKER_LOG", "CDP_PORT", "POKERFREAK_SEED", "POKERFREAK_SCRATCH",
|
||||
"POKERFREAK_SPERRE", "POKERFREAK_ZEIGER")}
|
||||
if k not in ("COINPOKER_LOG", "CDP_PORT", "SEED", "SCRATCH",
|
||||
"SPERRE", "ZEIGER")}
|
||||
umg.update(CLIENT="0", COINPOKER_KLONMAUS="1", COINPOKER_LOG=self.log,
|
||||
CDP_PORT=str(self.cdp_port), POKERFREAK_SCRATCH=self.scratch, PYTHONUNBUFFERED="1",
|
||||
POKERFREAK_STATS_DIR=os.path.join(self.ordner, "statistik"), POKERFREAK_STROM="0")
|
||||
CDP_PORT=str(self.cdp_port), SCRATCH=self.scratch, PYTHONUNBUFFERED="1",
|
||||
STATS_DIR=os.path.join(self.ordner, "statistik"), STROM="0")
|
||||
if "--gleiche-titel" in self.schalter:
|
||||
umg["COINPOKER_KLON_GLEICHE_TITEL"] = "1"
|
||||
if "--prozessform" in self.schalter:
|
||||
@@ -177,7 +177,7 @@ class Klonlauf:
|
||||
def laeufer_starten(self, seed="kette", **umg):
|
||||
p = subprocess.Popen(_steuern.engine_befehl(), stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT, text=True, encoding="utf-8", errors="replace",
|
||||
env=self.umgebung(POKERFREAK_SEED=seed, **umg))
|
||||
env=self.umgebung(SEED=seed, **umg))
|
||||
zeilen = self.ausgaben.setdefault(p.pid, [])
|
||||
datei = os.path.join(self.ordner, f"laeufer-{p.pid}.txt") # bleibt mit KLONLAUF_BEHALTEN=1
|
||||
|
||||
|
||||
@@ -47,8 +47,8 @@ ORDNER = tempfile.mkdtemp(prefix="laeufer-")
|
||||
LOG = os.path.join(ORDNER, "main.log")
|
||||
os.environ["COINPOKER_LOG"] = LOG
|
||||
os.environ["CLIENT"] = "1" # gegen den Client
|
||||
os.environ["POKERFREAK_STATS_DIR"] = os.path.join(ORDNER, "statistik")
|
||||
os.environ["POKERFREAK_SPERRE"] = os.path.join(ORDNER, "laeufer.pid") # nicht die Sperre eines Laufs
|
||||
os.environ["STATS_DIR"] = os.path.join(ORDNER, "statistik")
|
||||
os.environ["SPERRE"] = os.path.join(ORDNER, "laeufer.pid") # nicht die Sperre eines Laufs
|
||||
|
||||
KLICKS = [] # ("zug", aktion) | ("stellen", [Namen])
|
||||
STELLEN = [] # die Stellen dazu
|
||||
@@ -644,7 +644,7 @@ class Beenden(unittest.TestCase):
|
||||
self.assertEqual(KLICKS, [("stellen", ["kreuz"])], "in der Pause aufgestanden")
|
||||
|
||||
def test_pause_raeumt_mit_schalter_wie_frueher(self):
|
||||
"""POKERFREAK_PAUSE_RAEUMT=1: in der Pause aufstehen wie vorher - der Platz wird geraeumt."""
|
||||
"""PAUSE_RAEUMT=1: in der Pause aufstehen wie vorher - der Platz wird geraeumt."""
|
||||
alt = runner.PAUSE_RAEUMT
|
||||
runner.PAUSE_RAEUMT = True
|
||||
try:
|
||||
|
||||
+3
-3
@@ -75,16 +75,16 @@ def umgebung():
|
||||
sys.path.insert(0, os.path.join(HIER, "..", "client"))
|
||||
try:
|
||||
import umgebung as _umg # die Naht kennt die Engine (Nachbar oder ausdruecklich)
|
||||
umg.setdefault("POKERFREAK_ENGINE", _umg.engine())
|
||||
umg.setdefault("ENGINE", _umg.engine())
|
||||
_er = os.path.dirname(os.path.dirname(os.path.abspath(_umg.engine().split()[-1])))
|
||||
_pfade = [os.path.join(_er, d) for d in ("hand", "betrieb", "mcp", "lobby", "entscheiden")]
|
||||
umg["PYTHONPATH"] = os.pathsep.join([p for p in _pfade + [umg.get("PYTHONPATH", "")] if p])
|
||||
except Exception:
|
||||
pass
|
||||
umg.update(CDP_PORT=SPERRPORT, POKERFREAK_STOPP_ORDNER=tempfile.mkdtemp(prefix="pf-stopp-"))
|
||||
umg.update(CDP_PORT=SPERRPORT, STOPP_ORDNER=tempfile.mkdtemp(prefix="pf-stopp-"))
|
||||
if umg.get("MOCK_HEADLESS") != "0": # kein Prozess einer Prüfung fasst die Maus an (tests/wache/)
|
||||
umg["PYTHONPATH"] = os.pathsep.join(p for p in (WACHE, umg.get("PYTHONPATH")) if p)
|
||||
umg["POKERFREAK_WACHE_DATEI"] = WACHE_DATEI
|
||||
umg["WACHE_DATEI"] = WACHE_DATEI
|
||||
return umg
|
||||
|
||||
|
||||
|
||||
+11
-11
@@ -86,7 +86,7 @@ UHR = 16 # Bedenkzeit je eigenem Zug im Kettentest (--clock)
|
||||
# Die Aufnahme, die der Klon abspielt, hat 30 s Zusatzzeit an - der Zug ist also
|
||||
# länger als --clock (tests/lagen_spec.py hält dieselbe Rechnung fest).
|
||||
UHR_WIRKLICH = UHR + lagen.ZUSATZ_S
|
||||
SEED = "kette-1" # POKERFREAK_SEED: Gedenkzeiten exakt nachrechenbar
|
||||
SEED = "kette-1" # SEED: Gedenkzeiten exakt nachrechenbar
|
||||
KETTE_KONTO = 2000000 # Guthaben im Kettentest: lesen/geld.py erlaubt damit 6 Tische
|
||||
VORLAGE = os.path.join(WURZEL, "mock", "vorlage", "dom-lobby.json")
|
||||
HELD = "mmintel"
|
||||
@@ -703,15 +703,15 @@ class Klon(unittest.TestCase):
|
||||
# Der Test hat nur Join geklickt; er liest und verstellt höchstens den Stack.
|
||||
schatten = os.path.join(self.ordner, "scratch", "shadow.jsonl") # eigener Ordner, nie das Protokoll
|
||||
umg = {k: v for k, v in os.environ.items()
|
||||
if k not in ("COINPOKER_LOG", "CDP_PORT", "POKERFREAK_SEED")}
|
||||
if k not in ("COINPOKER_LOG", "CDP_PORT", "SEED")}
|
||||
if seed:
|
||||
umg["POKERFREAK_SEED"] = seed
|
||||
umg["SEED"] = seed
|
||||
runner = subprocess.Popen(
|
||||
[sys.executable, RUNNER, "--act"], stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT, text=True, encoding="utf-8", errors="replace",
|
||||
**NEUE_GRUPPE, env=dict(umg, CLIENT="0", PYTHONUNBUFFERED="1",
|
||||
POKERFREAK_STATS_DIR=os.path.join(self.ordner, "statistik"),
|
||||
POKERFREAK_SCRATCH=os.path.join(self.ordner, "scratch")))
|
||||
STATS_DIR=os.path.join(self.ordner, "statistik"),
|
||||
SCRATCH=os.path.join(self.ordner, "scratch")))
|
||||
try:
|
||||
for raum in tische:
|
||||
warte(lambda raum=raum: f'"Cmd":"game.seatInfo","RoomName":"{raum}"'
|
||||
@@ -871,13 +871,13 @@ class Klon(unittest.TestCase):
|
||||
self.assertFalse(os.path.exists(STOPP), f"Not-Aus gesetzt: {STOPP}")
|
||||
schatten = os.path.join(self.ordner, "scratch", "shadow.jsonl") # eigener Ordner, nie das Protokoll
|
||||
umg = {k: v for k, v in os.environ.items()
|
||||
if k not in ("COINPOKER_LOG", "CDP_PORT", "POKERFREAK_SEED")}
|
||||
if k not in ("COINPOKER_LOG", "CDP_PORT", "SEED")}
|
||||
runner = subprocess.Popen(
|
||||
[sys.executable, RUNNER, "--act"], stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT, text=True, encoding="utf-8", errors="replace",
|
||||
**NEUE_GRUPPE, env=dict(umg, CLIENT="0", PYTHONUNBUFFERED="1",
|
||||
POKERFREAK_STATS_DIR=os.path.join(self.ordner, "statistik"),
|
||||
POKERFREAK_SCRATCH=os.path.join(self.ordner, "scratch")))
|
||||
STATS_DIR=os.path.join(self.ordner, "statistik"),
|
||||
SCRATCH=os.path.join(self.ordner, "scratch")))
|
||||
try:
|
||||
def sitz():
|
||||
for d in bohnen(log_text(self.log), VOLL, "game.seatInfo"):
|
||||
@@ -1706,13 +1706,13 @@ class Klon(unittest.TestCase):
|
||||
self.ziel(lambda t: t.get("title") == "NLH 123456 - 1K/2K", "Tisch nach cdp.mjs")
|
||||
self.assertFalse(os.path.exists(STOPP), f"Not-Aus gesetzt: {STOPP}")
|
||||
umg = {k: v for k, v in os.environ.items()
|
||||
if k not in ("COINPOKER_LOG", "CDP_PORT", "POKERFREAK_SEED")}
|
||||
if k not in ("COINPOKER_LOG", "CDP_PORT", "SEED")}
|
||||
runner = subprocess.Popen(
|
||||
[sys.executable, RUNNER, "--act"], stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT, text=True, encoding="utf-8", errors="replace",
|
||||
**NEUE_GRUPPE, env=dict(umg, CLIENT="0", PYTHONUNBUFFERED="1",
|
||||
POKERFREAK_STATS_DIR=os.path.join(self.ordner, "statistik"),
|
||||
POKERFREAK_SCRATCH=os.path.join(self.ordner, "scratch")))
|
||||
STATS_DIR=os.path.join(self.ordner, "statistik"),
|
||||
SCRATCH=os.path.join(self.ordner, "scratch")))
|
||||
try:
|
||||
warte(lambda: self.zustand()["held_sitz"], 90, "der Läufer setzt sich")
|
||||
warte(lambda: self.zustand()["turnier"]["level"] >= 3, 120, "Level 3 beim Spielen")
|
||||
|
||||
@@ -48,7 +48,7 @@ class Dateien(unittest.TestCase):
|
||||
|
||||
def test_dieselben_dateien_wie_das_cockpit(self):
|
||||
self.assertEqual(sorted(stopp.STOPP_PFADE), sorted(notaus.PFADE))
|
||||
if not os.environ.get("POKERFREAK_STOPP_ORDNER"): # ohne Test-Ordner: die der App
|
||||
if not os.environ.get("STOPP_ORDNER"): # ohne Test-Ordner: die der App
|
||||
self.assertEqual(sorted(p.replace(notaus.WURZEL + "/", "") for p in notaus.PFADE),
|
||||
["betrieb/scratch/stop", "hand/scratch/stop", "scratch/stop"])
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import notaus
|
||||
|
||||
class Waechter(unittest.TestCase):
|
||||
def test_app_laeuft_gilt_als_waechter(self):
|
||||
liste = " 4711 /Applications/x/Pokerfreak Cockpit.app/Contents/MacOS/Cockpit\n 22 /usr/bin/ps\n"
|
||||
liste = " 4711 /Applications/x/Cockpit.app/Contents/MacOS/Cockpit\n 22 /usr/bin/ps\n"
|
||||
self.assertEqual(notaus.esc_waechter(liste), 4711)
|
||||
|
||||
def test_ohne_app_kein_waechter(self):
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user