"""
Once a model is learned, use this to play it.
"""

import game
import numpy as np
from neuralnet import neural_net

NUM_SENSORS = 3


def play(model):

    car_distance = 0
    game_state = game.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)
