New syllable based name generation, should increase startup performance

This commit is contained in:
luxick
2016-01-21 16:04:44 +01:00
parent e0e1db1b98
commit cf38fe207f
12 changed files with 58 additions and 94362 deletions

2
cli.py
View File

@@ -83,4 +83,4 @@ class cursesUI:
if not self.running:
curses.endwin()
ui = cursesUI()

22
firstsyllable.txt Normal file
View File

@@ -0,0 +1,22 @@
Da
Ka
Ta
Ra
Cus
Iss
Aba
Ton
Ar
At
Cu
Da
Ta
Ab
Ba
Meno
Tor
Wir
Wen
Ein
Dev
Ken

View File

@@ -4,7 +4,6 @@
from config import *
from mayorgotchi import Mayorgotchi
from util import Util
import names
import itertools
class Kinggotchi:
@@ -12,7 +11,7 @@ class Kinggotchi:
name = ''
def __init__(self):
self.name = names.get_last_name()
self.name = util.generateName()
def add_village(self, mayor):
self.myvillages.append(mayor)

View File

@@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
from tamagotchi import Tamagotchi
import names
import random
from config import *
@@ -13,7 +12,7 @@ class Mayorgotchi:
def __init__(self, list_of_tamagotchis):
self.mygotchis = list_of_tamagotchis
self.name = names.get_last_name()
self.name = util.generateName()
def remove_corpses(self):
for n in self.mygotchis:

View File

@@ -1,45 +0,0 @@
from __future__ import unicode_literals
from os.path import abspath, join, dirname
import random
__title__ = 'names'
__version__ = '0.3.0.post1'
__author__ = 'Trey Hunner'
__license__ = 'MIT'
full_path = lambda filename: abspath(join(dirname(__file__), filename))
FILES = {
'first:male': full_path('dist.male.first'),
'first:female': full_path('dist.female.first'),
'last': full_path('dist.all.last'),
}
def get_name(filename):
selected = random.random() * 90
with open(filename) as name_file:
for line in name_file:
name, _, cummulative, _ = line.split()
if float(cummulative) > selected:
return name
return "" # Return empty string if file is empty
def get_first_name(gender=None):
if gender is None:
gender = random.choice(('male', 'female'))
if gender not in ('male', 'female'):
raise ValueError("Only 'male' and 'female' are supported as gender")
return get_name(FILES['first:%s' % gender]).capitalize()
def get_last_name():
return get_name(FILES['last']).capitalize()
def get_full_name(gender=None):
return "{0} {1}".format(get_first_name(gender), get_last_name())

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +0,0 @@
from __future__ import print_function
from names import get_full_name
def main():
print(get_full_name())
if __name__ == "__main__":
main()

View File

@@ -1,6 +0,0 @@
#!/usr/bin/python
# coding=UTF-8
from cli import *
ui = cursesUI()

36
util.py
View File

@@ -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