def run_sim(controller=player_0(normalize=True),
            enemy=1,
            npop=50,
            ngens=10,
            m0=.07,
            m1=.1,
            m2=.07,
            m3=.07,
            m4=.07,
            highf_r=1.,
            lowf_r=.33,
            n_hidden=None,
            keep_elite=True):
    generations = {}
    for gen in range(ngens):
        print(" - - - - GENERATION %s - - - - " % gen)
        if gen == 0:
            pop = [{
                "bias": np.random.randn(1, 5),
                "weights": np.random.randn(20, 5),
                "ID": _,
                "parents": _
            } for _ in range(npop)]
            pop = test_pop(pop, enemy)
            generations[gen] = pop
        else:
            new_pop = reproduce(generations[gen - 1], highf_r, lowf_r, m0, m1,
                                m2, m3, m4, keep_elite)
            new_pop = test_pop(new_pop, enemy)
            generations[gen] = new_pop

    FF = []
    for gen in generations:
        pop = generations[gen]
        pop_fitness = [_["fitness"] for _ in pop]
        FF.append(pop_fitness)

    df = pd.DataFrame(FF).T
    result = {
        "data": df,
        "meta": {
            "npop": npop,
            "ngens": ngens,
            "m3": m3,
            "m4": m4,
            "m0": m0,
            "m1": m1,
            "m2": m2,
            "highf_r": highf_r,
            "lowf_r": lowf_r,
            "n_hidden": n_hidden,
            "elite": keep_elite,
            "enemy": enemy
        }
    }

    with open(str(datetime.datetime.now()), "wb") as f:
        pickle.dump(result, f)

    return df
def run(genes, norm_inputs, en=1):
    env = Environment(experiment_name=experiment_name,
                      playermode="ai",
                      player_controller=player_0(normalize=norm_inputs),
                      speed="fastest",
                      enemymode="static",
                      level=2,
                      randomini="no",
                      enemies=[en])
    return env.play(genes)
# results = []
# for e in [1,2,3,4,5,6,7,8]:
#     df = run_sim(controller=player_0(normalize=True),
#             enemy=e,
#             npop=100,
#             ngens=20,
#             m0=.12,
#             m1=.2,
#             m2=.12,
#             m3=.15,
#             m4=.12,
#             highf_r = 1.,
#             lowf_r = .05,
#             n_hidden=None,
#             keep_elite=True
#             )

res = run_sim(controller=player_0(normalize=True),
              enemy=1,
              npop=100,
              ngens=15,
              m0=.05,
              m1=.125,
              m2=.05,
              m3=.05,
              m4=.05,
              highf_r=1.,
              lowf_r=.05,
              n_hidden=None,
              keep_elite=True)