forked from rahulray11/github-fest-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutomated Bot For Chrome's Dino Game.py
57 lines (51 loc) · 1.4 KB
/
Automated Bot For Chrome's Dino Game.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
import keyboard
from PIL import ImageGrab
import time
def hit(key):
keyboard.press(key)
time.sleep(0.5)
keyboard.release(key)
def collide(data,color):
if color == 0: # For white screen
for i in range(270, 300):
for j in range(380, 440):
if data[i,j] < 100:
hit('up')
return
elif color == 1: # For black screen
for i in range(270, 300):
for j in range(380, 440):
if data[i,j] > 100:
hit('up')
return
return
def bird(data,color):
if color ==0 :
for i in range(320, 350):
for j in range(330, 375):
if data[i, j] < 100:
hit('down')
return
elif color == 1:
for i in range(320, 350):
for j in range(330, 375):
if data[i, j] > 100:
hit('down')
return
return
def color(data):
for i in range(100, 140):
for j in range(100, 140):
if data[i, j] < 100:
return(1)
return(0)
if __name__ == '__main__':
print('Game is about to start in 5 seconds !')
time.sleep(5)
hit('up')
while True:
image = ImageGrab.grab().convert('L')
data = image.load()
val = color(data)
bird(data,val)
collide(data,val)