Skip to content

Commit

Permalink
Upgrade object detector + clean up namespaces (#151)
Browse files Browse the repository at this point in the history
* Separate out namespaces

* Separate out namespaces

* Use namespace instaed of CSV

* Delete cards CSV

* Move classes to separate folder

* Update detector units

* Add possible units

* Fixing...

* Upgrade YOLOv10 model

* Upgrade to medium detector with more classes

* Add target anywhere flag to all cards

* Fix detector units

* Fix bug

* Fix bug

* Fix bugs

* Fix pylint errors

* Fix isort errors

* Use cards instead of card_names

* Use cards instead of card_names

* Remove standard bot
  • Loading branch information
Pbatch authored Jun 19, 2024
1 parent e1796a7 commit 9a39050
Show file tree
Hide file tree
Showing 27 changed files with 316 additions and 669 deletions.
8 changes: 4 additions & 4 deletions clashroyalebuildabot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from .bot import Bot
from .bot import PeteBot
from .bot import RandomBot
from .bot import StandardBot
from .bot import TwoSixHogCycle
from .data import cards
from .data import constants
from .namespaces import Cards
from .namespaces import Units
from .screen import Screen
from .state import CardDetector
from .state import Detector
Expand All @@ -16,12 +16,12 @@
from .state import UnitDetector

__all__ = [
"StandardBot",
"RandomBot",
"PeteBot",
"TwoSixHogCycle",
"constants",
"cards",
"Cards",
"Units",
"Detector",
"OnnxDetector",
"ScreenDetector",
Expand Down
2 changes: 0 additions & 2 deletions clashroyalebuildabot/bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
from .bot import Bot
from .pete import PeteBot
from .random import RandomBot
from .standard import StandardBot
from .two_six_hog_cycle import TwoSixHogCycle

__all__ = [
"TwoSixHogCycle",
"PeteBot",
"RandomBot",
"StandardBot",
"Action",
"Bot",
]
9 changes: 4 additions & 5 deletions clashroyalebuildabot/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

class Bot:
def __init__(
self, card_names, action_class=Action, auto_start=True, debug=False
self, cards, action_class=Action, auto_start=True, debug=False
):
self.card_names = card_names
self.cards = cards
self.action_class = action_class
self.auto_start = auto_start
self.debug = debug
self.screen = Screen()
self.detector = Detector(card_names, debug=self.debug)
self.detector = Detector(cards, debug=self.debug)
self.state = None

@staticmethod
Expand Down Expand Up @@ -71,15 +71,14 @@ def get_actions(self):
all_tiles = ALLY_TILES + LEFT_PRINCESS_TILES + RIGHT_PRINCESS_TILES
valid_tiles = self._get_valid_tiles()
actions = []

for i in range(4):
card = self.state["cards"][i + 1]
if (
int(self.state["numbers"]["elixir"]["number"]) >= card["cost"]
and card["ready"]
and card["name"] != "blank"
):
tiles = all_tiles if card["type"] == "spell" else valid_tiles
tiles = all_tiles if card["target_anywhere"] else valid_tiles
actions.extend(
[
self.action_class(i, x, y, *card.values())
Expand Down
18 changes: 9 additions & 9 deletions clashroyalebuildabot/bot/example/custom_action.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from clashroyalebuildabot.bot import Action
from clashroyalebuildabot.data.cards import Cards
from clashroyalebuildabot.namespaces.cards import Cards


class CustomAction(Action):
Expand Down Expand Up @@ -134,14 +134,14 @@ def _calculate_musketeer_score(self, state):

def calculate_score(self, state):
name_to_score = {
Cards.KNIGHT: self._calculate_knight_score,
Cards.MINIONS: self._calculate_minions_score,
Cards.FIREBALL: self._calculate_fireball_score,
Cards.GIANT: self._calculate_giant_score,
Cards.MINIPEKKA: self._calculate_minipekka_score,
Cards.MUSKETEER: self._calculate_musketeer_score,
Cards.ARROWS: self._calculate_arrows_score,
Cards.ARCHERS: self._calculate_archers_score,
Cards.KNIGHT.name: self._calculate_knight_score,
Cards.MINIONS.name: self._calculate_minions_score,
Cards.FIREBALL.name: self._calculate_fireball_score,
Cards.GIANT.name: self._calculate_giant_score,
Cards.MINIPEKKA.name: self._calculate_minipekka_score,
Cards.MUSKETEER.name: self._calculate_musketeer_score,
Cards.ARROWS.name: self._calculate_arrows_score,
Cards.ARCHERS.name: self._calculate_archers_score,
}
score_function = name_to_score.get(self.name)
self.score = score_function(state) if score_function else [0]
Expand Down
8 changes: 4 additions & 4 deletions clashroyalebuildabot/bot/example/custom_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

from clashroyalebuildabot.bot import Bot
from clashroyalebuildabot.bot.example.custom_action import CustomAction
from clashroyalebuildabot.data.cards import Cards
from clashroyalebuildabot.data.constants import DISPLAY_HEIGHT
from clashroyalebuildabot.data.constants import DISPLAY_WIDTH
from clashroyalebuildabot.data.constants import SCREENSHOT_HEIGHT
from clashroyalebuildabot.data.constants import SCREENSHOT_WIDTH
from clashroyalebuildabot.namespaces.cards import Cards


class CustomBot(Bot):
def __init__(self, card_names, debug=False):
def __init__(self, cards, debug=False):
preset_deck = {
Cards.MINIONS,
Cards.ARCHERS,
Expand All @@ -25,9 +25,9 @@ def __init__(self, card_names, debug=False):
Cards.KNIGHT,
Cards.MUSKETEER,
}
if set(card_names) != preset_deck:
if set(cards) != preset_deck:
raise ValueError(f"CustomBot must use cards: {preset_deck}")
super().__init__(card_names, CustomAction, debug=debug)
super().__init__(cards, CustomAction, debug=debug)
self.end_of_game_clicked = False
self.pause_until = 0
self.scale_x = DISPLAY_WIDTH / SCREENSHOT_WIDTH
Expand Down
2 changes: 1 addition & 1 deletion clashroyalebuildabot/bot/pete/pete_action.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from clashroyalebuildabot.bot.action import Action
from clashroyalebuildabot.data.cards import Cards
from clashroyalebuildabot.namespaces.cards import Cards


class PeteAction(Action):
Expand Down
4 changes: 2 additions & 2 deletions clashroyalebuildabot/bot/pete/pete_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@


class PeteBot(Bot):
def __init__(self, card_names, debug=False):
super().__init__(card_names, PeteAction, debug=debug)
def __init__(self, cards, debug=False):
super().__init__(cards, PeteAction, debug=debug)

def _preprocess(self):
"""
Expand Down
4 changes: 0 additions & 4 deletions clashroyalebuildabot/bot/standard/__init__.py

This file was deleted.

186 changes: 0 additions & 186 deletions clashroyalebuildabot/bot/standard/standard_action.py

This file was deleted.

Loading

0 comments on commit 9a39050

Please sign in to comment.