added fruit game support
This commit is contained in:
23
fruit.py
23
fruit.py
@@ -20,6 +20,9 @@ class Fruit(GameBase):
|
|||||||
|
|
||||||
self.colors = [GREEN, YELLOW, RED, BLUE, ORANGE]
|
self.colors = [GREEN, YELLOW, RED, BLUE, ORANGE]
|
||||||
|
|
||||||
|
self.offset_left = 553
|
||||||
|
self.offset_down = 188
|
||||||
|
|
||||||
self.fill_data_coordinates()
|
self.fill_data_coordinates()
|
||||||
|
|
||||||
self.needles = {GREEN: cv.imread("fruit/green.jpg", cv.IMREAD_COLOR),
|
self.needles = {GREEN: cv.imread("fruit/green.jpg", cv.IMREAD_COLOR),
|
||||||
@@ -30,9 +33,9 @@ class Fruit(GameBase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def fill_data_coordinates(self):
|
def fill_data_coordinates(self):
|
||||||
# 540 to 1870 = 1330 / 11 = 121
|
# 553 to 1861 = 1330 / 11 = 119
|
||||||
# 180 to 1030 = 1076 / 8 = 121.4
|
# 188 to 1022 = 1076 / 7 = 119
|
||||||
dim = 121.2
|
dim = 119
|
||||||
for e in range(0, 7, 1):
|
for e in range(0, 7, 1):
|
||||||
for i in range(0, 11, 1):
|
for i in range(0, 11, 1):
|
||||||
self.data_coordinates[e][i] = [i * dim, e * dim, dim, dim]
|
self.data_coordinates[e][i] = [i * dim, e * dim, dim, dim]
|
||||||
@@ -71,16 +74,18 @@ class Fruit(GameBase):
|
|||||||
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()
|
||||||
screenshot = screenshot[900:1100, 1100:1450]
|
#screenshot = screenshot[900:1030, 540:1870]
|
||||||
# screenshot = cv.imread("field_farm.jpg")
|
# screenshot = cv.imread("field_farm.jpg")
|
||||||
|
|
||||||
# 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]
|
||||||
if self.check_for_button_and_execute(screenshot, self.ok_button, 900, 1100):
|
if self.check_for_button_and_execute(screenshot, self.ok_button):
|
||||||
cv.waitKey(500)
|
cv.waitKey(500)
|
||||||
|
|
||||||
screenshot = self.capture_window.get_screenshot()
|
screenshot = self.capture_window.get_screenshot()
|
||||||
screenshot = screenshot[180:1030, 540:1870]
|
screenshot = screenshot[188:1022, 553:1861]
|
||||||
|
# 553 to 1861 = 1330 / 11 = 119
|
||||||
|
# 188 to 1022
|
||||||
# cv.imshow("screenshot", screenshot)
|
# cv.imshow("screenshot", screenshot)
|
||||||
# cv.waitKey(150)
|
# cv.waitKey(150)
|
||||||
# continue
|
# continue
|
||||||
@@ -133,15 +138,13 @@ class Fruit(GameBase):
|
|||||||
def check_pairs(self, state, e, i, color):
|
def check_pairs(self, state, e, i, color):
|
||||||
try:
|
try:
|
||||||
#
|
#
|
||||||
offset_left = 540
|
|
||||||
offset_down = 180
|
|
||||||
if state[e, i] == color and state[e + 1, i] == color:
|
if state[e, i] == color and state[e + 1, i] == color:
|
||||||
click_pt = self.get_click_point(self.data_coordinates[e, i])
|
click_pt = self.get_click_point(self.data_coordinates[e, i])
|
||||||
self.dig_point(click_pt[0] + offset_left, click_pt[1] + offset_down, 100)
|
self.dig_point(click_pt[0] + self.offset_left, click_pt[1] + self.offset_down, 100)
|
||||||
return True
|
return True
|
||||||
elif state[e, i] == color and state[e, i + 1] == color:
|
elif state[e, i] == color and state[e, i + 1] == color:
|
||||||
click_pt = self.get_click_point(self.data_coordinates[e, i])
|
click_pt = self.get_click_point(self.data_coordinates[e, i])
|
||||||
self.dig_point(click_pt[0] + offset_left, click_pt[1] + offset_down, 100)
|
self.dig_point(click_pt[0] + self.offset_left, click_pt[1] + self.offset_down, 100)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
except:
|
except:
|
||||||
|
|||||||
Reference in New Issue
Block a user