-
Notifications
You must be signed in to change notification settings - Fork 4
/
run.py
75 lines (64 loc) · 2.77 KB
/
run.py
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
from adb import PyADB
from cap import Cap
from PIL import Image
import cv2
import numpy as np
import time
from GameMapping.Board import Board
from GameMapping.Block import Block
from Analysis.TripleAnalyze import TripleAnalyze
# 请根据实际情况修改以下配置项
# ------------------------------------------------------------------------------
ADB_DEVICE_SERIAL = "d82f4a2e" # adb devices 命令得到的手机序列号
SHOW_MARKED_IMG = False # 展示标注数据的 RGB 图像
DEBUG = False
# ------------------------------------------------------------------------------
if __name__ == '__main__':
# 参数定义
blockSize = (126, 116)
sampleSize = (100, 100)
block = Block(
blockSize,
(blockSize[0] // 2 - sampleSize[0] // 2, blockSize[1] // 2 -
sampleSize[1] // 2, sampleSize[0], sampleSize[1]))
board = Board((7, 7), (698, 137), block, 0.9)
for round in range(30):
print(f"round: {round+1}")
# adb 初始化
adb = PyADB(ADB_DEVICE_SERIAL)
if DEBUG:
# 加载截图
# img = Image.open("cap.png") # pillow read image file
img = cv2.imread("cap.png",
cv2.IMREAD_COLOR) # openCV read image file
print(img.shape)
# img = cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR) # 从pillow image转换为cv image
# img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) # 从opencv image转换为pillow image
# img.show()
else:
# 屏幕截图
cap = Cap()
img = cap.screencap(adb)
img = cv2.cvtColor(np.asarray(img),
cv2.COLOR_RGB2BGR) # 从pillow image转换为cv image
#cv2.imwrite('start.png', img)
# 冗余操作,用于点击按钮
adb.short_tap((300, 1455)) # retry
adb.short_tap((540, 1430)) # begin
# 刷新面板
board.Update(img)
# 分析最佳三连情况
triple = TripleAnalyze()
result = triple.Analyze(board.BlockAreaFlags)
# 执行三连
if (result[0] is not None):
swipeFrom = board.GetlocationOfBlockMap(result[0])[::-1] # x,y 格式
swipeTo = board.GetlocationOfBlockMap(result[2])[::-1] # x,y 格式
swipeFrom = (board.BlockAreaLocation[1] + swipeFrom[0] +
board.Block.Size[1] // 2, board.BlockAreaLocation[0] +
swipeFrom[1] + board.Block.Size[0] // 2)
swipeTo = (board.BlockAreaLocation[1] + swipeTo[0] +
board.Block.Size[1] // 2, board.BlockAreaLocation[0] +
swipeTo[1] + board.Block.Size[0] // 2)
adb.swipe_tap(swipeFrom, swipeTo)
time.sleep(0)