通过百度和书籍了解了python的基本语法和一些相关知识,配置一些环境也花了很多时间,然后终于终于写出来辣(*/∇\*)虽然图像识别部分的算法写的很low,但是用起来效果不错,四五百分不是问题。
python的库很全面方便,使得代码很短。
主要步骤
1.配置好python的运行环境
下载地址:https://www.python.org/downloads/release/python-2715
2.设置环境变量(百度)
3.安装pip模块:
按windows+R键,输入cmd,在弹出的窗口分两次输入:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py
4.用pip安装其他包:
还是在上面的窗口输入:
pip install Pillow
安装其他包同理。
5.下载IDE软件Pycharm(不下也行),新建项目,把下面的代码粘贴进去:
import os
import time
import math
import random
from PIL import Image
fix = 0
x = 8102 # 命名
while True:
x = x + 1
os.system('adb shell screencap -p /storage/emulated/0/' + str(x) + '.png') # 截图保存
os.system('adb pull /storage/emulated/0/' + str(x) + '.png') # 提取截图
img = Image.open(str(x) + '.png') # 打开图像并转化为数字矩阵
px = img.load() # 加载图像
e1 = e2 = s1 = s2 = 0
for i in range(400, 1500):
a = px[5, i]
for j in range(50, 1000):
b = px[j, i]
if abs(a[0]-b[0]) > 15 or abs(a[1]-b[1]) > 15 or abs(a[2]-b[2]) > 15:
break
if abs(a[0] - b[0]) > 15 or abs(a[1] - b[1]) > 15 or abs(a[2] - b[2]) > 15:
break
e1 = j
e2 = i + 106 - fix
a = (40, 40, 70, 255)
for j in range(20, 1050):
for i in range(480, 1440):
b = px[j, i]
if abs(a[0]-b[0]) < 10 and abs(a[1]-b[1]) < 10 and abs(a[2]-b[2]) < 10:
break
if abs(a[0] - b[0]) < 10 and abs(a[1] - b[1]) < 10 and abs(a[2] - b[2]) < 10:
break
s1 = j+35
s2 = i+5
dis = (s1-e1)*(s1-e1) + (s2-e2)*(s2-e2)
dis = math.sqrt(dis)
t = int(376.0 * dis / 270)
if t > 910:
t = 910
if (t < 400) and (t > 330):
t = int(t * 1.12)
if t < 330:
t = 330
print('起点:', s1, ' ', s2, ' 终点:', e1, ' ', e2, ' 距离:', int(dis))
print('按压时长:', float(t / 1000.0), '秒 ')
x1 = random.randint(500, 800) # 随机按压位置
y1 = random.randint(1580, 1590)
os.system('adb shell input swipe ' + str(x1) + ' ' + str(y1) + ' ' + str(x1 + 1) + ' ' + str(y1 + 1) + ' ' + str(t))
time.sleep(2)
保存(当然你也可以用文档写,最后把后缀改成.py就可以了)
6.安装adb命令。(百度)
4.用usb线把电脑连接到手机,打开usb调试,微信打开跳一跳界面。
5.在pycharm里的代码窗口界面同时按Shift+Ctrl+Fn+F10运行程序(没下载的话在cmd窗口输入:python 文件目录/文件名.py)
运行效果图:
不知道怎么的,居然会被程序发现不是真人玩家,分数不会进排行榜,就当开心了