def play_against_boring_ai(self): # if nobody survived the last generation, generate a new population if len(self.population) == 0: print('\nCreating new population') self.strict_breeding = False self.games = [] self.generation = 0 while len(self.population) < self.population_size: game = PongGame() nn_paddle = NNPaddle(PongGame.window_width - 50, PongGame.window_height / 2, game.ball, game) nn_paddle.generation = self.generation game.paddle1 = nn_paddle # ai_2 = NNPaddle(50, PongGame.window_height / 2, ball, game) self.population.append(nn_paddle) self.games.append(game) for game in self.games: game.paddle2.ball = game.ball game.speed = self.cur_speed game.start_game() print(game.paddle1) self.cur_speed = game.speed else: print('\n=== Generation', self.generation, '===') for game in self.games: game.paddle2.ball = game.ball game.paddle2.score = 0 game.paddle1.score = 0 game.paddle1.reset(PongGame.window_width - 50, PongGame.window_height / 2, game.ball) game.speed = self.cur_speed game.start_game() print(game.paddle1) self.cur_speed = game.speed
def arena_battle(parent): game = PongGame(True) if type(parent) is list: if len(parent) == 4: # use these parents to start an arena battle game.paddle1.load_genomes(parent[0].name) game.paddle2.load_genomes(parent[1].name) game.paddle3.load_genomes(parent[2].name) game.paddle4.load_genomes(parent[3].name) else: print('Must supply a list of four names OR a single name') return elif type(parent) is NNPaddle: print(parent) game.paddle1.load_genomes(parent.name) game.paddle2.load_genomes(parent.name) game.paddle3.load_genomes(parent.name) game.paddle4.load_genomes(parent.name) game.start_game()