游戏可以运行

This commit is contained in:
2026-05-24 12:40:57 +08:00
parent 34ce39930c
commit 3df3e4f560
4 changed files with 12 additions and 10 deletions

View File

@@ -83,19 +83,20 @@ class AIPlayer:
actions = [] actions = []
player = self.battlefield.player player = self.battlefield.player
# Frontline units: attack enemy frontline > enemy support > capital # Frontline units: non-archer attacks enemy support only, archer attacks all
for unit in ai.get_frontline_units(): for unit in ai.get_frontline_units():
if not unit.can_attack or unit.has_attacked or not ai.can_afford_attack(unit): if not unit.can_attack or unit.has_attacked or not ai.can_afford_attack(unit):
continue continue
enemy_front = player.get_frontline_units() if unit.is_ranged():
enemy_support = player.get_support_units() targets = player.get_frontline_units() + player.get_support_units()
all_enemy = enemy_front + enemy_support else:
if all_enemy: targets = player.get_support_units()
killable = [u for u in all_enemy if u.current_hp <= unit.get_effective_attack()] if targets:
killable = [u for u in targets if u.current_hp <= unit.get_effective_attack()]
if killable: if killable:
target = min(killable, key=lambda u: u.current_hp) target = min(killable, key=lambda u: u.current_hp)
else: else:
target = max(all_enemy, key=lambda u: u.get_effective_attack()) target = max(targets, key=lambda u: u.get_effective_attack())
self.battlefield.resolve_attack(unit, target) self.battlefield.resolve_attack(unit, target)
actions.append(("attack_unit", unit, target)) actions.append(("attack_unit", unit, target))
else: else:

View File

@@ -296,8 +296,8 @@ class Game:
self.ui.selected_unit = unit self.ui.selected_unit = unit
self.ui.target_mode = "attack" self.ui.target_mode = "attack"
targets = list(opponent.get_frontline_units()) targets = list(opponent.get_frontline_units())
targets.extend(opponent.get_support_units())
if unit.is_ranged(): if unit.is_ranged():
targets.extend(opponent.get_support_units())
targets.append(("capital", opponent)) targets.append(("capital", opponent))
self.ui.valid_targets = targets self.ui.valid_targets = targets
return return
@@ -310,9 +310,10 @@ class Game:
if unit.can_attack and not unit.has_attacked and player.can_afford_attack(unit): if unit.can_attack and not unit.has_attacked and player.can_afford_attack(unit):
self.ui.selected_unit = unit self.ui.selected_unit = unit
self.ui.target_mode = "attack" self.ui.target_mode = "attack"
targets = list(opponent.get_frontline_units()) targets = list(opponent.get_support_units())
targets.extend(opponent.get_support_units())
targets.append(("capital", opponent)) targets.append(("capital", opponent))
if unit.is_ranged():
targets.extend(opponent.get_frontline_units())
self.ui.valid_targets = targets self.ui.valid_targets = targets
def _handle_deploy_click(self, pos): def _handle_deploy_click(self, pos):