-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathsimon.py
executable file
·88 lines (66 loc) · 1.91 KB
/
simon.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
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
from ppadb.client import Client
import numpy
import time
from mss import mss
adb = Client(host='127.0.0.1', port=5037)
devices = adb.devices()
if len(devices) == 0:
print('no device attached')
quit()
device = devices[0]
device.shell('input tap 532 957')
time.sleep(.5)
g = { 'left': 2750, 'top': 1790, 'width': 1, 'height': 1 }
y = { 'left': 2750, 'top': 2500, 'width': 1, 'height': 1 }
r = { 'left': 3120, 'top': 1790, 'width': 1, 'height': 1 }
b = { 'left': 3120, 'top': 2500, 'width': 1, 'height': 1 }
sct = mss()
def detect_next():
detecting = False
while True:
time.sleep(.1)
green_pixel = numpy.array(sct.grab(g))
yellow_pixel = numpy.array(sct.grab(y))
red_pixel = numpy.array(sct.grab(r))
blue_pixel = numpy.array(sct.grab(b))
green_r = green_pixel[0][0][2]
yellow_r = yellow_pixel[0][0][2]
red_r = red_pixel[0][0][2]
blue_r = blue_pixel[0][0][2]
if not detecting and \
green_r > 10 and \
yellow_r > 10 and \
red_r > 10 and \
blue_r > 10:
detecting = True
if not detecting:
continue
if 1 <= green_r <= 10:
return 'g'
if 1 <= yellow_r <= 10:
return 'y'
if 1 <= red_r <= 10:
return 'r'
if 1 <= blue_r <= 10:
return 'b'
moves = 1
colors = []
while True:
for i in range(moves):
color = detect_next()
print(f'detected {color}')
colors.append(color)
print(colors)
time.sleep(1)
for color in colors:
if color == 'g':
device.shell('input tap 300 450')
if color == 'y':
device.shell('input tap 300 1450')
if color == 'r':
device.shell('input tap 800 450')
if color == 'b':
device.shell('input tap 800 1450')
moves += 1
colors = []