Example #1
0
 def attack(self, button: "Box") -> Tuple[int, int]:
     """Click button, albeit 'skip', 'verify', or 'next'"""
     left = int(button.left + 0.2 * button.width)
     top = int(button.top + 0.2 * button.height)
     right = int(button.left + 0.8 * button.width)
     bottom = int(button.top + 0.8 * button.height)
     return human_click(left, top, right, bottom)
Example #2
0
 def refresh_puzzle(self, button: "Box") -> Tuple[int, int]:
     left = int(button.left) - 325 + int(
         (button.width + button.width % 2) / 2)
     top = int(button.top) - 10 + int(
         (button.height + button.height % 2) / 2)
     right = left + 20
     bottom = top + 20
     return human_click(left, top, right, bottom)
Example #3
0
    def run(self) -> None:
        print("\nEntered", self.__class__.__name__)

        print("Look for robot nazi...")
        starttime = time.time()
        while time.time() - starttime < 30:
            try:
                # Locate "I'm not a robot" button on-screen
                imnotarobot = locateOnScreen(os.path.join(
                    self.fullpath, "imnotarobot.png"),
                                             confidence=0.6)
                assert hasattr(imnotarobot, "left")
            except:
                pass
            else:
                # Click "I'm not a robot" button like a human
                left = int(imnotarobot.left + 0.20 * imnotarobot.width)
                top = int(imnotarobot.top + 0.20 * imnotarobot.height)
                right = int(imnotarobot.left + 0.75 * imnotarobot.width)
                bottom = int(imnotarobot.top + 0.80 * imnotarobot.height)
                clicked = human_click(left, top, right, bottom)  # type: ignore
                print(clicked, time.time())
                break
Example #4
0
    def select_things(
        self,
        things: List[Tuple[int, int, int, int]],
        grid: Tuple[str, int, int, int, int],
    ) -> None:
        """Click on all things, relative to button location.

        If grid parameter specified, click on all grid cells occupied by any things.

        INPUT
        -----
        cached_things : dict()
        """

        # Constant parameters
        puzzle_offset_y = 120
        click_margin_x = 5
        click_margin_y = 35

        # Check for whether nxn grid was identified
        if grid[0] == "4x4" or grid[0] == "3x3":

            # Constant parameters
            n, m = int(grid[0][0]), int(grid[0][2])
            grid_margin_x, grid_margin_y = self.grid_margins(n, m)
            cell_width, cell_height = self.cell_dimensions(
                grid[3], grid[4], grid_margin_x, grid_margin_y, n, m)

            # Grid exists. Iterate through cells in nxn grid and click it if occupied by an thing
            for cell in range(n * m):

                # Define cell as row & col no.
                row, col = self.nxm(n, m, cell)

                # Calculate cell region relative to puzzle coordinates
                cell_left = col * cell_width + grid_margin_x
                cell_top = row * cell_width + grid_margin_y
                cell_right = (col + 1) * cell_width + grid_margin_x
                cell_bottom = (row + 1) * cell_width + grid_margin_y

                # Determine whether cell region contains an thing
                for thing in things:

                    try:
                        # Check if a collision occurs
                        assert (
                            # Collision in x axis
                            self.is_collision(  # type: ignore
                                tuple([thing[0], thing[2]]),
                                tuple([cell_left, cell_right]),
                            )
                            # Collision in y axis
                            and self.is_collision(  # type: ignore
                                tuple([thing[1], thing[3]]),
                                tuple([cell_top, cell_bottom]),
                            ))

                    except:
                        # No collision here
                        pass

                    else:
                        # Click within cell region & proceed to next cell
                        left = grid[1] + cell_left + click_margin_x
                        top = grid[
                            2] + cell_top + puzzle_offset_y + click_margin_y
                        right = grid[1] + cell_right - click_margin_x
                        bottom = (grid[2] + cell_bottom + puzzle_offset_y -
                                  click_margin_y)

                        clicked = human_click(left, top, right, bottom)
                        print(clicked, time.time())
                        break

        # No grid specified. Click all things relative to button
        else:
            try:
                for thing in things:
                    left = thing[0] + grid[1] + int(0.2 *
                                                    (thing[2] - thing[0]))
                    top = (thing[1] + grid[2] +
                           int(0.2 * (thing[3] - thing[1])) + puzzle_offset_y)
                    right = thing[2] + grid[1] - int(0.2 *
                                                     (thing[2] - thing[0]))
                    bottom = (thing[3] + grid[2] - int(0.2 *
                                                       (thing[3] - thing[1])) +
                              puzzle_offset_y)

                    clicked = human_click(left, top, right, bottom)
                    print(clicked, time.time())
            except:
                pass