forked from harvitronix/reinforcement-learning-car
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playing.py
38 lines (26 loc) · 818 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
"""
Once a model is learned, use this to play it.
"""
from flat_game import carmunk
import numpy as np
from nn import neural_net
NUM_SENSORS = 3
def play(model):
car_distance = 0
game_state = carmunk.GameState()
# Do nothing to get initial.
_, state = game_state.frame_step((2))
# Move.
while True:
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)
if __name__ == "__main__":
saved_model = 'saved-models/164-150-100-50000-25000.h5'
model = neural_net(NUM_SENSORS, [164, 150], saved_model)
play(model)