This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathios_jump.py
68 lines (55 loc) · 1.83 KB
/
ios_jump.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
# coding: u8
from __future__ import print_function, unicode_literals
import itertools
import time
import os.path as osp
import traceback
import numpy
import wda
from libjump import Otsu, run_cmd, create_screenshot_directory
# Please install iOS environment
# https://testerhome.com/topics/10466
# directory where screenshot image will be saved in.
# if you use Windows, e.g 'c:/wechat_micro_jump_game_screenshot'
screenshot_directory = '/tmp/wechat_micro_jump_game_screenshot'
create_screenshot_directory(screenshot_directory)
ios = wda.Client('http://localhost:8100')
ios_session = ios.session()
jump_times = itertools.count(0)
while True:
try:
debug = False
if debug:
# your last failed image name
fn = '0.png'
fp = osp.join(screenshot_directory, fn)
else:
fn = str(next(jump_times)) + '.png'
fp = osp.join(screenshot_directory, fn)
t1 = time.time()
ios.screenshot(fp)
t2 = time.time()
print('time of screenshot', t2 - t1)
print(fp)
otsu = Otsu(fp, debug, 2.0)
holding = otsu.get_holding() / 1000.
if debug:
raise KeyboardInterrupt
else:
rand_x = lambda: numpy.random.randint(0, otsu.w)
rand_y = lambda: numpy.random.randint(otsu.h / 2, otsu.h * 3 / 4)
x1, y1 = rand_x(), rand_y()
x2, y2 = rand_x(), rand_y()
t1 = time.time()
ios_session.tap_hold(x1, y1, holding)
t2 = time.time()
print('time of tap', t2 - t1)
sleep_time = .7
time.sleep(sleep_time)
print('sleeping seconds', sleep_time)
print()
except KeyboardInterrupt:
raise KeyboardInterrupt
except:
traceback.print_exc()
time.sleep(2)