Skip to content

Commit

Permalink
Merge pull request #3 from HCA97/dev
Browse files Browse the repository at this point in the history
re-using the bot after few years
  • Loading branch information
HCA97 authored Aug 29, 2023
2 parents bdcc9ee + 02958f0 commit 8345041
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/__pycache__/
**/__pycache__/
.venv
31 changes: 17 additions & 14 deletions jw_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self):


# get the ratios (I get it from my PC to fit other screen sizes)
self.shooting_zone_ratio = (230 / 831, 740 / 971, 10 / 481, 440 / 481)
self.shooting_zone_ratio = (230 / 831, 740 / 971, 10 / 481, 410 / 481)
self.launch_button_loc_ratio = (650 / 831, 712 / 831, 132 / 481, 310 / 481)
self.supply_drop_text_loc_ratio = (92 / 831, 132 / 831, 110 /481, 330 / 481)
self.map_button_loc_ratio = (786 / 831, 222 / 481)
Expand Down Expand Up @@ -64,22 +64,22 @@ def __init__(self):
# (R_min, G_min, B_min, R_max, G_max, B_max)
# (R, G, B)
# normal
self.special_event_color = (0, 180, 0, 50, 255, 30)
self.supply_drop_color = (200, 100, 0, 255, 160, 60)
self.special_event_color = (0, 160, 0, 50, 255, 50)
self.supply_drop_color = (0, 100, 200, 60, 200, 255)
# lunar new year
# self.special_event_color = (170, 140, 50, 230, 190, 100)
# self.supply_drop_color = (150, 120, 0, 255, 180, 60)
# valentine
# self.special_event_color = (0, 140, 0, 100, 255, 100)
# self.supply_drop_color = (180, 0, 0, 255, 100, 120)
# st. petersburg
self.special_event_color = (0, 140, 0, 45, 255, 45)
self.supply_drop_color = (60, 60, 0, 210, 210, 120)
#self.special_event_color = (0, 140, 0, 45, 255, 45)
#self.supply_drop_color = (60, 60, 0, 210, 210, 120)

self.x_button_color = (117, 10, 10)
self.gmap_loc_color = (200, 0, 0, 255, 70, 60)
# default
# self.coin_color = (180, 160, 100, 240, 220, 120)
self.coin_color = (180, 160, 100, 240, 220, 120)
# lunar new year
# self.coin_color = (200, 50, 20, 255, 140, 50)
# winter games
Expand All @@ -92,7 +92,7 @@ def __init__(self):
# self.coin_color = (130, 150, 150, 175, 175, 200)
# self.coin_color = (175, 175, 150, 225, 225, 225)
# st. petersburg
self.coin_color = (60, 60, 0, 210, 210, 120)
# self.coin_color = (60, 60, 0, 210, 210, 120)

self.battery_color = (10, 30, 80)
self.dino_loading_screen_color = (230, 230, 230)
Expand All @@ -104,7 +104,7 @@ def __init__(self):

# extra stuff
self.loading_screen_pic = Image.open(r'figs/loading_screen.png')
self.moved_too_far_pic = Image.open(r'figs/moved_too_far.PNG')
#self.moved_too_far_pic = Image.open(r'figs/moved_too_far.PNG')

# self.coin_chests = [
# np.array(Image.open(r'figs/lunar_event_coin_chase_1.png')),
Expand Down Expand Up @@ -471,6 +471,9 @@ def determine_state(self, background):
"PECIALEVENT" in text2 or \
text2 == "SPECIALEVENT" or \
"DROP" in text2 or \
text2 == "SUDDLYDROD" or \
'SUPPLY' in text2 or \
'DROD' in text2 or \
text2 == "SUPPLYDROP":
state = "supply"
elif "COIN" in text2 or "CHASE" in text2 or "NEW" in text2 or \
Expand Down Expand Up @@ -632,8 +635,8 @@ def dino_location(background, shift, D):
D_ = D


mask = (background[:,:,0] >= 100) * \
(background[:,:,1] >= 140) * \
mask = (background[:,:,0] >= 180) * \
(background[:,:,1] >= 180) * \
(background[:,:,2] >= 180)

mask = filters.median(mask, np.ones((3, 3)))
Expand Down Expand Up @@ -756,7 +759,7 @@ def dino_location(background, shift, D):
while self.is_dino_loading_screen(background):
background = np.array(pyautogui.screenshot(region=(self.x, self.y, self.w, self.h)))
time.sleep(1)
time.sleep(1)
time.sleep(2)
# read how much and which dino we shoot it

pyautogui.click(x=self.x+self.w//2, y=self.y+self.h//2)
Expand Down Expand Up @@ -805,7 +808,7 @@ def collect_dino(self):

time.sleep(2)
self.shoot_dino()

# there is some bug in JW which is expected when I shoot a dino it turn to original direction
for _ in range(self.number_of_scrolls):
self.change_view()
Expand Down Expand Up @@ -959,8 +962,8 @@ def collect_supply_drop(self):
# HELPER
# ----------------------------------------------------------

def background_changed(self, b1, b2, threshold=1000):
def background_changed(self, b1, b2, threshold=2000):
"""Compare difference between two frames"""
diff = (b1.astype(np.float) - b2.astype(np.float))**2
diff = (b1.astype(float) - b2.astype(float))**2
print("DIFF", np.mean(diff))
return np.mean(diff) > threshold
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from jw_bot import Bot

if __name__ == "__main__":
print('Press Ctrl-C to quit.')
print("Press 'q' to quit.")
DEBUG = False

# for changing location
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ numpy
scikit-image
PyAutoGUI
pytesseract
keyboard
keyboard
Pillow==9.5.0
Binary file added requirements_detailed.txt
Binary file not shown.
40 changes: 20 additions & 20 deletions test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@ def show_regions(shooting_zone, supply_drop_text_loc, launch_button_loc, battery
battery_loc[1] - battery_loc[0],
linewidth=1,edgecolor='k',facecolor='none')
plt.gca().add_patch(rect)
rect = patches.Rectangle((supply_drop_resources_amount_loc[2], supply_drop_resources_amount_loc[0]),
supply_drop_resources_amount_loc[3] - supply_drop_resources_amount_loc[2],
supply_drop_resources_amount_loc[1] - supply_drop_resources_amount_loc[0],
linewidth=1,edgecolor='y',facecolor='none')
plt.gca().add_patch(rect)
rect = patches.Rectangle((supply_drop_resources_text_loc[2], supply_drop_resources_text_loc[0]),
supply_drop_resources_text_loc[3] - supply_drop_resources_text_loc[2],
supply_drop_resources_text_loc[1] - supply_drop_resources_text_loc[0],
linewidth=1,edgecolor='y',facecolor='none')
plt.gca().add_patch(rect)
rect = patches.Rectangle((dino_collected_amount_loc[2], dino_collected_amount_loc[0]),
dino_collected_amount_loc[3] - dino_collected_amount_loc[2],
dino_collected_amount_loc[1] - dino_collected_amount_loc[0],
linewidth=1,edgecolor='c',facecolor='none')
plt.gca().add_patch(rect)
rect = patches.Rectangle((dino_collected_text_loc[2], dino_collected_text_loc[0]),
dino_collected_text_loc[3] - dino_collected_text_loc[2],
dino_collected_text_loc[1] - dino_collected_text_loc[0],
linewidth=1,edgecolor='c',facecolor='none')
plt.gca().add_patch(rect)
# rect = patches.Rectangle((supply_drop_resources_amount_loc[2], supply_drop_resources_amount_loc[0]),
# supply_drop_resources_amount_loc[3] - supply_drop_resources_amount_loc[2],
# supply_drop_resources_amount_loc[1] - supply_drop_resources_amount_loc[0],
# linewidth=1,edgecolor='y',facecolor='none')
# plt.gca().add_patch(rect)
# rect = patches.Rectangle((supply_drop_resources_text_loc[2], supply_drop_resources_text_loc[0]),
# supply_drop_resources_text_loc[3] - supply_drop_resources_text_loc[2],
# supply_drop_resources_text_loc[1] - supply_drop_resources_text_loc[0],
# linewidth=1,edgecolor='y',facecolor='none')
# plt.gca().add_patch(rect)
# rect = patches.Rectangle((dino_collected_amount_loc[2], dino_collected_amount_loc[0]),
# dino_collected_amount_loc[3] - dino_collected_amount_loc[2],
# dino_collected_amount_loc[1] - dino_collected_amount_loc[0],
# linewidth=1,edgecolor='c',facecolor='none')
# plt.gca().add_patch(rect)
# rect = patches.Rectangle((dino_collected_text_loc[2], dino_collected_text_loc[0]),
# dino_collected_text_loc[3] - dino_collected_text_loc[2],
# dino_collected_text_loc[1] - dino_collected_text_loc[0],
# linewidth=1,edgecolor='c',facecolor='none')
# plt.gca().add_patch(rect)


def show_points(moved_too_far_loc, dart_loc):
Expand Down
Empty file removed test_detection.py
Empty file.

0 comments on commit 8345041

Please sign in to comment.