fixed instance bug with member variables

This commit is contained in:
2022-10-17 11:57:15 +02:00
parent 5aa2b59b37
commit 6941b2667a
3 changed files with 75 additions and 82 deletions

View File

@@ -41,19 +41,6 @@ ROCKET_STRATEGY = 7
BOMB_STRATEGY = 5
class Crops:
data_value_grid = []
data_coordinates = []
screenshot = []
next_level = cv.imread("crop/next_level.jpg", cv.IMREAD_COLOR)
next_level_x = cv.imread("crop/next_level_x.jpg", cv.IMREAD_COLOR)
reset_board = cv.imread("crop/reset_button.jpg", cv.IMREAD_COLOR)
reset_confirm = cv.imread("crop/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, overlay):
self.overlay = overlay
@@ -62,6 +49,18 @@ class Crops:
self.data_score_map = np.zeros((8, 14), dtype=int)
self.observation = np.zeros((8, 14), dtype=int)
self.screenshot = []
self.next_level = cv.imread("crop/next_level.jpg", cv.IMREAD_COLOR)
self.next_level_x = cv.imread("crop/next_level_x.jpg", cv.IMREAD_COLOR)
self.reset_board = cv.imread("crop/reset_button.jpg", cv.IMREAD_COLOR)
self.reset_confirm = cv.imread("crop/reset_confirm.jpg", cv.IMREAD_COLOR)
self.reset_counter = 0
self.colors_at_standard = True
self.needles = {}
self.hsh_needles = {}
self.explosives = [RAINBOW, ARROW_RIGHT, ARROW_DOWN, BIGBOMB, BOMB]
self.colors = [GREEN, YELLOW, RED, BLUE, PURPLE, MAGINENT, CHEMTRANT, TENESENT, CIBUTRANT, ARTISENT]
self.current_strategy = RAINBOW_STRATEGY
# 230 to 2110 = 1883 / 14 = 134.5

View File

@@ -22,16 +22,17 @@ HSV_DEFAULT = HsvFilter(0, 0, 0, 179, 255, 255, 0, 0, 0, 0)
class Equipment:
needles = []
hsvs = []
tresholds = []
masks = []
emitters = []
def __init__(self, overlay):
self.overlay = overlay
self.config = UserConfigs()
self.needles = []
self.hsvs = []
self.tresholds = []
self.masks = []
self.emitters = []
self.EMITTER_TO_USE = str(overlay.emitter_use.get())
self.SPAWN_COUNT = int(overlay.spawn_use.get())
self.ENERGY_TO_USE = int(overlay.energy_use.get())

121
farm.py
View File

@@ -31,32 +31,6 @@ ARTISENT = 25
class Farm:
data_value_grid = []
data_coordinates = []
next_level = cv.imread("farm/next_level.jpg", cv.IMREAD_COLOR)
next_level_x = cv.imread("farm/next_level_x.jpg", cv.IMREAD_COLOR)
reset_board = cv.imread("farm/reset_button.jpg", cv.IMREAD_COLOR)
reset_confirm = cv.imread("farm/reset_confirm.jpg", cv.IMREAD_COLOR)
reset_counter = 0
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(PINK)
colors.append(MAGINENT)
colors.append(CHEMTRANT)
colors.append(TENESENT)
colors.append(CIBUTRANT)
colors.append(ARTISENT)
def __init__(self, overlay):
self.overlay = overlay
@@ -64,6 +38,30 @@ class Farm:
self.data_coordinates = np.zeros((8, 14), dtype=object)
self.observation = np.zeros((8, 14), dtype=int)
self.next_level = cv.imread("farm/next_level.jpg", cv.IMREAD_COLOR)
self.next_level_x = cv.imread("farm/next_level_x.jpg", cv.IMREAD_COLOR)
self.reset_board = cv.imread("farm/reset_button.jpg", cv.IMREAD_COLOR)
self.reset_confirm = cv.imread("farm/reset_confirm.jpg", cv.IMREAD_COLOR)
self.reset_counter = 0
self.explosives = []
self.explosives.append(RAINBOW)
self.explosives.append(ARROW_RIGHT)
self.explosives.append(ARROW_DOWN)
self.explosives.append(BIGBOMB)
self.explosives.append(BOMB)
self.colors = []
self.colors.append(GREEN)
self.colors.append(YELLOW)
self.colors.append(BLUE)
self.colors.append(RED)
self.colors.append(PINK)
self.colors.append(MAGINENT)
self.colors.append(CHEMTRANT)
self.colors.append(TENESENT)
self.colors.append(CIBUTRANT)
self.colors.append(ARTISENT)
# 230 to 2110 = 1883 / 14 = 134.5
# 60 to 1130 = 1076 / 8 = 134.5
dim = 134.5
@@ -177,8 +175,8 @@ class Farm:
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
@@ -191,30 +189,25 @@ class Farm:
if self.detonate_explosive_when_stuck(self.observation):
return True
point = self.vision_stun.get_click_points(rectangles)[0]
self.dig_point(point[0]+ offset_left, point[1] + offset_down, 500)
self.dig_point(point[0] + offset_left, point[1] + offset_down, 500)
return True
def get_current_board_state(self):
try:
# get an updated image of the game
# get an updated image of the game
screenshot = self.capture_window.get_screenshot()
# screenshot = cv.imread("field_farm.jpg")
screenshot = screenshot[58:1134, 230:2113] # 1883,1076
# 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):
cv.waitKey(500)
screenshot = self.capture_window.get_screenshot()
#screenshot = cv.imread("field_farm.jpg")
screenshot = screenshot[58:1134, 230:2113] # 1883,1076
# 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):
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):
cv.waitKey(500)
screenshot = self.capture_window.get_screenshot()
screenshot = screenshot[58:1134, 230:2113]
screenshot = screenshot[58:1134, 230:2113]
if self.check_for_next_level(screenshot, self.next_level_x):
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")
return None
# cv.imshow("screenshot", screenshot)
# cv.waitKey(150)
# continue
@@ -330,14 +323,14 @@ class Farm:
return False
def local_pos_check(self, state, e, i, e_check, i_check, needle):
if e + e_check >= 0 and e + e_check <=7 and i + i_check >= 0 and i + i_check <=13:
if e + e_check >= 0 and e + e_check <= 7 and i + i_check >= 0 and i + i_check <= 13:
if state[e + e_check, i + i_check] == needle:
return True
else:
return False
def local_pos_checks(self, state, e, i, e_check, i_check, needles):
if e + e_check >= 0 and e + e_check <=7 and i + i_check >= 0 and i + i_check <=13:
if e + e_check >= 0 and e + e_check <= 7 and i + i_check >= 0 and i + i_check <= 13:
for needle in needles:
if state[e + e_check, i + i_check] == needle:
return True
@@ -370,14 +363,14 @@ class Farm:
# third left upper
if e + 2 <= 7 and i - 1 >= 0:
if state[e + 2, i - 1] == color:
#print("upper left", color, e, i)
# 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)
# 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)
@@ -393,7 +386,7 @@ class Farm:
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] >= 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])
@@ -410,7 +403,7 @@ class Farm:
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, 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])
@@ -433,7 +426,7 @@ class Farm:
# 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)
# 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)
@@ -441,7 +434,7 @@ class Farm:
# 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)
# 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)
@@ -449,7 +442,7 @@ class Farm:
# 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)
# 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)
@@ -457,7 +450,7 @@ class Farm:
# 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)
# 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)
@@ -465,7 +458,7 @@ class Farm:
# 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)
# 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)
@@ -474,7 +467,7 @@ class Farm:
# 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)
# 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)
@@ -489,7 +482,7 @@ class Farm:
# 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)
# 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)
@@ -505,7 +498,7 @@ class Farm:
# 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)
# 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)
@@ -513,7 +506,7 @@ class Farm:
# 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)
# 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)
@@ -521,7 +514,7 @@ class Farm:
# 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)
# 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)
@@ -529,7 +522,7 @@ class Farm:
# 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)
# 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)