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>
This commit is contained in:
25
test_rule_flow.py
Normal file
25
test_rule_flow.py
Normal file
@@ -0,0 +1,25 @@
|
||||
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']))
|
||||
Reference in New Issue
Block a user