Skip to content

Commit

Permalink
Apply isort, pylint and black
Browse files Browse the repository at this point in the history
  • Loading branch information
Pbatch committed Jun 19, 2024
1 parent b2383be commit 9c48b11
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 18 deletions.
3 changes: 2 additions & 1 deletion clashroyalebuildabot/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from PIL import Image
import yaml

from clashroyalebuildabot.constants import SCREENSHOT_HEIGHT, SRC_DIR
from clashroyalebuildabot.constants import SCREENSHOT_HEIGHT
from clashroyalebuildabot.constants import SCREENSHOT_WIDTH
from clashroyalebuildabot.constants import SRC_DIR


class Screen:
Expand Down
24 changes: 15 additions & 9 deletions clashroyalebuildabot/state/card_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from PIL import Image
from scipy.optimize import linear_sum_assignment

from clashroyalebuildabot.constants import CARD_CONFIG, SRC_DIR
from clashroyalebuildabot.constants import MULTI_HASH_INTERCEPT
from clashroyalebuildabot.constants import MULTI_HASH_SCALE
from clashroyalebuildabot.constants import CARD_CONFIG
from clashroyalebuildabot.constants import SRC_DIR
from clashroyalebuildabot.namespaces.cards import Cards


Expand All @@ -25,8 +24,12 @@ def __init__(self, cards, hash_size=8, grey_std_threshold=5):

def _calculate_multi_hash(self, image):
gray_image = self._calculate_hash(image)
light_image = self.MULTI_HASH_SCALE * gray_image + self.MULTI_HASH_INTERCEPT
dark_image = (gray_image - self.MULTI_HASH_INTERCEPT) / self.MULTI_HASH_SCALE
light_image = (
self.MULTI_HASH_SCALE * gray_image + self.MULTI_HASH_INTERCEPT
)
dark_image = (
gray_image - self.MULTI_HASH_INTERCEPT
) / self.MULTI_HASH_SCALE
multi_hash = np.vstack([gray_image, light_image, dark_image]).astype(
np.float32
)
Expand All @@ -42,13 +45,16 @@ def _calculate_hash(self, image):

def _calculate_card_hashes(self):
card_hashes = np.zeros(
(len(self.cards), 3, self.hash_size * self.hash_size, self.HAND_SIZE),
(
len(self.cards),
3,
self.hash_size * self.hash_size,
self.HAND_SIZE,
),
dtype=np.float32,
)
for i, card in enumerate(self.cards):
path = os.path.join(
SRC_DIR, "images", "cards", f"{card.name}.jpg"
)
path = os.path.join(SRC_DIR, "images", "cards", f"{card.name}.jpg")
pil_image = Image.open(path)

multi_hash = self._calculate_multi_hash(pil_image)
Expand Down
4 changes: 3 additions & 1 deletion clashroyalebuildabot/state/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class Detector:

def __init__(self, cards, debug=False):
if len(cards) != self.DECK_SIZE:
raise ValueError(f"You must specify all {self.DECK_SIZE} of your cards")
raise ValueError(
f"You must specify all {self.DECK_SIZE} of your cards"
)

self.cards = cards
self.debug = debug
Expand Down
3 changes: 2 additions & 1 deletion clashroyalebuildabot/state/screen_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import numpy as np
from PIL import Image

from clashroyalebuildabot.constants import SCREEN_CONFIG, IMAGES_DIR
from clashroyalebuildabot.constants import IMAGES_DIR
from clashroyalebuildabot.constants import SCREEN_CONFIG


class ScreenDetector:
Expand Down
4 changes: 3 additions & 1 deletion clashroyalebuildabot/state/side_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class SideDetector(OnnxDetector):
SIDE_SIZE = 16

def _preprocess(self, image):
image = image.resize((self.SIDE_SIZE, self.SIDE_SIZE), Image.Resampling.BICUBIC)
image = image.resize(
(self.SIDE_SIZE, self.SIDE_SIZE), Image.Resampling.BICUBIC
)
image = np.array(image, dtype=np.float32) / 255
return np.expand_dims(image, axis=0)

Expand Down
9 changes: 5 additions & 4 deletions clashroyalebuildabot/state/unit_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import numpy as np

from clashroyalebuildabot.constants import DETECTOR_UNITS, MODELS_DIR
from clashroyalebuildabot.constants import UNIT_Y_END
from clashroyalebuildabot.constants import UNIT_Y_START
from clashroyalebuildabot.constants import DETECTOR_UNITS
from clashroyalebuildabot.constants import MODELS_DIR
from clashroyalebuildabot.state.onnx_detector import OnnxDetector
from clashroyalebuildabot.state.side_detector import SideDetector

Expand All @@ -18,7 +17,9 @@ def __init__(self, model_path, cards):
super().__init__(model_path)
self.cards = cards

self.side_detector = SideDetector(os.path.join(MODELS_DIR, "side.onnx"))
self.side_detector = SideDetector(
os.path.join(MODELS_DIR, "side.onnx")
)
self.possible_ally_units = self._get_possible_ally_units()

def _get_possible_ally_units(self):
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from datetime import datetime
import os
import sys
import threading
import time
Expand Down

0 comments on commit 9c48b11

Please sign in to comment.