This commit is contained in:
Ubuntu
2026-07-03 16:58:28 +08:00
commit 32b43f85bd
6240 changed files with 1987678 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
"""测试创建房间并添加AI"""
import socketio
import asyncio
async def test():
sio = socketio.AsyncClient()
@sio.event
async def connect():
print("✅ 已连接服务器")
# 创建房间,带2个AI
await sio.emit('create_room', {
'game_type': 'doudizhu',
'player_name': '测试玩家',
'config': {'max_players': 3},
'ai_players': [
{'name': 'AI-1(rule)', 'ai_type': 'rule'},
{'name': 'AI-2(deepseek)', 'ai_type': 'deepseek'}
]
})
@sio.on('room_created')
async def on_room_created(data):
print(f"✅ 房间创建成功: {data['room']['code']}")
print(f" 玩家数: {len(data['room']['players'])}")
for p in data['room']['players']:
print(f" - {p['name']} ({p['type']})")
await sio.disconnect()
@sio.on('error')
async def on_error(data):
print(f"❌ 错误: {data}")
await sio.disconnect()
try:
await sio.connect('http://localhost:8900')
await sio.wait()
except Exception as e:
print(f"❌ 连接失败: {e}")
if __name__ == '__main__':
asyncio.run(test())