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) try: return json.loads(body) except Exception: return {'ok':False,'error':body} time.sleep(1) r=post('/api/create', {'game':'dice','name':'小鱼','playerId':'p-test'}) code=r['room']['code'] s=post('/api/start', {'code':code}) print('players', len(s['room']['players']), 'min', s['room']['diceRule']['minCount'], 'flyFrom', s['room']['diceRule']['flyFrom']) print('bad-low', post('/api/call', {'code':code,'playerId':'p-test','count':3,'point':6}).get('error')) c1=post('/api/call', {'code':code,'playerId':'p-test','count':4,'point':1}) print('call1', c1['ok'], c1['room']['currentCall']) # 如果机器人连续轮转后又轮到真人,当前叫点应被机器人加到更高 for i in range(5): room=post('/api/bot-turn', {'code':code})['room'] print('turn', i, room['turnPlayerName'], room['currentCall'], room['status']) if room['status']=='result' or not room['turnPlayerBot']: break print('final', room['status'], room['turnPlayerName'])