-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_team_logic.py
More file actions
143 lines (130 loc) · 5.21 KB
/
Copy pathtest_team_logic.py
File metadata and controls
143 lines (130 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python3
"""
测试新的团队分数计算逻辑
"""
import requests
import json
BASE_URL = "http://localhost:8000"
def test_team_scoring_logic():
print("开始测试团队分数计算逻辑...")
# 1. 重置游戏
print("\n1. 重置游戏状态...")
try:
response = requests.delete(f"{BASE_URL}/game/reset")
print(f"重置结果: {response.status_code}")
except Exception as e:
print(f"重置游戏失败: {e}")
return False
# 2. 设置游戏(4个玩家,2个团队)
print("\n2. 设置游戏...")
game_setup_data = {
"players": [
{"id": "player_1", "name": "张三"},
{"id": "player_2", "name": "李四"},
{"id": "player_3", "name": "王五"},
{"id": "player_4", "name": "赵六"}
],
"teams": [
{"id": "team_red", "name": "红队", "player_ids": []},
{"id": "team_blue", "name": "蓝队", "player_ids": []}
]
}
try:
response = requests.post(f"{BASE_URL}/game/setup", json=game_setup_data)
print(f"游戏设置结果: {response.status_code}")
print(f"响应: {response.json()}")
except Exception as e:
print(f"设置游戏失败: {e}")
return False
# 3. 添加第一轮(带团队分配和获胜团队)
print("\n3. 添加第一轮...")
round_data = {
"round_number": 1,
"base_amount": 10, # 底金为10
"scores": [
{
"player_id": "player_1",
"bomb_details": {"5炸": 1}, # 张三有1个5炸,基础得分为10*1=10
"score_change": 10, # 基础得分
"team_id": "team_red", # 红队成员
"team_bonus": 1 # 标记为获胜团队成员
},
{
"player_id": "player_2",
"bomb_details": {"6炸": 1}, # 李四有1个6炸,基础得分为10*2=20
"score_change": 20, # 基础得分
"team_id": "team_red", # 红队成员
"team_bonus": 1 # 标记为获胜团队成员
},
{
"player_id": "player_3",
"bomb_details": {"7炸": 1}, # 王五有1个7炸,基础得分为10*4=40
"score_change": 40, # 基础得分
"team_id": "team_blue", # 蓝队成员
"team_bonus": -1 # 标记为失败团队成员
},
{
"player_id": "player_4",
"bomb_details": {"8炸": 1}, # 赵六有1个8炸,基础得分为10*8=80
"score_change": 80, # 基础得分
"team_id": "team_blue", # 蓝队成员
"team_bonus": -1 # 标记为失败团队成员
}
]
}
try:
response = requests.post(f"{BASE_URL}/game/round", json=round_data)
print(f"添加轮次结果: {response.status_code}")
if response.status_code == 200:
print("成功添加第一轮")
else:
print(f"添加轮次失败: {response.text}")
except Exception as e:
print(f"添加轮次失败: {e}")
return False
# 4. 获取当前分数
print("\n4. 获取当前分数...")
try:
response = requests.get(f"{BASE_URL}/game/scores")
if response.status_code == 200:
scores_data = response.json()
print("当前分数:")
for player in scores_data["players"]:
print(f" {player['name']}: {player['total_score']}")
# 验证团队分数计算逻辑
# 红队获胜:张三(10+10=20),李四(20+10=30)
# 蓝队失败:王五(40-10=30),赵六(80-10=70)
expected_scores = {
"张三": 20, # 基础10 + 胜利10 = 20
"李四": 30, # 基础20 + 胜利10 = 30
"王五": 30, # 基础40 - 失败10 = 30
"赵六": 70 # 基础80 - 失败10 = 70
}
print("\n验证结果:")
all_correct = True
for player in scores_data["players"]:
expected = expected_scores[player['name']]
actual = player['total_score']
if actual == expected:
print(f" ✓ {player['name']}: 期望 {expected}, 实际 {actual}")
else:
print(f" ✗ {player['name']}: 期望 {expected}, 实际 {actual}")
all_correct = False
if all_correct:
print("\n✓ 团队分数计算逻辑测试通过!")
return True
else:
print("\n✗ 团队分数计算逻辑测试失败!")
return False
else:
print(f"获取分数失败: {response.status_code}, {response.text}")
return False
except Exception as e:
print(f"获取分数失败: {e}")
return False
if __name__ == "__main__":
success = test_team_scoring_logic()
if success:
print("\n所有测试通过!新的团队分数计算功能正常工作。")
else:
print("\n测试失败!请检查团队分数计算功能。")