45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
#!/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())
|