def evaluate(self, genome, generation, genome_id): """Generate a game, test the genome and return its fitness. Keyword arguments: genome -- genome to test generation -- number of the current generation genome_id -- genome id in the current generation """ # create neural network from genome. net = NEAT.NeuralNetwork() genome.BuildPhenotype(net) # create player and . player = Dino_player_neat(net) text = "generation : " + str(generation) + " || genome : " + str( genome_id) the_game = Dino(player, text) fitness = the_game.on_execute(start_immediately=True) return fitness
if len(arguments) != 0 and len(sys.argv) == 1: return arguments else: return None if __name__ == "__main__": arguments = verify_arguments() if arguments is None: print(f'Usage: python {sys.argv[0]} [ --type (human|random|neat \ [--population <size>] [--generations <size>]) ] ') elif "type" in arguments: if arguments["type"] == "human": player = Dino_player() theDino = Dino(player) theDino.on_execute() elif arguments["type"] == "random": player = Dino_player_random() theDino = Dino(player) theDino.on_execute() else: data = dict() if "population" in arguments: data["population_size"] = arguments["population"] if "generations" in arguments: data["generations"] = arguments["generations"] cycle = NEAT_trainer(**data) cycle.start_cycle() else: player = Dino_player() theDino = Dino(player)