Skip to content

Commit

Permalink
Automatically load the correct deck (#232)
Browse files Browse the repository at this point in the history
* Add ids to all the cards

* Add load deck feature

* Remove unneeded units is None code

* Deepcopy the detector cards

* Load the deck at the start of the game

* Use a list rather than a set to enforce order on the actions

* Add space after input str

* Make deck loading optional

* Remove redundant import
  • Loading branch information
Pbatch authored Sep 9, 2024
1 parent 93958fb commit 9296885
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 121 deletions.
3 changes: 3 additions & 0 deletions clashroyalebuildabot/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def __init__(self, actions, auto_start=True):
)
keyboard_thread.start()

if config["load_deck"]:
self.emulator.load_deck(cards)

@staticmethod
def _log_and_wait(prefix, delay):
suffix = ""
Expand Down
3 changes: 3 additions & 0 deletions clashroyalebuildabot/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ bot:
# "WARNING" for warning messages, "ERROR" for error messages, and "CRITICAL" for critical issues.
log_level: "DEBUG"

# Create a deck code when the game starts
load_deck: True

adb:
# The IP address of your device or emulator.
# Use 127.0.0.1 for a local emulator. If you're connecting to a physical device,
Expand Down
3 changes: 2 additions & 1 deletion clashroyalebuildabot/detectors/detector.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
import os
import time

Expand All @@ -20,7 +21,7 @@ def __init__(self, cards):
f"You must specify all {self.DECK_SIZE} of your cards"
)

self.cards = cards
self.cards = deepcopy(cards)

self.card_detector = CardDetector(self.cards)
self.number_detector = NumberDetector()
Expand Down
2 changes: 0 additions & 2 deletions clashroyalebuildabot/detectors/unit_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ def _get_tile_xy(bbox):
def _get_possible_ally_names(self):
possible_ally_names = set()
for card in self.cards:
if card.units is None:
continue
for unit in card.units:
possible_ally_names.add(unit.name)
return possible_ally_names
Expand Down
26 changes: 26 additions & 0 deletions clashroyalebuildabot/emulator/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,29 @@ def take_screenshot(self):
screenshot, self.frame = self.frame, None

return screenshot

def load_deck(self, cards):
id_str = ";".join([str(card.id_) for card in cards])
slot_str = ";".join("0" for _ in range(len(cards)))
url = "&".join(
[
f"https://link.clashroyale.com/en/?clashroyale://copyDeck?deck={id_str}",
f"slots={slot_str}",
"tt=159000000",
"l=Royals",
"id=JR2RU0L90",
]
)

self._run_command(
[
"shell",
"am",
"start",
"-n",
"com.android.chrome/com.google.android.apps.chrome.Main",
"-d",
f"'{url}'",
]
)
input("Press a key when you've finished copying the deck ")
Loading

0 comments on commit 9296885

Please sign in to comment.