Exemplo n.º 1
0
    genFile = open('gen.txt','r')
    read = genFile.readlines()
    totalGen = int(read[0])+1
    genFile.close()
except:
    totalGen=0

try:
    inputs1 = np.load('saves/inputsr.npy').tolist()
    outputs1 = np.load('saves/outputsr.npy').tolist()
    modelp1 = load_model('saves/pr.h5')
    species = Species(modelp1,inputs1,outputs1,mChance)
    print('Load models successful!')
except Exception:
    totalGen=0
    traceback.print_exc()
    print("Couldn't find save files... Initializing models")
    species = initializeModels()

for i in range(100):
    if i%10 == 0:
        species.save(f'pr{i}.h5')
    playGame(species)
    print(f'For a total of {species.score:.2f}!')
    species.create()
    species.output = []
    species.intake = []
    with open('tetris.log','a') as log:
        log.write(f'{strftime("%d %b %Y %H:%M:%S", localtime())}, {species.name}, finished with a score of {species.score:.2f}, clearing {species.cleared} lines\n')
    with open('gen.txt','w') as genFile:
        genFile.write(str(totalGen+i))