-
Notifications
You must be signed in to change notification settings - Fork 202
/
playing.py
38 lines (26 loc) · 817 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/128-128-64-50000-50000.h5'
model = neural_net(NUM_SENSORS, [128, 128], saved_model)
play(model)