def __init__(self, config): """Initializes the GPDriver class. Where config is a Config object. """ self.config = config self.seed = seed_class.Seed(self.config) self.run_count = 1 self.eval_count = 1 self.local_best_score = -1 self.log = log_class.Log(self.config, self.seed, overwrite=True) self.global_best_score = -1 self.gpac_world = gpac_world_class.GPacWorld(self.config, initial_instance=True) self.pacman_cont = pacman_cont_class.PacmanController() self.ghosts_cont = ghosts_cont_class.GhostsController() self.game_state = game_state_class.GameState( self.gpac_world.pacman_coord, self.gpac_world.ghost_coords, self.gpac_world.pill_coords)
def begin_run(self): """Initializes run variables and writes a run header to the log file. This should be called before each run. """ self.eval_count = 0 self.local_best_score = -1 self.avg_score = 0 self.prev_avg_score = 0 self.stale_score_count_termination = 0 self.log.write_run_header(self.run_count) # Initialize the population self.population = [] for _ in range(self.population_size): world = gpac_world_class.GPacWorld(self.config) game_state = game_state_class.GameState( world.pacman_coords, world.ghost_coords, world.pill_coords, self.get_num_adj_walls(world, world.pacman_coords[0])) pacman_cont = pacman_cont_class.PacmanController(self.config) ghosts_cont = ghosts_cont_class.GhostsController(self.config) game_state.update_walls(world.wall_coords) self.population.append( gpac_world_individual_class.GPacWorldIndividual( world, game_state, pacman_cont, ghosts_cont))
def begin_run(self): """Initializes run variables and writes a run header to the log file. This should be called before each run. """ self.eval_count = 0 self.local_best_pacman_fitness = -1 self.pacman_avg_fitness = 0 self.prev_pacman_avg_fitness = 0 self.stale_fitness_count_termination = 0 self.log.write_run_header(self.run_count) # Initialize the populations self.gpac_world_population = [] self.pacman_cont_population = [] self.ghost_cont_population = [] for _ in range( max(self.pacman_population_size, self.ghost_population_size, self.pacman_child_population_size, self.ghost_child_population_size)): world = gpac_world_class.GPacWorld(self.config) game_state = game_state_class.GameState( world.pacman_coords, world.ghost_coords, world.pill_coords, [ self.get_num_adj_walls(world, pacman_coord) for pacman_coord in world.pacman_coords ]) game_state.update_walls(world.wall_coords) self.gpac_world_population.append( gpac_world_individual_class.GPacWorldIndividual( world, game_state)) # BONUS2 if self.use_single_pacman_cont: num_pacman_conts = 1 else: num_pacman_conts = self.num_pacmen for _ in range(self.pacman_population_size): self.pacman_cont_population.append( cont_class.ControllerIndividual([ pacman_cont_class.PacmanController(self.config) for _ in range(num_pacman_conts) ])) # BONUS1, BONUS2 if self.use_single_ghost_cont: num_ghost_conts = 1 else: num_ghost_conts = self.num_ghosts for _ in range(self.ghost_population_size): self.ghost_cont_population.append( cont_class.ControllerIndividual([ ghost_cont_class.GhostController(self.config) for _ in range(num_ghost_conts) ]))