New syllable based name generation, should increase startup performance
This commit is contained in:
36
util.py
36
util.py
@@ -3,14 +3,12 @@
|
||||
|
||||
from tamagotchi import Tamagotchi
|
||||
import random
|
||||
import names
|
||||
from config import *
|
||||
|
||||
class Util:
|
||||
|
||||
def make_Tamagotchi(self):
|
||||
# name = names.get_last_name()
|
||||
name = 'Gotchi'
|
||||
name = self.generateName()
|
||||
hunger = random.randrange(min_stat,max_stat,1)
|
||||
happiness = random.randrange(min_stat,max_stat,1)
|
||||
hygiene = random.randrange(min_stat,max_stat,1)
|
||||
@@ -27,3 +25,35 @@ class Util:
|
||||
for n in range(0,number):
|
||||
tmp.append(self.make_Tamagotchi())
|
||||
return tmp
|
||||
|
||||
def generateName(self):
|
||||
# Load syllables from file
|
||||
min_syllable_count = 0
|
||||
max_syllable_count = 3
|
||||
|
||||
firstsyllables = []
|
||||
with open("firstsyllable.txt") as firstsyllable_file:
|
||||
for line in firstsyllable_file:
|
||||
line = line.strip()
|
||||
if len(line) == 0:
|
||||
continue
|
||||
if line[0] == "#":
|
||||
continue
|
||||
firstsyllables.append(line)
|
||||
|
||||
syllables = []
|
||||
with open("syllables.txt") as syllable_file:
|
||||
for line in syllable_file:
|
||||
line = line.strip()
|
||||
if len(line) == 0:
|
||||
continue
|
||||
if line[0] == "#":
|
||||
continue
|
||||
syllables.append(line)
|
||||
|
||||
# Generate the name
|
||||
name = ""
|
||||
name += firstsyllables[random.randint(0, len(firstsyllables) - 1)]
|
||||
for i in range(0, random.randint(int(min_syllable_count), int(max_syllable_count))):
|
||||
name += syllables[random.randint(0, len(syllables) - 1)]
|
||||
return name
|
||||
|
||||
Reference in New Issue
Block a user