Files
pokerfreak/hand/act.py
T
mmintel 9c79d8236b Acceptance 5.11.: channel play without AFK, quiet focus, working Cockpit, stronger play
- Practice tables: 20-min session 54/54 turns at the server, control session 28 turns,
  0 timeouts; stage: 3 tables, two rounds each, clean teardown.
- Never let the clock run: an engine abstention becomes check or fold (nie_verstreichen).
- Mittler join in a fixed order (kill the duplicate, then announce), a mittler ends with its
  game, the laufwache opens no tables, stop waits for the runner to stand up.
- Focus: no lobby connections from HUD, probes or layout; "Focus Window on Turn" off.
- Tables: disconnected or sitting-out opponents do not count; a table without channel is
  closed and avoided after 45 s; the join event keeps the writer's pid (strict invariants).
- Geldwache: same room list as the runner, the table's own report, stand up before closing.
- Engine: the small blind completes the top 65 % against limpers (price per fair share);
  the calling range of a bet is as wide as the villain calls - value bets into stations.
- Cockpit: the source tree never comes from SHELL; one operating set for laufwache and
  Cockpit (sicht/start.py --client, ServerStart).
- Project lives in ~/Projects/pokerfreak (kern was a detour).
2026-11-05 16:10:43 +01:00

164 lines
6.4 KiB
Python

#!/usr/bin/env python3
"""Setzt eine Entscheidung des Kerns in einen Klick um - mit Sicherungen.
Sicherungen:
* Aussetzen wird nicht geklickt.
* Der Klick geht in das Fenster des richtigen Tisches (nicht in irgendeines).
* Eine Stopp-Datei schaltet das Klicken ab, ohne den Lauf zu beenden.
* Vor dem Klick wird geprüft, dass das Fenster noch da ist.
from act import ausfuehren
"""
import os as _os, sys as _sys
_w = _os.path.dirname(_os.path.abspath(__file__))
while _w != "/" and not _os.path.isdir(_os.path.join(_w, "lesen")):
_w = _os.path.dirname(_w)
WURZEL = _w
for _u in ("lesen", "entscheiden", "hand", "client", "lobby", "korpus", "betrieb"):
_q = _os.path.join(_w, _u)
if _os.path.isdir(_q) and _q not in _sys.path:
_sys.path.insert(0, _q)
import importlib.util
import json
import os
import sys
import time
import umgebung
import fenster
import notaus
import zeiger
BASE = os.path.dirname(os.path.abspath(__file__))
STOPP = os.path.join(BASE, "scratch", "stop")
COCKPIT = os.path.join(umgebung.treffpunkt(), "cockpit.json") # Rahmen der Leiste (Naht)
AUSWEICHEN = os.path.join(umgebung.treffpunkt(), "ausweichen") # Naht: das Panel tritt zur Seite
if fenster.klon_ohne_mac(): # Klon ohne macOS: Mausereignisse über CDP, click.py bleibt ungeladen
import klonmaus as click
else:
_spec = importlib.util.spec_from_file_location("cpclick", os.path.join(BASE, "click.py"))
click = importlib.util.module_from_spec(_spec)
sys.modules["cpclick"] = click # hand/eingabe.py nimmt dasselbe Modul
_spec.loader.exec_module(click)
import eingabe # noqa: E402 (mit Maus oder ohne - hand/eingabe.py)
WARTEZEIT = 0.30
GESPERRT = {"ABSTAIN", None}
ZU_TAT = {"FOLD": "fold", "CHECK": "call", "CALL": "call", "RAISE": "raise"}
def gestoppt():
"""Not-Aus gesetzt (hand/notaus.py - alle Stopp-Dateien, wie das Cockpit sie schreibt)."""
return notaus.aktiv()
def ziel_fuer(aktion):
return ZU_TAT.get(aktion)
def ausfuehren(entscheidung, raum=None, warten=None, f=None):
"""Klickt die Entscheidung im Fenster des Raums. Gibt zurück, was geklickt wurde.
`warten` ist die Denkzeit in Sekunden; die Knopfleiste braucht ohnehin kurz. `f`: das Fenster,
falls der Läufer es schon kennt (namenlose Fenster: gebunden in betrieb/tischzustand.py).
"""
aktion = entscheidung.get("action")
if aktion in GESPERRT or gestoppt():
return None
ziel = ziel_fuer(aktion)
if not ziel:
return None
f = f or (fenster.fenster_fuer(raum) if raum else None)
rect = f["rect"] if f else click.window_rect()
if not rect:
return None
time.sleep(max(warten or 0.0, WARTEZEIT))
px, py = click.point_for(ziel, rect)
_klicken(px, py, f, click.maus.halbe_groesse(ziel, rect))
groesse = entscheidung.get("size")
return ziel + (f" {groesse}" if groesse else "")
def cockpit_ausweichen(px, py, jetzt=None):
"""Liegt der Klickpunkt unter dem schwebenden Cockpit (das Panel der Cockpit-App), tritt es
kurz zur Seite - ein globaler Klick trifft sonst sie statt des Tisches. True, wenn gewartet
wurde. Ohne Leiste (keine oder veraltete Rahmendatei) nichts."""
jetzt = time.time() if jetzt is None else jetzt
try:
with open(COCKPIT, encoding="utf-8") as f:
d = json.load(f)
if jetzt - float(d["zeit"]) > 10:
return False
x, y, w, h = (float(z) for z in d["rect"])
except (OSError, ValueError, KeyError, TypeError):
return False
rand = 12
if not (x - rand <= px <= x + w + rand and y - rand <= py <= y + h + rand):
return False
try:
with open(AUSWEICHEN, "w", encoding="utf-8") as f:
f.write(str(jetzt))
except OSError:
return False
time.sleep(0.35)
return True
# Vorgabe an (hand/click.py); die Klon-Maus (hand/klonmaus.py) hebt nichts an - dort gibt es
# nichts zurueckzuholen (ohne getattr brach der Import des Laeufers im Klonlauf ab, 5.11.).
FOKUS_ZURUECK = getattr(click, "FOKUS_ZURUECK", False)
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 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.
"""
if click.__name__ != "klonmaus" and eingabe.art() == eingabe.MAUS: # nur globale Klicks treffen die Leiste des Cockpits
cockpit_ausweichen(px, py)
vorher = True if FOKUS_ZURUECK else None # was "vorher" war, merkt click beim Anheben
zeiger.anhalten()
pos = None
try:
pos = click.click(px, py, fenster=f, halb=halb, **({"rng": rng} if rng else {}))
finally:
zeiger.weiter(pos if isinstance(pos, tuple) else (px, py), f)
return pos
# Kam das Zielfenster nicht nach vorn, klickt click.py nicht (der Klick träfe ein fremdes Fenster).
FensterNichtVorn = getattr(click, "FensterNichtVorn", ())
def stellen_klicken(f, stellen, pause=(0.6, 1.1), rng=None, trotz_stopp=False):
"""Klickt Stellen (Name, (fx, fy)) als Anteil des Fensterrahmens nacheinander - für das
Setzen (hand/sitzen.py). Mit Pause dazwischen, der Dialog braucht kurz. Gibt die Namen
zurück, die geklickt wurden. Not-Aus wird vor jedem Klick gefragt und gilt immer - auch mit
`trotz_stopp` (bleibt für die Aufrufer; am 30.10. klickte das Aufräumen nach ESC noch Sitout)."""
import random
rng = rng or random
if not f:
return []
geklickt = []
for i, (name, (fx, fy)) in enumerate(stellen):
if i:
time.sleep(rng.uniform(*pause))
if gestoppt():
break # Not-Aus zwischen zwei Klicks: der Rest fällt weg
x, y, w, h = f["rect"]
try:
_klicken(round(x + w * fx), round(y + h * fy), f, click.maus.halbe_groesse(name, f["rect"]), rng)
except FensterNichtVorn:
break # nicht vorn: der Rest der Folge träfe ein fremdes Fenster
geklickt.append(name)
return geklickt
if __name__ == "__main__":
print("Fenster:", click.window_rect())
print("gestoppt:", gestoppt())
for name in click.SPOTS:
print(f" {name:<8} {click.point_for(name, click.window_rect())}")