def run(N): """ Runs N episodes of a given length and then runs a demo with greedy policy """ agent = Agent() data = read_data('./data/q.dat') if data is not None: agent.Q = data for i in range(N): bot = Bot() run_episode(bot, agent, None, draw=False, policy='eps_greedy') # if bot.center[1] > 7: print "robot moved on: %i steps" % bot.center[1] pg.init() pg.display.init() surf = pg.display.set_mode((800, 600)) surf.fill((0, 0, 0)) pg.display.flip() print "Surf1:", surf bot = Bot() bot.info() run_episode(bot, agent, surf, draw=True, policy='eps_greedy', episode_len=60) print "Robot's moves:\n", bot.path print "Robot walked %i m" % bot.center[1] print "Last state value=%.1f" % agent.get_state_value(bot.get_state()) write_data(agent.Q, "data/q.dat") write_path(agent.Q_values, "data/path.csv")