Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bot.py #160

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading