Skip to content

Commit

Permalink
Update bot.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Leviaria authored Jun 20, 2024
1 parent 7cebf5c commit d0d23f7
Showing 1 changed file with 17 additions and 30 deletions.
47 changes: 17 additions & 30 deletions clashroyalebuildabot/bot/bot.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
import time

from loguru import logger

from clashroyalebuildabot.bot.action import Action
from clashroyalebuildabot.constants import ALLY_TILES
from clashroyalebuildabot.constants import DISPLAY_CARD_DELTA_X
from clashroyalebuildabot.constants import DISPLAY_CARD_HEIGHT
from clashroyalebuildabot.constants import DISPLAY_CARD_INIT_X
from clashroyalebuildabot.constants import DISPLAY_CARD_WIDTH
from clashroyalebuildabot.constants import DISPLAY_CARD_Y
from clashroyalebuildabot.constants import DISPLAY_HEIGHT
from clashroyalebuildabot.constants import LEFT_PRINCESS_TILES
from clashroyalebuildabot.constants import RIGHT_PRINCESS_TILES
from clashroyalebuildabot.constants import TILE_HEIGHT
from clashroyalebuildabot.constants import TILE_INIT_X
from clashroyalebuildabot.constants import TILE_INIT_Y
from clashroyalebuildabot.constants import TILE_WIDTH
from clashroyalebuildabot.constants import (
ALLY_TILES, DISPLAY_CARD_DELTA_X, DISPLAY_CARD_HEIGHT, DISPLAY_CARD_INIT_X, DISPLAY_CARD_WIDTH, DISPLAY_CARD_Y,
DISPLAY_HEIGHT, LEFT_PRINCESS_TILES, RIGHT_PRINCESS_TILES, TILE_HEIGHT, TILE_INIT_X, TILE_INIT_Y, TILE_WIDTH
)
from clashroyalebuildabot.detectors.detector import Detector
from clashroyalebuildabot.emulator import Emulator
from clashroyalebuildabot.namespaces import Screens

class Action:
def __init__(self, index, tile_x, tile_y, card):
self.index = index
self.tile_x = tile_x
self.tile_y = tile_y
self.card = card

def __repr__(self):
return f"{self.card.name} at ({self.tile_x}, {self.tile_y})"

class Bot:
def __init__(
self, cards, action_class=Action, auto_start=True, debug=False
):
def __init__(self, cards, action_class=Action, auto_start=True, debug=False):
self.cards = cards
self.action_class = action_class
self.auto_start = auto_start
Expand All @@ -36,9 +31,7 @@ def __init__(
@staticmethod
def _get_nearest_tile(x, y):
tile_x = round(((x - TILE_INIT_X) / TILE_WIDTH) - 0.5)
tile_y = round(
((DISPLAY_HEIGHT - TILE_INIT_Y - y) / TILE_HEIGHT) - 0.5
)
tile_y = round(((DISPLAY_HEIGHT - TILE_INIT_Y - y) / TILE_HEIGHT) - 0.5)
return tile_x, tile_y

@staticmethod
Expand All @@ -49,11 +42,7 @@ def _get_tile_centre(tile_x, tile_y):

@staticmethod
def _get_card_centre(card_n):
x = (
DISPLAY_CARD_INIT_X
+ DISPLAY_CARD_WIDTH / 2
+ card_n * DISPLAY_CARD_DELTA_X
)
x = DISPLAY_CARD_INIT_X + DISPLAY_CARD_WIDTH / 2 + card_n * DISPLAY_CARD_DELTA_X
y = DISPLAY_CARD_Y + DISPLAY_CARD_HEIGHT / 2
return x, y

Expand All @@ -77,9 +66,7 @@ def get_actions(self):
continue

tiles = all_tiles if card.target_anywhere else valid_tiles
actions.extend(
[self.action_class(i, x, y, card) for (x, y) in tiles]
)
actions.extend([self.action_class(i, x, y, card) for (x, y) in tiles])

return actions

Expand Down

0 comments on commit d0d23f7

Please sign in to comment.