修正了boss_fight,添加了样例

This commit is contained in:
Guanforever 2025-06-30 22:15:46 +08:00
parent f373e5dd43
commit 3e606f3ef6
20 changed files with 54 additions and 22 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

View File

@ -0,0 +1 @@
{"B":[11,13,8,17],"PlayerSkills":[[6,2],[2,0],[4,1]],"min_turns":13,"actions":[0,2,1,2,0,2,1,0,1,2,0,1,2]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

View File

@ -0,0 +1 @@
{"B":[19,17,14,19],"PlayerSkills":[[6,2],[9,5],[5,3],[4,3],[2,0]],"min_turns":13,"actions":[1,0,3,2,0,4,3,2,1,0,3,2,0]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

View File

@ -0,0 +1 @@
{"B":[11,7,18],"PlayerSkills":[[10,1],[11,4],[11,5],[3,0],[4,4]],"min_turns":4,"actions":[2,0,1,0]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

@ -0,0 +1 @@
{"B":[13,11],"PlayerSkills":[[3,2],[1,0],[10,2],[5,1]],"min_turns":4,"actions":[2,0,3,2]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 KiB

View File

@ -0,0 +1 @@
{"B":[13,18,19,14],"PlayerSkills":[[4,1],[3,2],[5,2],[9,4],[2,0]],"min_turns":13,"actions":[3,0,1,2,0,3,2,0,1,2,4,3,2]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

View File

@ -0,0 +1 @@
{"B":[20,10,20],"PlayerSkills":[[1,0],[9,4],[10,5]],"min_turns":11,"actions":[1,2,0,0,0,1,0,2,0,0,1]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

View File

@ -0,0 +1 @@
{"B":[15,18],"PlayerSkills":[[3,0],[2,1],[10,5]],"min_turns":7,"actions":[2,0,0,0,0,0,2]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

View File

@ -0,0 +1 @@
{"B":[14,14],"PlayerSkills":[[3,0],[6,2],[4,1],[4,1],[9,3]],"min_turns":5,"actions":[4,1,2,3,4]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

View File

@ -0,0 +1 @@
{"B":[13,13,20],"PlayerSkills":[[9,5],[3,0]],"min_turns":13,"actions":[0,1,1,1,1,1,1,1,0,1,1,1,1]}

View File

@ -150,25 +150,4 @@ if __name__ == '__main__':
print(f"总步数: {len(full_sequence)}") print(f"总步数: {len(full_sequence)}")
else: else:
print("无解 - 无法击败所有Boss") print("无解 - 无法击败所有Boss")
# if result:
# print("每个Boss的最优攻击序列:")
# for i, boss_sequence in enumerate(result):
# print(f"Boss {i+1} (血量{B[i]}): {boss_sequence}")
# # 显示详细的技能使用说明
# skill_details = []
# total_damage = 0
# for action in boss_sequence:
# if action == -1:
# skill_details.append("等待")
# else:
# damage, cooldown = PlayerSkills[action]
# total_damage += damage
# skill_details.append(f"技能{action}(伤害{damage},冷却{cooldown})")
# print(f" 详细: {' -> '.join(skill_details)}")
# print(f" 总伤害: {total_damage}, Boss血量: {B[i]}")
# print()
# else:
# print("无解 - 无法击败所有Boss")

44
test_boss_cases.py Normal file
View File

@ -0,0 +1,44 @@
import os
import json
import glob
from boss_fight import boss_fight as boss_fight_main
def run_boss_case_tests():
case_dir = 'BOSS战样例'
json_files = glob.glob(os.path.join(case_dir, '*.json'))
all_passed = True
for file in json_files:
with open(file, 'r', encoding='utf-8') as f:
data = json.load(f)
b = data.get('B')
playerskills = data.get('PlayerSkills')
min_turns = data.get('min_turns')
if b is None or playerskills is None or min_turns is None:
print(f"[FAIL] {file}: 缺少必要字段")
all_passed = False
continue
# 假设boss_fight.py的main返回技能使用次数
try:
print(b,playerskills)
result = boss_fight_main(b, playerskills)
except Exception as e:
print(f"[FAIL] {file}: boss_fight_main运行出错: {e}")
all_passed = False
continue
# result应为技能数量
ans = 0
for i in result:
ans += len(i)
if ans == min_turns:
print(f"[PASS] {file}: 技能数量={ans}, min_turns={min_turns}")
else:
print(f"[FAIL] {file}: 技能数量={ans}, min_turns={min_turns}")
all_passed = False
if all_passed:
print("所有样例通过!")
else:
print("部分样例未通过。")
if __name__ == '__main__':
run_boss_case_tests()