Пример #1
0
 def __init__(self, probs, scene_directory):
     super(StupidMonkey, self).__init__(probs)
     self.scene_detector = SceneDetector(scene_directory)
     self.scene_touches = {}
     self.scene_rects = {}
Пример #2
0
 def __init__(self, probs, scene_directory):
     super(StupidMonkey, self).__init__(probs)
     self.scene_detector = SceneDetector(scene_directory)
     self.scene_touches = {}
     self.scene_rects = {}
Пример #3
0
class StupidMonkey(Monkey):
    '''find touchables through hard work'''

    movestep = 30  #pixels

    def __init__(self, probs, scene_directory):
        super(StupidMonkey, self).__init__(probs)
        self.scene_detector = SceneDetector(scene_directory)
        self.scene_touches = {}
        self.scene_rects = {}

    def get_current_scene(self):
        screen = self.device.screenshot_cv2()
        h, w = screen.shape[:2]
        img = cv2.resize(screen, (w / 2, h / 2))
        scene = self.scene_detector.detect(img)

        for rect in self.scene_rects.get(str(scene), {}).itervalues():
            l, t, r, b = rect
            cv2.rectangle(img, (l, t), (r, b), 255, 2)
        cv2.imshow('scene', img)
        cv2.waitKey(1)
        return scene

    def do_touch(self):
        # width, height = self.device.display
        width, height = 1080, 1920
        scene = self.get_current_scene()
        if scene is None:
            # fall back to random point
            x, y = randint(1, width), randint(1, height)
        else:
            pos = self.scene_touches.get(str(scene), 0)
            w, h = width / self.movestep, height / self.movestep  # grid points
            dy, dx = divmod(pos, w - 1)
            if dy >= h - 1:
                # TODO: return a random clickable point
                x, y = randint(1, width), randint(1, height)
            else:
                x, y = (dx + 1) * self.movestep, (dy + 1) * self.movestep
                self.scene_touches[str(scene)] = pos + 1

        self.last_touch_point = x, y
        self.device.touch(x, y)

        # watch what happend after touch
        if scene is None:
            return
        newscene = self.get_current_scene()
        if newscene is None or newscene == scene:
            return
        s1 = str(scene)
        s2 = str(newscene)
        if s1 not in self.scene_rects:
            self.scene_rects[s1] = {}
        if s2 not in self.scene_rects[s1]:
            self.scene_rects[s1][s2] = (x, y, x, y)
        else:
            l, t, r, b = self.scene_rects[s1][s2]
            l, r = min(l, x), max(r, x)
            t, b = min(t, y), max(t, y)
            self.scene_rects[s1][s2] = (l, t, r, b)

    def do_swipe(self):
        pass
Пример #4
0
class StupidMonkey(Monkey):
    '''find touchables through hard work'''

    movestep = 30 #pixels

    def __init__(self, probs, scene_directory):
        super(StupidMonkey, self).__init__(probs)
        self.scene_detector = SceneDetector(scene_directory)
        self.scene_touches = {}
        self.scene_rects = {}

    def get_current_scene(self):
        screen = self.device.screenshot_cv2()
        h, w = screen.shape[:2]
        img = cv2.resize(screen, (w/2, h/2))
        scene = self.scene_detector.detect(img)

        for rect in self.scene_rects.get(str(scene),{}).itervalues():
            l, t, r, b = rect
            cv2.rectangle(img, (l, t), (r, b), 255, 2)
        cv2.imshow('scene', img)
        cv2.waitKey(1)
        return scene

    def do_touch(self):
        # width, height = self.device.display
        width, height = 1080, 1920
        scene = self.get_current_scene()
        if scene is None:
            # fall back to random point
            x, y = randint(1, width), randint(1, height)
        else:
            pos = self.scene_touches.get(str(scene), 0)
            w, h = width/self.movestep, height/self.movestep # grid points
            dy, dx = divmod(pos, w-1)
            if dy >= h-1:
                # TODO: return a random clickable point
                x, y = randint(1, width), randint(1, height)
            else:
                x, y = (dx+1)*self.movestep, (dy+1)*self.movestep
                self.scene_touches[str(scene)] = pos+1

        self.last_touch_point = x, y
        self.device.touch(x, y)

        # watch what happend after touch
        if scene is None:
            return
        newscene = self.get_current_scene()
        if newscene is None or newscene == scene:
            return
        s1 = str(scene)
        s2 = str(newscene)
        if s1 not in self.scene_rects:
            self.scene_rects[s1] = {}
        if s2 not in self.scene_rects[s1]:
            self.scene_rects[s1][s2] = (x, y, x, y)
        else:
            l, t, r, b = self.scene_rects[s1][s2]
            l, r = min(l, x), max(r, x)
            t, b = min(t, y), max(t, y)
            self.scene_rects[s1][s2] = (l, t, r, b)

    def do_swipe(self):
        pass