Files
drinking-game/test_rules.py
gongch 6d1dd5d56c Initial commit: 酒桌派对 / 大话骰 multiplayer drinking-game hub
- server.py: zero-dependency stdlib backend (HTTP + WebSocket /ws), 大话骰 rule engine, server-driven bots
- live.html: real MVP frontend wired to the backend over WebSocket
- index.html/app.js/style.css: older static prototype
- deploy/: systemd unit + Nginx reverse proxy + Let's Encrypt setup.sh
- test_*.py: standalone HTTP / in-process test scripts

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 10:05:10 +08:00

26 lines
1.3 KiB
Python

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'])