Example #1
0
class BotAgent:
    def __init__(self, env, forget=False):
        """An agent based on a GOFAI bot."""
        self.env = env
        self.forget = forget
        self.on_reset()

    def on_reset(self):
        self.bot = Bot(self.env, forget=self.forget)

    def act(self, *args, **kwargs):
        return {'action': self.bot.step()}

    def analyze_feedback(self, reward, done):
        pass
Example #2
0
    for run_no in range(options.num_runs):
        level = level_dict[level_name]

        mission_seed = options.seed + run_no
        mission = level(seed=mission_seed)
        expert = Bot(mission, forget=options.forget)

        if options.verbose:
            print(
                '%s/%s: %s, seed=%d' %
                (run_no + 1, options.num_runs, mission.surface, mission_seed))

        try:
            episode_steps = 0
            while True:
                action = expert.step()
                obs, reward, done, info = mission.step(action)

                total_reward += reward
                episode_steps += 1

                if done:
                    if reward > 0:
                        num_success += 1
                        total_steps += episode_steps
                    if reward <= 0:
                        print('FAILURE on %s, seed %d, reward %.2f' %
                              (level_name, mission_seed, reward))
                    break
        except Exception as e:
            print('FAILURE on %s, seed %d' % (level_name, mission_seed))