借鉴:  一百行代码实现微信跳一跳

之前需要安装adb

开启服务:

adb nodaemon server

显示设备:

adb devices

代码:

import math

import os

import tempfile

import time

from functools import reduce

from PIL import Image

BACKGROUND_POS = (, )

DISTANCE_TO_TIME_RATIO = 1.35

SCREENSHOT_PATH = tempfile.gettempdir() + "/screenshot.png"

def calculate_jump_distance():

    im = Image.open(SCREENSHOT_PATH)

    background_rgb = im.getpixel(BACKGROUND_POS)

    role_pos_list = None

    vertex1_pos = None

    block_background_rgb = None

    vertex2_pos = None

    role_line_flag = True

    for y in range(BACKGROUND_POS[], im.height):

        if role_pos_list and role_line_flag:

            break

        role_line_flag = True

        vertex2_line_flag = True

        for x in range(BACKGROUND_POS[], im.width):

            current_rgb = im.getpixel((x, y))

            next_rgb = im.getpixel((x + , y)) if x +  < im.width else (, , )

            # 识别顶点1

            if x > BACKGROUND_POS[] and y > BACKGROUND_POS[] and not vertex1_pos 

                    and not is_similar(background_rgb, current_rgb) and is_similar(current_rgb, next_rgb):

                vertex1_pos = (x, y)

                block_background_rgb = current_rgb

            # 识别顶点2

            if block_background_rgb and vertex2_line_flag and is_similar(current_rgb, block_background_rgb, ):

                vertex2_line_flag = False

                if vertex2_pos:

                    if x < vertex2_pos[] and vertex2_pos[] - x <  and y - vertex2_pos[] < :

                        vertex2_pos = (x, y)

                else:

                    vertex2_pos = (x, y)

            # 识别小人

            if is_part_of_role(current_rgb):

                if role_line_flag:

                    role_pos_list = []

                    role_line_flag = False

                role_pos_list.append((x, y))

    if len(role_pos_list) == :

        raise Exception('无法识别小人位置!!!')

    pos_sum = reduce((lambda o1, o2: (o1[] + o2[], o1[] + o2[])), role_pos_list)

    role_pos = (int(pos_sum[] / len(role_pos_list)), int(pos_sum[] / len(role_pos_list)))

    destination_pos = (vertex1_pos[], vertex2_pos[])

    return int(linear_distance(role_pos, destination_pos))

def is_part_of_role(rgb):

    return  < rgb[] <  and  < rgb[] <  and  < rgb[] < 

def linear_distance(xy1, xy2):

    return math.sqrt(pow(xy1[] - xy2[], ) + pow(xy1[] - xy2[], ))

def is_similar(rgb1, rgb2, degree=):

    return abs(rgb1[] - rgb2[]) <= degree and abs(rgb1[] - rgb2[]) <= degree and abs(rgb1[] - rgb2[]) <= degree

def screenshot():

    os.system("adb shell screencap -p /mnt/sdcard/screencap.png")

    os.system("adb pull /mnt/sdcard/screencap.png {} >> {}/jump.out".format(SCREENSHOT_PATH, tempfile.gettempdir()))

def jump(touch_time):

    os.system("adb shell input swipe 0 0 0 0 {}".format(touch_time))

def distance2time(distance):

    return int(distance * DISTANCE_TO_TIME_RATIO)

if __name__ == '__main__':

    count = 

    while True:

        screenshot()

        distance = calculate_jump_distance()

        touch_time = distance2time(distance)

        jump(touch_time)

        print("#{}: distance={}, time={}".format(count, distance, touch_time))

        count += 

        time.sleep()

python链接安卓 跳一跳的更多相关文章

  1. python如何玩“跳一跳”!(windows安桌版本请进!)

    最近"跳一跳",很火爆,有木有? 看了一下网上的教程,动作搭建了一下环境,就可以用脚本自动跑起来啦!!! 下面说一下android手机的实现过程: 首先,是python环境的搭建 ...

  2. 利用Python玩微信跳一跳

    创建python项目jump_weixin,新建python程序jump.py 需要4个辅助文件[adb.exe,AdbWinApi.dll,AdbWinUsbApi.dll,fastboot.exe ...

  3. 【辅助工具】Python实现微信跳一跳

    最近迷上了微信跳一跳小游戏,正好也看到知乎上有大神分享了技术贴,我也参考了好多资料,原理就是通过abd命令截取图片,python计算两个点距离,然后转化按压时间,让电脑来完成游戏.我花了很长时间才把程 ...

  4. Python操作微信跳一跳

    “跳一跳”这个东西还是今天刚接触到的,看到了python群中有人再问“微信跳一跳的外挂有人写了没”,“早就有了”,“github”,“等着出个更详细的教程教程没看懂,主要没有用过adb”. 不过没关系 ...

  5. Python版本微信跳一跳,软件配置

    一.安装python3的环境: 直接从python官方网站下载python3的安装包,直接安装. 记得将python3放到PATH环境变量中,安装的过程中在该配置地方打钩就可以了. 如果安装的过程中出 ...

  6. 使用python编写微信跳一跳的自动脚本

    实现思路: 调用adb命令,截图 寻找小小人的底部中心点role(从下到上扫描,直到找到小小人相同像素的点,至于小小人像素点rgb是什么,可以使用photoshop查看) 寻找棋盘最高点top,然后寻 ...

  7. Python 帮你玩微信跳一跳 GitHub Python脚本

    前言想自己搞游戏小程序的 在github 有人已经利用 python程序, 通过adb 获取不同型号安卓手机的系统截图,然后通过计算小人与目标位置距离之后得到准确的触摸时间,再通过 开发者模式里的 a ...

  8. PYTHON 实现的微信跳一跳【辅助工具】仅作学习

    备注原地址:https://my.oschina.net/anlve/blog/1604163 我又做了一些优化,防止WX检测作弊 准备环境: Windows 10安卓手机,源码中有适配ios,然后链 ...

  9. 微信跳一跳Python辅助无需配置一键操作

    作者:NiceCui 本文谢绝转载,如需转载需征得作者本人同意,谢谢. 本文链接:http://www.cnblogs.com/NiceCui/p/8350329.html 邮箱:moyi@moyib ...

随机推荐

  1. .net core 的优点

    [1]为什么使用.net core 首先.net core 是一个跨平台的高性能开源框架用具生成基于云连接的Internet的新的应用程序,可以建造web应用程序和服务,lot应用和移动后端,可以在W ...

  2. 《The One!团队》第一次作业:团队亮相

    项目 内容 作业所属课程 http://www.cnblogs.com/nwnu-daizh/ 作业要求 https://www.cnblogs.com/nwnu-daizh/p/10687492.h ...

  3. CentOS&.NET Core初试-4-安装守护服务(Supervisor)

    系列目录 CentOS的安装和网卡的配置 安装.NET Core SDK和发布网站 Nginx的安装和配置 安装守护服务(Supervisor) Supervisor是什么? Supervisor 是 ...

  4. Linux -定时任务调度

    l crond 任务调度   crontab 进行定时任务的设置,. 概述 任务调度:是指系统在某个时间执行的特定的命令或程序. 任务调度分类:1.系统工作:有些重要的工作必须周而复始地执行.如病毒扫 ...

  5. CSAPP阅读笔记-汇编语言初探(控制类指令)-来自第三章3.6的笔记-P135-P163

    1.正溢出与负溢出: 首先,一个正数与一个负数相加,不可能溢出,因为结果的绝对值一定小于两个加数的绝对值,既然两个加数能合理表示出来,结果一定也能合理表示出来. 其次,正溢出是由于两个很大的正数相加, ...

  6. python fileinput处理多文件

    import fileinput with fileinput.input(files=(path1,path2)) as f: for line in f: print(line)

  7. 《大数据日知录》读书笔记-ch15机器学习:范型与架构

    机器学习算法特点:迭代运算 损失函数最小化训练过程中,在巨大参数空间中迭代寻找最优解 比如:主题模型.回归.矩阵分解.SVM.深度学习 分布式机器学习的挑战: - 网络通信效率 - 不同节点执行速度不 ...

  8. (转)python之os,sys模块详解

    python之sys模块详解 原文:http://www.cnblogs.com/cherishry/p/5725184.html sys模块功能多,我们这里介绍一些比较实用的功能,相信你会喜欢的,和 ...

  9. PHP面向对象的基本思路

    第一步:识别对象 ——任何实体都可以被识别为一个对象 第二步:识别对象的属性 ——对象里面存储的数据被识别为属性 ——对于不同的业务逻辑,关注的数据不同,独享里面存储的属性也不同 第三步:识别对象的行 ...

  10. CentOS 6.5中配置RabbitMQ

    先配置erlang依赖环境 yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel 安装erlang 1 ...