Files
pokerfreak/hand/act.py
T
mmintelandClaude Opus 5.5 56265f343d Not-Aus heisst keine Eingabe mehr; offene Tische je Raum
Live 30.10.: ESC at 11:03:09 set all stop files, yet the runner clicked
"max" and "buyin" at 11:03:12 - stellen_klicken checked only before a
sequence, the mouse path never, and cleanup clicked sitout/cross
"trotz_stopp". hand/notaus.py is now the one source for the stop files
(act, click, stopp); click.click checks before start, on every movement
step and before pressing (KlickNotAus), pid_klick too, sequences check
before each click, trotz_stopp no longer overrides Not-Aus, dialog.esc
sends no key and the live pointer stops. The runner logs "nicht geklickt
(Not-Aus)" instead of a sitout it did not do. The header counted every
window of a table process (table + dialog = 2); it now counts rooms from
the process list. Tests get their own stop folder (POKERFREAK_STOPP_ORDNER)
so they never see or touch the machine's Not-Aus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 11:20:36 +01:00

156 lines
6.0 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, "hand")):
_w = _os.path.dirname(_w)
WURZEL = _w
for _u in ("lesen", "entscheiden", "hand", "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 fenster
import notaus
import zeiger
BASE = os.path.dirname(os.path.abspath(__file__))
STOPP = os.path.join(BASE, "scratch", "stop")
COCKPIT = os.path.join(WURZEL, "sicht", "scratch", "cockpit.json") # Rahmen der Leiste
AUSWEICHEN = os.path.join(WURZEL, "sicht", "scratch", "ausweichen")
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, wie=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), wie=wie)
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 Mac-App, mac/Sources/Cockpit/Panel.swift), 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
def _klicken(px, py, f, halb, rng=None, wie=None):
"""Ein Klick nach der Eingabe-Strategie (hand/eingabe.py: mit Maus oder ohne), und der Zeiger
(hand/zeiger.py) ruht so lange - ohne Lauf ohne Wirkung. `wie` erzwingt eine Strategie."""
klon = click.__name__ == "klonmaus"
wie = None if klon else (wie or eingabe.art())
if not klon and wie == eingabe.MAUS: # nur globale Klicks treffen die Leiste des Cockpits
cockpit_ausweichen(px, py)
zeiger.anhalten()
pos = None
try:
pos = (click.click(px, py, fenster=f, halb=halb, **({"rng": rng} if rng else {})) if klon
else eingabe.tisch_klick(px, py, f, halb=halb, wie=wie, rng=rng))
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, wie=None):
"""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; live 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, wie)
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())}")