Пример #1
0
def main():
    '''
    主函数
    '''
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    check_screenshot()

    i, next_rest, next_rest_time = 0, random.randrange(3,
                                                       10), random.randrange(
                                                           5, 10)
    while True:
        pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x)**2 + (board_y - piece_y)**2))
        if debug_switch:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x,
                                        board_y)
            debug.backup_screenshot(ts)
        time.sleep(random.uniform(0.9, 1.2))  # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
Пример #2
0
def main():
    '''
    主函数
    '''
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    check_screenshot()

    i, next_rest, next_rest_time = 0, random.randrange(3,
                                                       10), random.randrange(
                                                           5, 10)
    while True:
        pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x)**2 + (board_y - piece_y)**2))
        if debug_switch:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x,
                                        board_y)
            debug.backup_screenshot(ts)
        i += 1

        time.sleep(random.uniform(0.3, 1.9))  # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
Пример #3
0
def main():
    """
    主函数
    """
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,'
                   '然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()

    i, next_rest, next_rest_time = (0, random.randrange(3, 10),
                                    random.randrange(5, 10))

    count = file_num('../img') 
    jump_num = 0
    while True:

        jump_num = jump_num + 1
        print('------------>跳了'+str(jump_num)+'次<------------')

        time.sleep(0.5)
        screenshot.pull_screenshot()
        
        imgPath='./autojump.png'

        im = Image.open(imgPath)

        img_rgb = cv2.imread(imgPath)
        count = count+1
        # cv2.imwrite('../img/'+'{}.png'.format(count), img_rgb)
        # print('-----****------>writing img to ../img/''{}.png'.format(count))

        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = combine_opencv.find_jumper_and_board(imgPath,show=False)
        
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2))
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x,
                                        piece_y, board_x, board_y)
            debug.backup_screenshot(ts)
        im.close()
        i += 1

        if i == 1000:
            print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            i, next_rest, next_rest_time = (0, random.randrange(30, 100),
                                            random.randrange(10, 60))
        # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
        time.sleep(random.uniform(0.9, 1.2))
Пример #4
0
def main():
    '''
    主函数
    '''
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    check_screenshot()

    i, next_rest, next_rest_time = 0, random.randrange(3, 10), random.randrange(5, 10)
    while True:
        pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2))
        if debug_switch:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x, board_y)
            debug.backup_screenshot(ts)
        i += 1
        if i == next_rest:
            print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            i, next_rest, next_rest_time = 0, random.randrange(30, 100), random.randrange(10, 60)
        time.sleep(random.uniform(1.5, 2.0))   # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
Пример #5
0
def main():
    """
    主函数
    """
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,' '然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()

    i, next_rest, next_rest_time = (0, random.randrange(3, 10),
                                    random.randrange(5, 10))
    while True:
        screenshot.pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x)**2 + (board_y - piece_y)**2))
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x,
                                        board_y)
            debug.backup_screenshot(ts)
        im.close()
        i += 1
        time.sleep(random.uniform(0.9, 1.2))
Пример #6
0
def main():
    """
    主函数
    """
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()

    while True:
        screenshot.pull_screenshot()
        im = Image.open('./autojump.png')
        w, h = im.size
        im_pixel = im.load()
        scan_start_x = int(w / 8)  # 扫描棋子时的左右边界
        scan_start_y = find_scan_start_y(w, h, im_pixel)  # 扫描的起始 y 坐标
        # 获取棋子和 board 的位置
        piece_x, piece_y = find_piece(
            w, h, im_pixel, scan_start_x, scan_start_y)
        board_x, board_y = find_board(
            w, h, im_pixel, piece_x, piece_y, scan_start_y)
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(w, h)
        jump(abs(piece_x - board_x))
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x,
                                        piece_y, board_x, board_y)
            debug.backup_screenshot(ts)
        im.close()
        # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
        time.sleep(random.uniform(1.2, 1.6))
Пример #7
0
def update_img():
    _pull_screenshot()
    global im, im_pixels
    im = Image.open(img_path)
    im_pixels = im.load()
    if DEBUG_SWITCH:
        ts = int(time.time())
        debug.save_debug_screenshot(ts, im, screen_width, screen_height)
        debug.backup_screenshot(ts)
Пример #8
0
def main():
    """
    主函数
    """
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,'
                   '然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()
    #######################################
    #                                     #
    #            物理外挂部分             #
    #                                     #
    #######################################
    ser = serial.Serial()
    ser.baudrate = 9600  #波特率
    ser.port = 'COM3'   #  Arduino连接的COM口,根据实际情况修改
    ser.open()    #打开串口之前记得关闭Arduino IDE的串口工具和其他串口工具
    if ser.is_open:
        print("和Arduino握手成功!")


    i, next_rest, next_rest_time = (0, random.randrange(3, 10),
                                    random.randrange(5, 10))

    while True:
        screenshot.pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2))
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x,
                                        piece_y, board_x, board_y)
            debug.backup_screenshot(ts)
        im.close()
        ser.write(milsec)
        time.sleep(3)
        # i += 1
        # if i == next_rest:
        #     print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
        #     for j in range(next_rest_time):
        #         sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
        #         sys.stdout.flush()
        #         time.sleep(1)
        #     print('\n继续')
        #     i, next_rest, next_rest_time = (0, random.randrange(30, 100),
        #                                     random.randrange(10, 60))
        # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
        time.sleep(random.uniform(0.9, 1.2))
Пример #9
0
def main():
    """
    主函数
    """
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,'
                   '然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return

    # 设置最大分数
    score = input("请输入想达到的最大分数:")
    try:
        init_set_score(int(score))
    except:
        pass

    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()  

    i, next_rest, next_rest_time = (0, random.randrange(3, 10),
                                    random.randrange(5, 10))
    while True:
        screenshot.pull_screenshot()
        im = Image.open('./autojump.png')
        # 判断是否想退出
        print("====")
        if want_to_die(im):
            break
        print("====")
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)

        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2))
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x,
                                        piece_y, board_x, board_y)
            debug.backup_screenshot(ts)
        im.close()
        i += 1
        if i == next_rest:
            print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            i, next_rest, next_rest_time = (0, random.randrange(30, 100),
                                            random.randrange(10, 60))
        # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
        time.sleep(random.uniform(1.7, 2.2))
Пример #10
0
def main():
    '''
    主函数
    '''
    # op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    # if not op:
    #    print('bye')
    #    return
    # 初始化AI
    ai.init()

    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    check_screenshot()

    i, next_rest, next_rest_time = 0, random.randrange(3,
                                                       10), random.randrange(
                                                           5, 10)
    while True:
        pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        # print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        press_time = jump(
            math.sqrt((board_x - piece_x)**2 + (board_y - piece_y)**2))

        # 在跳跃落下的瞬间 摄像机移动前截图 这个参数要自己校调
        time.sleep(0.2)
        pull_screenshot_temp()
        im_temp = Image.open('./autojump_temp.png')
        temp_piece_x, temp_piece_y = find_piece(im_temp)
        debug.computing_error(press_time, board_x, board_y, piece_x, piece_y,
                              temp_piece_x, temp_piece_y)

        if debug_switch:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x,
                                        board_y)
            debug.save_debug_screenshot(ts, im_temp, temp_piece_x,
                                        temp_piece_y, board_x, board_y)
            # debug.backup_screenshot(ts)
        i = 0
        if i == next_rest:
            print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            i, next_rest, next_rest_time = 0, random.randrange(
                30, 100), random.randrange(10, 60)
        time.sleep(random.uniform(0.5, 0.6))  # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
Пример #11
0
def main():
    """
    主函数
    """
    op = yes_or_no(
        'Please make sure that the phone has opened ADB and connected to Yanshee,'
        'Then open and "jump game" and start the game, then run this program? '
    )
    if not op:
        print('bye')
        return
    print("Exit program: press CTRL + C\n")
    print('Program version:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()

    i, next_rest, next_rest_time = (0, random.randrange(3, 10),
                                    random.randrange(5, 10))

    action_func(startAction, 1)

    while True:
        screenshot.pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x)**2 + (board_y - piece_y)**2))
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x,
                                        board_y)
            debug.backup_screenshot(ts)
        im.close()
        # i += 1
        # if i == next_rest:
        #     print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
        #     for j in range(next_rest_time):
        #         sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
        #         sys.stdout.flush()
        #         time.sleep(1)
        #     print('\n继续')
        #     i, next_rest, next_rest_time = (0, random.randrange(30, 100),
        #                                     random.randrange(10, 60))

        # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
        time.sleep(random.uniform(0.9, 1.2))

    action_func(resetAction, 1)
    action.sdkFinish(sys.argv[0])
def main():
    '''
    主函数
    '''
    # op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    # if not op:
    #    print('bye')
    #    return
    # 初始化AI
    ai.init()

    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    check_screenshot()

    i, next_rest, next_rest_time = 0, random.randrange(3, 10), random.randrange(5, 10)
    while True:
        pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        # print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        press_time = jump(math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2))

        # 在跳跃落下的瞬间 摄像机移动前截图 这个参数要自己校调
        time.sleep(0.2)
        pull_screenshot_temp()
        im_temp = Image.open('./autojump_temp.png')
        temp_piece_x, temp_piece_y = find_piece(im_temp)
        debug.computing_error(press_time, board_x, board_y, piece_x, piece_y, temp_piece_x, temp_piece_y)

        if debug_switch:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x, board_y)
            debug.save_debug_screenshot(ts, im_temp, temp_piece_x, temp_piece_y, board_x, board_y)
            # debug.backup_screenshot(ts)
        i = 0
        if i == next_rest:
            print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            i, next_rest, next_rest_time = 0, random.randrange(30, 100), random.randrange(10, 60)
        time.sleep(random.uniform(0.5, 0.6))  # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
def main():
    """
    主函数
    """
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,' '然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()

    curJumpIndex, next_rest, next_rest_time = (0, random.randrange(3, 10),
                                               random.randrange(5, 10))
    while True:
        screenshot.pull_screenshot()
        im = Image.open('./autojump.png')

        # 获取棋子位置(piece_x, piece_y)和 board 的位置(board_x, board_y)
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)

        # 获取当前时间作为debug备份的图片文件名,用于错误调试
        curTime = int(time.time())
        print(curTime, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x)**2 + (board_y - piece_y)**2))
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(curTime, im, piece_x, piece_y, board_x,
                                        board_y)
            debug.backup_screenshot(curTime)
        im.close()

        curJumpIndex += 1
        if curJumpIndex == next_rest:
            print('已经连续打了 {} 下,休息 {}s'.format(curJumpIndex, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            curJumpIndex, next_rest, next_rest_time = (0,
                                                       random.randrange(
                                                           30, 100),
                                                       random.randrange(
                                                           10, 60))
        # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
        time.sleep(random.uniform(0.9, 1.2))
def main():
    """
    主函数
    """
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,'
                   '然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()

    i, next_rest, next_rest_time = (0, random.randrange(3, 10), random.randrange(5, 10))
    while True:
        screenshot.pull_screenshot()
        im = Image.open('./autojump.png')
#         img = cv2.imread("./autojump.png")
#         emptyImage = np.zeros(img.shape, np.uint8)
#         emptyImage2 = img.copy()
#         
#         cv2.imshow("Python+OpenCV", emptyImage2)
#         cv2.waitKey (0)
#         cv2.destroyAllWindows()
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2))
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x, board_y)
            debug.backup_screenshot(ts)
#         im.close()
        i += 1
        if i == next_rest:
            print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            i, next_rest, next_rest_time = (0, random.randrange(30, 100),
                                            random.randrange(10, 60))
        # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
        time.sleep(random.uniform(0.9, 1))
Пример #15
0
def main():
    """
    主函数
    """
    #op = yes_or_no(u'请确保手机打开了 ADB 并连接了电脑,然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    op = yes_or_no('Please ensure that adb is opened.')
    if not op:
        print('bye')
        return
    print(u'程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()

    i, next_rest, next_rest_time = (0, random.randrange(3, 10),
                                    random.randrange(5, 10))
    while True:
        screenshot.pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        # print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        global last_distance 
        global last_time
        print("\033[34;1m [-] ",last_distance,last_time,"\033[0m")
        distance = math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2)
        last_distance = int(round(distance))
        last_time = jump(distance)
        
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x,piece_y, board_x, board_y)
            debug.backup_screenshot(ts)
        im.close()
        i += 1
        # if i == next_rest:
        #     print(u'已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
        #     for j in range(next_rest_time):
        #         sys.stdout.write(u'\r程序将在 {}s 后继续'.format(next_rest_time - j))
        #         sys.stdout.flush()
        #         time.sleep(1)
        #     print(u'\n继续')
        #     i, next_rest, next_rest_time = (0, random.randrange(30, 100),
        #                                     random.randrange(10, 20))
        # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
        time.sleep(random.uniform(0.8, 1.3))
Пример #16
0
def main():
    """
    主函数
    """
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,' '然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()

    i, next_rest, next_rest_time = (0, random.randrange(3, 20),
                                    random.randrange(2, 10))

    flag_cout = 1  ##连跳计数
    screen_size = configPy._get_screen_size()  ##获取屏幕大小
    screen_size_board_y_coefficient = int(GetMiddleStr(screen_size))
    while True:
        time.sleep(random.random() * 5)  ##每次操作时间不同
        screenshot.pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(
            im, flag_cout, screen_size_board_y_coefficient)
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x)**2 + (board_y - piece_y)**2))
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x,
                                        board_y)
            debug.backup_screenshot(ts)
        im.close()
        i += 1
        if i == next_rest:
            print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            i, next_rest, next_rest_time = (0, random.randrange(30, 100),
                                            random.randrange(10, 60))
        # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
        time.sleep(random.uniform(0.9, 1.2))
Пример #17
0
def main():
    ai.init()

    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    check_screenshot()

    i, next_rest, next_rest_time = 0, random.randrange(3,
                                                       10), random.randrange(
                                                           5, 10)
    while True:
        pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        # print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        press_time = jump(
            math.sqrt((board_x - piece_x)**2 + (board_y - piece_y)**2))

        # 在跳跃落下的瞬间 摄像机移动前截图 这个参数要自己校调
        time.sleep(0.04)
        pull_screenshot_temp()
        im_temp = Image.open('./autojump_temp.png')
        temp_piece_x, temp_piece_y = find_piece(im_temp)
        debug.computing_error(press_time, board_x, board_y, piece_x, piece_y,
                              temp_piece_x, temp_piece_y)

        if debug_switch:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x,
                                        board_y, "d")
            debug.save_debug_screenshot(ts, im_temp, temp_piece_x,
                                        temp_piece_y, board_x, board_y, "t")
            # debug.backup_screenshot(ts)
        # i = 0
        # if i == next_rest:
        # print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
        # for j in range(next_rest_time):
        #     sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
        #     sys.stdout.flush()
        #     time.sleep(1)
        # print('\n继续')
        # i, next_rest, next_rest_time = 0, random.randrange(1, 5), random.randrange(2, 6)
        time.sleep(random.uniform(1.0, 1.5))  # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
Пример #18
0
def get_magicnumber():
    pull_screenshot()
    im = Image.open('./autojump.png')
    # 获取棋子和 board 的位置
    x1, y1 = find_piece_and_board(im, True)
    ts = int(time.time())
    debug.backup_screenshot(ts)
    set_button_position(im)
    jump(0)  #100ms
    time.sleep(1)
    pull_screenshot()
    im = Image.open('./autojump.png')
    # 获取棋子和 board 的位置
    x2, y2 = find_piece_and_board(im, True)
    ts = int(time.time())
    debug.save_debug_screenshot(ts, im, x1, y1, x2, y2)
    global press_coefficient
    press_coefficient = 150 / abs(x2 - x1)  #100ms 的距离
    print('number', press_coefficient)
def main():
    """
    主函数
    """
    print('激活窗口并按 CONTROL + C 组合键退出')
    if DEBUG_SWITCH:
        print('DEBUG模式已开启')
    else:
        print('DEBUG模式已关闭')
    debug.dump_device_info()
    screenshot.check_screenshot()

    i, next_rest, next_rest_time = (0, random.randrange(3, 10),
                                    random.randrange(5, 10))
    while True:
        image = screenshot.pull_screenshot()
        work_path = sys.path[0]
        template = cv2.imread(os.path.join(work_path, 'piece.png'))
        # 获取棋子和 board 的位置
        piece_top_left, piece_bottom_right, piece_loc, board_loc = get_piece_board_loc(
            image, template)
        ts = int(time.time())
        print("\ntime:{}, piece_loc:{}, board_loc:{}".format(
            ts, piece_loc, board_loc))
        set_button_position(image)
        jump(piece_loc, board_loc)
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, image, piece_top_left,
                                        piece_bottom_right, piece_loc,
                                        board_loc)
            # debug.backup_screenshot(ts)
        i += 1
        if i == next_rest:
            print('已经连续打了 {} 下,休息 {}秒'.format(i, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}秒 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            i, next_rest, next_rest_time = (0, random.randrange(30, 100),
                                            random.randrange(10, 60))
        # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
        time.sleep(random.uniform(1.2, 1.4))
Пример #20
0
def main():
    """
    主函数
    """
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,'
                   '然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()

    i, next_rest, next_rest_time = (0, random.randrange(3, 10),
                                    random.randrange(5, 10))
    while True:
        screenshot.pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2))
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x,
                                        piece_y, board_x, board_y)
            debug.backup_screenshot(ts)
        im.close()
        i += 1
        if i == next_rest:
            print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            i, next_rest, next_rest_time = (0, random.randrange(30, 100),
                                            random.randrange(10, 60))
        # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
        time.sleep(random.uniform(0.9, 1.2))
Пример #21
0
def main():
    """
    主函数
    """
    op = yes_or_no('输入y确定开始,输入n退出程序')
    if not op:
        print('bye')
        return
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()

    i, next_rest, next_rest_time = (0, random.randrange(3, 10),
                                    random.randrange(5, 10))
    while True:
        screenshot.pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2))
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x,
                                        piece_y, board_x, board_y)
            debug.backup_screenshot(ts)
        im.close()
        i += 1
        if i == next_rest:
            print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            i, next_rest, next_rest_time = (0, random.randrange(30, 100),
                                            random.randrange(10, 60))
        # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
        time.sleep(random.uniform(0.9, 1.2))
Пример #22
0
def main():
    """
    主函数
    """
    print('程序版本号:{}'.format(VERSION))
    print('激活窗口并按 CONTROL + C 组合键退出')
    debug.dump_device_info()
    screenshot.check_screenshot()

    i, next_rest, next_rest_time = (0, random.randrange(3, 10),
                                    random.randrange(5, 10))
    while True:
        im = screenshot.pull_screenshot()
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y, delta_piece_y = find_piece_and_board(
            im)
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x)**2 + (board_y - piece_y)**2),
             delta_piece_y)
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x,
                                        board_y)
            debug.backup_screenshot(ts)
        im.close()
        i += 1
        if i == next_rest:
            print('已经连续打了 {} 下,休息 {}秒'.format(i, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}秒 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            i, next_rest, next_rest_time = (0, random.randrange(30, 100),
                                            random.randrange(10, 60))
        # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
        time.sleep(random.uniform(1.2, 1.4))
Пример #23
0
    def step(self, action):
        self._jump(action)
        time.sleep(SLEEP_TIME)
        screenshot.pull_screenshot()
        im = Image.open('autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = self._find_piece_and_board(im)
        # print(piece_x, piece_y, board_x, board_y, bias)
        if piece_x == 0:
            done = True
            reward = -1
        else:
            done = False
            reward = 0.5
        self._set_button_position(im)
        state_ = math.sqrt((board_x - piece_x)**2 + (board_y - piece_y)**2)
        debug.save_debug_screenshot(time.time(), im, piece_x, piece_y, board_x,
                                    board_y)
        debug.backup_screenshot(time.time())
        im.close()

        a = [(state_ - self.MIN_DISTANCE) /
             (self.MAX_DISTANCE - self.MIN_DISTANCE)]
        return np.array(a), reward, done
Пример #24
0
def main():
    global target_score
    global current_score
    global finnal_score
    tool ,lang = pyocr_init()

    #txt = tool.image_to_string(Image.open('./spilt.png'), config='tessedit_char_whitelist 01234567890')


    #//////////////

    #api = pytesseract.TessBaseAPI()
    #pytesseract.Init(".", "eng", pytesseract.OEM_DEFAULT)
    #pytesseract.SetVariable("tessedit_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyz")
    #pytesseract.SetPageSegMode(pytesseract.PSM_AUTO)
    #txt = pytesseract.image_to_string(Image.open('./spilt.png'))
    #print(txt)
    """
    主函数
    """
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,'
                   '然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()

    i, next_rest, next_rest_time = (0, random.randrange(3, 10),
                                    random.randrange(5, 10))
    while True:
        screenshot.pull_screenshot()

        current_score = find_current_score(tool, lang)
        print('当前分数是: '+ str(current_score))

        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)
        jump(math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2))
        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x,
                                        piece_y, board_x, board_y)
            debug.backup_screenshot(ts)
        im.close()

        if current_score > finnal_score:
            print('We get our target, stop play')
            break;

        i += 1
        if i == next_rest:
            print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            i, next_rest, next_rest_time = (0, random.randrange(30, 100),
                                            random.randrange(10, 60))
        # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
        time.sleep(random.uniform(0.9, 1.2))
Пример #25
0
def main():
    print('激活窗口并按 CONTROL + C 组合键退出')
    debug.dump_device_info()
    screenshot.check_screenshot()
    i = 0
    press_time = 20
    press_time = int(press_time)
    im = screenshot.pull_screenshot()
    w, h = im.size
    im_pixel = im.load()
    pixel_1 = im_pixel[240, 715]
    pixel_2 = im_pixel[440, 715]
    pixel_3 = im_pixel[640, 715]
    pixel_4 = im_pixel[835, 715]
    pixel_5 = im_pixel[240, 925]
    pixel_6 = im_pixel[440, 925]
    pixel_7 = im_pixel[640, 925]
    pixel_8 = im_pixel[835, 925]
    pixel_9 = im_pixel[240, 1135]
    pixel_10 = im_pixel[440, 1135]
    pixel_11 = im_pixel[640, 1135]
    pixel_12 = im_pixel[835, 1135]
    pixel_13 = im_pixel[240, 1340]
    pixel_14 = im_pixel[440, 1340]
    pixel_15 = im_pixel[640, 1340]
    pixel_16 = im_pixel[835, 1340]
    while True:
        if (250 < pixel_1[0] < 256 and 250 < pixel_1[1] < 256
                and 250 < pixel_1[2] < 256):
            cmd = 'shell input tap 240 715'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_2[0] < 256 and 250 < pixel_2[1] < 256
                and 250 < pixel_2[2] < 256):
            cmd = 'shell input tap 440 715'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_3[0] < 256 and 250 < pixel_3[1] < 256
                and 250 < pixel_3[2] < 256):
            cmd = 'shell input tap 640 715'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_4[0] < 256 and 250 < pixel_4[1] < 256
                and 250 < pixel_4[2] < 256):
            cmd = 'shell input tap 835 715'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_5[0] < 256 and 250 < pixel_5[1] < 256
                and 250 < pixel_5[2] < 256):
            cmd = 'shell input tap 240 925'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_6[0] < 256 and 250 < pixel_6[1] < 256
                and 250 < pixel_6[2] < 256):
            cmd = 'shell input tap 440 925'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_7[0] < 256 and 250 < pixel_7[1] < 256
                and 250 < pixel_7[2] < 256):
            cmd = 'shell input tap 640 925'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_8[0] < 256 and 250 < pixel_8[1] < 256
                and 250 < pixel_8[2] < 256):
            cmd = 'shell input tap 835 925'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_9[0] < 256 and 250 < pixel_9[1] < 256
                and 250 < pixel_9[2] < 256):
            cmd = 'shell input tap 240 1135'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_10[0] < 256 and 250 < pixel_10[1] < 256
                and 250 < pixel_10[2] < 256):
            cmd = 'shell input tap 440 1135'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_11[0] < 256 and 250 < pixel_11[1] < 256
                and 250 < pixel_11[2] < 256):
            cmd = 'shell input tap 640 1135'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_12[0] < 256 and 250 < pixel_12[1] < 256
                and 250 < pixel_12[2] < 256):
            cmd = 'shell input tap 835 1135'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_13[0] < 256 and 250 < pixel_13[1] < 256
                and 250 < pixel_13[2] < 256):
            cmd = 'shell input tap 240 1340'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_14[0] < 256 and 250 < pixel_14[1] < 256
                and 250 < pixel_14[2] < 256):
            cmd = 'shell input tap 440 1340'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_15[0] < 256 and 250 < pixel_15[1] < 256
                and 250 < pixel_15[2] < 256):
            cmd = 'shell input tap 640 1340'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)
        if (250 < pixel_16[0] < 256 and 250 < pixel_16[1] < 256
                and 250 < pixel_16[2] < 256):
            cmd = 'shell input tap 835 1340'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.05)

        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x,
                                        board_y)
            debug.backup_screenshot(ts)
        im.close()
        i += 1
def main():
    '''
    主函数
    '''
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return
    debug.dump_device_info()
    check_screenshot()

    x = tf.placeholder(tf.float32, [None, 51, 86])
    y_conv, keep_prob = deepnn(x)

    saver = tf.train.Saver()
    sess = tf.Session()
    saver.restore(sess, tf.train.latest_checkpoint('./TF_Saved_Model/'))

    Num = 0
    while (True):
        pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x_o, piece_y_o, board_x_o, board_y_o = find_piece_and_board(im)
        """
        if i == next_rest:
            print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            i, next_rest, next_rest_time = 0, random.randrange(1, 10), random.randrange(1, 10)
        """
        #time.sleep(random.uniform(1.9, 2.2))   # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban

        im_cv = cv2.imread('./autojump.png')
        im_cvrs = cv2.resize(im_cv,
                             None,
                             fx=ReshapeRatio1,
                             fy=ReshapeRatio1,
                             interpolation=cv2.INTER_CUBIC)
        im_cvrs_back = cv2.resize(im_cv,
                                  None,
                                  fx=ReshapeRatio1,
                                  fy=ReshapeRatio1,
                                  interpolation=cv2.INTER_CUBIC)

        H_org, W_org, _ = im_cv.shape
        H_rs_org, W_rs_org, _ = im_cvrs.shape
        print(H_org, W_org)

        Num = Num + 1
        Name = str(int(piece_x_o*ReshapeRatio1))+'_'\
             + str(int(piece_y_o*ReshapeRatio1))+'_'\
             + str(int(board_x_o*ReshapeRatio1))+'_'\
             + str(int(board_y_o*ReshapeRatio1))+'_'\
             +str(Num)+".png"
        Path = '/home/zhy/Pic/'
        cv2.imwrite(Path + Name, im_cvrs,
                    [int(cv2.IMWRITE_PNG_COMPRESSION), 9])

        im_cvrs = im_cvrs[250:506, :]

        im_cvrs_cnn = cv2.resize(im_cvrs,
                                 None,
                                 fx=ReshapeRatio2,
                                 fy=ReshapeRatio2,
                                 interpolation=cv2.INTER_CUBIC)
        im_cvrs_cnn_gray = cv2.cvtColor(im_cvrs_cnn, cv2.COLOR_BGR2GRAY)
        cv2.imshow('im_cvrs_cnn_gray', im_cvrs_cnn_gray)

        print(im_cvrs_cnn_gray.shape)

        im_cvrs_cnn_gray = (im_cvrs_cnn_gray - 127) / 255
        x_batch = im_cvrs_cnn_gray[np.newaxis, :, :]
        prediction = sess.run([y_conv], feed_dict={x: x_batch, keep_prob: 1})
        prediction = prediction[0][0]
        print('Prediction:\n', prediction)

        piece_x = int(prediction[0] * W_org)
        piece_y = int(prediction[1] * H_org)
        board_x = int(prediction[2] * W_org)
        board_y = int(prediction[3] * H_org)

        piece_x_rs = int(prediction[0] * W_rs_org)
        piece_y_rs = int(prediction[1] * H_rs_org)
        board_x_rs = int(prediction[2] * W_rs_org)
        board_y_rs = int(prediction[3] * H_rs_org)

        cv2.circle(im_cvrs_back, (piece_x_rs, piece_y_rs), 15, (255, 0, 0), -1)
        cv2.circle(im_cvrs_back, (board_x_rs, board_y_rs), 15, (0, 0, 255), -1)

        cv2.imshow('Image', im_cvrs_back)
        cv2.waitKey(500)

        ts = int(time.time())
        print(piece_x, piece_y, board_x, board_y)
        print(piece_x_o, piece_y_o, board_x_o, board_y_o)

        set_button_position(im)
        #if Num%100 == 99:
        #jump(math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2))
        #else:
        jump(math.sqrt((board_x - piece_x)**2 + (board_y - piece_y)**2))
        if debug_switch:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x,
                                        board_y)
            debug.backup_screenshot(ts)
        time.sleep(random.uniform(1.9, 2.2))  # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
Пример #27
0
def main():
    '''
    主函数
    '''
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    check_screenshot()

    i, next_rest, next_rest_time = 0, random.randrange(3,
                                                       10), random.randrange(
                                                           5, 10)
    while True:
        pull_screenshot()
        im = Image.open('./autojump.png')
        # 获取棋子和 board 的位置
        piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
        ts = int(time.time())
        print(ts, piece_x, piece_y, board_x, board_y)
        set_button_position(im)

        distance = math.sqrt((board_x - piece_x)**2 + (board_y - piece_y)**2)
        print("start-------- distance --------start: ", distance)
        tmp = 0
        if distance < 220:
            tmp = 38
            print("200-------- distance --------200:", tmp)
        elif distance < 380:
            tmp = 30
            print("350-------- distance --------350:", tmp)
        elif distance < 480:
            tmp = 25
            print("465-------- distance --------465:", tmp)
        elif distance < 515:
            tmp = 14
            print("500-------- distance --------500:", tmp)
        elif distance < 580:
            tmp = 12
            print("540-------- distance --------540:", tmp)
        elif distance < 635:
            tmp = 5
            print("630-------- distance --------630:", tmp)
        distance = distance + tmp
        print("end-------- distance --------end: ", distance)

        jump(distance)
        if debug_switch:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x,
                                        board_y)
            debug.backup_screenshot(ts)
        i += 1
        if i == next_rest:
            print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
            for j in range(next_rest_time):
                sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                sys.stdout.flush()
                time.sleep(1)
            print('\n继续')
            i, next_rest, next_rest_time = 0, random.randrange(
                30, 100), random.randrange(10, 60)
        time.sleep(random.uniform(1.0, 1.3))  # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
Пример #28
0
def main():
    print('激活窗口并按 CONTROL + C 组合键退出')
    debug.dump_device_info()
    screenshot.check_screenshot()
    i = 0
    im = screenshot.pull_screenshot()
    w, h = im.size
    im_pixel = im.load()
    pixel_1 = im_pixel[215, 690]
    pixel_2 = im_pixel[320, 690]
    pixel_3 = im_pixel[430, 690]
    pixel_4 = im_pixel[535, 690]
    pixel_5 = im_pixel[645, 690]
    pixel_6 = im_pixel[755, 690]
    pixel_7 = im_pixel[865, 690]
    pixel_8 = im_pixel[215, 810]
    pixel_9 = im_pixel[320, 810]
    pixel_10 = im_pixel[430, 810]
    pixel_11 = im_pixel[535, 810]
    pixel_12 = im_pixel[645, 810]
    pixel_13 = im_pixel[755, 810]
    pixel_14 = im_pixel[865, 810]
    pixel_15 = im_pixel[215, 930]
    pixel_16 = im_pixel[320, 930]
    pixel_17 = im_pixel[430, 930]
    pixel_18 = im_pixel[535, 930]
    pixel_19 = im_pixel[645, 930]
    pixel_20 = im_pixel[755, 930]
    pixel_21 = im_pixel[865, 930]
    pixel_22 = im_pixel[215, 1050]
    pixel_23 = im_pixel[320, 1050]
    pixel_24 = im_pixel[430, 1050]
    pixel_25 = im_pixel[535, 1050]
    pixel_26 = im_pixel[645, 1050]
    pixel_27 = im_pixel[755, 1050]
    pixel_28 = im_pixel[865, 1050]
    pixel_29 = im_pixel[215, 1180]
    pixel_30 = im_pixel[320, 1180]
    pixel_31 = im_pixel[430, 1180]
    pixel_32 = im_pixel[535, 1180]
    pixel_33 = im_pixel[645, 1180]
    pixel_34 = im_pixel[755, 1180]
    pixel_35 = im_pixel[865, 1180]
    pixel_36 = im_pixel[215, 1290]
    pixel_37 = im_pixel[320, 1290]
    pixel_38 = im_pixel[430, 1290]
    pixel_39 = im_pixel[535, 1290]
    pixel_40 = im_pixel[645, 1290]
    pixel_41 = im_pixel[755, 1290]
    pixel_42 = im_pixel[865, 1290]
    pixel_43 = im_pixel[215, 1410]
    pixel_44 = im_pixel[320, 1410]
    pixel_45 = im_pixel[430, 1410]
    pixel_46 = im_pixel[535, 1410]
    pixel_47 = im_pixel[645, 1410]
    pixel_48 = im_pixel[755, 1410]
    pixel_49 = im_pixel[865, 1410]

    while True:
        if (250 < pixel_1[0] < 256 and 250 < pixel_1[1] < 256
                and 250 < pixel_1[2] < 256):
            cmd = 'shell input tap 215 690'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_2[0] < 256 and 250 < pixel_2[1] < 256
                and 250 < pixel_2[2] < 256):
            cmd = 'shell input tap 320 690'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_3[0] < 256 and 250 < pixel_3[1] < 256
                and 250 < pixel_3[2] < 256):
            cmd = 'shell input tap 430 690'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_4[0] < 256 and 250 < pixel_4[1] < 256
                and 250 < pixel_4[2] < 256):
            cmd = 'shell input tap 535 690'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_5[0] < 256 and 250 < pixel_5[1] < 256
                and 250 < pixel_5[2] < 256):
            cmd = 'shell input tap 645 690'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_6[0] < 256 and 250 < pixel_6[1] < 256
                and 250 < pixel_6[2] < 256):
            cmd = 'shell input tap 755 690'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_7[0] < 256 and 250 < pixel_7[1] < 256
                and 250 < pixel_7[2] < 256):
            cmd = 'shell input tap 865 690'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_8[0] < 256 and 250 < pixel_8[1] < 256
                and 250 < pixel_8[2] < 256):
            cmd = 'shell input tap 215 810'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_9[0] < 256 and 250 < pixel_9[1] < 256
                and 250 < pixel_9[2] < 256):
            cmd = 'shell input tap 320 810'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_10[0] < 256 and 250 < pixel_10[1] < 256
                and 250 < pixel_10[2] < 256):
            cmd = 'shell input tap 430 810'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_11[0] < 256 and 250 < pixel_11[1] < 256
                and 250 < pixel_11[2] < 256):
            cmd = 'shell input tap 535 810'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_12[0] < 256 and 250 < pixel_12[1] < 256
                and 250 < pixel_12[2] < 256):
            cmd = 'shell input tap 645 810'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_13[0] < 256 and 250 < pixel_13[1] < 256
                and 250 < pixel_13[2] < 256):
            cmd = 'shell input tap 755 810'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_14[0] < 256 and 250 < pixel_14[1] < 256
                and 250 < pixel_14[2] < 256):
            cmd = 'shell input tap 865 810'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_15[0] < 256 and 250 < pixel_15[1] < 256
                and 250 < pixel_15[2] < 256):
            cmd = 'shell input tap 215 930'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_16[0] < 256 and 250 < pixel_16[1] < 256
                and 250 < pixel_16[2] < 256):
            cmd = 'shell input tap 320 930'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_17[0] < 256 and 250 < pixel_17[1] < 256
                and 250 < pixel_17[2] < 256):
            cmd = 'shell input tap 430 930'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_18[0] < 256 and 250 < pixel_18[1] < 256
                and 250 < pixel_18[2] < 256):
            cmd = 'shell input tap 535 930'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_19[0] < 256 and 250 < pixel_19[1] < 256
                and 250 < pixel_19[2] < 256):
            cmd = 'shell input tap 645 930'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_20[0] < 256 and 250 < pixel_20[1] < 256
                and 250 < pixel_20[2] < 256):
            cmd = 'shell input tap 755 930'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_21[0] < 256 and 250 < pixel_21[1] < 256
                and 250 < pixel_21[2] < 256):
            cmd = 'shell input tap 865 930'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_22[0] < 256 and 250 < pixel_22[1] < 256
                and 250 < pixel_22[2] < 256):
            cmd = 'shell input tap 215 1050'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_23[0] < 256 and 250 < pixel_23[1] < 256
                and 250 < pixel_23[2] < 256):
            cmd = 'shell input tap 320 1050'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_24[0] < 256 and 250 < pixel_24[1] < 256
                and 250 < pixel_24[2] < 256):
            cmd = 'shell input tap 430 1050'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_25[0] < 256 and 250 < pixel_25[1] < 256
                and 250 < pixel_25[2] < 256):
            cmd = 'shell input tap 535 1050'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_26[0] < 256 and 250 < pixel_26[1] < 256
                and 250 < pixel_26[2] < 256):
            cmd = 'shell input tap 645 1050'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_27[0] < 256 and 250 < pixel_27[1] < 256
                and 250 < pixel_27[2] < 256):
            cmd = 'shell input tap 755 1050'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_28[0] < 256 and 250 < pixel_28[1] < 256
                and 250 < pixel_28[2] < 256):
            cmd = 'shell input tap 865 1050'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_29[0] < 256 and 250 < pixel_29[1] < 256
                and 250 < pixel_29[2] < 256):
            cmd = 'shell input tap 215 1180'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_30[0] < 256 and 250 < pixel_30[1] < 256
                and 250 < pixel_30[2] < 256):
            cmd = 'shell input tap 320 1180'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_31[0] < 256 and 250 < pixel_31[1] < 256
                and 250 < pixel_31[2] < 256):
            cmd = 'shell input tap 430 1180'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_32[0] < 256 and 250 < pixel_32[1] < 256
                and 250 < pixel_32[2] < 256):
            cmd = 'shell input tap 535 1180'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_33[0] < 256 and 250 < pixel_33[1] < 256
                and 250 < pixel_33[2] < 256):
            cmd = 'shell input tap 645 1180'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_34[0] < 256 and 250 < pixel_34[1] < 256
                and 250 < pixel_34[2] < 256):
            cmd = 'shell input tap 755 1180'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_35[0] < 256 and 250 < pixel_35[1] < 256
                and 250 < pixel_35[2] < 256):
            cmd = 'shell input tap 865 1180'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_36[0] < 256 and 250 < pixel_36[1] < 256
                and 250 < pixel_36[2] < 256):
            cmd = 'shell input tap 215 1290'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_37[0] < 256 and 250 < pixel_37[1] < 256
                and 250 < pixel_37[2] < 256):
            cmd = 'shell input tap 320 1290'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_38[0] < 256 and 250 < pixel_38[1] < 256
                and 250 < pixel_38[2] < 256):
            cmd = 'shell input tap 430 1290'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_39[0] < 256 and 250 < pixel_39[1] < 256
                and 250 < pixel_39[2] < 256):
            cmd = 'shell input tap 535 1290'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_40[0] < 256 and 250 < pixel_40[1] < 256
                and 250 < pixel_40[2] < 256):
            cmd = 'shell input tap 645 1290'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_41[0] < 256 and 250 < pixel_41[1] < 256
                and 250 < pixel_41[2] < 256):
            cmd = 'shell input tap 755 1290'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_42[0] < 256 and 250 < pixel_42[1] < 256
                and 250 < pixel_42[2] < 256):
            cmd = 'shell input tap 865 1290'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_43[0] < 256 and 250 < pixel_43[1] < 256
                and 250 < pixel_43[2] < 256):
            cmd = 'shell input tap 215 1410'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_44[0] < 256 and 250 < pixel_44[1] < 256
                and 250 < pixel_44[2] < 256):
            cmd = 'shell input tap 320 1410'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_45[0] < 256 and 250 < pixel_45[1] < 256
                and 250 < pixel_45[2] < 256):
            cmd = 'shell input tap 430 1410'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_46[0] < 256 and 250 < pixel_46[1] < 256
                and 250 < pixel_46[2] < 256):
            cmd = 'shell input tap 535 1410'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_47[0] < 256 and 250 < pixel_47[1] < 256
                and 250 < pixel_47[2] < 256):
            cmd = 'shell input tap 645 1410'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_48[0] < 256 and 250 < pixel_48[1] < 256
                and 250 < pixel_48[2] < 256):
            cmd = 'shell input tap 755 1410'
            print(cmd)
            adb.run(cmd)
        if (250 < pixel_49[0] < 256 and 250 < pixel_49[1] < 256
                and 250 < pixel_49[2] < 256):
            cmd = 'shell input tap 865 1410'
            print(cmd)
            adb.run(cmd)

        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x,
                                        board_y)
            debug.backup_screenshot(ts)
        im.close()
        i += 1
def main():
    """
    主函数
    """
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,'
                   '然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()

    i, next_rest, next_rest_time = (0, random.randrange(3, 10),
                                    random.randrange(5, 10))
    j= 0
    ################ 分数曲线公式

    y_score=[]
    next_start=0
    global start_score
    for i in range(total_step):
        each_score=target_score*(1-np.exp(-0.15*(1024.0/target_score)*i))
        y_score.append(each_score)
        if start_score>each_score:
            next_start=i
    next_start+=1
    #print(y_score)
    if start_score<y_score[0]:
        next_start=0

    ###################
    with tf.Session() as sess:
        saver = tf.train.import_meta_graph('./resource/model/model.ckpt.meta')
        saver.restore(sess,tf.train.latest_checkpoint('./resource/model/'))

        graph = tf.get_default_graph()
        x = graph.get_tensor_by_name("x:0")
        logits = graph.get_tensor_by_name("logits_eval:0")
    #####################识别分数
        while True:
            screenshot.pull_screenshot()
            im = Image.open('./autojump.png')
            ##比例系数
            pix_w=im.size[0]*1.0/1080
            pix_h=im.size[1]
            region=im.crop((0,pix_h*0.1,460*pix_w,pix_h*0.2))
            region=region.convert('L')
            start_h,end_h,pixels_Widh=pixel_division(region,int(460*pix_w),int(pix_h*0.1))
            if start_h==end_h:
                continue
            data = []
            for i in range(len(pixels_Widh)-1):
                region1=region.crop((pixels_Widh[i],start_h,pixels_Widh[i+1],end_h))
                region1.putdata(pross_data(region1))
                str1="./region"+str(i)+".png"
                region1.save(str1)
                data1 = read_one_image(str1)
                data.append(data1)
            feed_dict = {x:data}
            classification_result = sess.run(logits,feed_dict)
            output = []
            output = tf.argmax(classification_result,1).eval()
            m_score=""
            for i in range(len(output)):
                m_score+=strint(output[i])
            if m_score=="":
                continue
            m_score=int(m_score)
            print('score:{}'.format(m_score))
            ####################################
            # 获取棋子和 board 的位置
            print(j)
            piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
            ts = int(time.time())
            print(ts, piece_x, piece_y, board_x, board_y)
            set_button_position(im)

            if m_score > y_score[next_start]: ##自动结束这一次
                print("----------------")
                jump(math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2)*5)
                next_start+=1
                time.sleep(5*random.random())
            if next_start >len(y_score):
                break
            jump(math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2))
            if DEBUG_SWITCH:
                debug.save_debug_screenshot(ts, im, piece_x,
                                            piece_y, board_x, board_y)
                debug.backup_screenshot(ts)
            im.close()
            i += 1
            j += 1
            if i == next_rest:
                print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
                for j in range(next_rest_time):
                    sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                    sys.stdout.flush()
                    time.sleep(1)
                print('\n继续')
                i, next_rest, next_rest_time = (0, random.randrange(30, 100),
                                                random.randrange(10, 60))
            # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
            time.sleep(random.uniform(0.9, 1.2))
Пример #30
0
def main():
    print('激活窗口并按 CONTROL + C 组合键退出')
    debug.dump_device_info()
    screenshot.check_screenshot()
    i = 0
    press_time = 20
    press_time = int(press_time)
    im = screenshot.pull_screenshot()
    w, h = im.size
    im_pixel = im.load()
    pixel_1 = im_pixel[220, 695]
    pixel_2 = im_pixel[350, 695]
    pixel_3 = im_pixel[470, 695]
    pixel_4 = im_pixel[595, 695]
    pixel_5 = im_pixel[730, 695]
    pixel_6 = im_pixel[858, 695]
    pixel_7 = im_pixel[220, 835]
    pixel_8 = im_pixel[350, 835]
    pixel_9 = im_pixel[470, 835]
    pixel_10 = im_pixel[595, 835]
    pixel_11 = im_pixel[730, 835]
    pixel_12 = im_pixel[858, 835]
    pixel_13 = im_pixel[220, 975]
    pixel_14 = im_pixel[350, 975]
    pixel_15 = im_pixel[470, 975]
    pixel_16 = im_pixel[595, 975]
    pixel_17 = im_pixel[730, 975]
    pixel_18 = im_pixel[858, 975]
    pixel_19 = im_pixel[220, 1110]
    pixel_20 = im_pixel[350, 1110]
    pixel_21 = im_pixel[470, 1110]
    pixel_22 = im_pixel[595, 1110]
    pixel_23 = im_pixel[730, 1110]
    pixel_24 = im_pixel[858, 1110]
    pixel_25 = im_pixel[220, 1250]
    pixel_26 = im_pixel[350, 1250]
    pixel_27 = im_pixel[470, 1250]
    pixel_28 = im_pixel[595, 1250]
    pixel_29 = im_pixel[730, 1250]
    pixel_30 = im_pixel[858, 1250]
    pixel_31 = im_pixel[220, 1390]
    pixel_32 = im_pixel[350, 1390]
    pixel_33 = im_pixel[470, 1390]
    pixel_34 = im_pixel[595, 1390]
    pixel_35 = im_pixel[730, 1390]
    pixel_36 = im_pixel[858, 1390]
    while True:
        if (250 < pixel_1[0] < 256 and 250 < pixel_1[1] < 256
                and 250 < pixel_1[2] < 256):
            cmd = 'shell input tap 220 695'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_2[0] < 256 and 250 < pixel_2[1] < 256
                and 250 < pixel_2[2] < 256):
            cmd = 'shell input tap 350 695'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_3[0] < 256 and 250 < pixel_3[1] < 256
                and 250 < pixel_3[2] < 256):
            cmd = 'shell input tap 470 695'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_4[0] < 256 and 250 < pixel_4[1] < 256
                and 250 < pixel_4[2] < 256):
            cmd = 'shell input tap 595 695'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_5[0] < 256 and 250 < pixel_5[1] < 256
                and 250 < pixel_5[2] < 256):
            cmd = 'shell input tap 730 695'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_6[0] < 256 and 250 < pixel_6[1] < 256
                and 250 < pixel_6[2] < 256):
            cmd = 'shell input tap 858 695'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_7[0] < 256 and 250 < pixel_7[1] < 256
                and 250 < pixel_7[2] < 256):
            cmd = 'shell input tap 220 835'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_8[0] < 256 and 250 < pixel_8[1] < 256
                and 250 < pixel_8[2] < 256):
            cmd = 'shell input tap 350 835'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_9[0] < 256 and 250 < pixel_9[1] < 256
                and 250 < pixel_9[2] < 256):
            cmd = 'shell input tap 470 835'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_10[0] < 256 and 250 < pixel_10[1] < 256
                and 250 < pixel_10[2] < 256):
            cmd = 'shell input tap 595 835'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_11[0] < 256 and 250 < pixel_11[1] < 256
                and 250 < pixel_11[2] < 256):
            cmd = 'shell input tap 730 835'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_12[0] < 256 and 250 < pixel_12[1] < 256
                and 250 < pixel_12[2] < 256):
            cmd = 'shell input tap 858 835'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_13[0] < 256 and 250 < pixel_13[1] < 256
                and 250 < pixel_13[2] < 256):
            cmd = 'shell input tap 220 975'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_14[0] < 256 and 250 < pixel_14[1] < 256
                and 250 < pixel_14[2] < 256):
            cmd = 'shell input tap 350 975'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_15[0] < 256 and 250 < pixel_15[1] < 256
                and 250 < pixel_15[2] < 256):
            cmd = 'shell input tap 470 975'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_16[0] < 256 and 250 < pixel_16[1] < 256
                and 250 < pixel_16[2] < 256):
            cmd = 'shell input tap 595 975'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_17[0] < 256 and 250 < pixel_17[1] < 256
                and 250 < pixel_17[2] < 256):
            cmd = 'shell input tap 730 975'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_18[0] < 256 and 250 < pixel_18[1] < 256
                and 250 < pixel_18[2] < 256):
            cmd = 'shell input tap 858 975'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_19[0] < 256 and 250 < pixel_19[1] < 256
                and 250 < pixel_19[2] < 256):
            cmd = 'shell input tap 220 1110'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_20[0] < 256 and 250 < pixel_20[1] < 256
                and 250 < pixel_20[2] < 256):
            cmd = 'shell input tap 350 1110'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_21[0] < 256 and 250 < pixel_21[1] < 256
                and 250 < pixel_21[2] < 256):
            cmd = 'shell input tap 470 1110'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_22[0] < 256 and 250 < pixel_22[1] < 256
                and 250 < pixel_22[2] < 256):
            cmd = 'shell input tap 595 1110'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_23[0] < 256 and 250 < pixel_23[1] < 256
                and 250 < pixel_23[2] < 256):
            cmd = 'shell input tap 730 1110'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_24[0] < 256 and 250 < pixel_24[1] < 256
                and 250 < pixel_24[2] < 256):
            cmd = 'shell input tap 858 1110'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_25[0] < 256 and 250 < pixel_25[1] < 256
                and 250 < pixel_25[2] < 256):
            cmd = 'shell input tap 220 1250'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_26[0] < 256 and 250 < pixel_26[1] < 256
                and 250 < pixel_26[2] < 256):
            cmd = 'shell input tap 350 1250'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_27[0] < 256 and 250 < pixel_27[1] < 256
                and 250 < pixel_27[2] < 256):
            cmd = 'shell input tap 470 1250'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_28[0] < 256 and 250 < pixel_28[1] < 256
                and 250 < pixel_28[2] < 256):
            cmd = 'shell input tap 595 1250'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_29[0] < 256 and 250 < pixel_29[1] < 256
                and 250 < pixel_29[2] < 256):
            cmd = 'shell input tap 730 1250'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_30[0] < 256 and 250 < pixel_30[1] < 256
                and 250 < pixel_30[2] < 256):
            cmd = 'shell input tap 858 1250'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_31[0] < 256 and 250 < pixel_31[1] < 256
                and 250 < pixel_31[2] < 256):
            cmd = 'shell input tap 220 1390'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_32[0] < 256 and 250 < pixel_32[1] < 256
                and 250 < pixel_32[2] < 256):
            cmd = 'shell input tap 350 1390'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_33[0] < 256 and 250 < pixel_33[1] < 256
                and 250 < pixel_33[2] < 256):
            cmd = 'shell input tap 470 1390'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_34[0] < 256 and 250 < pixel_34[1] < 256
                and 250 < pixel_34[2] < 256):
            cmd = 'shell input tap 595 1390'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_35[0] < 256 and 250 < pixel_35[1] < 256
                and 250 < pixel_35[2] < 256):
            cmd = 'shell input tap 730 1390'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)
        if (250 < pixel_36[0] < 256 and 250 < pixel_36[1] < 256
                and 250 < pixel_36[2] < 256):
            cmd = 'shell input tap 858 1390'
            print(cmd)
            adb.run(cmd)
            time.sleep(0.01)

        if DEBUG_SWITCH:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x,
                                        board_y)
            debug.backup_screenshot(ts)
        im.close()
        i += 1
Пример #31
0
def main():

    op = yes_or_no(
        'Enter "y" to start if ensure ADB is installed and Jump-Jump is open:')
    if not op:
        print('bye')
        return
    debug.dump_device_info()
    check_screenshot()

    x = tf.placeholder(tf.float32, [None, 51, 86])
    y_conv, keep_prob = CNN_Training.deepnn(x)

    saver = tf.train.Saver()
    sess = tf.Session()
    saver.restore(sess, tf.train.latest_checkpoint('./TF_Saved_Model/'))

    Num = 0
    while (True):
        pull_screenshot()

        im_cv = cv2.imread('./autojump.png')
        im_cvrs = cv2.resize(im_cv,
                             None,
                             fx=ReshapeRatio1,
                             fy=ReshapeRatio1,
                             interpolation=cv2.INTER_CUBIC)
        im_cvrs_back = cv2.resize(im_cv,
                                  None,
                                  fx=ReshapeRatio1,
                                  fy=ReshapeRatio1,
                                  interpolation=cv2.INTER_CUBIC)

        H_org, W_org, _ = im_cv.shape
        H_rs_org, W_rs_org, _ = im_cvrs.shape

        im_cvrs = im_cvrs[250:506, :]

        im_cvrs_cnn = cv2.resize(im_cvrs,
                                 None,
                                 fx=ReshapeRatio2,
                                 fy=ReshapeRatio2,
                                 interpolation=cv2.INTER_CUBIC)
        im_cvrs_cnn_gray = cv2.cvtColor(im_cvrs_cnn, cv2.COLOR_BGR2GRAY)
        cv2.imshow('im_cvrs_cnn_gray', im_cvrs_cnn_gray)

        im_cvrs_cnn_gray = (im_cvrs_cnn_gray - 127) / 255
        x_batch = im_cvrs_cnn_gray[np.newaxis, :, :]
        prediction = sess.run([y_conv], feed_dict={x: x_batch, keep_prob: 1})
        prediction = prediction[0][0]

        piece_x = int(prediction[0] * W_org)
        piece_y = int(prediction[1] * H_org)
        board_x = int(prediction[2] * W_org)
        board_y = int(prediction[3] * H_org)
        print('CNN Predicted Position:\n', piece_x, piece_y, board_x, board_y)

        piece_x_rs = int(prediction[0] * W_rs_org)
        piece_y_rs = int(prediction[1] * H_rs_org)
        board_x_rs = int(prediction[2] * W_rs_org)
        board_y_rs = int(prediction[3] * H_rs_org)

        cv2.circle(im_cvrs_back, (piece_x_rs, piece_y_rs), 15, (255, 0, 0), -1)
        cv2.circle(im_cvrs_back, (board_x_rs, board_y_rs), 15, (0, 0, 255), -1)

        cv2.imshow('Image', im_cvrs_back)
        cv2.waitKey(500)

        ts = int(time.time())
        im = Image.open('./autojump.png')
        set_button_position(im)

        jump(math.sqrt((board_x - piece_x)**2 + (board_y - piece_y)**2))
        if debug_switch:
            debug.save_debug_screenshot(ts, im, piece_x, piece_y, board_x,
                                        board_y)
            debug.backup_screenshot(ts)
        time.sleep(random.uniform(1.9, 2.2))  # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
def main():
    """
    主函数
    """
    op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,'
                   '然后打开跳一跳并【开始游戏】后再用本程序,确定开始?')
    if not op:
        print('bye')
        return
    print('程序版本号:{}'.format(VERSION))
    debug.dump_device_info()
    screenshot.check_screenshot()

    i, next_rest, next_rest_time = (0, random.randrange(3, 10),
                                    random.randrange(5, 10))
    j= 0
    ################ 分数曲线公式

    y_score=[]
    next_start=0
    global start_score
    for i in range(total_step):
        each_score=target_score*(1-np.exp(-0.15*(1024.0/target_score)*i))
        y_score.append(each_score)
        if start_score>each_score:
            next_start=i
    next_start+=1
    #print(y_score)
    if start_score<y_score[0]:
        next_start=0

    ###################
    with tf.Session() as sess:
        saver = tf.train.import_meta_graph('./resource/model/model.ckpt.meta')
        saver.restore(sess,tf.train.latest_checkpoint('./resource/model/'))

        graph = tf.get_default_graph()
        x = graph.get_tensor_by_name("x:0")
        logits = graph.get_tensor_by_name("logits_eval:0")
    #####################识别分数
        while True:
            screenshot.pull_screenshot()
            im = Image.open('./autojump.png')
            ##比例系数
            pix_w=im.size[0]*1.0/1080
            pix_h=im.size[1]
            region=im.crop((0,pix_h*0.1,460*pix_w,pix_h*0.2))
            region=region.convert('L')
            start_h,end_h,pixels_Widh=pixel_division(region,int(460*pix_w),int(pix_h*0.1))
            if start_h==end_h:
                continue
            data = []
            for i in range(len(pixels_Widh)-1):
                region1=region.crop((pixels_Widh[i],start_h,pixels_Widh[i+1],end_h))
                region1.putdata(pross_data(region1))
                str1="./region"+str(i)+".png"
                region1.save(str1)
                data1 = read_one_image(str1)
                data.append(data1)
            feed_dict = {x:data}
            classification_result = sess.run(logits,feed_dict)
            output = []
            output = tf.argmax(classification_result,1).eval()
            m_score=""
            for i in range(len(output)):
                m_score+=strint(output[i])
            if m_score=="":
                continue
            m_score=int(m_score)
            print('score:{}'.format(m_score))
            ####################################
            # 获取棋子和 board 的位置
            print(j)
            piece_x, piece_y, board_x, board_y = find_piece_and_board(im)
            ts = int(time.time())
            print(ts, piece_x, piece_y, board_x, board_y)
            set_button_position(im)

            if m_score > y_score[next_start]: ##自动结束这一次
                print("----------------")
                jump(math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2)*5)
                next_start+=1
                time.sleep(5*random.random())
            if next_start >len(y_score):
                break
            jump(math.sqrt((board_x - piece_x) ** 2 + (board_y - piece_y) ** 2))
            if DEBUG_SWITCH:
                debug.save_debug_screenshot(ts, im, piece_x,
                                            piece_y, board_x, board_y)
                debug.backup_screenshot(ts)
            im.close()
            i += 1
            j += 1
            if i == next_rest:
                print('已经连续打了 {} 下,休息 {}s'.format(i, next_rest_time))
                for j in range(next_rest_time):
                    sys.stdout.write('\r程序将在 {}s 后继续'.format(next_rest_time - j))
                    sys.stdout.flush()
                    time.sleep(1)
                print('\n继续')
                i, next_rest, next_rest_time = (0, random.randrange(30, 100),
                                                random.randrange(10, 60))
            # 为了保证截图的时候应落稳了,多延迟一会儿,随机值防 ban
            time.sleep(random.uniform(0.9, 1.2))
Пример #33
0
def find_piece_and_board(im, r=False):
    '''
    寻找关键坐标
    '''
    w, h = im.size

    piece_x = 0
    piece_y = 0
    board_x = 0
    board_y = 0
    scan_start_y = int(h / 3)  # 扫描的起始 y 坐标
    scan_stop_y = int(h * 2 / 3)  # 扫描的终止 y 坐标
    scan_start_x = int(w / 9)  # 扫描的起始 x 坐标
    scan_stop_x = int(w * 8 / 9)  # 扫描的终止 y 坐标
    im_pixel = im.load()
    #get 图片中一个紫色坐标
    for x in range(scan_stop_x, scan_start_x, -50):
        for y in range(scan_stop_y, scan_start_y, -100):
            if pipei([57, 50, 89], im_pixel[x, y], 15):
                break
        else:
            continue
        break
    #print('qizi',x,y)
    #get 左边缘
    yuan = im_pixel[x, y]
    for x1 in range(x, scan_start_x, -1):
        if not pipei(yuan, im_pixel[x1, y], 15):
            for yp in range(-10, 15, 1):
                if pipei(yuan, im_pixel[x1, y + yp], 15):
                    y = y + yp
                    break
            else:
                break
        yuan = im_pixel[x1, y]
    x = x1 + 1

    yuan = im_pixel[x, y]
    for y1 in range(y, y + 10, 1):
        if not pipei(yuan, im_pixel[x, y1], 15):
            break
        yuan = im_pixel[x, y1]
    y = y1 - 1
    #get 右边缘
    yuan = im_pixel[x, y]
    for x1 in range(x, scan_stop_x, 1):
        if not pipei(yuan, im_pixel[x1, y], 15):
            break
        yuan = im_pixel[x1, y]
    x1 -= 1
    #左边缘x,y 右边缘 x1,y
    zx = x
    yx = x1
    piece_w = x1 - x
    piece_x = (x + x1) / 2
    piece_y = y
    #棋子ok
    print('qizi', piece_x, piece_y)
    if r == True:
        return piece_x, piece_y

    #贴边法 140,70 取70,35
    for y in range(scan_start_y, scan_stop_y, 35):
        bj_ys = im_pixel[10, y]
        for x in range(scan_stop_x, scan_start_x, -70):
            #print(x,y)
            if bj_ys != im_pixel[x, y] and not zx < x < yx:
                break  #找到方块上点 x,y
        else:
            continue
        break
    print('suid', x, y, bj_ys, im_pixel[x, y])

    #上点(最后一个,同背景色)
    for y1 in range(y, y - 35, -1):
        if im_pixel[x, y1] == im_pixel[10, y1]:
            break

    print('sd', x, y1)
    for y in range(y1, y1 - 150, -1):
        for xp in range(0, 10):
            #print(x,xp,y)
            if im_pixel[x + xp, y] != im_pixel[10, y]:
                x += xp
                break
            if im_pixel[x - xp, y] != im_pixel[10, y]:
                x -= xp
                break
        else:
            break

    #x,y 最高的(beijingse)
    y += 1
    zuo = 0
    you = 0
    for xp in range(0, 15):
        if im_pixel[x + xp, y] != im_pixel[10, y]:
            you = xp

        if im_pixel[x - xp, y] != im_pixel[10, y]:
            zuo = xp
    dx = (zuo + you) / 2 + x

    #dx,y 顶点
    syb = y
    print("顶点", dx, y)
    for xp in range(0, 340):
        #int((300-xp)/269*156)
        for yp in range(0, 10):
            #print([dx-xp,y+yp])
            if im_pixel[dx - xp, y + yp] != im_pixel[10, y + yp]:
                #print("bu")
                if pipei2(im_pixel[10, y + yp], im_pixel[dx - xp, y + yp]):

                    continue
                y += yp - 1
                break
        else:
            break

    # x-xp,y+yp 左点
    zx = dx - xp
    zy = y
    print("zuo点", zx, zy)
    sy = syb
    for xp in range(0, 340):
        for yp in range(0, 5):
            if im_pixel[dx + xp, sy + yp] != im_pixel[10, sy + yp]:
                sy += yp - 1
                break
        else:
            break
    yx = dx + xp
    yy = sy
    #右点
    print("you点", yx, yy)
    ts = int(time.time())
    debug.save_debug_screenshot(ts, im, piece_x, piece_y, int((zx + yx) / 2),
                                int((zy + yy) / 2))
    return abs((zx + yx) / 2 - piece_x)
    '''