Exemplo n.º 1
0
def initializeModels():
    model = newModel()
    generations = Generation(model, mChance)
    for i in range(2):
        board = [0 for x in range(10)]
        board = [list(board) for x in range(20)]
        species = Species(model, [board] * 2,
                          [[1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0]],
                          mChance)
        species.evolve()
        species.addName(f'Gen 0, Species {i}')
        print(species.name)
        playGame(species)
        generations.population.append(species)
        print(f'For a total of {species.score:.2f}!')
    generations.breed()
    generations.child.addName('Gen 0, Species Child')
    generations.saveGen()
    print('Finished initialization!')
    return generations
Exemplo n.º 2
0
def initializeModels():
    model = Sequential()
    model.add(LSTM(200,activation='sigmoid',input_shape=(10,20)))
    model.add(LSTM(1800,activation='softplus'))
    model.add(LSTM(8,activation='softmax'))
    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

    generations = [Generation(model,9)]
    for i in range(2):
        species = Species(model,[[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]],[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]],[[1,0,0,0,0,0,0,0],[1,0,0,0,0,0,0,0]],5)
        species.evolve()
        species.addName('Gen 0, Species {}'.format(i))
        print(species.name)
        playGame(species)
        generations[0].population.append(species)
        print('For a total of {:.2f}!'.format(species.score))
    generations[0].breed()
    generations[0].child.addName('Gen 0, Species Child')
    generations[0].saveGen()
    print('Finished initialization!')
    return generations