-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaying.py
44 lines (32 loc) · 977 Bytes
/
playing.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
"""
Once a model is learned, use this to play it.
"""
from game import main
import pygame
import numpy as np
from nn import neural_net
NUM_SENSORS = 17
def play(model):
car_distance = 0
game_state = main.GameState()
# Do nothing to get initial.
_, state = game_state.frame_step((2))
exit = False
# Move.
while not exit:
car_distance += 1
# Choose action.
action = (np.argmax(model.predict(state, batch_size=1)))
# Take action.
_, state = game_state.frame_step(action)
# Tell us something.
if car_distance % 1000 == 0:
print("Current distance: %d frames." % car_distance)
# Event queue
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit = True
if __name__ == "__main__":
saved_model = 'saved-models/320-320-1000-50000-100000.h5'
model = neural_net(NUM_SENSORS, [320, 320], saved_model)
play(model)