Example #1
0
    def __init__(self, environment, agent, config, output_dir):
        self.environment = environment
        self.s = self.environment.initial_state()
        self.total_pos_r = 0.0
        self.total_neg_r = 0.0
        self.agent = agent
        self.fps = config["fps"]
        self.show = config["show"]
        self.max_time = config["max_time"]
        self.output_dir = output_dir
        self.oserializer = ObservationSerializer()
        self.debug_mode = config["debug_mode"]

        if config["log_observations"]:
            self.obs_log_file = open("{}/observations.json".format(output_dir),
                                     "w")
        else:
            self.obs_log_file = None

        if config["replay_observations"]:
            for i in range(config["replay_count"]):
                for fn in config["replay_observations"]:
                    self.replay_observations(fn)

        if self.show:
            import pygame
            from pygame.locals import *
            pygame.init()
            self.font = pygame.font.SysFont(None, 28)
            self.screen = pygame.display.set_mode(Globals.SCREEN_DIMS, 0, 32)
            self.clock = pygame.time.Clock()
            pygame.display.set_caption("Tetris")
            self.draw()