def solve(self, image, offset, sides_info, screenshot_helper, current_module_position): top_buttons, bottom_buttons = find_column_buttons(image) top_buttons = apply_offset_to_locations(top_buttons, offset) bottom_buttons = apply_offset_to_locations(bottom_buttons, offset) submit_button = apply_offset_to_single_location( find_submit_button(image), offset) letter_rows = [get_letters(image, self._letter_classifier)] for i in range(NUM_LETTERS_PER_COLUMN - 1): for button_x, button_y in bottom_buttons: click_pixels(MouseButton.left, button_x, button_y) post_click_delay() image, offset = screenshot_helper.get_current_module_screenshot_and_position( ) letter_rows.append(get_letters(image, self._letter_classifier)) button_rows = { UP: top_buttons, DOWN: bottom_buttons, } buttons_to_click = get_buttons_to_click_to_solve(letter_rows) for i, (direction, amount) in enumerate(buttons_to_click): button_x, button_y = button_rows[direction][i] for _ in range(amount): click_pixels(MouseButton.left, button_x, button_y) post_click_delay() click_pixels(MouseButton.left, submit_button[0], submit_button[1]) post_click_delay()
def solve(self, image, offset, sides_info, screenshot_helper, current_module_position): top_buttons, bottom_buttons = find_column_buttons(image) top_buttons = apply_offset_to_locations(top_buttons, offset) bottom_buttons = apply_offset_to_locations(bottom_buttons, offset) submit_button = apply_offset_to_single_location(find_submit_button(image), offset) letter_rows = [get_letters(image, self._letter_classifier)] for i in range(NUM_LETTERS_PER_COLUMN - 1): for button_x, button_y in bottom_buttons: click_pixels(MouseButton.left, button_x, button_y) post_click_delay() image, offset = screenshot_helper.get_current_module_screenshot_and_position() letter_rows.append(get_letters(image, self._letter_classifier)) button_rows = { UP: top_buttons, DOWN: bottom_buttons, } buttons_to_click = get_buttons_to_click_to_solve(letter_rows) for i, (direction, amount) in enumerate(buttons_to_click): button_x, button_y = button_rows[direction][i] for _ in range(amount): click_pixels(MouseButton.left, button_x, button_y) post_click_delay() click_pixels(MouseButton.left, submit_button[0], submit_button[1]) post_click_delay()
def solve(self, image, offset, sides_info, screenshot_helper, current_module_position): first_time = True for _ in range(NUM_TIMES_TO_SOLVE): if not first_time: # Wait for the screen to redraw. Takes surprisingly long time.sleep(4) first_time = False image, offset = screenshot_helper.get_current_module_screenshot_and_position() print "\n----- In game try %s -----" % self._debug_image cv2.imwrite(os.path.join(MODULE_SPECIFIC_DIR, "whos_on_first", "in_game_%i.png" % self._debug_image), image) screen_text = get_screen_content(image, self._tesseract, self._debug_image) buttons, positions = get_buttons_and_positions( image, self._button_classifier, self._debug_image) print screen_text print buttons print positions to_press = button_to_press(screen_text, buttons) print "Pressing", to_press x, y = apply_offset_to_locations(positions, offset)[to_press.value] click_pixels(MouseButton.left, x, y) post_click_delay() self._debug_image += 1
def solve(self, image, offset, sides_info, screenshot_helper, current_module_position): symbols, positions = get_symbols_and_positions(image, self._symbol_classifier) positions = apply_offset_to_locations(positions, offset) order = get_symbol_order(symbols) for idx in order: x, y = positions[idx] click_pixels(MouseButton.left, x, y) post_click_delay()
def solve(self, image, offset, sides_info, screenshot_helper, current_module_position): lookup_key, start_coordinates, end_coordinates = get_maze_params(image) top, right, bottom, left = apply_offset_to_locations( get_button_locations(image), offset) moves = find_path_through_maze(lookup_key, start_coordinates, end_coordinates) move_to_button = { UP: top, RIGHT: right, DOWN: bottom, LEFT: left, } for move in moves: x_raw, y_raw = move_to_button[move] click_pixels(MouseButton.left, x_raw, y_raw) post_click_delay()
def solve(self, image, offset, sides_info, screenshot_helper, current_module_position): state = MemoryState() first_time = True while not state.is_done(): if not first_time: time.sleep(4) first_time = False image, offset = screenshot_helper.get_current_module_screenshot_and_position() screen = get_screen(image, self.screen_classifier) buttons, button_locations = get_buttons_and_locations(image, self.button_classifier) idx_to_click = state.get_button_idx_to_click(screen, buttons) button_locations = apply_offset_to_locations(button_locations, offset) x, y = button_locations[idx_to_click] click_pixels(MouseButton.left, x, y) post_click_delay()
def solve(self, image, offset, sides_info, screenshot_helper, current_module_position): state = MemoryState() first_time = True while not state.is_done(): if not first_time: time.sleep(4) first_time = False image, offset = screenshot_helper.get_current_module_screenshot_and_position( ) screen = get_screen(image, self.screen_classifier) buttons, button_locations = get_buttons_and_locations( image, self.button_classifier) idx_to_click = state.get_button_idx_to_click(screen, buttons) button_locations = apply_offset_to_locations( button_locations, offset) x, y = button_locations[idx_to_click] click_pixels(MouseButton.left, x, y) post_click_delay()
def solve(self, image, offset, sides_info, screenshot_helper, current_module_position): state = MorseCodeState() arrow_locations = apply_offset_to_locations(find_arrows(image), offset) right_arrow_location = arrow_locations[1] tx_button_location = apply_offset_to_single_location(find_tx_button(image), offset) def get_light_state(): # We're very timing dependent, so we turn off the mouse movement (which introduces a # .2 second delay for each screenshot) and the bad light detection (which would # totally screw us up and isn't relevant because the morse code light looks the same # regardless of if the lights are on). We also supress the debug copy because we take # these so frequently, there end up being way too many (and saving the copy takes a # bit of time). return is_light_on(screenshot_helper.get_current_module_screenshot_and_position( allow_bad_lighting=True, suppress_debug_copy=True, suppress_mouse_movement=True)[0]) last_seen_light_state = get_light_state() last_seen_start_time = None while not state.is_word_known(): current_light_state = get_light_state() if current_light_state == last_seen_light_state: # Not sleeping because it takes long enough to grab and process a screenshot. # Busy waiting FTW! continue current_time = time.time() if last_seen_start_time is not None: duration = current_time - last_seen_start_time state.ingest_timing(duration, last_seen_light_state) last_seen_light_state = current_light_state last_seen_start_time = current_time num_time_to_press_right = state.get_num_time_to_press_right_arrow() for _ in xrange(num_time_to_press_right): click_pixels(MouseButton.left, right_arrow_location[0], right_arrow_location[1]) post_click_delay() click_pixels(MouseButton.left, tx_button_location[0], tx_button_location[1]) post_click_delay()