Bots: Tegn og Gæt-bots sover kun før en handling

Under afsløringen kom snapshots hurtigere, end en bot med en pause
efter hver besked kunne læse dem, og forbindelsen faldt (ping-timeout).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
agw
2026-10-20 18:01:31 +02:00
co-authored by Claude Opus 5.5
parent 9b0f604a69
commit 5a98917864
+6 -2
View File
@@ -176,15 +176,20 @@ async def _tegn_player(ws_base, code, name, n_players, done, rng, stop_at_final)
return
task = me.get("task")
key = (st["phase"], (st.get("step") or {}).get("index"))
await asyncio.sleep(rng.uniform(0.05, 0.4))
# Tænkepausen kun før en handling: under afsløringen kommer der mange snapshots, og en bot,
# der sover efter hvert, når ikke at læse dem (og serverens ping) i tide.
pause = lambda: asyncio.sleep(rng.uniform(0.05, 0.4)) # noqa: E731
if st["phase"] == "lobby" and me["vip"] and len(st["players"]) >= n_players and key not in acted:
acted.add(key)
await pause()
await ws.send(json.dumps({"action": "start"}))
elif st["phase"] == "theme" and me.get("can_choose") and key not in acted:
acted.add(key)
await pause()
await ws.send(json.dumps({"action": "choose_theme", "theme_id": rng.choice(st["theme"]["options"])["id"]}))
elif task and not task["done"] and key not in acted:
acted.add(key)
await pause()
if task["kind"] == "word":
if rng.random() < 0.3:
await ws.send(json.dumps({"action": "suggest"})) # svaret afleveres, når det kommer
@@ -205,7 +210,6 @@ async def _tegn_player(ws_base, code, name, n_players, done, rng, stop_at_final)
if st["phase"] == "reveal" and rng.random() < 0.2:
await ws.send(json.dumps({"action": "react", "emoji": rng.choice(st.get("reactions") or ["😂"])}))
async def main():
ap = argparse.ArgumentParser()
ap.add_argument("--base", default="http://127.0.0.1:8000")