std_out = open("std.txt", "w") # hall of fame best_ind = [] best_score = -1 # GA loop for g in range(1, n_gen + 1): print("On generation " + str(g)) # collect statistics for each generation scores = [] # simulate for each individual for ind in pop: score = game.run_brain(ind) scores.append(score) ind.fitness.values = (score,) # update hall of fame if score > best_score: best_ind = ind best_score = score # by this point each ind.fitness.values should be the score # output statistics for the scores max_out.write(str(max(scores)) + "\n") mean_out.write(str(np.mean(scores)) + "\n") std_out.write(str(np.std(scores)) + "\n") # Create children