added color preference to crop bot
@@ -43,10 +43,10 @@ class Field:
|
||||
next_level_x = cv.imread("next_level_x.jpg", cv.IMREAD_COLOR)
|
||||
explosives = []
|
||||
explosives.append(RAINBOW)
|
||||
explosives.append(ARROW_RIGHT)
|
||||
explosives.append(ARROW_DOWN)
|
||||
explosives.append(BIGBOMB)
|
||||
explosives.append(BOMB)
|
||||
#explosives.append(ARROW_RIGHT)
|
||||
#explosives.append(ARROW_DOWN)
|
||||
#explosives.append(BIGBOMB)
|
||||
#explosives.append(BOMB)
|
||||
colors = []
|
||||
colors.append(GREEN)
|
||||
colors.append(YELLOW)
|
||||
@@ -85,13 +85,13 @@ class Field:
|
||||
YELLOW: cv.imread("yellow.jpg", cv.IMREAD_COLOR),
|
||||
PURPLE: cv.imread("purple.jpg", cv.IMREAD_COLOR),
|
||||
BLUE: cv.imread("blue.jpg", cv.IMREAD_COLOR),
|
||||
RED: cv.imread("red.jpg", cv.IMREAD_COLOR)
|
||||
RED: cv.imread("red.jpg", cv.IMREAD_COLOR),
|
||||
|
||||
# RAINBOW: cv.imread("rainbow.jpg", cv.IMREAD_COLOR),
|
||||
# BIGBOMB: cv.imread("bigbomb.jpg", cv.IMREAD_COLOR),
|
||||
# BOMB: cv.imread("bomb.jpg", cv.IMREAD_COLOR),
|
||||
# ARROW_DOWN: cv.imread("arrow_down.jpg", cv.IMREAD_COLOR),
|
||||
# ARROW_RIGHT: cv.imread("arrow_right.jpg", cv.IMREAD_COLOR),
|
||||
RAINBOW: cv.imread("rainbow.jpg", cv.IMREAD_COLOR),
|
||||
#BIGBOMB: cv.imread("bigbomb.jpg", cv.IMREAD_COLOR),
|
||||
#BOMB: cv.imread("bomb.jpg", cv.IMREAD_COLOR),
|
||||
#ARROW_DOWN: cv.imread("arrow_down.jpg", cv.IMREAD_COLOR),
|
||||
#ARROW_RIGHT: cv.imread("arrow_right.jpg", cv.IMREAD_COLOR)
|
||||
# ROCK_1: cv.imread("rock1.jpg", cv.IMREAD_COLOR),
|
||||
# ROCK_2: cv.imread("rock2.jpg", cv.IMREAD_COLOR),
|
||||
# ROCK_3: cv.imread("rock3.jpg", cv.IMREAD_COLOR),
|
||||
@@ -166,7 +166,7 @@ class Field:
|
||||
self.screenshot = screenshot
|
||||
# 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()
|
||||
@@ -175,7 +175,7 @@ class Field:
|
||||
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")
|
||||
@@ -216,6 +216,51 @@ class Field:
|
||||
|
||||
return data_coords, screenshot
|
||||
|
||||
def detonate_explosive_when_stuck(self, state):
|
||||
for e in range(0, 8, 1):
|
||||
for i in range(0, 14, 1):
|
||||
for explosive in self.explosives:
|
||||
if self.local_pos_check(state, e, i, 0, 0, explosive):
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e, i])
|
||||
if self.local_pos_checks(state, e, i, 1, 0, self.colors):
|
||||
src_pt = self.get_click_point(self.data_coordinates[e + 1, i])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
elif self.local_pos_checks(state, e, i, 0, 1, self.colors):
|
||||
src_pt = self.get_click_point(self.data_coordinates[e, i + 1])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
elif self.local_pos_checks(state, e, i, -1, 0, self.colors):
|
||||
src_pt = self.get_click_point(self.data_coordinates[e - 1, i])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
elif self.local_pos_checks(state, e, i, 0, -1, self.colors):
|
||||
src_pt = self.get_click_point(self.data_coordinates[e, i - 1])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
else:
|
||||
continue
|
||||
return
|
||||
|
||||
def check_explosives(self, state, e, i):
|
||||
for explosive in self.explosives:
|
||||
if self.local_pos_check(state, e, i, 0, 0, explosive):
|
||||
dest_pt = self.get_click_point(self.data_coordinates[e, i])
|
||||
if self.local_pos_checks(state, e, i, 1, 0, self.explosives):
|
||||
src_pt = self.get_click_point(self.data_coordinates[e + 1, i])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
elif self.local_pos_checks(state, e, i, 0, 1, self.explosives):
|
||||
src_pt = self.get_click_point(self.data_coordinates[e, i + 1])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
elif self.local_pos_checks(state, e, i, -1, 0, self.explosives):
|
||||
src_pt = self.get_click_point(self.data_coordinates[e - 1, i])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
elif self.local_pos_checks(state, e, i, 0, -1, self.explosives):
|
||||
src_pt = self.get_click_point(self.data_coordinates[e, i - 1])
|
||||
self.move_tile(src_pt, dest_pt)
|
||||
else:
|
||||
continue
|
||||
return True
|
||||
else:
|
||||
continue
|
||||
return False
|
||||
|
||||
def find_patterns_and_valid_moves(self, state):
|
||||
|
||||
#score_map = np.zeros((8, 14), dtype=object)
|
||||
@@ -227,6 +272,8 @@ class Field:
|
||||
reserve_moves = []
|
||||
for x in range(0, 8, 1):
|
||||
for y in range(0, 14, 1):
|
||||
if self.check_explosives(state, x, y):
|
||||
return
|
||||
if self.data_score_map[x, y] >= 4:
|
||||
path_option = []
|
||||
path_option.append([x, y])
|
||||
@@ -236,7 +283,7 @@ class Field:
|
||||
if result == STATUS_FOUND_ENDING:
|
||||
path_option.append([x, y])
|
||||
if len(path_option) >= 5:
|
||||
full_moves.append(path_option)
|
||||
full_moves.append((state[x,y], path_option))
|
||||
if self.data_score_map[x, y] >= 1:
|
||||
path_option = []
|
||||
path_option.append([x, y])
|
||||
@@ -244,11 +291,12 @@ class Field:
|
||||
recursion_reminder.append([x, y])
|
||||
self.find_next_same_color_all_directions_recursion2(state, x, y, path_option)
|
||||
if len(path_option) >= 3:
|
||||
reserve_moves.append(path_option)
|
||||
reserve_moves.append((state[x,y], path_option))
|
||||
#print(self.data_score_map)
|
||||
|
||||
#screenshot = cv.imread("screenshot_scored.jpg")
|
||||
|
||||
full_dic = self.convert_moves_to_dic_by_color(full_moves)
|
||||
res_dic = self.convert_moves_to_dic_by_color(reserve_moves)
|
||||
|
||||
full_moves.sort(key=len, reverse=True)
|
||||
reserve_moves.sort(key=len, reverse=True)
|
||||
@@ -256,21 +304,33 @@ class Field:
|
||||
|
||||
'''
|
||||
|
||||
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
|
||||
if len(full_dic) >= 1:
|
||||
for key in sorted(full_dic):
|
||||
if len(full_dic[key]) >= 10:
|
||||
self.print_move(full_dic[key])
|
||||
self.execute_move(full_dic[key])
|
||||
break
|
||||
if len(reserve_moves) >= 1:
|
||||
for key in sorted(res_dic):
|
||||
self.print_move(res_dic[key])
|
||||
self.execute_move(res_dic[key])
|
||||
break
|
||||
|
||||
def print_move(self, moves):
|
||||
|
||||
def convert_moves_to_dic_by_color(self, reserve_moves):
|
||||
dic = {}
|
||||
for color, move in reserve_moves:
|
||||
if color in dic:
|
||||
if len(move) > len(dic[color]):
|
||||
dic[color] = move
|
||||
else:
|
||||
dic[color] = move
|
||||
return dic
|
||||
|
||||
|
||||
def print_move(self, move):
|
||||
mp = []
|
||||
for point in moves[0]:
|
||||
for point in move:
|
||||
cp = self.get_click_point(self.data_coordinates[point[0], point[1]])
|
||||
mp.append(cp)
|
||||
cv.polylines(self.screenshot,
|
||||
@@ -281,12 +341,12 @@ class Field:
|
||||
|
||||
cv.imwrite('screenshot_pathed.jpg', self.screenshot)
|
||||
|
||||
def execute_move(self, moves):
|
||||
def execute_move(self, move):
|
||||
offset_left = 230
|
||||
offset_down = 58
|
||||
if len(moves) >= 1:
|
||||
|
||||
first = True
|
||||
for cords in moves[0]:
|
||||
for cords in move:
|
||||
square = self.data_coordinates[cords[0], cords[1]]
|
||||
pydirectinput.moveTo(get_click_point(square)[0] + offset_left, get_click_point(square)[1]+offset_down)
|
||||
cv.waitKey(50)
|
||||
@@ -417,7 +477,7 @@ class Field:
|
||||
|
||||
score = 0
|
||||
color = state[current_x, current_y]
|
||||
if color == 0:
|
||||
if color <= 0 or color >= 6:
|
||||
return score
|
||||
for direction in directions:
|
||||
score = score + self.is_direction_in_bounce_and_same_color(state, direction, color)
|
||||
|
||||
BIN
crop/arrow_down.jpg
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
crop/arrow_right.jpg
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
crop/bigbomb.jpg
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
crop/bomb.jpg
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
crop/next_level.jpg
Normal file
|
After Width: | Height: | Size: 7.8 KiB |
BIN
crop/next_level_x.jpg
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
crop/rainbow.jpg
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 728 KiB After Width: | Height: | Size: 726 KiB |
|
Before Width: | Height: | Size: 715 KiB After Width: | Height: | Size: 597 KiB |