refactoring to game base class
@@ -54,6 +54,7 @@ def run():
|
|||||||
mine = Mine(overlay)
|
mine = Mine(overlay)
|
||||||
mine.execute_main_loop()
|
mine.execute_main_loop()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
run()
|
run()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
6
craft.py
@@ -4,6 +4,7 @@ import pydirectinput
|
|||||||
from config_file import UserConfigs
|
from config_file import UserConfigs
|
||||||
from window_capture import WindowCapture
|
from window_capture import WindowCapture
|
||||||
from vision import Vision
|
from vision import Vision
|
||||||
|
from game_base_class import GameBase
|
||||||
|
|
||||||
MODE25X1 = "m25x1"
|
MODE25X1 = "m25x1"
|
||||||
MODE10X2 = "m10x2"
|
MODE10X2 = "m10x2"
|
||||||
@@ -14,11 +15,10 @@ MODE1X5_X = "m1x5_X"
|
|||||||
MODE_HOUSE = "house"
|
MODE_HOUSE = "house"
|
||||||
|
|
||||||
|
|
||||||
class Craft:
|
class Craft(GameBase):
|
||||||
|
|
||||||
def __init__(self, overlay):
|
def __init__(self, overlay):
|
||||||
self.overlay = overlay
|
super().__init__(overlay)
|
||||||
self.config = UserConfigs()
|
|
||||||
|
|
||||||
self.mode = str(overlay.emitter_use.get())
|
self.mode = str(overlay.emitter_use.get())
|
||||||
self.run_target = int(overlay.energy_use.get())
|
self.run_target = int(overlay.energy_use.get())
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1013 KiB |
|
Before Width: | Height: | Size: 986 KiB |
|
Before Width: | Height: | Size: 761 KiB |
|
Before Width: | Height: | Size: 726 KiB |
|
Before Width: | Height: | Size: 597 KiB |
236
crops.py
@@ -2,12 +2,10 @@ import random
|
|||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pydirectinput
|
import pydirectinput
|
||||||
from window_capture import WindowCapture
|
|
||||||
from vision import Vision
|
|
||||||
from config_file import UserConfigs
|
|
||||||
from utils import mse
|
from utils import mse
|
||||||
from utils import get_click_point
|
from utils import get_click_point
|
||||||
from hsvfilter import HsvFilter
|
from hsvfilter import HsvFilter
|
||||||
|
from game_base_class import GameBase
|
||||||
|
|
||||||
GREEN = 1
|
GREEN = 1
|
||||||
YELLOW = 2
|
YELLOW = 2
|
||||||
@@ -40,43 +38,22 @@ BIGBOMB_STRATEGY = 9
|
|||||||
ROCKET_STRATEGY = 7
|
ROCKET_STRATEGY = 7
|
||||||
BOMB_STRATEGY = 5
|
BOMB_STRATEGY = 5
|
||||||
|
|
||||||
class Crops:
|
|
||||||
|
class Crops(GameBase):
|
||||||
|
|
||||||
def __init__(self, overlay):
|
def __init__(self, overlay):
|
||||||
self.overlay = overlay
|
super().__init__(overlay)
|
||||||
self.data_value_grid = np.zeros((8, 14), dtype=int)
|
|
||||||
self.data_coordinates = np.zeros((8, 14), dtype=object)
|
|
||||||
self.data_score_map = np.zeros((8, 14), dtype=int)
|
|
||||||
self.observation = np.zeros((8, 14), dtype=int)
|
|
||||||
|
|
||||||
self.screenshot = []
|
self.screenshot = []
|
||||||
self.next_level = cv.imread("crop/next_level.jpg", cv.IMREAD_COLOR)
|
|
||||||
self.next_level_x = cv.imread("crop/next_level_x.jpg", cv.IMREAD_COLOR)
|
|
||||||
self.reset_board = cv.imread("crop/reset_button.jpg", cv.IMREAD_COLOR)
|
|
||||||
self.reset_confirm = cv.imread("crop/reset_confirm.jpg", cv.IMREAD_COLOR)
|
|
||||||
self.reset_counter = 0
|
|
||||||
self.colors_at_standard = True
|
|
||||||
self.needles = {}
|
self.needles = {}
|
||||||
self.hsh_needles = {}
|
self.hsh_needles = {}
|
||||||
self.explosives = [RAINBOW, ARROW_RIGHT, ARROW_DOWN, BIGBOMB, BOMB]
|
|
||||||
self.colors = [GREEN, YELLOW, RED, BLUE, PURPLE, MAGINENT, CHEMTRANT, TENESENT, CIBUTRANT, ARTISENT]
|
self.colors.append(PURPLE)
|
||||||
|
|
||||||
self.current_strategy = RAINBOW_STRATEGY
|
self.current_strategy = RAINBOW_STRATEGY
|
||||||
|
|
||||||
# 230 to 2110 = 1883 / 14 = 134.5
|
self.fill_data_coordinates()
|
||||||
# 60 to 1130 = 1076 / 8 = 134.5
|
|
||||||
dim = 134.5
|
|
||||||
for e in range(0, 8, 1):
|
|
||||||
for i in range(0, 14, 1):
|
|
||||||
self.data_coordinates[e][i] = [i * dim, e * dim, dim, dim]
|
|
||||||
|
|
||||||
# initialize the user-class
|
|
||||||
self.config = UserConfigs()
|
|
||||||
|
|
||||||
# initialize the StunWindowCapture class
|
|
||||||
self.capture_window = WindowCapture(None, None, self.config)
|
|
||||||
# initialize the StunVision class
|
|
||||||
self.vision_stun = Vision()
|
|
||||||
|
|
||||||
self.set_color_order((GREEN, YELLOW, RED, BLUE, PURPLE))
|
self.set_color_order((GREEN, YELLOW, RED, BLUE, PURPLE))
|
||||||
|
|
||||||
@@ -90,9 +67,6 @@ class Crops:
|
|||||||
|
|
||||||
self.assess_playfield_and_make_move()
|
self.assess_playfield_and_make_move()
|
||||||
|
|
||||||
def reset(self):
|
|
||||||
self.observation = []
|
|
||||||
|
|
||||||
def set_color_order(self, order):
|
def set_color_order(self, order):
|
||||||
self.needles.clear()
|
self.needles.clear()
|
||||||
self.needles = {order[0]: cv.imread("crop/green.jpg", cv.IMREAD_COLOR),
|
self.needles = {order[0]: cv.imread("crop/green.jpg", cv.IMREAD_COLOR),
|
||||||
@@ -172,65 +146,28 @@ class Crops:
|
|||||||
self.observation = new_observation
|
self.observation = new_observation
|
||||||
return new_observation
|
return new_observation
|
||||||
|
|
||||||
def move_to(self, x, y):
|
|
||||||
point_src = (1113, 598)
|
|
||||||
pydirectinput.moveTo(point_src[0], point_src[1])
|
|
||||||
pydirectinput.mouseDown()
|
|
||||||
w = random.randint(1, 100)
|
|
||||||
cv.waitKey(150 + w)
|
|
||||||
pydirectinput.moveTo(x, y)
|
|
||||||
pydirectinput.mouseUp()
|
|
||||||
cv.waitKey(500 + w)
|
|
||||||
|
|
||||||
def change_value(self, x, y, val):
|
|
||||||
self.data_value_grid[x][y] = val
|
|
||||||
|
|
||||||
def point_in_rect(self, point):
|
|
||||||
for e in range(0, 8, 1):
|
|
||||||
for i in range(0, 14, 1):
|
|
||||||
x1, y1, w, h = self.data_coordinates[e][i]
|
|
||||||
x2, y2 = x1 + w, y1 + h
|
|
||||||
x, y = point
|
|
||||||
if x1 < x and x < x2:
|
|
||||||
if y1 < y and y < y2:
|
|
||||||
return e, i
|
|
||||||
return None, None
|
|
||||||
|
|
||||||
def check_for_button_and_execute(self, screen, needle, offset_left=0, offset_down=0):
|
|
||||||
rectangles = self.vision_stun.find(screen, needle, 0.70, 1)
|
|
||||||
if len(rectangles) == 0:
|
|
||||||
return False
|
|
||||||
point = self.vision_stun.get_click_points(rectangles)[0]
|
|
||||||
self.dig_point(point[0] + offset_left, point[1] + offset_down, 500)
|
|
||||||
return True
|
|
||||||
|
|
||||||
def get_current_board_state(self):
|
def get_current_board_state(self):
|
||||||
try:
|
|
||||||
# get an updated image of the game
|
|
||||||
screenshot = self.capture_window.get_screenshot()
|
|
||||||
# screenshot = cv.imread("playfield.jpg")
|
|
||||||
screenshot = screenshot[58:1134, 230:2113] # 1883,1076
|
|
||||||
self.screenshot = screenshot
|
|
||||||
# gray = cv.cvtColor(screenshot, cv.COLOR_BGR2GRAY)
|
|
||||||
# thresh = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
|
||||||
offset_left = 230
|
|
||||||
offset_down = 58
|
|
||||||
if self.check_for_button_and_execute(screenshot, self.next_level, offset_left, offset_down):
|
|
||||||
self.set_color_order((GREEN, YELLOW, RED, BLUE, PURPLE))
|
|
||||||
self.current_strategy = RAINBOW_STRATEGY
|
|
||||||
cv.waitKey(500)
|
|
||||||
screenshot = self.capture_window.get_screenshot()
|
|
||||||
screenshot = screenshot[58:1134, 230:2113]
|
|
||||||
if self.check_for_button_and_execute(screenshot, self.next_level_x, offset_left, offset_down):
|
|
||||||
cv.waitKey(500)
|
|
||||||
screenshot = self.capture_window.get_screenshot()
|
|
||||||
screenshot = screenshot[58:1134, 230:2113]
|
|
||||||
|
|
||||||
except:
|
# get an updated image of the game
|
||||||
# self.capture_window.release()
|
screenshot = self.capture_window.get_screenshot()
|
||||||
# print("Game window not available - shutting down application")
|
# screenshot = cv.imread("playfield.jpg")
|
||||||
# return None
|
screenshot = screenshot[58:1134, 230:2113] # 1883,1076
|
||||||
pass
|
self.screenshot = screenshot
|
||||||
|
# gray = cv.cvtColor(screenshot, cv.COLOR_BGR2GRAY)
|
||||||
|
# thresh = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
||||||
|
offset_left = 230
|
||||||
|
offset_down = 58
|
||||||
|
if self.check_for_button_and_execute(screenshot, self.next_level, offset_left, offset_down):
|
||||||
|
self.set_color_order((GREEN, YELLOW, RED, BLUE, PURPLE))
|
||||||
|
self.current_strategy = RAINBOW_STRATEGY
|
||||||
|
cv.waitKey(500)
|
||||||
|
screenshot = self.capture_window.get_screenshot()
|
||||||
|
screenshot = screenshot[58:1134, 230:2113]
|
||||||
|
if self.check_for_button_and_execute(screenshot, self.next_level_x, offset_left, offset_down):
|
||||||
|
cv.waitKey(500)
|
||||||
|
screenshot = self.capture_window.get_screenshot()
|
||||||
|
screenshot = screenshot[58:1134, 230:2113]
|
||||||
|
|
||||||
# cv.imshow("screenshot", screenshot)
|
# cv.imshow("screenshot", screenshot)
|
||||||
# cv.waitKey(150)
|
# cv.waitKey(150)
|
||||||
# continue
|
# continue
|
||||||
@@ -270,57 +207,7 @@ class Crops:
|
|||||||
|
|
||||||
return data_coords, screenshot
|
return data_coords, screenshot
|
||||||
|
|
||||||
def detonate_explosive_when_stuck(self, state):
|
|
||||||
for e in range(0, 8, 1):
|
|
||||||
for i in range(0, 14, 1):
|
|
||||||
for explosive in self.explosives:
|
|
||||||
if self.local_pos_check(state, e, i, 0, 0, explosive):
|
|
||||||
src_pt = self.get_click_point(self.data_coordinates[e, i])
|
|
||||||
if self.local_pos_checks(state, e, i, 1, 0, self.colors):
|
|
||||||
dest_pt = self.get_click_point(self.data_coordinates[e + 1, i])
|
|
||||||
self.move_tile(src_pt, dest_pt)
|
|
||||||
return True
|
|
||||||
elif self.local_pos_checks(state, e, i, 0, 1, self.colors):
|
|
||||||
dest_pt = self.get_click_point(self.data_coordinates[e, i + 1])
|
|
||||||
self.move_tile(src_pt, dest_pt)
|
|
||||||
return True
|
|
||||||
elif self.local_pos_checks(state, e, i, -1, 0, self.colors):
|
|
||||||
dest_pt = self.get_click_point(self.data_coordinates[e - 1, i])
|
|
||||||
self.move_tile(src_pt, dest_pt)
|
|
||||||
return True
|
|
||||||
elif self.local_pos_checks(state, e, i, 0, -1, self.colors):
|
|
||||||
dest_pt = self.get_click_point(self.data_coordinates[e, i - 1])
|
|
||||||
self.move_tile(src_pt, dest_pt)
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
return False
|
|
||||||
|
|
||||||
def check_explosives(self, state, e, i):
|
|
||||||
for explosive in self.explosives:
|
|
||||||
if self.local_pos_check(state, e, i, 0, 0, explosive):
|
|
||||||
dest_pt = self.get_click_point(self.data_coordinates[e, i])
|
|
||||||
if self.local_pos_checks(state, e, i, 1, 0, self.explosives):
|
|
||||||
src_pt = self.get_click_point(self.data_coordinates[e + 1, i])
|
|
||||||
self.move_tile(src_pt, dest_pt)
|
|
||||||
elif self.local_pos_checks(state, e, i, 0, 1, self.explosives):
|
|
||||||
src_pt = self.get_click_point(self.data_coordinates[e, i + 1])
|
|
||||||
self.move_tile(src_pt, dest_pt)
|
|
||||||
elif self.local_pos_checks(state, e, i, -1, 0, self.explosives):
|
|
||||||
src_pt = self.get_click_point(self.data_coordinates[e - 1, i])
|
|
||||||
self.move_tile(src_pt, dest_pt)
|
|
||||||
elif self.local_pos_checks(state, e, i, 0, -1, self.explosives):
|
|
||||||
src_pt = self.get_click_point(self.data_coordinates[e, i - 1])
|
|
||||||
self.move_tile(src_pt, dest_pt)
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
return False
|
|
||||||
|
|
||||||
def find_patterns_and_valid_moves(self, state):
|
def find_patterns_and_valid_moves(self, state):
|
||||||
|
|
||||||
# score_map = np.zeros((8, 14), dtype=object)
|
# score_map = np.zeros((8, 14), dtype=object)
|
||||||
for x in range(0, 8, 1):
|
for x in range(0, 8, 1):
|
||||||
for y in range(0, 14, 1):
|
for y in range(0, 14, 1):
|
||||||
@@ -512,70 +399,3 @@ class Crops:
|
|||||||
score = score + self.is_direction_in_bounce_and_same_color(state, direction, color)
|
score = score + self.is_direction_in_bounce_and_same_color(state, direction, color)
|
||||||
|
|
||||||
return score
|
return score
|
||||||
|
|
||||||
def is_direction_in_bounce_and_same_color(self, state, loc, color):
|
|
||||||
x, y = loc
|
|
||||||
if x <= 7 and x >= 0 and y <= 13 and y >= 0:
|
|
||||||
if state[x, y] == color:
|
|
||||||
return 1
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def local_pos_check(self, state, e, i, e_check, i_check, needle):
|
|
||||||
if e + e_check >= 0 and e + e_check <= 7 and i + i_check >= 0 and i + i_check <= 13:
|
|
||||||
if state[e + e_check, i + i_check] == needle:
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def local_pos_checks(self, state, e, i, e_check, i_check, needles):
|
|
||||||
if e + e_check >= 0 and e + e_check <= 7 and i + i_check >= 0 and i + i_check <= 13:
|
|
||||||
for needle in needles:
|
|
||||||
if state[e + e_check, i + i_check] == needle:
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
return False
|
|
||||||
|
|
||||||
def move_tile(self, point_source, point_dest):
|
|
||||||
offset_left = 230
|
|
||||||
offset_down = 58
|
|
||||||
pydirectinput.moveTo(point_source[0] + offset_left, point_source[1] + offset_down)
|
|
||||||
# pydirectinput.moveTo(0,0)
|
|
||||||
pydirectinput.mouseDown()
|
|
||||||
w = random.randint(25, 50)
|
|
||||||
cv.waitKey(100 + w)
|
|
||||||
pydirectinput.moveTo(point_dest[0] + offset_left, point_dest[1] + offset_down)
|
|
||||||
pydirectinput.mouseUp()
|
|
||||||
cv.waitKey(400 + w)
|
|
||||||
|
|
||||||
def check_for_button_and_click_it(self, button_url):
|
|
||||||
screenshot = self.capture_window.get_screenshot()
|
|
||||||
# gray = cv.cvtColor(screenshot, cv.COLOR_BGR2GRAY)
|
|
||||||
# thresh = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
|
||||||
# gray_needle = cv.cvtColor(cv.imread(button_url, cv.IMREAD_UNCHANGED), cv.COLOR_BGR2GRAY)
|
|
||||||
# thresh_needle = cv.threshold(gray_needle, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
|
||||||
needle = cv.imread(button_url, cv.IMREAD_UNCHANGED)
|
|
||||||
# rectangles = self.vision_stun.find(thresh, thresh_needle, 0.4, 1)
|
|
||||||
rectangles = self.vision_stun.find(screenshot, needle, 0.7, 1)
|
|
||||||
|
|
||||||
if len(rectangles) == 1:
|
|
||||||
pointis = self.vision_stun.get_click_points(rectangles)
|
|
||||||
for pointi in pointis:
|
|
||||||
self.dig_point(pointi[0], pointi[1], 150)
|
|
||||||
|
|
||||||
def dig_point(self, point1, point2, dig_time):
|
|
||||||
pydirectinput.moveTo(point1, point2)
|
|
||||||
cv.waitKey(dig_time)
|
|
||||||
pydirectinput.mouseDown()
|
|
||||||
w = random.randint(50, 100)
|
|
||||||
cv.waitKey(w)
|
|
||||||
pydirectinput.mouseUp()
|
|
||||||
|
|
||||||
def get_click_point(self, rectangle):
|
|
||||||
# Loop over all the rectangles
|
|
||||||
x, y, w, h = rectangle
|
|
||||||
# Determine the center position
|
|
||||||
center_x = x + int(w / 2)
|
|
||||||
center_y = y + int(h / 2)
|
|
||||||
# Save the points
|
|
||||||
return int(center_x), int(center_y)
|
|
||||||
|
|||||||
15
equipment.py
@@ -1,13 +1,11 @@
|
|||||||
import random
|
import random
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from time import time
|
from time import time
|
||||||
from window_capture import WindowCapture
|
|
||||||
from vision import Vision
|
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
from hsvfilter import HsvFilter
|
from hsvfilter import HsvFilter
|
||||||
from config_file import UserConfigs
|
|
||||||
import pydirectinput
|
import pydirectinput
|
||||||
from utils import dig_point
|
from utils import dig_point
|
||||||
|
from game_base_class import GameBase
|
||||||
|
|
||||||
EMITTER_MAIN = "main"
|
EMITTER_MAIN = "main"
|
||||||
EMITTER_MUSH = "mushroom"
|
EMITTER_MUSH = "mushroom"
|
||||||
@@ -21,11 +19,10 @@ EMITTER_MULTI = "multi"
|
|||||||
HSV_DEFAULT = HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0)
|
HSV_DEFAULT = HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
class Equipment:
|
class Equipment(GameBase):
|
||||||
|
|
||||||
def __init__(self, overlay):
|
def __init__(self, overlay):
|
||||||
self.overlay = overlay
|
super().__init__(overlay)
|
||||||
self.config = UserConfigs()
|
|
||||||
|
|
||||||
self.needles = []
|
self.needles = []
|
||||||
self.hsvs = []
|
self.hsvs = []
|
||||||
@@ -37,12 +34,6 @@ class Equipment:
|
|||||||
self.SPAWN_COUNT = int(overlay.spawn_use.get())
|
self.SPAWN_COUNT = int(overlay.spawn_use.get())
|
||||||
self.ENERGY_TO_USE = int(overlay.energy_use.get())
|
self.ENERGY_TO_USE = int(overlay.energy_use.get())
|
||||||
|
|
||||||
# initialize the StunWindowCapture class
|
|
||||||
self.capture_window = WindowCapture(None, "equip", self.config)
|
|
||||||
|
|
||||||
# initialize the StunVision class
|
|
||||||
self.vision_stun = Vision()
|
|
||||||
|
|
||||||
if self.EMITTER_TO_USE == EMITTER_MULTI:
|
if self.EMITTER_TO_USE == EMITTER_MULTI:
|
||||||
self.emitters.append(EMITTER_RING)
|
self.emitters.append(EMITTER_RING)
|
||||||
self.emitters.append(EMITTER_WAND)
|
self.emitters.append(EMITTER_WAND)
|
||||||
|
|||||||
182
farm.py
@@ -1,11 +1,7 @@
|
|||||||
import random
|
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pydirectinput
|
|
||||||
from window_capture import WindowCapture
|
|
||||||
from vision import Vision
|
|
||||||
from config_file import UserConfigs
|
|
||||||
from utils import mse
|
from utils import mse
|
||||||
|
from game_base_class import GameBase
|
||||||
|
|
||||||
GREEN = 1
|
GREEN = 1
|
||||||
YELLOW = 2
|
YELLOW = 2
|
||||||
@@ -30,52 +26,14 @@ CIBUTRANT = 24
|
|||||||
ARTISENT = 25
|
ARTISENT = 25
|
||||||
|
|
||||||
|
|
||||||
class Farm:
|
class Farm(GameBase):
|
||||||
|
|
||||||
def __init__(self, overlay):
|
def __init__(self, overlay):
|
||||||
self.overlay = overlay
|
super().__init__(overlay)
|
||||||
self.data_value_grid = np.zeros((8, 14), dtype=int)
|
|
||||||
self.data_coordinates = np.zeros((8, 14), dtype=object)
|
|
||||||
self.observation = np.zeros((8, 14), dtype=int)
|
|
||||||
|
|
||||||
self.next_level = cv.imread("farm/next_level.jpg", cv.IMREAD_COLOR)
|
|
||||||
self.next_level_x = cv.imread("farm/next_level_x.jpg", cv.IMREAD_COLOR)
|
|
||||||
self.reset_board = cv.imread("farm/reset_button.jpg", cv.IMREAD_COLOR)
|
|
||||||
self.reset_confirm = cv.imread("farm/reset_confirm.jpg", cv.IMREAD_COLOR)
|
|
||||||
self.reset_counter = 0
|
|
||||||
|
|
||||||
self.explosives = []
|
|
||||||
self.explosives.append(RAINBOW)
|
|
||||||
self.explosives.append(ARROW_RIGHT)
|
|
||||||
self.explosives.append(ARROW_DOWN)
|
|
||||||
self.explosives.append(BIGBOMB)
|
|
||||||
self.explosives.append(BOMB)
|
|
||||||
self.colors = []
|
|
||||||
self.colors.append(GREEN)
|
|
||||||
self.colors.append(YELLOW)
|
|
||||||
self.colors.append(BLUE)
|
|
||||||
self.colors.append(RED)
|
|
||||||
self.colors.append(PINK)
|
self.colors.append(PINK)
|
||||||
self.colors.append(MAGINENT)
|
|
||||||
self.colors.append(CHEMTRANT)
|
|
||||||
self.colors.append(TENESENT)
|
|
||||||
self.colors.append(CIBUTRANT)
|
|
||||||
self.colors.append(ARTISENT)
|
|
||||||
|
|
||||||
# 230 to 2110 = 1883 / 14 = 134.5
|
self.fill_data_coordinates()
|
||||||
# 60 to 1130 = 1076 / 8 = 134.5
|
|
||||||
dim = 134.5
|
|
||||||
for e in range(0, 8, 1):
|
|
||||||
for i in range(0, 14, 1):
|
|
||||||
self.data_coordinates[e][i] = [i * dim, e * dim, dim, dim]
|
|
||||||
|
|
||||||
# initialize the user-class
|
|
||||||
self.config = UserConfigs()
|
|
||||||
|
|
||||||
# initialize the StunWindowCapture class
|
|
||||||
self.capture_window = WindowCapture(None, None, self.config)
|
|
||||||
# initialize the StunVision class
|
|
||||||
self.vision_stun = Vision()
|
|
||||||
|
|
||||||
self.needles = {GREEN: cv.imread("farm/green.jpg", cv.IMREAD_COLOR),
|
self.needles = {GREEN: cv.imread("farm/green.jpg", cv.IMREAD_COLOR),
|
||||||
YELLOW: cv.imread("farm/yellow.jpg", cv.IMREAD_COLOR),
|
YELLOW: cv.imread("farm/yellow.jpg", cv.IMREAD_COLOR),
|
||||||
@@ -110,9 +68,6 @@ class Farm:
|
|||||||
|
|
||||||
self.assess_playfield_and_make_move()
|
self.assess_playfield_and_make_move()
|
||||||
|
|
||||||
def reset(self):
|
|
||||||
self.observation = []
|
|
||||||
|
|
||||||
def assess_playfield_and_make_move(self):
|
def assess_playfield_and_make_move(self):
|
||||||
|
|
||||||
new_observation, new_screenshot = self.get_current_board_state()
|
new_observation, new_screenshot = self.get_current_board_state()
|
||||||
@@ -148,50 +103,6 @@ class Farm:
|
|||||||
self.observation = new_observation
|
self.observation = new_observation
|
||||||
return new_observation
|
return new_observation
|
||||||
|
|
||||||
def check_for_button_and_execute(self, screen, needle, offset_left=0, offset_down=0):
|
|
||||||
rectangles = self.vision_stun.find(screen, needle, 0.70, 1)
|
|
||||||
if len(rectangles) == 0:
|
|
||||||
return False
|
|
||||||
point = self.vision_stun.get_click_points(rectangles)[0]
|
|
||||||
self.dig_point(point[0] + offset_left, point[1] + offset_down, 500)
|
|
||||||
return True
|
|
||||||
|
|
||||||
def move_to(self, x, y):
|
|
||||||
point_src = (1113, 598)
|
|
||||||
pydirectinput.moveTo(point_src[0], point_src[1])
|
|
||||||
pydirectinput.mouseDown()
|
|
||||||
w = random.randint(1, 100)
|
|
||||||
cv.waitKey(150 + w)
|
|
||||||
pydirectinput.moveTo(x, y)
|
|
||||||
pydirectinput.mouseUp()
|
|
||||||
cv.waitKey(500 + w)
|
|
||||||
|
|
||||||
def change_value(self, x, y, val):
|
|
||||||
self.data_value_grid[x][y] = val
|
|
||||||
|
|
||||||
def pointInRect(self, point):
|
|
||||||
for e in range(0, 8, 1):
|
|
||||||
for i in range(0, 14, 1):
|
|
||||||
x1, y1, w, h = self.data_coordinates[e][i]
|
|
||||||
x2, y2 = x1 + w, y1 + h
|
|
||||||
x, y = point
|
|
||||||
if x1 < x and x < x2:
|
|
||||||
if y1 < y and y < y2:
|
|
||||||
return e, i
|
|
||||||
return None, None
|
|
||||||
|
|
||||||
def check_for_next_level(self, screen, needle):
|
|
||||||
offset_left = 230
|
|
||||||
offset_down = 58
|
|
||||||
rectangles = self.vision_stun.find(screen, needle, 0.70, 1)
|
|
||||||
if len(rectangles) == 0:
|
|
||||||
return False
|
|
||||||
if self.detonate_explosive_when_stuck(self.observation):
|
|
||||||
return True
|
|
||||||
point = self.vision_stun.get_click_points(rectangles)[0]
|
|
||||||
self.dig_point(point[0] + offset_left, point[1] + offset_down, 500)
|
|
||||||
return True
|
|
||||||
|
|
||||||
def get_current_board_state(self):
|
def get_current_board_state(self):
|
||||||
# get an updated image of the game
|
# get an updated image of the game
|
||||||
screenshot = self.capture_window.get_screenshot()
|
screenshot = self.capture_window.get_screenshot()
|
||||||
@@ -222,7 +133,7 @@ class Farm:
|
|||||||
points = self.vision_stun.get_click_points(rectangles)
|
points = self.vision_stun.get_click_points(rectangles)
|
||||||
|
|
||||||
for point in points:
|
for point in points:
|
||||||
x, y = self.pointInRect(point)
|
x, y = self.point_in_rect(point)
|
||||||
if x is not None and y is not None:
|
if x is not None and y is not None:
|
||||||
data_coords[x][y] = int(needle_key)
|
data_coords[x][y] = int(needle_key)
|
||||||
# self.change_value(x, y, int(needle_key))
|
# self.change_value(x, y, int(needle_key))
|
||||||
@@ -299,45 +210,6 @@ class Farm:
|
|||||||
continue
|
continue
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def check_explosives(self, state, e, i):
|
|
||||||
for explosive in self.explosives:
|
|
||||||
if self.local_pos_check(state, e, i, 0, 0, explosive):
|
|
||||||
dest_pt = self.get_click_point(self.data_coordinates[e, i])
|
|
||||||
if self.local_pos_checks(state, e, i, 1, 0, self.explosives):
|
|
||||||
src_pt = self.get_click_point(self.data_coordinates[e + 1, i])
|
|
||||||
self.move_tile(src_pt, dest_pt)
|
|
||||||
elif self.local_pos_checks(state, e, i, 0, 1, self.explosives):
|
|
||||||
src_pt = self.get_click_point(self.data_coordinates[e, i + 1])
|
|
||||||
self.move_tile(src_pt, dest_pt)
|
|
||||||
elif self.local_pos_checks(state, e, i, -1, 0, self.explosives):
|
|
||||||
src_pt = self.get_click_point(self.data_coordinates[e - 1, i])
|
|
||||||
self.move_tile(src_pt, dest_pt)
|
|
||||||
elif self.local_pos_checks(state, e, i, 0, -1, self.explosives):
|
|
||||||
src_pt = self.get_click_point(self.data_coordinates[e, i - 1])
|
|
||||||
self.move_tile(src_pt, dest_pt)
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
return False
|
|
||||||
|
|
||||||
def local_pos_check(self, state, e, i, e_check, i_check, needle):
|
|
||||||
if e + e_check >= 0 and e + e_check <= 7 and i + i_check >= 0 and i + i_check <= 13:
|
|
||||||
if state[e + e_check, i + i_check] == needle:
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def local_pos_checks(self, state, e, i, e_check, i_check, needles):
|
|
||||||
if e + e_check >= 0 and e + e_check <= 7 and i + i_check >= 0 and i + i_check <= 13:
|
|
||||||
for needle in needles:
|
|
||||||
if state[e + e_check, i + i_check] == needle:
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
return False
|
|
||||||
|
|
||||||
def check_5_horizontal(self, state, e, i, color):
|
def check_5_horizontal(self, state, e, i, color):
|
||||||
try:
|
try:
|
||||||
#
|
#
|
||||||
@@ -529,47 +401,3 @@ class Farm:
|
|||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def move_tile(self, point_source, point_dest):
|
|
||||||
offset_left = 230
|
|
||||||
offset_down = 58
|
|
||||||
pydirectinput.moveTo(point_source[0] + offset_left, point_source[1] + offset_down)
|
|
||||||
# pydirectinput.moveTo(0,0)
|
|
||||||
pydirectinput.mouseDown()
|
|
||||||
w = random.randint(25, 50)
|
|
||||||
cv.waitKey(100 + w)
|
|
||||||
pydirectinput.moveTo(point_dest[0] + offset_left, point_dest[1] + offset_down)
|
|
||||||
pydirectinput.mouseUp()
|
|
||||||
cv.waitKey(400 + w)
|
|
||||||
|
|
||||||
def check_for_button_and_click_it(self, button_url):
|
|
||||||
screenshot = self.capture_window.get_screenshot()
|
|
||||||
# gray = cv.cvtColor(screenshot, cv.COLOR_BGR2GRAY)
|
|
||||||
# thresh = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
|
||||||
# gray_needle = cv.cvtColor(cv.imread(button_url, cv.IMREAD_UNCHANGED), cv.COLOR_BGR2GRAY)
|
|
||||||
# thresh_needle = cv.threshold(gray_needle, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
|
||||||
needle = cv.imread(button_url, cv.IMREAD_UNCHANGED)
|
|
||||||
# rectangles = self.vision_stun.find(thresh, thresh_needle, 0.4, 1)
|
|
||||||
rectangles = self.vision_stun.find(screenshot, needle, 0.7, 1)
|
|
||||||
|
|
||||||
if len(rectangles) == 1:
|
|
||||||
pointis = self.vision_stun.get_click_points(rectangles)
|
|
||||||
for pointi in pointis:
|
|
||||||
self.dig_point(pointi[0], pointi[1], 150)
|
|
||||||
|
|
||||||
def dig_point(self, point1, point2, dig_time):
|
|
||||||
pydirectinput.moveTo(point1, point2)
|
|
||||||
cv.waitKey(dig_time)
|
|
||||||
pydirectinput.mouseDown()
|
|
||||||
w = random.randint(50, 100)
|
|
||||||
cv.waitKey(w)
|
|
||||||
pydirectinput.mouseUp()
|
|
||||||
|
|
||||||
def get_click_point(self, rectangle):
|
|
||||||
# Loop over all the rectangles
|
|
||||||
x, y, w, h = rectangle
|
|
||||||
# Determine the center position
|
|
||||||
center_x = x + int(w / 2)
|
|
||||||
center_y = y + int(h / 2)
|
|
||||||
# Save the points
|
|
||||||
return int(center_x), int(center_y)
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 890 KiB |
|
Before Width: | Height: | Size: 928 KiB |
|
Before Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 13 KiB |
14
magic.py
@@ -1,25 +1,17 @@
|
|||||||
import random
|
import random
|
||||||
from window_capture import WindowCapture
|
|
||||||
from vision import Vision
|
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
from hsvfilter import HsvFilter
|
from hsvfilter import HsvFilter
|
||||||
from config_file import UserConfigs
|
|
||||||
import pydirectinput
|
import pydirectinput
|
||||||
|
from game_base_class import GameBase
|
||||||
|
|
||||||
|
|
||||||
class Magic:
|
class Magic(GameBase):
|
||||||
|
|
||||||
def __init__(self, overlay):
|
def __init__(self, overlay):
|
||||||
self.overlay = overlay
|
super().__init__(overlay)
|
||||||
self.config = UserConfigs()
|
|
||||||
|
|
||||||
self.SPAWN_COUNT = int(overlay.spawn_use.get())
|
self.SPAWN_COUNT = int(overlay.spawn_use.get())
|
||||||
|
|
||||||
self.capture_window = WindowCapture(None, "magic", self.config)
|
|
||||||
|
|
||||||
# initialize the StunVision class
|
|
||||||
self.vision_stun = Vision()
|
|
||||||
# initialize the StunOverlay class
|
|
||||||
hsv_filter_orange = HsvFilter(10, 156, 0, 17, 255, 255, 0, 0, 0, 0)
|
hsv_filter_orange = HsvFilter(10, 156, 0, 17, 255, 255, 0, 0, 0, 0)
|
||||||
hsv_filter_p = HsvFilter(130, 156, 0, 179, 255, 255, 0, 0, 0, 0)
|
hsv_filter_p = HsvFilter(130, 156, 0, 179, 255, 255, 0, 0, 0, 0)
|
||||||
hsv_filter_b = HsvFilter(88, 156, 0, 128, 255, 255, 0, 0, 0, 0)
|
hsv_filter_b = HsvFilter(88, 156, 0, 128, 255, 255, 0, 0, 0, 0)
|
||||||
|
|||||||
15
mine.py
@@ -1,20 +1,12 @@
|
|||||||
from config_file import UserConfigs
|
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
from utils import dig_point, check_for_ok_button
|
from utils import dig_point, check_for_ok_button
|
||||||
from window_capture import WindowCapture
|
from game_base_class import GameBase
|
||||||
from vision import Vision
|
|
||||||
|
|
||||||
|
|
||||||
class Mine:
|
class Mine(GameBase):
|
||||||
|
|
||||||
def __init__(self, overlay):
|
def __init__(self, overlay):
|
||||||
self.overlay = overlay
|
super().__init__(overlay)
|
||||||
self.config = UserConfigs()
|
|
||||||
|
|
||||||
self.capture_window = WindowCapture(None, "screen_conf", self.config)
|
|
||||||
|
|
||||||
# initialize the StunVision class
|
|
||||||
self.vision_stun = Vision()
|
|
||||||
|
|
||||||
self.level = 1
|
self.level = 1
|
||||||
|
|
||||||
@@ -39,6 +31,7 @@ class Mine:
|
|||||||
if self.overlay.run_mode == 'stopped':
|
if self.overlay.run_mode == 'stopped':
|
||||||
return
|
return
|
||||||
dig_point(290, 100, 200)
|
dig_point(290, 100, 200)
|
||||||
|
self.reset()
|
||||||
self.execute_loop()
|
self.execute_loop()
|
||||||
|
|
||||||
def execute_loop(self):
|
def execute_loop(self):
|
||||||
|
|||||||