Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pbatch committed Jun 19, 2024
1 parent a1f0e49 commit d9ad1bf
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 295 deletions.
21 changes: 10 additions & 11 deletions clashroyalebuildabot/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ 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 (
Expand All @@ -90,16 +89,16 @@ def get_actions(self):
return actions

def set_state(self):
# try:
screenshot = self.screen.take_screenshot()
self.state = self.detector.run(screenshot)
if self.auto_start and self.state["screen"] != "in_game":
self.screen.click(
*SCREEN_CONFIG[self.state["screen"]]["click_coordinates"]
)
time.sleep(2)
# except Exception as e:
# logger.error(f"Error occurred while taking screenshot: {e}")
try:
screenshot = self.screen.take_screenshot()
self.state = self.detector.run(screenshot)
if self.auto_start and self.state["screen"] != "in_game":
self.screen.click(
*SCREEN_CONFIG[self.state["screen"]]["click_coordinates"]
)
time.sleep(2)
except Exception as e:
logger.error(f"Error occurred while taking screenshot: {e}")

def play_action(self, action):
card_centre = self._get_card_centre(action.index)
Expand Down
16 changes: 8 additions & 8 deletions clashroyalebuildabot/bot/example/custom_action.py
Original file line number Diff line number Diff line change
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
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.

72 changes: 0 additions & 72 deletions clashroyalebuildabot/bot/standard/standard_bot.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ def _calculate_fireball_score(self, state):

def calculate_score(self, state):
name_to_score = {
Cards.HOG_RIDER: self._calculate_hog_rider_score,
Cards.ICE_GOLEM: self._calculate_ice_golem_score,
Cards.FIREBALL: self._calculate_fireball_score,
Cards.ICE_SPIRIT: self._calculate_ice_spirit_score,
Cards.THE_LOG: self._calculate_log_score,
Cards.MUSKETEER: self._calculate_musketeer_score,
Cards.CANNON: self._calculate_cannon_score,
Cards.SKELETONS: self._calculate_ice_spirit_score,
Cards.HOG_RIDER.name: self._calculate_hog_rider_score,
Cards.ICE_GOLEM.name: self._calculate_ice_golem_score,
Cards.FIREBALL.name: self._calculate_fireball_score,
Cards.ICE_SPIRIT.name: self._calculate_ice_spirit_score,
Cards.THE_LOG.name: self._calculate_log_score,
Cards.MUSKETEER.name: self._calculate_musketeer_score,
Cards.CANNON.name: self._calculate_cannon_score,
Cards.SKELETONS.name: self._calculate_ice_spirit_score,
}

score_function = name_to_score[self.name]
Expand Down
10 changes: 5 additions & 5 deletions clashroyalebuildabot/namespaces/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ class Unit:
class _UnitsNamespace:
ARCHER: Unit = ("archer", "troop", "both", "ground")
BARBARIAN: Unit = ("barbarian", "troop", "ground", "ground")
BARBARIAN_HUT: Unit = ("barbarian_hut", "building")
BARBARIAN_HUT: Unit = ("barbarian_hut", "building", None, None)
BOMBER: Unit = ("bomber", "troop", "ground", "ground")
BOMB_TOWER: Unit = ("bomb_tower", "building", "ground", "ground")
BRAWLER: Unit = ("brawler", "troop", "ground", "ground")
CANNON: Unit = ("cannon", "building", "ground", "ground")
DARK_PRINCE: Unit = ("dark_prince", "troop", "ground", "ground")
ELIXIR_COLLECTOR: Unit = ("elixir_collector", "building")
FURNACE: Unit = ("furnace", "building")
FURNACE: Unit = ("furnace", "building", None, None)
GIANT: Unit = ("giant", "troop", "ground", "ground")
GOBLIN: Unit = ("goblin", "troop", "ground", "ground")
GOBLIN_CAGE: Unit = ("goblin_cage", "building")
GOBLIN_HUT: Unit = ("goblin_hut", "building")
GOBLIN_CAGE: Unit = ("goblin_cage", "building", None, None)
GOBLIN_HUT: Unit = ("goblin_hut", "building", None, None)
HUNGRY_DRAGON: Unit = ("hungry_dragon", "troop", "all", "air")
HUNTER: Unit = ("hunter", "troop", "all", "ground")
ICE_GOLEM: Unit = ("ice_golem", "troop", "buildings", "ground")
Expand All @@ -41,7 +41,7 @@ class _UnitsNamespace:
SKELETON: Unit = ("skeleton", "troop", "ground", "ground")
SPEAR_GOBLIN: Unit = ("spear_goblin", "troop", "both", "ground")
TESLA: Unit = ("tesla", "building", "both", "ground")
TOMBSTONE: Unit = ("tombstone", "building")
TOMBSTONE: Unit = ("tombstone", "building", None, None)
VALKYRIE: Unit = ("valkyrie", "troop", "ground", "ground")
WALL_BREAKER: Unit = ("wall_breaker", "troop", "buildings", "ground")
X_BOW: Unit = ("x_bow", "building", "ground", "ground")
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
import sys
import threading
import time
from datetime import datetime

from clashroyalebuildabot.bot.example.custom_bot import CustomBot
from clashroyalebuildabot.namespaces.cards import Cards
Expand Down

0 comments on commit d9ad1bf

Please sign in to comment.