while (nb_games < nb_max): if p.game_over(): #check if the game is over if (len(agent.memory) > 1): agent.replay(int(len(agent.memory) * 0.8)) scores.append(reward) nb_games += 1 distance.append(step) step = 0 p.reset_game() if (nb_games % (10) == 0): print(nb_games) obs = process_obs(game.getGameState()) action = agent.act(obs) reward = p.act(action) + step step += 1 if p.game_over() is False: agent.remember(obs, action, reward, process_obs(game.getGameState()), p.game_over()) agent.save_alt() plt.figure() plt.plot(range(len(scores)), scores) plt.show() plt.figure() plt.plot(range(len(distance)), distance) plt.show()
agent = Human(actions=env.getActionSet()) env.init() scores = [] min_reward = float('inf') max_reward = float('-inf') while True: episode_reward = 0.0 print 'Press s to start' while not keyboard.is_pressed('s'): continue while not env.game_over(): state = game.getGameState() action = agent.pickAction(state) reward = env.act(action) episode_reward += reward print 'Player score: {:0.1f}.'.format(episode_reward) scores.append(episode_reward) min_reward = min(min_reward, episode_reward) max_reward = max(max_reward, episode_reward) answer = raw_input('Keep playing ("y" to continue)? ') if answer is not 'y': break env.reset_game() print 'Average score for %d runs: {:0.1f}'.format( np.mean(scores)) % len(scores)
scores = [] agent = DQL.deep_learner(1, 2, p.getActionSet()) agent.learning_rate = 0.001 agent.epsilon = 0.001 agent.epsilon_decay = 1.0 agent.epsilon_min = 0.00001 #agent.load_model_json() agent.load_alt() nb_games = 0 for layer in agent.model.layers: print(layer.get_config()) while (nb_games < 20): if p.game_over(): #check if the game is over scores.append(game.getScore()) nb_games += 1 p.reset_game() if (nb_games % (50) == 0): print(nb_games) obs = process_obs(game.getGameState()) action = agent.act(obs) reward = p.act(action) plt.plot(range(len(scores)), scores) plt.show()