火影忍者手游心转身练习自动化脚本

学了Python,游戏也该自动化了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import json
from io import BytesIO
from time import sleep
# pip install Pillow, pyautogui
import pyautogui
from PIL import Image, ImageGrab
# pip install baidu-aip
from aip import AipOcr

numberlist = [(550, 750), (630, 750), (710, 750), (790, 750), (870, 750), (950, 750), (1030, 750), (1110, 750), (1190, 750), (1270, 750), (1413, 785)]
# 百度API的客户端
def getClient():
""" 你的 APPID AK SK """
APP_ID = 'xxx'
API_KEY = 'xxx'
SECRET_KEY = 'xxxx'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
return client

def click(num : str):
for c in num:
pyautogui.click(*numberlist[int(c)])
sleep(0.1)
pass
pyautogui.click(*numberlist[10])
sleep(0.5)

def base(difficuty):
max = None
if difficuty == 1:
max = 100
elif difficuty == 2:
max = 1000
elif difficuty == 3:
max = 10000
else:
return
bbox = (1300, 286, 1500, 314)
client = getClient()
min = 0
while True:
cur = (max + min) // 2
s = str(cur)
while len(s) != difficuty + 1:
s = "0" + s
click(s) # 二分查找
# 获取屏幕截图,并转换为JPG
img = ImageGrab.grab(bbox).convert('RGB')
# img.show()
buffer = BytesIO()
img.save(buffer, format='JPEG')
res = client.basicGeneral(buffer.getvalue())
assert res["words_result_num"] == 1
res = res["words_result"][0]["words"]
print("min = ", min, ", max = ", max, ", cur = ", cur, sep = "", end="")
if "小" in res.strip():
print(", 过小", end="\n")
min = cur + 1
elif "大" in res.strip():
print(", 过大", end="\n")
max = cur - 1
else:
return


def first():
base(1)

def second():
base(2)

def third():
base(3)

if __name__ == "__main__":
third()
作者

Uchiha Kakashi

发布于

2019-12-15

更新于

2019-12-26

许可协议