Created
July 8, 2018 16:07
-
-
Save simoninithomas/fd077bfd8b7f7803d0eaf3db0a532354 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with tf.Session() as sess: | |
| game, possible_actions = create_environment() | |
| totalScore = 0 | |
| # Load the model | |
| saver.restore(sess, "./models/model.ckpt") | |
| game.init() | |
| for i in range(1): | |
| done = False | |
| game.new_episode() | |
| state = game.get_state().screen_buffer | |
| state, stacked_frames = stack_frames(stacked_frames, state, True) | |
| while not game.is_episode_finished(): | |
| # Take the biggest Q value (= the best action) | |
| Qs = sess.run(DQNetwork.output, feed_dict = {DQNetwork.inputs_: state.reshape((1, *state.shape))}) | |
| # Take the biggest Q value (= the best action) | |
| choice = np.argmax(Qs) | |
| action = possible_actions[int(choice)] | |
| game.make_action(action) | |
| done = game.is_episode_finished() | |
| score = game.get_total_reward() | |
| if done: | |
| break | |
| else: | |
| print("else") | |
| next_state = game.get_state().screen_buffer | |
| next_state, stacked_frames = stack_frames(stacked_frames, next_state, False) | |
| state = next_state | |
| score = game.get_total_reward() | |
| print("Score: ", score) | |
| game.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment