Exemple #1
0
def main():
    print("Severus start")
    print("Randomizing population")
    population = mgenetics.randomizePopulation()
    print("Starting evolution")
    for g in range(mgenetics.MaxGeneration):
        generation = g + 1
        print("")
        print("Generation: ", generation, " - population size: ", len(population))
        motherChromosome, fatherChromosome = mgenetics.selection(population)
        print("Training mother")
        motherDNN = mlearner.generateDNN(motherChromosome)
        if fatherChromosome is not None:
            print("Training father")
            fatherDNN = mlearner.generateDNN(fatherChromosome)
            child = mgenetics.crossover(motherDNN, fatherDNN)
        else:
            child = motherDNN
        if generation < mgenetics.MaxGeneration-1: 
            population = mgenetics.breed(child, generation)
    
    finalIndividual = child
    print()
    input("Press ENTER to start Final-Individual's game...")
    game = mgame.Game()
    result = game.playOneMatch_Predict(finalIndividual, True)
    print("Score = ", result[2])
    print()
    print("Severus end")
Exemple #2
0
        #Main game loop
        while not game_over(player):
            # enemy.update_state(p1.fly_me(turtle))
            player.update_state(p1.fly_ai(flight_params(player, enemy, game)))
            #enemy.update_state(p2.fly_ai(flight_params(enemy,player,game))) # using saved for enemy
            game.update_score(player, enemy)
            player.move()
            enemy.move()
            # # To show playable animation
            #game.show_status(player,enemy)
            # To show quick animation
            if counter % 15 == 0:
                turtle.update()
        scores[specie] = game.score
        print("Final Score: " + str("%9.2f" % game.score) + " [GEN] " +
              str(generation) + " [#] " + str(specie))

        turtle.reset()
        player.reset()
        enemy.reset()
        counter += 1
    #import code; code.interact(local=dict(globals(), **locals()))
    selected_dnas = gen.select_dna(SURVIVORS, DNA_SIZE, dnas, scores)
    dyn_mut = MUTATION  #gen.dyn_mutation(MUTATION,scores)
    actual_best = dnas[np.argmax(scores)]
    dnas = gen.breed(selected_dnas, SURVIVORS, SPECIES, dyn_mut, DNA_SIZE)

a = dnas
np.savetxt('save.txt', a, fmt='%f')
print("Saved: " + str(dnas))