游戏可以运行
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -82,36 +82,48 @@ class AIPlayer:
|
||||
def _attack(self, ai):
|
||||
actions = []
|
||||
player = self.battlefield.player
|
||||
|
||||
# Frontline units: attack enemy frontline > enemy support > capital
|
||||
for unit in ai.get_frontline_units():
|
||||
if not unit.can_attack or unit.has_attacked:
|
||||
continue
|
||||
enemy_units = player.get_frontline_units()
|
||||
if enemy_units:
|
||||
killable = [u for u in enemy_units if u.current_hp <= unit.get_effective_attack()]
|
||||
enemy_front = player.get_frontline_units()
|
||||
enemy_support = player.get_support_units()
|
||||
all_enemy = enemy_front + enemy_support
|
||||
if all_enemy:
|
||||
killable = [u for u in all_enemy if u.current_hp <= unit.get_effective_attack()]
|
||||
if killable:
|
||||
target = min(killable, key=lambda u: u.current_hp)
|
||||
else:
|
||||
target = max(enemy_units, key=lambda u: u.get_effective_attack())
|
||||
dead = self.battlefield.resolve_attack(unit, target)
|
||||
actions.append(("attack_unit", unit, target))
|
||||
else:
|
||||
self.battlefield.attack_capital(unit)
|
||||
actions.append(("attack_capital", unit))
|
||||
|
||||
# Ranged units in support attack
|
||||
for unit in ai.get_support_units():
|
||||
if not unit.can_attack or unit.has_attacked or not unit.is_ranged():
|
||||
continue
|
||||
enemy_units = player.get_frontline_units()
|
||||
if enemy_units:
|
||||
killable = [u for u in enemy_units if u.current_hp <= unit.get_effective_attack()]
|
||||
target = min(killable, key=lambda u: u.current_hp) if killable else min(enemy_units, key=lambda u: u.current_hp)
|
||||
target = max(all_enemy, key=lambda u: u.get_effective_attack())
|
||||
self.battlefield.resolve_attack(unit, target)
|
||||
actions.append(("attack_unit", unit, target))
|
||||
else:
|
||||
self.battlefield.attack_capital(unit)
|
||||
actions.append(("attack_capital", unit))
|
||||
|
||||
# Support units: attack enemy frontline > enemy support > capital (ranged only)
|
||||
for unit in ai.get_support_units():
|
||||
if not unit.can_attack or unit.has_attacked:
|
||||
continue
|
||||
enemy_front = player.get_frontline_units()
|
||||
enemy_support = player.get_support_units()
|
||||
if unit.is_ranged():
|
||||
all_enemy = enemy_front + enemy_support
|
||||
if all_enemy:
|
||||
killable = [u for u in all_enemy if u.current_hp <= unit.get_effective_attack()]
|
||||
target = min(killable, key=lambda u: u.current_hp) if killable else min(all_enemy, key=lambda u: u.current_hp)
|
||||
self.battlefield.resolve_attack(unit, target)
|
||||
actions.append(("attack_unit", unit, target))
|
||||
else:
|
||||
self.battlefield.attack_capital(unit)
|
||||
actions.append(("attack_capital", unit))
|
||||
elif enemy_front:
|
||||
killable = [u for u in enemy_front if u.current_hp <= unit.get_effective_attack()]
|
||||
target = min(killable, key=lambda u: u.current_hp) if killable else min(enemy_front, key=lambda u: u.current_hp)
|
||||
self.battlefield.resolve_attack(unit, target)
|
||||
actions.append(("attack_unit", unit, target))
|
||||
|
||||
return actions
|
||||
|
||||
def _handle_deploy(self, card, ai):
|
||||
|
||||
@@ -267,11 +267,13 @@ class Game:
|
||||
opponent = self.battlefield.get_opponent(player)
|
||||
|
||||
if unit.zone == "support":
|
||||
if unit.can_attack and not unit.has_attacked and unit.is_ranged():
|
||||
if unit.can_attack and not unit.has_attacked:
|
||||
self.ui.selected_unit = unit
|
||||
self.ui.target_mode = "attack"
|
||||
targets = list(opponent.get_frontline_units())
|
||||
targets.append(("capital", opponent))
|
||||
targets.extend(opponent.get_support_units())
|
||||
if unit.is_ranged():
|
||||
targets.append(("capital", opponent))
|
||||
self.ui.valid_targets = targets
|
||||
return
|
||||
if self.battlefield.can_move_to_frontline(player):
|
||||
@@ -284,6 +286,7 @@ class Game:
|
||||
self.ui.selected_unit = unit
|
||||
self.ui.target_mode = "attack"
|
||||
targets = list(opponent.get_frontline_units())
|
||||
targets.extend(opponent.get_support_units())
|
||||
targets.append(("capital", opponent))
|
||||
self.ui.valid_targets = targets
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class Player:
|
||||
unit.reset_turn_flags()
|
||||
if unit.zone == "frontline" and unit.turn_played < turn_number:
|
||||
unit.can_attack = True
|
||||
if unit.zone == "support" and unit.is_ranged() and unit.turn_played < turn_number:
|
||||
if unit.zone == "support" and unit.turn_played < turn_number:
|
||||
unit.can_attack = True
|
||||
|
||||
# Chu healer
|
||||
|
||||
Reference in New Issue
Block a user