Skip to content

Commit

Permalink
Add goblin barrel as playable card
Browse files Browse the repository at this point in the history
  • Loading branch information
Pbatch committed Jul 6, 2024
1 parent c8304d8 commit 51776e6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
20 changes: 20 additions & 0 deletions clashroyalebuildabot/actions/goblin_barrel_action.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 7 additions & 5 deletions clashroyalebuildabot/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,6 +15,7 @@
from clashroyalebuildabot.constants import DISPLAY_CARD_WIDTH
from clashroyalebuildabot.constants import DISPLAY_CARD_Y
from clashroyalebuildabot.constants import DISPLAY_HEIGHT
from clashroyalebuildabot.constants import ENEMY_TILES
from clashroyalebuildabot.constants import LEFT_PRINCESS_TILES
from clashroyalebuildabot.constants import RIGHT_PRINCESS_TILES
from clashroyalebuildabot.constants import SRC_DIR
Expand Down Expand Up @@ -92,18 +94,18 @@ 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:
card = self.state.cards[i + 1]
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

Expand Down
2 changes: 2 additions & 0 deletions clashroyalebuildabot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 4 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,7 +35,7 @@ def main():
actions = {
ArchersAction,
ZapAction,
FireballAction,
GoblinBarrelAction,
GiantAction,
KnightAction,
MinionsAction,
Expand Down

0 comments on commit 51776e6

Please sign in to comment.