-
Notifications
You must be signed in to change notification settings - Fork 61
/
dino_automation.py
76 lines (51 loc) · 1.63 KB
/
dino_automation.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
# This script uses the automation to play the Dino Game which pops into Google Browser when Internet is not connected
# 1. Run this Game
# 2. Within 3 seconds switch your screen to the browser tab while letting the program run
# 3. The most important step: ! ENJOY !
import pyautogui # pip install pyautogui
from PIL import Image, ImageGrab # pip install pillow
# from numpy import asarray
import time
def hit(key):
pyautogui.keyDown(key)
def isCollide(data):
# Draw the rectangle for birds
for i in range(660, 700):
for j in range(190,230):
if data[i, j] < 100:
hit("down")
return
for i in range(660, 730):
for j in range(240, 290):
if data[i, j] < 100:
hit("up")
return
return
if __name__ == "__main__":
print("Hey.. Dino game about to start in 3 seconds")
time.sleep(2)
hit('up')
while True:
image = ImageGrab.grab().convert('L')
data = image.load()
isCollide(data)
# the code below is to make the rectangle visible
#image.show()
#isCollide(data)
#im2=ImageGrab.grab(bbox=(300, 415,410, 563)).convert('L')
#im2.show()
#print(im2.getextrema())
#isCollide(data)
# print(asarray(image))
'''
# Draw the rectangle for cactus
for i in range(275, 325):
for j in range(563, 650):
data[i, j] = 0
# Draw the rectangle for birds
for i in range(250, 300):
for j in range(410, 563):
data[i, j] = 171
image.show()
break
'''