Merge remote-tracking branch 'origin/master'
# Conflicts: # craft_table/main_craft.py
@@ -23,8 +23,10 @@ def run():
|
||||
overlay.run_mode = 'init'
|
||||
continue
|
||||
elif overlay.run_mode == 'started':
|
||||
cv.waitKey(1000)
|
||||
pass
|
||||
elif overlay.run_mode == 'init':
|
||||
cv.waitKey(1)
|
||||
continue
|
||||
elif overlay.run_mode == 'paused':
|
||||
continue
|
||||
|
||||
@@ -26,8 +26,9 @@ def run():
|
||||
overlay.run_mode = 'init'
|
||||
continue
|
||||
elif overlay.run_mode == 'started':
|
||||
cv.waitKey(500)
|
||||
cv.waitKey(1000)
|
||||
elif overlay.run_mode == 'init':
|
||||
cv.waitKey(1)
|
||||
continue
|
||||
elif overlay.run_mode == 'finished':
|
||||
overlay.update_status_label("finished", "0")
|
||||
@@ -307,7 +308,7 @@ def run():
|
||||
# initialize the StunVision class
|
||||
vision_stun = Vision()
|
||||
# odig_overlay = DiggingOverlay(config)
|
||||
check_for_craft_button(capture_window2, vision_stun)
|
||||
check_for_craft_button(capture_window2, vision_stun, capture_config)
|
||||
check_for_craft_ok_button(capture_window2, vision_stun)
|
||||
run_counter = run_counter + 1
|
||||
overlay.update_status_label(mode, run_target - run_counter)
|
||||
|
||||
@@ -7,11 +7,12 @@ from vision import Vision
|
||||
from config_file import UserConfigs
|
||||
from utils import mse
|
||||
from utils import get_click_point
|
||||
from hsvfilter import HsvFilter
|
||||
|
||||
GREEN = 1
|
||||
YELLOW = 2
|
||||
BLUE = 3
|
||||
RED = 4
|
||||
RED = 3
|
||||
BLUE = 4
|
||||
PURPLE = 5
|
||||
RAINBOW = 6
|
||||
BIGBOMB = 7
|
||||
@@ -41,24 +42,14 @@ class Field:
|
||||
screenshot = []
|
||||
next_level = cv.imread("next_level.jpg", cv.IMREAD_COLOR)
|
||||
next_level_x = cv.imread("next_level_x.jpg", cv.IMREAD_COLOR)
|
||||
explosives = []
|
||||
explosives.append(RAINBOW)
|
||||
explosives.append(ARROW_RIGHT)
|
||||
explosives.append(ARROW_DOWN)
|
||||
explosives.append(BIGBOMB)
|
||||
explosives.append(BOMB)
|
||||
colors = []
|
||||
colors.append(GREEN)
|
||||
colors.append(YELLOW)
|
||||
colors.append(BLUE)
|
||||
colors.append(RED)
|
||||
colors.append(PURPLE)
|
||||
|
||||
# colors.append(MAGINENT)
|
||||
# colors.append(CHEMTRANT)
|
||||
# colors.append(TENESENT)
|
||||
# colors.append(CIBUTRANT)
|
||||
# colors.append(ARTISENT)
|
||||
reset_board = cv.imread("reset_button.jpg", cv.IMREAD_COLOR)
|
||||
reset_confirm = cv.imread("reset_confirm.jpg", cv.IMREAD_COLOR)
|
||||
reset_counter = 0
|
||||
colors_at_standard = True
|
||||
needles = {}
|
||||
hsh_needles = {}
|
||||
explosives = [RAINBOW, ARROW_RIGHT, ARROW_DOWN, BIGBOMB, BOMB]
|
||||
colors = [GREEN, YELLOW, RED, BLUE, PURPLE, MAGINENT, CHEMTRANT, TENESENT, CIBUTRANT, ARTISENT]
|
||||
|
||||
def __init__(self):
|
||||
self.data_value_grid = np.zeros((8, 14), dtype=int)
|
||||
@@ -81,33 +72,51 @@ class Field:
|
||||
# initialize the StunVision class
|
||||
self.vision_stun = Vision()
|
||||
|
||||
self.needles = {GREEN: cv.imread("green.jpg", cv.IMREAD_COLOR),
|
||||
YELLOW: cv.imread("yellow.jpg", cv.IMREAD_COLOR),
|
||||
PURPLE: cv.imread("purple.jpg", cv.IMREAD_COLOR),
|
||||
BLUE: cv.imread("blue.jpg", cv.IMREAD_COLOR),
|
||||
RED: cv.imread("red.jpg", cv.IMREAD_COLOR)
|
||||
|
||||
# RAINBOW: cv.imread("rainbow.jpg", cv.IMREAD_COLOR),
|
||||
# BIGBOMB: cv.imread("bigbomb.jpg", cv.IMREAD_COLOR),
|
||||
# BOMB: cv.imread("bomb.jpg", cv.IMREAD_COLOR),
|
||||
# ARROW_DOWN: cv.imread("arrow_down.jpg", cv.IMREAD_COLOR),
|
||||
# ARROW_RIGHT: cv.imread("arrow_right.jpg", cv.IMREAD_COLOR),
|
||||
# ROCK_1: cv.imread("rock1.jpg", cv.IMREAD_COLOR),
|
||||
# ROCK_2: cv.imread("rock2.jpg", cv.IMREAD_COLOR),
|
||||
# ROCK_3: cv.imread("rock3.jpg", cv.IMREAD_COLOR),
|
||||
# BURGER: cv.imread("burger.jpg", cv.IMREAD_COLOR),
|
||||
# GOLDBAR: cv.imread("burger.jpg", cv.IMREAD_COLOR),
|
||||
# PAB1: cv.imread("pab1.jpg", cv.IMREAD_COLOR),
|
||||
# MAGINENT: cv.imread("maginent.jpg", cv.IMREAD_COLOR),
|
||||
# CHEMTRANT: cv.imread("chemtrant.jpg", cv.IMREAD_COLOR),
|
||||
# TENESENT: cv.imread("tenesent.jpg", cv.IMREAD_COLOR),
|
||||
# CIBUTRANT: cv.imread("cibutrant.jpg", cv.IMREAD_COLOR),
|
||||
# ARTISENT: cv.imread("artisent.jpg", cv.IMREAD_COLOR)
|
||||
}
|
||||
self.set_color_order((GREEN, YELLOW, RED, BLUE, PURPLE))
|
||||
|
||||
def reset(self):
|
||||
self.observation = []
|
||||
|
||||
def set_color_order(self, order):
|
||||
self.needles.clear()
|
||||
self.needles = {order[0]: cv.imread("green.jpg", cv.IMREAD_COLOR),
|
||||
order[1]: cv.imread("yellow.jpg", cv.IMREAD_COLOR),
|
||||
order[2]: cv.imread("red.jpg", cv.IMREAD_COLOR),
|
||||
order[3]: cv.imread("blue.jpg", cv.IMREAD_COLOR),
|
||||
order[4]: cv.imread("purple.jpg", cv.IMREAD_COLOR),
|
||||
|
||||
RAINBOW: cv.imread("rainbow.jpg", cv.IMREAD_COLOR),
|
||||
BIGBOMB: cv.imread("bigbomb.jpg", cv.IMREAD_COLOR),
|
||||
BOMB: cv.imread("bomb.jpg", cv.IMREAD_COLOR),
|
||||
ARROW_DOWN: cv.imread("arrow_down.jpg", cv.IMREAD_COLOR),
|
||||
ARROW_RIGHT: cv.imread("arrow_right.jpg", cv.IMREAD_COLOR),
|
||||
|
||||
MAGINENT: cv.imread("maginent.jpg", cv.IMREAD_COLOR),
|
||||
CHEMTRANT: cv.imread("chemtrant.jpg", cv.IMREAD_COLOR),
|
||||
TENESENT: cv.imread("tenesent.jpg", cv.IMREAD_COLOR),
|
||||
CIBUTRANT: cv.imread("cibutrant.jpg", cv.IMREAD_COLOR),
|
||||
ARTISENT: cv.imread("artisent.jpg", cv.IMREAD_COLOR)
|
||||
}
|
||||
self.hsh_needles.clear()
|
||||
self.hsh_needles = {order[0]: HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0),
|
||||
order[1]: HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0),
|
||||
order[2]: HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0),
|
||||
order[3]: HsvFilter(60, 40, 0, 115, 255, 255, 0, 0, 0, 0),
|
||||
order[4]: HsvFilter(120, 45, 0, 170, 255, 255, 0, 0, 0, 0),
|
||||
|
||||
RAINBOW: HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0),
|
||||
BIGBOMB: HsvFilter(60, 40, 0, 179, 129, 129, 0, 0, 0, 0),
|
||||
BOMB: HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0),
|
||||
ARROW_DOWN: HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0),
|
||||
ARROW_RIGHT: HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0),
|
||||
|
||||
MAGINENT: HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0),
|
||||
CHEMTRANT: HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0),
|
||||
TENESENT: HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0),
|
||||
CIBUTRANT: HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0),
|
||||
ARTISENT: HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0)
|
||||
}
|
||||
|
||||
def assess_playfield_and_make_move(self):
|
||||
|
||||
new_observation, new_screenshot = self.get_current_board_state()
|
||||
@@ -116,8 +125,31 @@ class Field:
|
||||
# last board state is same as actual
|
||||
if mse(new_observation, self.observation) == 0.0:
|
||||
# no movement detected -> blow explosives or reset
|
||||
#self.detonate_explosive_when_stuck(new_observation)
|
||||
cv.waitKey(500)
|
||||
|
||||
self.reset_counter += 1
|
||||
if self.reset_counter == 1:
|
||||
pass
|
||||
elif self.reset_counter == 2:
|
||||
self.detonate_explosive_when_stuck(new_observation)
|
||||
return
|
||||
elif self.reset_counter >= 3:
|
||||
screenshot = self.capture_window.get_screenshot()
|
||||
if self.check_for_button_and_execute(screenshot, self.reset_board):
|
||||
cv.waitKey(500)
|
||||
screenshot = self.capture_window.get_screenshot()
|
||||
if self.check_for_button_and_execute(screenshot, self.reset_confirm):
|
||||
cv.waitKey(500)
|
||||
|
||||
if self.colors_at_standard:
|
||||
self.set_color_order((PURPLE, BLUE, RED, YELLOW, GREEN))
|
||||
self.colors_at_standard = False
|
||||
else:
|
||||
self.set_color_order((GREEN, YELLOW, RED, BLUE, PURPLE))
|
||||
self.colors_at_standard = True
|
||||
self.reset_counter = 0
|
||||
return
|
||||
else:
|
||||
return
|
||||
|
||||
self.find_patterns_and_valid_moves(new_observation)
|
||||
self.observation = new_observation
|
||||
@@ -136,20 +168,18 @@ class Field:
|
||||
def change_value(self, x, y, val):
|
||||
self.data_value_grid[x][y] = val
|
||||
|
||||
def pointInRect(self, point):
|
||||
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):
|
||||
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
|
||||
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
|
||||
@@ -161,21 +191,22 @@ class Field:
|
||||
try:
|
||||
# get an updated image of the game
|
||||
screenshot = self.capture_window.get_screenshot()
|
||||
#screenshot = cv.imread("playfield.jpg")
|
||||
# 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]
|
||||
'''
|
||||
if self.check_for_next_level(screenshot, self.next_level):
|
||||
offset_left = 230
|
||||
offset_down = 58
|
||||
if self.check_for_button_and_execute(screenshot, self.next_level, offset_left, offset_down):
|
||||
cv.waitKey(500)
|
||||
screenshot = self.capture_window.get_screenshot()
|
||||
screenshot = screenshot[58:1134, 230:2113]
|
||||
if self.check_for_next_level(screenshot, self.next_level_x):
|
||||
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:
|
||||
# self.capture_window.release()
|
||||
# print("Game window not available - shutting down application")
|
||||
@@ -186,16 +217,20 @@ class Field:
|
||||
# continue
|
||||
data_coords = np.zeros((8, 14), dtype=object)
|
||||
# field = Field()
|
||||
|
||||
for needle_key in self.needles.keys():
|
||||
# gray_needle = cv.cvtColor(self.needles[needle_key], cv.COLOR_BGR2GRAY)
|
||||
# thresh_needle = cv.threshold(gray_needle, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
||||
rectangles = self.vision_stun.find(screenshot, self.needles[needle_key], 0.70, 56)
|
||||
processed_screenshot = self.vision_stun.apply_hsv_filter(screenshot, self.hsh_needles[needle_key])
|
||||
processed_needle = self.vision_stun.apply_hsv_filter(self.needles[needle_key], self.hsh_needles[needle_key])
|
||||
rectangles = self.vision_stun.find(processed_screenshot, processed_needle, 0.70, 56)
|
||||
# rectangles = self.vision_stun.find(screenshot, self.needles[needle_key], 0.70, 56)
|
||||
if len(rectangles) == 0:
|
||||
continue
|
||||
points = self.vision_stun.get_click_points(rectangles)
|
||||
|
||||
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:
|
||||
data_coords[x][y] = int(needle_key)
|
||||
# self.change_value(x, y, int(needle_key))
|
||||
@@ -216,9 +251,54 @@ class Field:
|
||||
|
||||
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):
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e, i])
|
||||
if self.local_pos_checks(state, e, i, 1, 0, self.colors):
|
||||
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.colors):
|
||||
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.colors):
|
||||
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.colors):
|
||||
src_pt = self.get_click_point(self.data_coordinates[e, i - 1])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
else:
|
||||
continue
|
||||
return
|
||||
|
||||
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):
|
||||
|
||||
#score_map = np.zeros((8, 14), dtype=object)
|
||||
# score_map = np.zeros((8, 14), dtype=object)
|
||||
for x in range(0, 8, 1):
|
||||
for y in range(0, 14, 1):
|
||||
self.data_score_map[x, y] = self.score_for_attached_same_color_all_directions(state, x, y)
|
||||
@@ -227,28 +307,27 @@ class Field:
|
||||
reserve_moves = []
|
||||
for x in range(0, 8, 1):
|
||||
for y in range(0, 14, 1):
|
||||
if self.check_explosives(state, x, y):
|
||||
return
|
||||
if self.data_score_map[x, y] >= 4:
|
||||
path_option = []
|
||||
path_option.append([x, y])
|
||||
recursion_reminder = []
|
||||
recursion_reminder.append([x, y])
|
||||
result = self.find_next_same_color_all_directions_recursion(state, x, y, path_option, recursion_reminder, True)
|
||||
path_option = [[x, y]]
|
||||
recursion_reminder = [[x, y]]
|
||||
result = self.find_next_same_color_all_directions_recursion(state, x, y, path_option,
|
||||
recursion_reminder, True)
|
||||
if result == STATUS_FOUND_ENDING:
|
||||
path_option.append([x, y])
|
||||
if len(path_option) >= 5:
|
||||
full_moves.append(path_option)
|
||||
full_moves.append((state[x, y], path_option))
|
||||
if self.data_score_map[x, y] >= 1:
|
||||
path_option = []
|
||||
path_option.append([x, y])
|
||||
recursion_reminder = []
|
||||
recursion_reminder.append([x, y])
|
||||
path_option = [[x, y]]
|
||||
self.find_next_same_color_all_directions_recursion2(state, x, y, path_option)
|
||||
if len(path_option) >= 3:
|
||||
reserve_moves.append(path_option)
|
||||
#print(self.data_score_map)
|
||||
|
||||
#screenshot = cv.imread("screenshot_scored.jpg")
|
||||
reserve_moves.append((state[x, y], path_option))
|
||||
# print(self.data_score_map)
|
||||
|
||||
# screenshot = cv.imread("screenshot_scored.jpg")
|
||||
full_dic = self.convert_moves_to_dic_by_color(full_moves)
|
||||
res_dic = self.convert_moves_to_dic_by_color(reserve_moves)
|
||||
|
||||
full_moves.sort(key=len, reverse=True)
|
||||
reserve_moves.sort(key=len, reverse=True)
|
||||
@@ -256,46 +335,56 @@ class Field:
|
||||
|
||||
'''
|
||||
|
||||
if len(full_moves) >= 1:
|
||||
self.print_move(full_moves)
|
||||
self.execute_move(full_moves)
|
||||
elif len(reserve_moves) >= 1:
|
||||
#moves = []
|
||||
#moves.append(reserve_moves[random.randint(0, len(reserve_moves)-1)])
|
||||
self.print_move(reserve_moves)
|
||||
self.execute_move(reserve_moves)
|
||||
else:
|
||||
# boelk
|
||||
pass
|
||||
if len(full_dic) >= 1:
|
||||
for key in sorted(full_dic):
|
||||
if len(full_dic[key]) >= 10:
|
||||
self.print_move(full_dic[key])
|
||||
self.execute_move(full_dic[key])
|
||||
break
|
||||
if len(reserve_moves) >= 1:
|
||||
for key in sorted(res_dic):
|
||||
self.print_move(res_dic[key])
|
||||
self.execute_move(res_dic[key])
|
||||
break
|
||||
|
||||
def print_move(self, moves):
|
||||
def convert_moves_to_dic_by_color(self, reserve_moves):
|
||||
dic = {}
|
||||
for color, move in reserve_moves:
|
||||
if color in dic:
|
||||
if len(move) > len(dic[color]):
|
||||
dic[color] = move
|
||||
else:
|
||||
dic[color] = move
|
||||
return dic
|
||||
|
||||
def print_move(self, move):
|
||||
mp = []
|
||||
for point in moves[0]:
|
||||
for point in move:
|
||||
cp = self.get_click_point(self.data_coordinates[point[0], point[1]])
|
||||
mp.append(cp)
|
||||
cv.polylines(self.screenshot,
|
||||
[np.array(mp)],
|
||||
isClosed=False,
|
||||
color=(0, 255, 0),
|
||||
thickness=3)
|
||||
[np.array(mp)],
|
||||
isClosed=False,
|
||||
color=(0, 255, 0),
|
||||
thickness=3)
|
||||
|
||||
cv.imwrite('screenshot_pathed.jpg', self.screenshot)
|
||||
|
||||
def execute_move(self, moves):
|
||||
def execute_move(self, move):
|
||||
offset_left = 230
|
||||
offset_down = 58
|
||||
if len(moves) >= 1:
|
||||
first = True
|
||||
for cords in moves[0]:
|
||||
square = self.data_coordinates[cords[0], cords[1]]
|
||||
pydirectinput.moveTo(get_click_point(square)[0] + offset_left, get_click_point(square)[1]+offset_down)
|
||||
cv.waitKey(50)
|
||||
if first:
|
||||
pydirectinput.mouseDown()
|
||||
cv.waitKey(100)
|
||||
first = False
|
||||
pydirectinput.mouseUp()
|
||||
|
||||
first = True
|
||||
for cords in move:
|
||||
square = self.data_coordinates[cords[0], cords[1]]
|
||||
pydirectinput.moveTo(get_click_point(square)[0] + offset_left, get_click_point(square)[1] + offset_down)
|
||||
cv.waitKey(50)
|
||||
if first:
|
||||
pydirectinput.mouseDown()
|
||||
cv.waitKey(100)
|
||||
first = False
|
||||
pydirectinput.mouseUp()
|
||||
cv.waitKey(50)
|
||||
|
||||
def get_directions_array(self, current_x, current_y):
|
||||
left_x = current_x
|
||||
@@ -322,19 +411,14 @@ class Field:
|
||||
upper_right_x = current_x - 1
|
||||
upper_right_y = current_y + 1
|
||||
|
||||
directions = []
|
||||
directions.append([left_x, left_y])
|
||||
directions.append([lower_left_x, lower_left_y])
|
||||
directions.append([lower_x, lower_y])
|
||||
directions.append([lower_right_x, lower_right_y])
|
||||
directions.append([right_x, right_y])
|
||||
directions.append([upper_right_x, upper_right_y])
|
||||
directions.append([upper_x, upper_y])
|
||||
directions.append([upper_left_x, upper_left_y])
|
||||
directions = [[left_x, left_y], [lower_left_x, lower_left_y], [lower_x, lower_y],
|
||||
[lower_right_x, lower_right_y], [right_x, right_y], [upper_right_x, upper_right_y],
|
||||
[upper_x, upper_y], [upper_left_x, upper_left_y]]
|
||||
|
||||
return directions
|
||||
|
||||
def find_next_same_color_all_directions_recursion(self, state, current_x, current_y, path_store, recursion_reminder, look_for_ending):
|
||||
def find_next_same_color_all_directions_recursion(self, state, current_x, current_y, path_store, recursion_reminder,
|
||||
look_for_ending):
|
||||
directions = self.get_directions_array(current_x, current_y)
|
||||
color = state[current_x, current_y]
|
||||
|
||||
@@ -342,7 +426,9 @@ class Field:
|
||||
if self.is_direction_in_bounce_and_same_color(state, direction, color) == 1:
|
||||
if (self.data_score_map[direction[0], direction[1]] >= 2) and (direction not in recursion_reminder):
|
||||
recursion_reminder.append(direction)
|
||||
result = self.find_next_same_color_all_directions_recursion(state, direction[0], direction[1], path_store , recursion_reminder, look_for_ending)
|
||||
result = self.find_next_same_color_all_directions_recursion(state, direction[0], direction[1],
|
||||
path_store, recursion_reminder,
|
||||
look_for_ending)
|
||||
if result == STATUS_FOUND_CONTINUATION:
|
||||
path_store.append(direction)
|
||||
return STATUS_FOUND_CONTINUATION
|
||||
@@ -359,7 +445,7 @@ class Field:
|
||||
if look_for_ending:
|
||||
for direction in directions:
|
||||
if direction == path_store[0]:
|
||||
#path_store.append(direction)
|
||||
# path_store.append(direction)
|
||||
return STATUS_FOUND_ENDING
|
||||
|
||||
return STATUS_FOUND_DEADEND
|
||||
@@ -372,59 +458,26 @@ class Field:
|
||||
if self.is_direction_in_bounce_and_same_color(state, direction, color) == 1:
|
||||
if (self.data_score_map[direction[0], direction[1]] >= 1) and (direction not in path_store):
|
||||
path_store.append(direction)
|
||||
result = self.find_next_same_color_all_directions_recursion2(state, direction[0], direction[1], path_store)
|
||||
result = self.find_next_same_color_all_directions_recursion2(state, direction[0], direction[1],
|
||||
path_store)
|
||||
|
||||
if result == STATUS_FOUND_DEADEND:
|
||||
return STATUS_FOUND_DEADEND
|
||||
|
||||
return STATUS_FOUND_DEADEND
|
||||
|
||||
|
||||
def score_for_attached_same_color_all_directions(self, state, current_x, current_y):
|
||||
left_x = current_x - 1
|
||||
left_y = current_y
|
||||
|
||||
right_x = current_x + 1
|
||||
right_y = current_y
|
||||
|
||||
upper_x = current_x
|
||||
upper_y = current_y - 1
|
||||
|
||||
lower_x = current_x
|
||||
lower_y = current_y + 1
|
||||
|
||||
lower_left_x = current_x + 1
|
||||
lower_left_y = current_y - 1
|
||||
|
||||
lower_right_x = current_x + 1
|
||||
lower_right_y = current_y + 1
|
||||
|
||||
upper_left_x = current_x - 1
|
||||
upper_left_y = current_y - 1
|
||||
|
||||
upper_right_x = current_x - 1
|
||||
upper_right_y = current_y + 1
|
||||
|
||||
directions = []
|
||||
directions.append([left_x, left_y])
|
||||
directions.append([right_x, right_y])
|
||||
directions.append([lower_x, lower_y])
|
||||
directions.append([upper_x, upper_y])
|
||||
directions.append([lower_left_x, lower_left_y])
|
||||
directions.append([lower_right_x, lower_right_y])
|
||||
directions.append([upper_left_x, upper_left_y])
|
||||
directions.append([upper_right_x, upper_right_y])
|
||||
directions = self.get_directions_array(current_x, current_y)
|
||||
|
||||
score = 0
|
||||
color = state[current_x, current_y]
|
||||
if color == 0:
|
||||
if color not in self.colors:
|
||||
return score
|
||||
for direction in directions:
|
||||
score = score + self.is_direction_in_bounce_and_same_color(state, direction, color)
|
||||
|
||||
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:
|
||||
@@ -448,198 +501,6 @@ class Field:
|
||||
continue
|
||||
return False
|
||||
|
||||
def check_5_horizontal(self, state, e, i, color):
|
||||
try:
|
||||
#
|
||||
if state[e, i] == color and state[e, i + 1] == color and state[e, i + 3] == color and state[
|
||||
e, i + 4] == color:
|
||||
if state[e, i + 2] <= 0 or state[e, i + 2] >= 6:
|
||||
return False
|
||||
#
|
||||
if e - 1 >= 0 and i + 2 <= 13:
|
||||
if state[e - 1, i + 2] == color:
|
||||
return True
|
||||
return False
|
||||
except:
|
||||
return False
|
||||
|
||||
def check_5_vertical(self, state, e, i, color):
|
||||
try:
|
||||
#
|
||||
if state[e, i] == color and state[e + 1, i] == color and state[e + 3, i] == color and state[
|
||||
e + 4, i] == color:
|
||||
if state[e + 2, i] <= 0 or state[e + 2, i] >= 6:
|
||||
return False
|
||||
# third left upper
|
||||
if e + 2 <= 7 and i - 1 >= 0:
|
||||
if state[e + 2, i - 1] == color:
|
||||
print("upper left", color, e, i)
|
||||
src_pt = self.get_click_point(self.data_coordinates[e + 2, i - 1])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e + 2, i])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
if e + 2 <= 7 and i + 1 <= 13:
|
||||
if state[e + 2, i + 1] == color:
|
||||
print("upper left", color, e, i)
|
||||
src_pt = self.get_click_point(self.data_coordinates[e + 2, i + 1])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e + 2, i])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
return False
|
||||
except:
|
||||
return False
|
||||
|
||||
def check_3_with_gap(self, state, e, i, color):
|
||||
try:
|
||||
# second color next to starting point
|
||||
if i + 2 <= 13:
|
||||
if state[e, i] == color and state[e, i + 2] == color:
|
||||
# third upper
|
||||
if e - 1 >= 0 and i + 1 <= 13:
|
||||
# if state[e - 1, i - 1] == color and (state[e, i - 1] >= 1 and state[e, i - 1] <= 5):
|
||||
if state[e - 1, i + 1] == color and (state[e, i + 1] in self.colors):
|
||||
src_pt = self.get_click_point(self.data_coordinates[e - 1, i + 1])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e, i + 1])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
# third left lower
|
||||
if e + 1 <= 7 and i + 1 <= 13:
|
||||
if state[e + 1, i + 1] == color and (state[e, i + 1] in self.colors):
|
||||
src_pt = self.get_click_point(self.data_coordinates[e + 1, i + 1])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e, i + 1])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
if e + 2 <= 7:
|
||||
if state[e, i] == color and state[e + 2, i] == color:
|
||||
# third upper
|
||||
if e + 1 >= 0 and i + 1 <= 13:
|
||||
# if state[e - 1, i - 1] == color and (state[e, i - 1] >= 1 and state[e, i - 1] <= 5):
|
||||
if state[e + 1, i + 1] == color and (state[e + 1, i] in self.colors):
|
||||
src_pt = self.get_click_point(self.data_coordinates[e + 1, i + 1])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e + 1, i])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
# third left lower
|
||||
if e + 1 <= 7 and i - 1 >= 0:
|
||||
if state[e + 1, i - 1] == color and (state[e + 1, i] in self.colors):
|
||||
src_pt = self.get_click_point(self.data_coordinates[e + 1, i - 1])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e + 1, i])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def check_3_horizontal(self, state, e, i, color):
|
||||
try:
|
||||
# second color next to starting point
|
||||
if state[e, i] == color and state[e, i + 1] == color:
|
||||
# third left upper
|
||||
if e - 1 >= 0 and i - 1 >= 0:
|
||||
if state[e - 1, i - 1] == color and (state[e, i - 1] in self.colors):
|
||||
print("upper left", color, e, i)
|
||||
src_pt = self.get_click_point(self.data_coordinates[e - 1, i - 1])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e, i - 1])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
# third left lower
|
||||
if e + 1 <= 7 and i - 1 >= 0:
|
||||
if state[e + 1, i - 1] == color and (state[e, i - 1] in self.colors):
|
||||
print("lower left", color, e, i)
|
||||
src_pt = self.get_click_point(self.data_coordinates[e + 1, i - 1])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e, i - 1])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
# third left with gap
|
||||
if i - 2 >= 0:
|
||||
if state[e, i - 2] == color and (state[e, i - 1] in self.colors):
|
||||
print("left gap ", color, e, i)
|
||||
src_pt = self.get_click_point(self.data_coordinates[e, i - 2])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e, i - 1])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
# third right upper
|
||||
if e - 1 >= 0 and i + 2 <= 13:
|
||||
if state[e - 1, i + 2] == color and (state[e, i + 2] in self.colors):
|
||||
print("upper right", color, e, i)
|
||||
src_pt = self.get_click_point(self.data_coordinates[e - 1, i + 2])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e, i + 2])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
# third right lower
|
||||
if e + 1 <= 7 and i + 2 <= 13:
|
||||
if state[e + 1, i + 2] == color and (state[e, i + 2] in self.colors):
|
||||
print("upper lower", color, e, i)
|
||||
src_pt = self.get_click_point(self.data_coordinates[e + 1, i + 2])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e, i + 2])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
|
||||
# third right with gap
|
||||
if i + 3 <= 13:
|
||||
if state[e, i + 3] == color and (state[e, i + 2] in self.colors):
|
||||
print("right gap ", color, e, i)
|
||||
src_pt = self.get_click_point(self.data_coordinates[e, i + 3])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e, i + 2])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def check_3_vertical(self, state, e, i, color):
|
||||
try:
|
||||
# second color next to starting point o
|
||||
if state[e, i] == color and state[e + 1, i] == color:
|
||||
# third left upper
|
||||
if e - 1 >= 0 and i - 1 >= 0:
|
||||
if state[e - 1, i - 1] == color and (state[e - 1, i] in self.colors):
|
||||
print("upper left", color, e, i)
|
||||
src_pt = self.get_click_point(self.data_coordinates[e - 1, i - 1])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e - 1, i])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
# third left lower
|
||||
if e + 2 <= 7 and i - 1 >= 0:
|
||||
if state[e + 2, i - 1] == color and (state[e + 2, i] in self.colors):
|
||||
print("lower left", color, e, i)
|
||||
src_pt = self.get_click_point(self.data_coordinates[e + 2, i - 1])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e + 2, i])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
# third right upper
|
||||
if e - 1 >= 0 and i + 1 <= 13:
|
||||
if state[e - 1, i + 1] == color and (state[e - 1, i] in self.colors):
|
||||
print("upper right", color, e, i)
|
||||
src_pt = self.get_click_point(self.data_coordinates[e - 1, i + 1])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e - 1, i])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
# third right lower
|
||||
if e + 2 <= 7 and i + 1 <= 13:
|
||||
if state[e + 2, i + 1] == color and (state[e + 2, i] in self.colors):
|
||||
print("upper lower", color, e, i)
|
||||
src_pt = self.get_click_point(self.data_coordinates[e + 2, i + 1])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e + 2, i])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
# third upper with gap
|
||||
if e - 2 >= 0:
|
||||
if state[e - 2, i] == color and (state[e - 1, i] in self.colors):
|
||||
print("upper gap ", color, e, i)
|
||||
src_pt = self.get_click_point(self.data_coordinates[e - 2, i])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e - 1, i])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
# third lower with gap
|
||||
if e + 3 <= 7:
|
||||
if state[e + 3, i] == color and (state[e + 2, i] in self.colors):
|
||||
print("lower gap ", color, e, i)
|
||||
src_pt = self.get_click_point(self.data_coordinates[e + 3, i])
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e + 2, i])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def move_tile(self, point_source, point_dest):
|
||||
offset_left = 230
|
||||
offset_down = 58
|
||||
|
||||
BIN
crop/arrow_down.jpg
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
crop/arrow_right.jpg
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
crop/artisent.jpg
Normal file
|
After Width: | Height: | Size: 8.7 KiB |
BIN
crop/bigbomb.jpg
Normal file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
crop/bomb.jpg
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
crop/chemtrant.jpg
Normal file
|
After Width: | Height: | Size: 7.8 KiB |
BIN
crop/cibutrant.jpg
Normal file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
crop/hsh_base.jpg
Normal file
|
After Width: | Height: | Size: 1013 KiB |
BIN
crop/hsh_base_bigbomb.jpg
Normal file
|
After Width: | Height: | Size: 986 KiB |
BIN
crop/maginent.jpg
Normal file
|
After Width: | Height: | Size: 7.1 KiB |
@@ -15,8 +15,9 @@ def run():
|
||||
overlay.run_mode = 'init'
|
||||
continue
|
||||
elif overlay.run_mode == 'started':
|
||||
cv.waitKey(500)
|
||||
cv.waitKey(1000)
|
||||
elif overlay.run_mode == 'init':
|
||||
cv.waitKey(1)
|
||||
continue
|
||||
else:
|
||||
# boelk
|
||||
|
||||
BIN
crop/next_level.jpg
Normal file
|
After Width: | Height: | Size: 7.8 KiB |
BIN
crop/next_level_x.jpg
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
crop/rainbow.jpg
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
crop/reset_button.jpg
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
crop/reset_confirm.jpg
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
crop/reset_screen.jpg
Normal file
|
After Width: | Height: | Size: 761 KiB |
|
Before Width: | Height: | Size: 728 KiB After Width: | Height: | Size: 726 KiB |
|
Before Width: | Height: | Size: 715 KiB After Width: | Height: | Size: 597 KiB |
BIN
crop/tenesent.jpg
Normal file
|
After Width: | Height: | Size: 7.2 KiB |
@@ -131,7 +131,7 @@ def run():
|
||||
|
||||
while True:
|
||||
if overlay.run_mode == 'paused':
|
||||
# cv.waitKey(500)
|
||||
cv.waitKey(1)
|
||||
if (time() - loop_time_p) >= 5:
|
||||
loop_time_p = time()
|
||||
print("pausing")
|
||||
|
||||
@@ -15,8 +15,9 @@ def run():
|
||||
overlay.run_mode = 'init'
|
||||
continue
|
||||
elif overlay.run_mode == 'started':
|
||||
cv.waitKey(500)
|
||||
cv.waitKey(1000)
|
||||
elif overlay.run_mode == 'init':
|
||||
cv.waitKey(1)
|
||||
continue
|
||||
else:
|
||||
# boelk
|
||||
|
||||