# 微信小游戏“跳一跳” 用Python运行脚本编写

def screenshot():

cmd = 'adb shell screencap -p /sdcard/1.png'

os.system(cmd)

os.system(cmd)12345

#开始查找棋子的坐标，从start_y开始据目测棋子不会位于屏幕底部1/3处for i in range(start_y, int(height * 2 / 3)): for j in range(border_x, width - border_x): #删除周围空白部分，加快程序运行速度

next_point = im[j,i] # 根据棋子的颜色判断，求所有点的和然后求平均值

if (50

x1_temp += j #点求和

x1_num += 1 #点的个数

y1_max = max(i, y1_max)if not all((x1_temp,x1_num)): return 0,0,0,0x1 = x1_temp / x1_num

y1 = y1_max - piece_height/2 # 棋子Y轴坐标上移到底盘高度的一半1234567891011121314

#查找下一个棋盘的位置for i in range(start_y, height * 2 / 3):

start_point = im[0, i] if x2 or y2: break

x2_temp = 0

x2_num = 0

for j in range(width):

next_point = im[j,i] if abs(j - x1)

# 棋盘为圆

if abs(next_point[0] - start_point[0]) + abs(next_point[1] - start_point[1]) + abs(next_point[2] - start_point[2]) > 10:

x2_temp += j

x2_num += 1

if x2_temp:

x2 = x2_temp / x2_num# 按实际的角度通过tan值来算计算下一个棋盘的中心点的Y轴坐标y2 = y1 - abs(x2 - x1) * abs(sample_y1 - sample_y2) / abs(sample_x1 - sample_x2)if not all((x2, y2)): return 0, 0, 0, 0123456789101112131415161718192021222324

#跳到下一个棋盘def jump(distance):

press_time = distance * press

press_time = max(press_time, 200) # 设置最小的按压时间位200ms

press_time = int(press_time)

cmd = 'adb shell input swipe {} {} {} {} {}'.format(swipe_x1, swipe_y1, swipe_x2, swipe_y2, press_time)

print(cmd)

os.system(cmd)12345678

• 发表于:
• 原文链接：http://kuaibao.qq.com/s/20180107A061GN00?refer=cp_1026
• 腾讯「云+社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。

2019-03-24

2019-03-24

2018-05-31

2019-03-24

2019-03-24

2019-03-24

2019-03-24

2019-03-24