import json, urllib.request base='http://127.0.0.1:8765' def post(path, data): req=urllib.request.Request(base+path, data=json.dumps(data).encode(), headers={'Content-Type':'application/json'}) try: return json.loads(urllib.request.urlopen(req, timeout=5).read()) except Exception as e: body=e.read().decode() if hasattr(e,'read') else str(e) return json.loads(body) if body.startswith('{') else {'ok':False,'error':body} def get_room(code): return json.loads(urllib.request.urlopen(base+'/api/room?code='+code).read())['room'] def actor_id(p): if p['type'] in ('open2','split2'): idx=p.get('currentIndex',0); targets=p.get('targets',[]) return targets[idx]['playerId'] if (p['stage']=='wait_target' and idx