kards-env/tests/test_attack_count_limit.py....

71 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
专门测试攻击次数限制
"""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from kards_battle.core.battle_engine import BattleEngine
from kards_battle.units.unit_loader import load_unit
from interactive.command_parser import CommandParser
def test_attack_count_limit():
"""测试攻击次数限制"""
print("=== 测试攻击次数限制 ===")
engine = BattleEngine("Germany", "USA", debug_mode=True)
parser = CommandParser(engine)
# 部署Tank单位可以移动后攻击
panzer = load_unit('ger_tank_panzer_iv')
engine.deploy_unit_to_support(panzer, 0)
# 部署多个目标到美军支援线
targets = []
for i in range(3):
marine = load_unit('usa_infantry_marine')
engine.deploy_unit_to_support(marine, 1)
targets.append(marine)
# 让德军单位进入下一回合(可以行动)
engine.end_turn() # 美军回合
engine.end_turn() # 德军新回合
engine.debug_set_kredits(0, kredits=20)
# 移动到前线以便攻击
parser.parse("move 1 0")
engine.debug_set_kredits(0, kredits=20)
print(f"单位攻击次数: {panzer.attacks_this_turn}/{panzer.max_attacks_per_turn}")
print(f"can_attack: {panzer.can_attack()}")
# 第一次攻击
print("\\n1. 第一次攻击美军支援线:")
success, message = parser.parse("attack F0 S1") # 前线攻击支援线
print(f"攻击结果: {success} - {message}")
if success:
print(f"攻击后状态: attacks_this_turn={panzer.attacks_this_turn}")
print(f"can_attack: {panzer.can_attack()}")
# 第二次攻击
print("\\n2. 第二次攻击:")
success, message = parser.parse("attack F0 S2")
print(f"攻击结果: {success} - {message}")
if not success and "maximum attacks" in message:
print("✅ 正确限制了多次攻击")
elif success:
print("⚠️ 单位可以攻击多次(可能有特殊能力)")
else:
print(f"❌ 攻击失败但不是因为次数限制: {message}")
assert False, f"攻击失败但不是因为次数限制: {message}"
else:
print(f"第一次攻击就失败了: {message}")
assert False, f"第一次攻击就失败了: {message}"
if __name__ == "__main__":
test_attack_count_limit()