added reset trigger to farm

This commit is contained in:
2022-10-15 21:20:00 +02:00
parent 45451cb185
commit 577aab928a
3 changed files with 31 additions and 2 deletions

View File

@@ -35,6 +35,10 @@ class Field:
data_coordinates = []
next_level = cv.imread("next_level.jpg", cv.IMREAD_COLOR)
next_level_x = cv.imread("next_level_x.jpg", cv.IMREAD_COLOR)
reset_board = cv.imread("reset_button.jpg", cv.IMREAD_COLOR)
reset_confirm = cv.imread("reset_confirm.jpg", cv.IMREAD_COLOR)
reset_counter = 0
explosives = []
explosives.append(RAINBOW)
explosives.append(ARROW_RIGHT)
@@ -108,13 +112,38 @@ 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.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)
self.reset_counter = 0
return
else:
return
self.find_patterns_and_valid_moves(new_observation)
self.observation = 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])

BIN
farm/reset_button.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
farm/reset_confirm.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB