Maintinance 🔧

This commit is contained in:
NikolajDanger
2020-12-03 15:58:13 +01:00
parent d03ae74937
commit 1fb2df546e
6 changed files with 82 additions and 78 deletions

View File

@ -1,6 +1,6 @@
"""Misc. functions for Gwendolyn."""
__all__ = ["nameGen", "tavernGen", "movieFunc"]
__all__ = ["Generators", "movieFunc"]
from .generators import nameGen, tavernGen
from .generators import Generators
from .movie import movieFunc

View File

@ -3,89 +3,90 @@ import random
from funcs import logThis
# Returns a list of all letter pairs in the text
def make_pairs(corpus):
for i in range(len(corpus)-1):
yield (corpus[i], corpus[i+1])
class Generators():
# Returns a list of all letter pairs in the text
def make_pairs(self, corpus):
for i in range(len(corpus)-1):
yield (corpus[i], corpus[i+1])
# Returns a list of all letter triplets in the text
def make_triplets(corpus):
for i in range(len(corpus)-2):
yield (corpus[i], corpus[i+1], corpus[i+2])
# Returns a list of all letter triplets in the text
def make_triplets(self, corpus):
for i in range(len(corpus)-2):
yield (corpus[i], corpus[i+1], corpus[i+2])
# Generates a random name
def nameGen():
# Makes a list of all names from "names.txt"
names = open('resources/names.txt', encoding='utf8').read()
corpus = list(names)
# Generates a random name
def nameGen(self):
# Makes a list of all names from "names.txt"
names = open('resources/names.txt', encoding='utf8').read()
corpus = list(names)
# Makes a list of pairs
pairs = make_pairs(corpus)
triplets = make_triplets(corpus)
# Makes a list of pairs
pairs = self.make_pairs(corpus)
triplets = self.make_triplets(corpus)
letter_dict = {}
letter_dict = {}
# Makes a dictionary of all letters that come after all other letters
for letter_1, letter_2 in pairs:
if letter_1 in letter_dict.keys():
letter_dict[letter_1].append(letter_2)
else:
letter_dict[letter_1] = [letter_2]
# Makes a dictionary of all letters that come after all other letters
for letter_1, letter_2 in pairs:
if letter_1 in letter_dict.keys():
letter_dict[letter_1].append(letter_2)
else:
letter_dict[letter_1] = [letter_2]
for letter_1, letter_2, letter_3 in triplets:
if letter_1+letter_2 in letter_dict.keys():
letter_dict[letter_1+letter_2].append(letter_3)
else:
letter_dict[letter_1+letter_2] = [letter_3]
for letter_1, letter_2, letter_3 in triplets:
if letter_1+letter_2 in letter_dict.keys():
letter_dict[letter_1+letter_2].append(letter_3)
else:
letter_dict[letter_1+letter_2] = [letter_3]
# Choses a random first letter
first_letter = random.choice(corpus)
# Makes sure the first letter is not something a name can't start with.
while first_letter.islower() or first_letter == " " or first_letter == "-" or first_letter == "\n":
# Choses a random first letter
first_letter = random.choice(corpus)
# Starts the name
chain = [first_letter]
# Makes sure the first letter is not something a name can't start with.
while first_letter.islower() or first_letter == " " or first_letter == "-" or first_letter == "\n":
first_letter = random.choice(corpus)
# Picks second letter
second_letter = random.choice(letter_dict[chain[-1]])
# Starts the name
chain = [first_letter]
while second_letter == "\n":
# Picks second letter
second_letter = random.choice(letter_dict[chain[-1]])
chain.append(second_letter)
while second_letter == "\n":
second_letter = random.choice(letter_dict[chain[-1]])
done = False
chain.append(second_letter)
# Creates the name one letter at a time
while done == False:
if random.randint(1,10) > 1:
try:
new_letter = random.choice(letter_dict[chain[-2]+chain[-1]])
except:
done = False
# Creates the name one letter at a time
while done == False:
if random.randint(1,10) > 1:
try:
new_letter = random.choice(letter_dict[chain[-2]+chain[-1]])
except:
new_letter = random.choice(letter_dict[chain[-1]])
else:
new_letter = random.choice(letter_dict[chain[-1]])
else:
new_letter = random.choice(letter_dict[chain[-1]])
chain.append(new_letter)
# Ends name if the name ends
if new_letter == "\n":
done = True
genName = "".join(chain)
logThis("Generated "+genName)
# Returns the name
return(genName)
chain.append(new_letter)
# Ends name if the name ends
if new_letter == "\n":
done = True
genName = "".join(chain)
logThis("Generated "+genName)
# Returns the name
return(genName)
# Generates a random tavern name
def tavernGen():
# Lists first parts, second parts and third parts of tavern names
fp = ["The Silver","The Golden","The Staggering","The Laughing","The Prancing","The Gilded","The Running","The Howling","The Slaughtered","The Leering","The Drunken","The Leaping","The Roaring","The Frowning","The Lonely","The Wandering","The Mysterious","The Barking","The Black","The Gleaming","The Tap-Dancing","The Sad","The Sexy","The Artificial","The Groovy","The Merciful","The Confused","The Pouting","The Horny","The Okay","The Friendly","The Hungry","The Handicapped","The Fire-breathing","The One-Eyed","The Psychotic","The Mad","The Evil","The Idiotic","The Trusty","The Busty"]
sp = ["Eel","Dolphin","Dwarf","Pegasus","Pony","Rose","Stag","Wolf","Lamb","Demon","Goat","Spirit","Horde","Jester","Mountain","Eagle","Satyr","Dog","Spider","Star","Dad","Rat","Jeremy","Mouse","Unicorn","Pearl","Ant","Crab","Penguin","Octopus","Lawyer","Ghost","Toad","Handjob","Immigrant","SJW","Dragon","Bard","Sphinx","Soldier","Salmon","Owlbear","Kite","Frost Giant","Arsonist"]
tp = [" Tavern"," Inn","","","","","","","","",""]
# Generates a random tavern name
def tavernGen(self):
# Lists first parts, second parts and third parts of tavern names
fp = ["The Silver","The Golden","The Staggering","The Laughing","The Prancing","The Gilded","The Running","The Howling","The Slaughtered","The Leering","The Drunken","The Leaping","The Roaring","The Frowning","The Lonely","The Wandering","The Mysterious","The Barking","The Black","The Gleaming","The Tap-Dancing","The Sad","The Sexy","The Artificial","The Groovy","The Merciful","The Confused","The Pouting","The Horny","The Okay","The Friendly","The Hungry","The Handicapped","The Fire-breathing","The One-Eyed","The Psychotic","The Mad","The Evil","The Idiotic","The Trusty","The Busty"]
sp = ["Eel","Dolphin","Dwarf","Pegasus","Pony","Rose","Stag","Wolf","Lamb","Demon","Goat","Spirit","Horde","Jester","Mountain","Eagle","Satyr","Dog","Spider","Star","Dad","Rat","Jeremy","Mouse","Unicorn","Pearl","Ant","Crab","Penguin","Octopus","Lawyer","Ghost","Toad","Handjob","Immigrant","SJW","Dragon","Bard","Sphinx","Soldier","Salmon","Owlbear","Kite","Frost Giant","Arsonist"]
tp = [" Tavern"," Inn","","","","","","","","",""]
# Picks one of each
genTav = random.choice(fp)+" "+random.choice(sp)+random.choice(tp)
logThis("Generated "+genTav)
# Picks one of each
genTav = random.choice(fp)+" "+random.choice(sp)+random.choice(tp)
logThis("Generated "+genTav)
# Return the name
return(genTav)
# Return the name
return(genTav)