import json, urllib.request, time 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} time.sleep(1) r=post('/api/create', {'game':'dice','name':'小鱼','playerId':'p-test-rule'}) code=r['room']['code'] s=post('/api/start', {'code':code}) print('players/min/zhai', len(s['room']['players']), s['room']['minCount'], s['room']['zhaiMax']) print('bad low', post('/api/call', {'code':code,'playerId':'p-test-rule','count':1,'point':1})) c=post('/api/call', {'code':code,'playerId':'p-test-rule','count':4,'point':1}) print('first', c['ok'], c['room']['currentCall']) # Let bots rotate until user turn or result room=c['room'] for _ in range(5): if room['status']!='playing' or not room['turnIsBot']: break room=post('/api/bot-turn', {'code':code})['room'] print('after bots', room['status'], room['currentCall'], room['turnPlayerName'], room.get('lastResult')) if room['status']=='playing': op=post('/api/open', {'code':code,'playerId':'p-test-rule'}) print('open', op['ok'], op['room']['lastResult']['text'], len(op['room']['lastResult']['allDice']))