fixed numerous bugs

This commit is contained in:
2022-10-13 17:50:13 +02:00
parent 9bc892cc75
commit 0e2c2d5318

View File

@@ -38,6 +38,7 @@ STATUS_FOUND_ENDING = "3"
class Field:
data_value_grid = []
data_coordinates = []
screenshot = []
next_level = cv.imread("next_level.jpg", cv.IMREAD_COLOR)
next_level_x = cv.imread("next_level_x.jpg", cv.IMREAD_COLOR)
explosives = []
@@ -162,6 +163,7 @@ class Field:
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]
'''
@@ -203,14 +205,14 @@ class Field:
# cv.imshow("output_image", output_image)
# cv.waitKey(150)
#score_map = np.zeros((8, 14), dtype=object)
#for x in range(0, 8, 1):
# for y in range(0, 14, 1):
# score_map[x, y] = self.score_for_attached_same_color_all_directions(data_coords, x, y)
# cv.putText(screenshot, str(score_map[x, y]),
# self.get_click_point(self.data_coordinates[x, y]), cv.FONT_HERSHEY_SIMPLEX,
# 1, (0, 0, 0), 3, 2)
#cv.imwrite('screenshot_scored.jpg', screenshot)
score_map = np.zeros((8, 14), dtype=object)
for x in range(0, 8, 1):
for y in range(0, 14, 1):
score_map[x, y] = self.score_for_attached_same_color_all_directions(data_coords, x, y)
cv.putText(screenshot, str(score_map[x, y]),
self.get_click_point(self.data_coordinates[x, y]), cv.FONT_HERSHEY_SIMPLEX,
1, (0, 0, 0), 3, 2)
cv.imwrite('screenshot_scored.jpg', 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)
if result == STATUS_FOUND_ENDING:
path_option.append([x, y])
if len(path_option) >= 5:
full_moves.append(path_option)
if self.data_score_map[x, y] >= 3:
if self.data_score_map[x, y] >= 1:
path_option = []
path_option.append([x, y])
recursion_reminder = []
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:
reserve_moves.append(path_option)
#print(self.data_score_map)
@@ -250,27 +253,33 @@ class Field:
full_moves.sort(key=len, reverse=True)
reserve_moves.sort(key=len, reverse=True)
'''
for move in full_moves:
'''
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
def print_move(self, moves):
mp = []
for point in move:
for point in moves[0]:
cp = self.get_click_point(self.data_coordinates[point[0], point[1]])
mp.append(cp)
cv.polylines(screenshot,
cv.polylines(self.screenshot,
[np.array(mp)],
isClosed=False,
color=(0, 255, 0),
thickness=3)
cv.imwrite('screenshot_pathed.jpg', screenshot)
'''
if len(full_moves) >= 1:
self.execute_move(full_moves)
elif len(reserve_moves) >= 1:
self.execute_move(reserve_moves)
else:
# boelk
pass
cv.imwrite('screenshot_pathed.jpg', self.screenshot)
def execute_move(self, moves):
offset_left = 230
@@ -355,6 +364,21 @@ class Field:
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):
left_x = current_x - 1