def blocked_via_right_wall_shot(self, bubble): starting_point_left = Point(209, 413) starting_point_right = Point(234, 413) bubble_x_offset = 24 if is_odd(bubble[1][0]) else 12 # bubble_x_offset = 0 bubble_middle = Point(17 + 24 * bubble[1][1] + bubble_x_offset - 12, bubble[1][0] * 24 + 18 + 25) bubble_left = Point(bubble_middle.x - 12, bubble_middle.y) bubble_right = Point(bubble_middle.x + 12, bubble_middle.y) for offset in xrange(-4, 4, 4): line_left = Line(starting_point_left.x + offset, starting_point_left.y, bubble_left.x, bubble_left.y) line_right = Line(starting_point_right.x + offset, starting_point_right.y, bubble_right.x, bubble_right.y) first = self.check_if_line_is_clear_right(line_left) second = self.check_if_line_is_clear_right(line_right) if not first and not second: bubble[0].shoot_location = Point(first[0], first[1]) print "RIGHT shoot at color:{} count:{} location:{},{} x:{} y:{}".format(bubble[0].bubble_data, bubble[0].neighbors_count, bubble[1][1], bubble[1][0], bubble[0].shoot_location.x, bubble[0].shoot_location.y) return False return True
def read_board_from_screen(self): self.screen.read_screenshot() height_index = 0 for height in xrange(self.x1, self.x1 + COLUMN * TILE_SIZE[0], TILE_SIZE[0]): width_index = 0 for width in xrange(self.y1, self.y1 + ROW * TILE_SIZE[1], TILE_SIZE[1]): if is_odd(height_index): width += ODD_TILE_SPACR single_tile_from_screen = self.screen.image[height:height + TILE_SIZE[0], width:width+ TILE_SIZE[1]] if self._debug: cv2.imwrite("all_images/im{}.png".format(width_index + COLUMN * height_index), single_tile_from_screen) self.board[height_index][width_index].bubble_data = color_from_image(single_tile_from_screen) width_index += 1 height_index += 1
def get_x_y_for_shot(self): current_color = self.get_current_color() reachable_bubbles = self.get_all_tiles_next_to_empty() reachable_bubbles = self.get_only_my_colors(reachable_bubbles, current_color) reachable_bubbles, reachable_wall_shot = self.remove_blocked_bubbles(reachable_bubbles) highest_neighbor = [Tile('empty', 0), self.last_shot] for array in reachable_bubbles: if highest_neighbor[0].neighbors_count == 0: highest_neighbor = array continue if array[0].neighbors_count > highest_neighbor[0].neighbors_count: highest_neighbor = array self.last_shot = highest_neighbor[1] if highest_neighbor in reachable_wall_shot: pass if highest_neighbor[0].shoot_location: return 316 + highest_neighbor[0].shoot_location.x, 280 + highest_neighbor[0].shoot_location.y offset = 12 if is_odd(highest_neighbor[1][0]) else 0 return 316 + 17 + 24*highest_neighbor[1][1] + offset, 280 + highest_neighbor[1][0]*24 + 20