diff --git a/card_game/__pycache__/ai.cpython-312.pyc b/card_game/__pycache__/ai.cpython-312.pyc index abd2ed9..3a0805a 100644 Binary files a/card_game/__pycache__/ai.cpython-312.pyc and b/card_game/__pycache__/ai.cpython-312.pyc differ diff --git a/card_game/__pycache__/main.cpython-312.pyc b/card_game/__pycache__/main.cpython-312.pyc index e9caf3f..42a1eb7 100644 Binary files a/card_game/__pycache__/main.cpython-312.pyc and b/card_game/__pycache__/main.cpython-312.pyc differ diff --git a/card_game/__pycache__/player.cpython-312.pyc b/card_game/__pycache__/player.cpython-312.pyc index 6106fc6..2a4d497 100644 Binary files a/card_game/__pycache__/player.cpython-312.pyc and b/card_game/__pycache__/player.cpython-312.pyc differ diff --git a/card_game/ai.py b/card_game/ai.py index b278ff4..68f6c24 100644 --- a/card_game/ai.py +++ b/card_game/ai.py @@ -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): diff --git a/card_game/main.py b/card_game/main.py index 9662646..95a125f 100644 --- a/card_game/main.py +++ b/card_game/main.py @@ -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 diff --git a/card_game/player.py b/card_game/player.py index ada2569..4547a59 100644 --- a/card_game/player.py +++ b/card_game/player.py @@ -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 diff --git a/saved_decks/qi.json b/saved_decks/qi.json new file mode 100644 index 0000000..66fea01 --- /dev/null +++ b/saved_decks/qi.json @@ -0,0 +1,35 @@ +{ + "faction": "qi", + "cards": [ + "qi_tongshang", + "qi_tongshang", + "qi_tongshang", + "qi_changgong", + "qi_changgong", + "qi_changgong", + "qi_guanzhong", + "qi_guanzhong", + "qi_jiji", + "qi_jiji", + "qi_jiji", + "qi_shangren", + "qi_shangren", + "qi_shangren", + "qi_sunbin", + "qi_sunbin", + "qi_gongshou", + "qi_gongshou", + "qi_gongshou", + "qi_maobing", + "qi_maobing", + "qi_maobing", + "qi_fuguo", + "qi_tianqi", + "qi_tianqi", + "ally_wu_shuijun", + "ally_wu_shuijun", + "ally_wu_shuijun", + "ally_yue_nvjian", + "ally_yue_nvjian" + ] +} \ No newline at end of file