-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dinosaur.py
76 lines (61 loc) · 1.34 KB
/
Dinosaur.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
"""
Dino(action)
performs action decided in DecisionMaker.py and saved in action array
check outcome (dead or not)
restarts the game if dead
return reward depending on dead or not
"""
import pyautogui
import time
def jump():
"""
Jump over the obstacle
:return: None
"""
pyautogui.keyDown('up')
def unJump():
"""
Stop pressing the jump key
:return: None
"""
pyautogui.keyUp('up')
def duck():
"""
Get on the ground /!\ the dino stays down with this function
:return: None
"""
pyautogui.keyDown('down')
def unDuck():
"""
Get the dino up
:return: None
"""
pyautogui.keyUp('down')
def restart():
"""
restart the game when the dino is dead
:return: None
"""
restart_coords = (490, 465)
pyautogui.click(restart_coords)
def checkState(arr):
"""
Check if the dino is still running
:parameter: arr, the 16x4 array of the last image
:return: True if it does, False otherwise
"""
alive = True
if arr[1][7] < 200 and arr[2][7] < 200:
alive = False
return alive
def resetWebPage():
"""
Refreshes the webpage
:return: None
"""
refresh_button_coords = (110, 75)
pyautogui.click(refresh_button_coords)
time.sleep(10)
pyautogui.keyDown('up')
pyautogui.keyUp('up')
time.sleep(10)