fixed numerous bugs
This commit is contained in:
@@ -38,6 +38,7 @@ STATUS_FOUND_ENDING = "3"
|
|||||||
class Field:
|
class Field:
|
||||||
data_value_grid = []
|
data_value_grid = []
|
||||||
data_coordinates = []
|
data_coordinates = []
|
||||||
|
screenshot = []
|
||||||
next_level = cv.imread("next_level.jpg", cv.IMREAD_COLOR)
|
next_level = cv.imread("next_level.jpg", cv.IMREAD_COLOR)
|
||||||
next_level_x = cv.imread("next_level_x.jpg", cv.IMREAD_COLOR)
|
next_level_x = cv.imread("next_level_x.jpg", cv.IMREAD_COLOR)
|
||||||
explosives = []
|
explosives = []
|
||||||
@@ -162,6 +163,7 @@ class Field:
|
|||||||
screenshot = self.capture_window.get_screenshot()
|
screenshot = self.capture_window.get_screenshot()
|
||||||
#screenshot = cv.imread("playfield.jpg")
|
#screenshot = cv.imread("playfield.jpg")
|
||||||
screenshot = screenshot[58:1134, 230:2113] # 1883,1076
|
screenshot = screenshot[58:1134, 230:2113] # 1883,1076
|
||||||
|
self.screenshot = screenshot
|
||||||
# gray = cv.cvtColor(screenshot, cv.COLOR_BGR2GRAY)
|
# gray = cv.cvtColor(screenshot, cv.COLOR_BGR2GRAY)
|
||||||
# thresh = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
# thresh = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
||||||
'''
|
'''
|
||||||
@@ -203,14 +205,14 @@ class Field:
|
|||||||
# cv.imshow("output_image", output_image)
|
# cv.imshow("output_image", output_image)
|
||||||
# cv.waitKey(150)
|
# cv.waitKey(150)
|
||||||
|
|
||||||
#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):
|
||||||
# score_map[x, y] = self.score_for_attached_same_color_all_directions(data_coords, x, y)
|
score_map[x, y] = self.score_for_attached_same_color_all_directions(data_coords, x, y)
|
||||||
# cv.putText(screenshot, str(score_map[x, y]),
|
cv.putText(screenshot, str(score_map[x, y]),
|
||||||
# self.get_click_point(self.data_coordinates[x, y]), cv.FONT_HERSHEY_SIMPLEX,
|
self.get_click_point(self.data_coordinates[x, y]), cv.FONT_HERSHEY_SIMPLEX,
|
||||||
# 1, (0, 0, 0), 3, 2)
|
1, (0, 0, 0), 3, 2)
|
||||||
#cv.imwrite('screenshot_scored.jpg', screenshot)
|
cv.imwrite('screenshot_scored.jpg', screenshot)
|
||||||
|
|
||||||
return data_coords, screenshot
|
return data_coords, screenshot
|
||||||
|
|
||||||
@@ -233,13 +235,14 @@ class Field:
|
|||||||
result = self.find_next_same_color_all_directions_recursion(state, x, y, path_option, recursion_reminder, True)
|
result = self.find_next_same_color_all_directions_recursion(state, x, y, path_option, recursion_reminder, True)
|
||||||
if result == STATUS_FOUND_ENDING:
|
if result == STATUS_FOUND_ENDING:
|
||||||
path_option.append([x, y])
|
path_option.append([x, y])
|
||||||
full_moves.append(path_option)
|
if len(path_option) >= 5:
|
||||||
if self.data_score_map[x, y] >= 3:
|
full_moves.append(path_option)
|
||||||
|
if self.data_score_map[x, y] >= 1:
|
||||||
path_option = []
|
path_option = []
|
||||||
path_option.append([x, y])
|
path_option.append([x, y])
|
||||||
recursion_reminder = []
|
recursion_reminder = []
|
||||||
recursion_reminder.append([x, y])
|
recursion_reminder.append([x, y])
|
||||||
self.find_next_same_color_all_directions_recursion(state, x, y, path_option, recursion_reminder, False)
|
self.find_next_same_color_all_directions_recursion2(state, x, y, path_option)
|
||||||
if len(path_option) >= 3:
|
if len(path_option) >= 3:
|
||||||
reserve_moves.append(path_option)
|
reserve_moves.append(path_option)
|
||||||
#print(self.data_score_map)
|
#print(self.data_score_map)
|
||||||
@@ -250,28 +253,34 @@ class Field:
|
|||||||
full_moves.sort(key=len, reverse=True)
|
full_moves.sort(key=len, reverse=True)
|
||||||
reserve_moves.sort(key=len, reverse=True)
|
reserve_moves.sort(key=len, reverse=True)
|
||||||
'''
|
'''
|
||||||
for move in full_moves:
|
|
||||||
mp = []
|
|
||||||
for point in move:
|
|
||||||
cp = self.get_click_point(self.data_coordinates[point[0], point[1]])
|
|
||||||
mp.append(cp)
|
|
||||||
cv.polylines(screenshot,
|
|
||||||
[np.array(mp)],
|
|
||||||
isClosed=False,
|
|
||||||
color=(0, 255, 0),
|
|
||||||
thickness=3)
|
|
||||||
|
|
||||||
cv.imwrite('screenshot_pathed.jpg', screenshot)
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
if len(full_moves) >= 1:
|
if len(full_moves) >= 1:
|
||||||
|
self.print_move(full_moves)
|
||||||
self.execute_move(full_moves)
|
self.execute_move(full_moves)
|
||||||
elif len(reserve_moves) >= 1:
|
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)
|
self.execute_move(reserve_moves)
|
||||||
else:
|
else:
|
||||||
# boelk
|
# boelk
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def print_move(self, moves):
|
||||||
|
mp = []
|
||||||
|
for point in moves[0]:
|
||||||
|
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)
|
||||||
|
|
||||||
|
cv.imwrite('screenshot_pathed.jpg', self.screenshot)
|
||||||
|
|
||||||
def execute_move(self, moves):
|
def execute_move(self, moves):
|
||||||
offset_left = 230
|
offset_left = 230
|
||||||
offset_down = 58
|
offset_down = 58
|
||||||
@@ -355,6 +364,21 @@ class Field:
|
|||||||
|
|
||||||
return STATUS_FOUND_DEADEND
|
return STATUS_FOUND_DEADEND
|
||||||
|
|
||||||
|
def find_next_same_color_all_directions_recursion2(self, state, current_x, current_y, path_store):
|
||||||
|
directions = self.get_directions_array(current_x, current_y)
|
||||||
|
color = state[current_x, current_y]
|
||||||
|
|
||||||
|
for direction in directions:
|
||||||
|
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)
|
||||||
|
|
||||||
|
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):
|
def score_for_attached_same_color_all_directions(self, state, current_x, current_y):
|
||||||
left_x = current_x - 1
|
left_x = current_x - 1
|
||||||
|
|||||||
Reference in New Issue
Block a user