-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
62 lines (43 loc) · 1.42 KB
/
main.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
import time
import mss as mss
from pynput.mouse import Button, Controller
import keyboard
import pyautogui
mouse = Controller()
from FlappyBirdEnv import FlappyGame
width = 0
height = 0
top = 0
left = 0
game_location = 0
time.sleep(1)
################ CHECK GAME SCREEN TO START GAME #################
# Find game window
result = None
try:
if pyautogui.locateOnScreen('GameScreen.png', confidence=0.6) is not None:
print("Game button found")
result = pyautogui.locateOnScreen('GameScreen.png', confidence=0.6)
except:
print("Game Screen Not Found")
if result is not None:
print("Game screen found, program starting...")
left, top, width, height = result
print(f"Left: {left}, Top: {top}, Width: {width}, Height: {height}")
else:
print("Game not found, program not started")
#############################################################################
env = FlappyGame(width, height, top, left)
env.reset()
while not keyboard.is_pressed('q'):
# Random play
for episode in range(100):
obs = env.reset()
terminated = False
total_reward = 0
while not terminated:
obs, reward, terminated, truncated , info = env.step(env.action_space.sample())
total_reward += reward
# env.render()
# time.sleep(0.001)
print('Total Reward for episode {} is {}'.format(episode, total_reward))