Files
pokerfreak/hand/eingabe.py
T
mmintelandClaude Opus 5.5 bbadd2b2f3 Erst schauen, dann klicken: aktiver Reiter, offene Tische, Klick nur im Fenster; Tests ohne echten Client
Live 30.10. the bot clicked the Practice tab it was already on and the
user saw clicks beside the window. Lobby: read the active tab (.active-tab,
measured) and click only if needed, then verify it switched; never Join a
table whose window is open (fill and self-heal). A real mouse click is only
sent when the point and its scattered end lie inside the target window
(KlickAusserhalb, a FensterNichtVorn), and not at all without a lobby
window. Two mcp_server_spec tests patched the wrong name and clicked the
real lobby with the real mouse whenever CoinPoker ran - they now patch
lobby_adapter and demand an opened table; tests/lauf.py blocks the real
debug port for every spec.

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

85 lines
3.5 KiB
Python

#!/usr/bin/env python3
"""Eingabe als Strategie - einheitlich für Lobby und Tisch, mit einem Schalter (Spielplan "maus").
mit Maus Tisch: globaler Klick, Fenster vorher nachweislich vorn (hand/click.py)
Lobby: cdp.mjs liefert die Bildschirmlage des Knopfs ("MAUS {x, y}"), hier echter Klick
ohne Maus Tisch: Klick an den Prozess (CGEventPostToPid) - kein Fenster nach vorn, Zeiger bleibt
Lobby: JavaScript-Klick über den Debug-Port (wie bisher)
Standard bis zur Messung am Unity-Tisch: mit Maus. Wird ein Klick ohne Maus nicht bestätigt, weicht
der Läufer für den zweiten Versuch auf die Maus aus und sagt es im Protokoll (betrieb/runner.py).
Spezifikation: tests/eingabe_spec.py. Auftrag: AUFTRAG-eingabe.md.
"""
import importlib.util
import json
import os
import re
import sys
_w = os.path.dirname(os.path.abspath(__file__))
WURZEL = os.path.dirname(_w)
SPIELPLAN = os.path.join(os.environ.get("POKERFREAK_SCRATCH") or os.path.join(WURZEL, "betrieb", "scratch"),
"spielplan.json")
MAUS, OHNE = "maus", "ohne"
MAUS_ANTWORT = re.compile(r"^MAUS (\{.*\})\s*$", re.S)
def _click():
"""hand/click.py als dasselbe Modul wie in hand/act.py ("cpclick", über den Pfad geladen - ein
PyPI-Paket "click" darf nie gemeint sein). Erst bei Bedarf: im Klon ohne Mac fehlt macOS."""
m = sys.modules.get("cpclick")
if m is None:
spec = importlib.util.spec_from_file_location("cpclick", os.path.join(_w, "click.py"))
m = importlib.util.module_from_spec(spec)
sys.modules["cpclick"] = m
spec.loader.exec_module(m)
return m
def art():
""""maus" oder "ohne" - aus dem Spielplan; fehlt er oder die Angabe: mit Maus. Im Klon nie die
echte Maus: dort klickt die Lobby über die Seite und die Klon-Maus den Tisch (Chaos chaos-1)."""
if os.environ.get("COINPOKER_MOCK") == "1" and (
sys.platform != "darwin" or os.environ.get("COINPOKER_KLONMAUS") == "1"):
return OHNE # wie fenster.klon_ohne_mac: es klickt die Klon-Maus
try:
with open(SPIELPLAN, encoding="utf-8") as f:
d = json.load(f)
except (OSError, ValueError):
return MAUS
return OHNE if isinstance(d, dict) and d.get("maus") is False else MAUS
def tisch_klick(px, py, fenster, halb=(0.0, 0.0), wie=None, rng=None):
"""Ein Klick am Tisch nach der Strategie (`wie` erzwingt eine). -> Zeigerposition danach."""
wie = wie or art()
if wie == OHNE and fenster and fenster.get("pid"):
return _click().pid_klick(px, py, fenster)
return _click().click(px, py, fenster=fenster, halb=halb, **({"rng": rng} if rng else {}))
def lobby_maus_klick(x, y):
"""Echter Mausklick in der Lobby (Bildschirmpunkte), Lobbyfenster vorher nach vorn. Ohne
erkanntes Lobbyfenster kein Klick (False) - der Punkt läge sonst irgendwo (live 30.10.)."""
import fenster as fenster_
lobby = next((f for f in fenster_.alle() if not f.get("tischfenster")), None)
if lobby is None:
return False
_click().click(x, y, fenster=lobby)
return True
def lobby_antwort(text):
"""Antwort von lobby/cdp.mjs auswerten: "MAUS {...}" heisst - hier mit der Maus klicken."""
m = MAUS_ANTWORT.match(text or "")
if not m:
return text
try:
d = json.loads(m.group(1))
x, y = float(d["x"]), float(d["y"])
except (ValueError, KeyError, TypeError):
return text
if not lobby_maus_klick(x, y):
return "nicht geklickt: kein Lobbyfenster gefunden"
return "per Maus geklickt: " + str(d.get("text") or "")