Skip to content

Instantly share code, notes, and snippets.

@llSourcell
Created August 3, 2016 19:24
Show Gist options
  • Select an option

  • Save llSourcell/743c82771c5aca4c915e5534014c97ea to your computer and use it in GitHub Desktop.

Select an option

Save llSourcell/743c82771c5aca4c915e5534014c97ea to your computer and use it in GitHub Desktop.
"""
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment