From 85552efc6e4a138c83bc8801811902fce6940f4e Mon Sep 17 00:00:00 2001 From: Pbatch <37177749+Pbatch@users.noreply.github.com> Date: Sat, 6 Jul 2024 13:15:31 +0100 Subject: [PATCH] Add goblin barrel as a playable card (#205) * Add goblin barrel as playable card * Add goblin barrel as playable card --- .../actions/goblin_barrel_action.py | 20 +++++++++++++++++++ clashroyalebuildabot/bot/bot.py | 11 +++++----- clashroyalebuildabot/constants.py | 2 ++ main.py | 5 ++++- 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 clashroyalebuildabot/actions/goblin_barrel_action.py diff --git a/clashroyalebuildabot/actions/goblin_barrel_action.py b/clashroyalebuildabot/actions/goblin_barrel_action.py new file mode 100644 index 0000000..d712b43 --- /dev/null +++ b/clashroyalebuildabot/actions/goblin_barrel_action.py @@ -0,0 +1,20 @@ +from clashroyalebuildabot import Cards +from clashroyalebuildabot.actions.action import Action + + +class GoblinBarrelAction(Action): + CARD = Cards.GOBLIN_BARREL + + def calculate_score(self, state): + left_hp, right_hp = ( + state.numbers[f"{direction}_enemy_princess_hp"]["number"] + for direction in ["left", "right"] + ) + if (self.tile_x, self.tile_y) == (14, 25) and right_hp <= left_hp: + score = [1] + elif (self.tile_x, self.tile_y) == (3, 25) and left_hp <= right_hp: + score = [1] + else: + score = [0] + + return score diff --git a/clashroyalebuildabot/bot/bot.py b/clashroyalebuildabot/bot/bot.py index 0132842..727e195 100644 --- a/clashroyalebuildabot/bot/bot.py +++ b/clashroyalebuildabot/bot/bot.py @@ -6,6 +6,7 @@ from loguru import logger import yaml +from clashroyalebuildabot.constants import ALL_TILES from clashroyalebuildabot.constants import ALLY_TILES from clashroyalebuildabot.constants import DEBUG_DIR from clashroyalebuildabot.constants import DISPLAY_CARD_DELTA_X @@ -92,7 +93,6 @@ def _get_valid_tiles(self): def get_actions(self): if not self.state: return [] - all_tiles = ALLY_TILES + LEFT_PRINCESS_TILES + RIGHT_PRINCESS_TILES valid_tiles = self._get_valid_tiles() actions = [] for i in self.state.ready: @@ -100,10 +100,11 @@ def get_actions(self): if int(self.state.numbers["elixir"]["number"]) < card.cost: continue - tiles = all_tiles if card.target_anywhere else valid_tiles - actions.extend( - [self.cards_to_actions[card](i, x, y) for (x, y) in tiles] - ) + tiles = ALL_TILES if card.target_anywhere else valid_tiles + card_actions = [ + self.cards_to_actions[card](i, x, y) for (x, y) in tiles + ] + actions.extend(card_actions) return actions diff --git a/clashroyalebuildabot/constants.py b/clashroyalebuildabot/constants.py index aa6f306..b6b5fa8 100644 --- a/clashroyalebuildabot/constants.py +++ b/clashroyalebuildabot/constants.py @@ -32,6 +32,8 @@ ALLY_TILES += [ [x, y] for x in range(N_WIDE_TILES) for y in range(1, N_HEIGHT_TILES) ] +ENEMY_TILES = [[x, 31 - y] for x, y in ALLY_TILES] +ALL_TILES = ALLY_TILES + ENEMY_TILES LEFT_PRINCESS_TILES = [[3, N_HEIGHT_TILES], [3, N_HEIGHT_TILES + 1]] LEFT_PRINCESS_TILES += [ [x, y] diff --git a/main.py b/main.py index 7dbb99b..335df51 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,9 @@ from clashroyalebuildabot.actions.archers_action import ArchersAction from clashroyalebuildabot.actions.fireball_action import FireballAction from clashroyalebuildabot.actions.giant_action import GiantAction +from clashroyalebuildabot.actions.goblin_barrel_action import ( + GoblinBarrelAction, +) from clashroyalebuildabot.actions.knight_action import KnightAction from clashroyalebuildabot.actions.minions_action import MinionsAction from clashroyalebuildabot.actions.minipekka_action import MinipekkaAction @@ -32,7 +35,7 @@ def main(): actions = { ArchersAction, ZapAction, - FireballAction, + GoblinBarrelAction, GiantAction, KnightAction, MinionsAction,