def set_vowels(self): ''' Establish which vowels exist in this language ''' # Copy all vowels vowels = ALL_VOWELS[:] ## Make a list of common vowels common_vowels = [] for i in xrange(roll(NUM_COMMON_VOWELS[0], NUM_COMMON_VOWELS[1])): common_vowel = vowels.pop(roll(0, len(vowels)-1) ) common_vowels.append(common_vowel) freq = roll(COMMON_VOWEL_FREQS[0], COMMON_VOWEL_FREQS[1]) self.vowel_freqs.append( (common_vowel, freq) ) ## Shuffle the remaining list shuffle(vowels) # Generate frequencies for remaining vowels - if they're low enough, remove them entirely from the inventory for vowel in vowels: freq = roll(REG_VOWEL_FREQS[0], REG_VOWEL_FREQS[1]) # If frequency is low enough, we'll drop it from the language # Make sure that the frequency is high enough, and that we have a min number of vowels if freq > VOWEL_CUTOFF_FREQ or len(self.vowel_freqs) < MIN_VOWEL_INVENTORY: self.vowel_freqs.append( (vowel, freq) ) # Weird, but some vowels associated more with males, or females # Hopefully will help distinguish male/female names vf_ind = roll(1, len(self.vowel_freqs)-1) self.vowel_F = self.vowel_freqs[vf_ind][0] self.vowel_M = self.vowel_freqs[vf_ind-1][0]
def add_building_to_map(self, *args): # Find an ok center point building_center = (roll(50, 100), roll(50, 100)) building_size = (roll(15, 20), roll(15, 20)) ''' ## Make a nice rectangle, with walls at the corners for q in xrange(building_center[0], building_center[0] + building_size[0] + 1): for r in xrange(building_center[1], building_center[1] + building_size[1] + 1): g.M.tiles[q][r].building = self self.physical_property.append((q, r)) ## Add wall or floor if q in [building_center[0], building_center[0] + building_size[0]] or r in [building_center[1], building_center[1] + building_size[1]]: g.M.tiles[q][r].make_wall(libtcod.darkest_grey) else: g.M.tiles[q][r].make_floor(floor_type='dirt') door_coords = (int(building_center[0] + (building_size[0] / 2)), building_center[1] + building_size[1]) g.M.make_door(x=door_coords[0], y=door_coords[1], floor_type='dirt') ''' bx, by = building_center[0], building_center[1] for i, row in enumerate(BUILDINGS[self.template]): for j, tile in enumerate(row): x, y = bx + j, by + i self.physical_property.append((x, y)) if tile == '#': g.M.tiles[x][y].make_wall(libtcod.darkest_grey) elif tile == ' ': g.M.tiles[x][y].make_floor(floor_type='stone') elif tile in ('d', '-'): g.M.make_door(x=x, y=y, floor_type='stone')
def add_building_to_map(self, *args): # Find an ok center point building_center = (roll(50, 100), roll(50, 100)) building_size = (roll(15, 20), roll(15, 20)) ''' ## Make a nice rectangle, with walls at the corners for q in xrange(building_center[0], building_center[0] + building_size[0] + 1): for r in xrange(building_center[1], building_center[1] + building_size[1] + 1): g.M.tiles[q][r].building = self self.physical_property.append((q, r)) ## Add wall or floor if q in [building_center[0], building_center[0] + building_size[0]] or r in [building_center[1], building_center[1] + building_size[1]]: g.M.tiles[q][r].make_wall(libtcod.darkest_grey) else: g.M.tiles[q][r].make_floor(floor_type='dirt') door_coords = (int(building_center[0] + (building_size[0] / 2)), building_center[1] + building_size[1]) g.M.make_door(x=door_coords[0], y=door_coords[1], floor_type='dirt') ''' bx, by = building_center[0], building_center[1] for i, row in enumerate(BUILDINGS[self.template]): for j, tile in enumerate(row): x, y = bx+j, by+i self.physical_property.append((x, y)) if tile == '#': g.M.tiles[x][y].make_wall(libtcod.darkest_grey) elif tile == ' ': g.M.tiles[x][y].make_floor(floor_type='stone') elif tile in ('d', '-'): g.M.make_door(x=x, y=y, floor_type='stone')
def rolling(): for x in range(dice): x = roll(1, 6) turn.append(x) print('your roll is: ', turn) for x in range(compdice): x = roll(1, 6) compturn.append(x)
def randa_ola(n=328937): from random import randint as roll a='' for i in range(n): if roll(0,1)==1 : b=65 else : b=97 c=roll(1,26) c+=b a+=chr(c) return a
def __init__(self, possible_vowels, possible_consonants, nordic_i=0, use_weird_symbols=0): # Allow specification of any symbols that are predefined self.mapping = {} # Making copies of the possible written vowel representations, to be modified here potential_v_rep = {} for vowel in possible_vowels: potential_v_rep[vowel] = VOWEL_WRITTEN[vowel][:] # Making copies of the possible written consonant representations, to be modified here potential_c_rep = {} for consonant in possible_consonants: potential_c_rep[consonant] = CONSONANT_WRITTEN[consonant][:] ## Sort of silly, but it we allow "y" to be used in place of "i", we need ## to make sure that "y" cannot also be a consonant (we'll replace with J for now) if nordic_i: if 101 in potential_v_rep: potential_v_rep[101] = ['y', chr(152)] if 108 in potential_v_rep: potential_v_rep[101] = ['y', chr(152)] potential_c_rep = self.replace_grapheme(mapping=potential_c_rep, phoneme=222, old='y', new='j') # If we want to (possibly) use non-english symbols in place of some of the consonants if (use_weird_symbols is None and roll(1, 5) == 1) or use_weird_symbols == 1: # Use "thorn"/"eth" (sigma symbol in our library) if roll(0, 1) == 1: potential_c_rep = self.replace_grapheme(mapping=potential_c_rep, phoneme=211, old='th', new=chr(235)) potential_c_rep = self.replace_grapheme(mapping=potential_c_rep, phoneme=212, old='th', new=chr(235)) # Use ç in place of ch if roll(0, 1) == 1: potential_c_rep = self.replace_grapheme(mapping=potential_c_rep, phoneme=207, old='ch', new=chr(135)) # Use ƒ instead of sh if roll(0, 1) == 1: potential_c_rep = self.replace_grapheme(mapping=potential_c_rep, phoneme=215, old='sh', new=chr(159)) potential_c_rep = self.replace_grapheme(mapping=potential_c_rep, phoneme=216, old='zh', new=chr(159)) for i in WEIRD_CONS_LIST: if roll(1, 5) == 1: cons = choice(potential_c_rep.keys()) # Make sure that the cons that's being replaced is not 'empty' if cons < 300: potential_c_rep[cons] = [i] # Here's where consonants get mapped for consonant, grapheme_list in potential_c_rep.iteritems(): if not consonant in self.mapping: grapheme = choice(grapheme_list) self.mapping[consonant] = grapheme # Here's where vowels get mapped for vowel, grapheme_list in potential_v_rep.iteritems(): if not vowel in self.mapping: grapheme = choice(grapheme_list) self.mapping[vowel] = grapheme
def gen_creature_description(creature_name, creature_size=2): # Using the human template for now, this will be updated to include actual procedurally generated creatures eventually possible_flavor_text_values = ['eyes', 'teeth', 'ears', 'face'] flavor_text_values = [] for i in xrange(2): flavor_text = describe_feature( possible_flavor_text_values.pop( roll(0, len(possible_flavor_text_values) - 1))) flavor_text_values.append(flavor_text) # Creature generator will need to be expanded in the future, for now a working prototype lets us hack in a pre-specified size # (All sentient humanoids are size 2, whereas large ones become unintelligent for now if creature_size == 1: size = '{0} {1}'.format(random.choice(('small', 'smallish')), 'humanoid') elif creature_size == 2: size = describe_feature('size') elif creature_size == 3: size = '{0}, {1}'.format( random.choice(('large', 'large', 'hulking', 'hefty')), 'barely intelligent humanoid') skin_type = random.choice(('skin_naked', 'skin_naked', 'skin_naked', 'skin_naked', 'skin_scaled', 'skin_chitin')) skin = describe_feature(skin_type) if skin_type == 'skin_naked' and roll(1, 10) > 2: if roll(0, 1): hair = describe_feature('skin_covering_hair') else: hair = describe_feature('skin_covering_fur') else: hair = describe_feature('skin_covering_hairless') description = random.choice([ 'A {0} with {1} and {2}. It has {3} and its body is {4}.', 'A {0} with {1} and {2}. It has {3} and is {4}.', 'A {0} with {1} and {2}. It is {4} and has {3}.', 'A {0} with {1} and {2}. Is body is {4} and has {3}.', 'A {0} with {3}. It has {1} and {2}. It is {4}.', 'A {0} with {3}. It has {1} and {2}. Its body is {4}.', 'A {0} that is {4}. It has {3}, {1}, and {2}.', 'This {0} has {3} and is {4}. It has {1} and {2}.', 'This {0} is {4} and has {3}. It has {1} and {2}.', 'The {5}s are {0}s who are {4} and have {3}. They have {1} and {2}.', '{5}s are a race of {0}s who are {4} and have {3}. They have {1} and {2}.', ]) description = description.format(size, flavor_text_values[0], flavor_text_values[1], skin, hair, creature_name) return description
def create_misc_gods(self, num_misc_gods): # Create misc gods for i in xrange(num_misc_gods): sphere = self.available_spheres.pop(roll(0, len(self.available_spheres)-1)) name = self.astrology.language.gen_word(syllables=roll(1, 2), num_phonemes=(3, 20)) name = lang.spec_cap(name) self.gods.append(God(name=name, sphere=sphere)) # Further shuffle gods random.shuffle(self.gods)
def preprocess(img, augment=True): img = CLAHE3d(np.uint16(img)) img = standardize(img) if augment: y_shift = roll(-scale, scale) x_shift = roll(0, scale) img = crop(img, y_shift, x_shift, img_rows, img_cols) img = add_gaussian_noise(img, 0.01) return normalize(img) else: img = crop(img, 0, 0, img_rows, img_cols) return normalize(img)
def create_celestial_gods(self): # Create gods for each celestial body for c_body in self.astrology.suns + self.astrology.moons: name = self.astrology.language.gen_word(syllables=roll(1, 2), num_phonemes=(3, 20)) name = lang.spec_cap(name) self.gods.append(God(name=name, sphere=c_body.describe()) )
def set_name(self): if self.type_ == 'Tavern': num = roll(1, 5) if num == 1: front = 'The {0} {1}'.format( random.choice(g.TAVERN_ADJECTIVES), random.choice(g.TAVERN_NOUNS)) ending = random.choice([ '', '', '', ' Inn', ' Tavern', ' Tavern', ' Lodge', ' Bar and Inn' ]) elif num == 2: front = 'The {0}\'s {1}'.format( random.choice(g.TAVERN_NOUNS), random.choice(g.TAVERN_OBJECTS)) ending = '' elif num == 3: front = '{0}\'s {1}'.format(random.choice(g.TAVERN_NOUNS), random.choice(g.TAVERN_OBJECTS)) ending = random.choice( [' Inn', ' Tavern', ' Tavern', ' Lodge', ' Bar and Inn']) elif num == 4: front = '{0}\'s {1}'.format(self.site.name, random.choice(g.TAVERN_OBJECTS)) ending = '' elif num == 5: front = 'The {0} of the {1} {2}'.format( random.choice(('Inn', 'Tavern', 'Lodge')), random.choice(g.TAVERN_ADJECTIVES), random.choice(g.TAVERN_NOUNS)) ending = '' self.name = front + ending
def generate_weapon(self, wtype, material, special_properties): ''' Will take a weapon blueprint, vary some of the parameters, and return the full blueprint for the object ''' # Important to deepcopy ths dict or bad things may happen (components/layers referencing the same object...) weapon_info_dict = copy.deepcopy(blueprint_dict[wtype]) # Loop through all components to vary their parameters for component in weapon_info_dict['components']: # Loop through all layers of the component for layer in component['layers']: # There is a "dimensions" tuple: width/height/depth/filled. # TODO - Vary this a bit. Also handle cases for multiple layers so they fit inside each other correctly ndims = [] for dim in layer['dimensions']: ndim = round(dim + (dim * (roll(0, 15) / 100)), 3) ndims.append(ndim) ndims = tuple(ndims) # Re-assign the new dimensions to the layer layer['dimensions'] = ndims # Properties specified just by the weapon type properties = WEAPON_PROPERTIES[wtype].copy() # Add any other special properties for wproperty, value in special_properties.iteritems(): if wproperty in properties: properties[wproperty] += value + random.choice( (-10, -5, 0, 0, 10, 20)) else: properties[wproperty] = value + random.choice( (-10, -5, 0, 0, 10, 20)) weapon_component = {'wtype': wtype, 'properties': properties} weapon_info_dict['weapon_component'] = weapon_component return weapon_info_dict
def enemyTurn(): #50/50 chance if enemy attacks or defends. move = roll(1, 2) if move == 1: enemyAttack() if move == 2: enemyDefend()
def __init__(self, initial_location, target_location, entity, travel_verb='travel'): ActionBase.__init__(self) self.behavior = 'move' self.initial_location = initial_location self.target_location = target_location self.entity = entity self.travel_verb = travel_verb self.preconditions = [AmAvailableToAct(self.entity)] self.costs = {'money':0, 'time':0, 'distance':0, 'morality':0, 'legality':0} if g.WORLD: # This would otherwise stop this module running as __main__, leaving this in for testing purposes target_site = g.WORLD.tiles[self.target_location[0]][self.target_location[1]].site current_site = g.WORLD.tiles[self.entity.wx][self.entity.wy].site if target_site in g.WORLD.cities and current_site in g.WORLD.cities: full_path = current_site.path_to[target_site][:] else: # Default - use libtcod's A* to create a path to destination path = libtcod.path_compute(p=g.WORLD.path_map, ox=self.entity.wx, oy=self.entity.wy, dx=self.target_location[0], dy=self.target_location[1]) full_path = libtcod_path_to_list(path_map=g.WORLD.path_map) # Add path to brain self.entity.world_brain.path = full_path # Update the cost of this behavior self.costs['time'] += len(full_path) self.costs['distance'] += len(full_path) else: # Stuff to give this movement a random cost cost = roll(1, 10) self.costs['distance'] = cost self.costs['time'] = cost
def generate_weapon(self, wtype, material, special_properties): ''' Will take a weapon blueprint, vary some of the parameters, and return the full blueprint for the object ''' # Important to deepcopy ths dict or bad things may happen (components/layers referencing the same object...) weapon_info_dict = copy.deepcopy(blueprint_dict[wtype]) # Loop through all components to vary their parameters for component in weapon_info_dict['components']: # Loop through all layers of the component for layer in component['layers']: # There is a "dimensions" tuple: width/height/depth/filled. # TODO - Vary this a bit. Also handle cases for multiple layers so they fit inside each other correctly ndims = [] for dim in layer['dimensions']: ndim = round(dim + (dim * (roll(0, 15)/100)), 3) ndims.append(ndim) ndims = tuple(ndims) # Re-assign the new dimensions to the layer layer['dimensions'] = ndims # Properties specified just by the weapon type properties = WEAPON_PROPERTIES[wtype].copy() # Add any other special properties for wproperty, value in special_properties.iteritems(): if wproperty in properties: properties[wproperty] += value + random.choice((-10, -5, 0, 0, 10, 20)) else: properties[wproperty] = value + random.choice((-10, -5, 0, 0, 10, 20)) weapon_component = {'wtype':wtype, 'properties':properties} weapon_info_dict['weapon_component'] = weapon_component return weapon_info_dict
def gen_creature_description(creature_name, creature_size=2): # Using the human template for now, this will be updated to include actual procedurally generated creatures eventually possible_flavor_text_values = ['eyes', 'teeth', 'ears', 'face'] flavor_text_values = [] for i in xrange(2): flavor_text = describe_feature(possible_flavor_text_values.pop(roll(0, len(possible_flavor_text_values)-1))) flavor_text_values.append(flavor_text) # Creature generator will need to be expanded in the future, for now a working prototype lets us hack in a pre-specified size # (All sentient humanoids are size 2, whereas large ones become unintelligent for now if creature_size == 1: size = '{0} {1}'.format(random.choice(('small', 'smallish')), 'humanoid') elif creature_size == 2: size = describe_feature('size') elif creature_size == 3: size = '{0}, {1}'.format(random.choice(('large', 'large', 'hulking', 'hefty')), 'barely intelligent humanoid') skin_type = random.choice(('skin_naked', 'skin_naked', 'skin_naked', 'skin_naked', 'skin_scaled', 'skin_chitin')) skin = describe_feature(skin_type) if skin_type == 'skin_naked' and roll(1, 10) > 2: if roll(0, 1): hair = describe_feature('skin_covering_hair') else: hair = describe_feature('skin_covering_fur') else: hair = describe_feature('skin_covering_hairless') description = random.choice([ 'A {0} with {1} and {2}. It has {3} and its body is {4}.', 'A {0} with {1} and {2}. It has {3} and is {4}.', 'A {0} with {1} and {2}. It is {4} and has {3}.', 'A {0} with {1} and {2}. Is body is {4} and has {3}.', 'A {0} with {3}. It has {1} and {2}. It is {4}.', 'A {0} with {3}. It has {1} and {2}. Its body is {4}.', 'A {0} that is {4}. It has {3}, {1}, and {2}.', 'This {0} has {3} and is {4}. It has {1} and {2}.', 'This {0} is {4} and has {3}. It has {1} and {2}.', 'The {5}s are {0}s who are {4} and have {3}. They have {1} and {2}.', '{5}s are a race of {0}s who are {4} and have {3}. They have {1} and {2}.', ]) description = description.format(size, flavor_text_values[0], flavor_text_values[1], skin, hair, creature_name) return description
def create_astronomy(): moons= [] suns = [] num_moons = random.choice(moon_nums) num_suns = random.choice(sun_nums) available_moon_colors = moon_colors[:] available_sun_colors = moon_colors[:] for i in xrange(num_moons): moons.append(available_moon_colors.pop(roll(0, len(available_moon_colors)-1))) for i in xrange(num_suns): suns.append(available_sun_colors.pop(roll(0, len(available_sun_colors)-1))) return moons, suns
def reroll(self, kept): kept = re.sub(' ', '', kept) kept = re.sub(',', '', kept) for dice in kept: self.roll[int(dice) - 1] = int(roll(1, 7)) self.roll = sorted(self.roll) self.rerolls -= 1 return self.roll
def main(): lista = [] length = 20 for i in range(length): lista.append(roll(1, 20)) MO = stats(lista) SD = stats(lista, MO) print(f"\nThe list's mean is {MO} with a \n standart deviation of {SD}\n")
def gen_structs(self, phonological_inv_size): ''' Generate possible structures (consonants, syllables, codas) for the language based on size of phonological inventory ''' consonant_drop_chance = PHONOLOGICAL_INV_DROP_CHANCES[phonological_inv_size] consonant_possibilities = [] # Now we check to see which ones (if any) are dropped for consonant in CONSONANTS[:]: if roll(1, 100) <= consonant_drop_chance: consonant_possibilities.append(consonant) # Give each one a frequency. Currently very weird because # the only time this frequency is really used is computing # consonants that make up a syllable onset or coda # The onset and coda structures themselves have their own frequencies for cons in consonant_possibilities: cons.freq = roll(1, 70) self.consonants.append(cons) # Now it's time to use brute force and see which of all possible # onsets/codas can be used. If phon_list returns empty, it means # our language can't find phonemes for that onset/coda, and so must be discarded # # Tricky here - need to copy all of the sublists to make sure original lists aren't modified for onset in POSSIBLE_ONSETS[:]: all_valid_phonemes = 1 for phoneme_properties in onset[:]: phon_list = self.find_phoneme(phoneme_properties[0], phoneme_properties[1], phoneme_properties[2]) if phon_list == []: all_valid_phonemes = 0 if all_valid_phonemes: self.valid_onsets.append(onset[:]) # Same for codas for coda in POSSIBLE_CODAS[:]: all_valid_phonemes = 1 for phoneme_properties in coda[:]: phon_list = self.find_phoneme(phoneme_properties[0], phoneme_properties[1], phoneme_properties[2]) if phon_list == []: all_valid_phonemes = 0 if all_valid_phonemes: self.valid_codas.append(coda[:])
def create_script(self): ''' Here's where the mapping of phonemes to graphemes gets established ''' possible_vowels = [vowel for (vowel, freq) in self.vowel_freqs] possible_consonants = [consonant.num for consonant in self.consonants] possible_consonants.extend([300, 301]) if roll(0, 10) == 10: nordic_i = 1 else: nordic_i = 0 self.orthography = Orthography(possible_vowels=possible_vowels, possible_consonants=possible_consonants, nordic_i=nordic_i)
def calculate_winner_of_opening_round(c1_dict, c2_dict): c1_total = max(1, sum(c1_dict.values())) c2_total = max(1, sum(c2_dict.values())) num = roll(0, c1_total + c2_total) if num <= c1_total: return 1 else: return 2
def __init__(self, moons, suns, language): self.moons = [] self.suns = [] self.language = language self.earth_name = lang.spec_cap(self.language.gen_word(syllables=roll(1, 2), num_phonemes=(3, 20))) for moon_color in moons: name = self.language.gen_word(syllables=roll(1, 2), num_phonemes=(3, 20)) name = lang.spec_cap(name) self.moons.append(Moon(name=name, earth_name=self.earth_name, astronomy=self, color=moon_color)) for sun_color in suns: name = self.language.gen_word(syllables=roll(1, 2), num_phonemes=(3, 20)) name = lang.spec_cap(name) self.suns.append(Sun(name=name, earth_name=self.earth_name, astronomy=self, color=sun_color))
def create_nature_gods(self, num_nature_gods): # Create misc gods for i in xrange(num_nature_gods): sphere = random.choice([s for s in natural_spheres if s in self.available_spheres]) self.available_spheres.remove(sphere) name = self.astrology.language.gen_word(syllables=roll(1, 2), num_phonemes=(3, 20)) name = lang.spec_cap(name) self.gods.append(God(name=name, sphere=sphere))
def get_vowel(self, vowel_pref=None): ## Weird little function. Here I'm attempting to bypass the normal ## weighted vowel thing in favor of the masc or fem vowel. ## The main reason to do this is try to distinguish masc or fem names num = roll(1, 9) if num >= 5 and vowel_pref == 'f': return self.vowel_F elif num >= 5 and vowel_pref == 'm': return self.vowel_M else: return w_rand(self.vowel_freqs)
def update_god_relationships(self): # Gods have relationships with each other for god in self.gods: if god.gender == 1 and roll(0, 1): potential_spouses = [g for g in self.gods if g.gender == 0 and g.spouse is None] if len(potential_spouses): choice = random.choice(potential_spouses) god.add_spouse(spouse=choice) # Kids for j in xrange(roll(0, 2)): sphere = self.available_spheres.pop(roll(0, len(self.available_spheres)-1)) name = self.astrology.language.gen_word(syllables=roll(1, 2), num_phonemes=(3, 20)) name = lang.spec_cap(name) child = God(name=name, sphere=sphere) god.have_child(child) self.gods.append(child)
def set_onsets(self, onsets=None, no_onset_chance=NO_ONSET_C_CHANCE): ''' Establish which syllable onsets are valid in this language ''' if onsets is not None: self.valid_onsets = onsets ## Otherwise, create the possible onsets randomly else: shuffle(self.valid_onsets) common_onset_nums = min(roll(COMMON_ONSET_NUMS[0], COMMON_ONSET_NUMS[1]), len(self.valid_onsets) ) for i, onset in enumerate(self.valid_onsets): if i <= common_onset_nums: freq = roll(COMMON_ONSET_FREQS[0], COMMON_ONSET_FREQS[1]) onset.append(freq) else: freq = roll(REG_ONSET_FREQS[0], REG_ONSET_FREQS[1]) onset.append(freq) ## Some languages have a high occurance of syllables with no onset consonant if roll(1, 100) >= no_onset_chance: perc_sylls_with_no_onset = roll(HIGH_ONSET_C_FREQS[0], HIGH_ONSET_C_FREQS[1]) self.valid_onsets.append( [(300, None, []), perc_sylls_with_no_onset] ) else: perc_sylls_with_no_onset = roll(LOW_ONSET_C_FREQS[0], LOW_ONSET_C_FREQS[1]) self.valid_onsets.append( [(300, None, []), perc_sylls_with_no_onset] ) # Now get a list of tuples, only containing the valid onsets (in num or long form) and their freqs (out of 1000, roughly?) for entry in range(0, len(self.valid_onsets)): self.valid_onset_freqs.append((entry, self.valid_onsets[entry][-1]))
def set_codas(self, codas=None, no_coda_chance=NO_CODA_C_CHANCE): ''' Establish which syllable codas are valid in this language ''' if codas is not None: self.valid_codas = codas ## Otherwise, create the possible codas randomly else: shuffle(self.valid_codas) common_coda_nums = min(roll(COMMON_CODA_NUMS[0], COMMON_CODA_NUMS[1]), len(self.valid_codas) ) for i, coda in enumerate(self.valid_codas): if i < common_coda_nums: freq = roll(COMMON_CODA_FREQS[0], COMMON_CODA_FREQS[1]) coda.append(freq) else: freq = roll(REG_CODA_FREQS[0], REG_CODA_FREQS[1]) coda.append(freq) ## Some languages have a high occurance of syllables with no coda consonant if roll(1, 100) >= no_coda_chance: perc_sylls_with_no_coda = roll(HIGH_CODA_C_FREQS[0], HIGH_CODA_C_FREQS[1]) self.valid_codas.append( [(301, None, []), perc_sylls_with_no_coda] ) else: perc_sylls_with_no_coda = roll(LOW_CODA_C_FREQS[0], LOW_CODA_C_FREQS[1]) self.valid_codas.append( [(301, None, []), perc_sylls_with_no_coda] ) for entry in range(0, len(self.valid_codas)): self.valid_coda_freqs.append((entry, self.valid_codas[entry][-1]))
def gen_vocabulary(self): ''' This will generate some sample vocabulary of the language ''' # Generate some "Masculine", "Feminine", and "neutral" words word_lists = ( (VOCAB_M, 'm', self.vocab_m), (VOCAB_F, 'f', self.vocab_f), (VOCAB_N, None, self.vocab_n) ) for (eng_list, vowel_pref, append_list) in word_lists: # Basically, make sure the word is "valid" (not too short), and if so, use it for eng_word in eng_list: syllables = roll(1, 2) # Here's where the "Masculine" or "feminine" words come into play word = self.gen_word(syllables, num_phonemes=(3, 20), use_onset=1, onset_can_have_no_consonant=1, use_coda=1, vowel_pref=vowel_pref) self.vocabulary[eng_word] = word append_list[eng_word] = word # Generate function words for eng_word in VOCAB_FUNC: use_onset, use_coda = choice( ( (0, 1), (1, 0) ) ) onset_cons = roll(0, 1) word = self.gen_word(syllables=1, num_phonemes=(1, 4), use_onset=use_onset, onset_can_have_no_consonant=onset_cons, use_coda=use_coda, vowel_pref=None) self.vocab_function[eng_word] = word
def __init__(self): # The language will name itself in a later step self.name = None # Orthography will be set in a later step self.orthography = None # Start with empty list of consonants, will build up later self.consonants = [] # Vocabulary will also be set later self.vocabulary = {} self.vocab_m = {} self.vocab_f = {} self.vocab_n = {} self.vocab_function = {} # Onsets and codas which are valid in this language self.valid_onsets = [] self.valid_onset_freqs = [] self.valid_codas = [] self.valid_coda_freqs = [] self.vowel_freqs = [] # To distinguish male/female names, some vowels will later be associated as "male" or "female" self.vowel_F = None self.vowel_M = None # Generate a phonological inventory - but make sure it leaves us with valid onsets/offsets phonological_inventory_size=choice(PHONOLOGICAL_INV_DROP_CHANCES.keys()) while 1: # This continuously generates a phonological inventory, but makes sure there are # always at least 1 valid syllable onset and coda self.gen_structs(phonological_inventory_size) if len(self.valid_onsets) > 0 and len(self.valid_codas) > 0: break # These will generate frequencies for syllable onsets, codas, and vowels self.set_onsets() self.set_codas() self.set_vowels() # Create transcription - map letters to writing symbols self.create_script() # Have the language name itself self.name = spec_cap( self.gen_word( syllables=roll(2, 3), num_phonemes=(3, 20) ) ) # Have the language generate some vocabulary self.gen_vocabulary()
def rlist(): while True: try: n = int(input("mege8os listas plz: \n")) except TypeError: print("me akeraio ari8mo to", end=' ') else: break lista = [] for i in range(n): lista.append(roll(1, 6)) return (lista)
def __init__(self, initial_location, target_location, entity, travel_verb='travel'): ActionBase.__init__(self) self.behavior = 'move' self.initial_location = initial_location self.target_location = target_location self.entity = entity self.travel_verb = travel_verb self.preconditions = [AmAvailableToAct(self.entity)] self.costs = { 'money': 0, 'time': 0, 'distance': 0, 'morality': 0, 'legality': 0 } if g.WORLD: # This would otherwise stop this module running as __main__, leaving this in for testing purposes target_site = g.WORLD.tiles[self.target_location[0]][ self.target_location[1]].site current_site = g.WORLD.tiles[self.entity.wx][self.entity.wy].site if target_site in g.WORLD.cities and current_site in g.WORLD.cities: full_path = current_site.path_to[target_site][:] else: # Default - use libtcod's A* to create a path to destination path = libtcod.path_compute(p=g.WORLD.path_map, ox=self.entity.wx, oy=self.entity.wy, dx=self.target_location[0], dy=self.target_location[1]) full_path = libtcod_path_to_list(path_map=g.WORLD.path_map) # Add path to brain self.entity.world_brain.path = full_path # Update the cost of this behavior self.costs['time'] += len(full_path) self.costs['distance'] += len(full_path) else: # Stuff to give this movement a random cost cost = roll(1, 10) self.costs['distance'] = cost self.costs['time'] = cost
def fill_position(self, profession): # Give temples and nobles and stuff an initial dynasty to begin with potential_employees = [figure for figure in g.WORLD.tiles[self.site.x][self.site.y].entities if figure.creature.profession is None and figure.creature.sex == 1 and figure.creature.get_age() > g.MIN_MARRIAGE_AGE] # Mostly try to use existing folks to fill the position if not profession.name in ('Assassin', ) and len(potential_employees) > 0: human = random.choice(potential_employees) # Otherwise, create a new person else: born = g.WORLD.time_cycle.years_ago(roll(18, 40)) human = self.site.create_inhabitant(sex=1, born=born, dynasty=None, important=0, house=None) ## Actually give profession to the person ## profession.give_profession_to(human)
def set_name(self): if self.type_ == 'Tavern': num = roll(1, 5) if num == 1: front = 'The {0} {1}'.format(random.choice(g.TAVERN_ADJECTIVES), random.choice(g.TAVERN_NOUNS)) ending = random.choice(['', '', '', ' Inn', ' Tavern', ' Tavern', ' Lodge', ' Bar and Inn']) elif num == 2: front = 'The {0}\'s {1}'.format(random.choice(g.TAVERN_NOUNS), random.choice(g.TAVERN_OBJECTS)) ending = '' elif num == 3: front = '{0}\'s {1}'.format(random.choice(g.TAVERN_NOUNS), random.choice(g.TAVERN_OBJECTS)) ending = random.choice([' Inn', ' Tavern', ' Tavern', ' Lodge', ' Bar and Inn']) elif num == 4: front = '{0}\'s {1}'.format(self.site.name, random.choice(g.TAVERN_OBJECTS)) ending = '' elif num == 5: front = 'The {0} of the {1} {2}'.format(random.choice(('Inn', 'Tavern', 'Lodge')), random.choice(g.TAVERN_ADJECTIVES), random.choice(g.TAVERN_NOUNS)) ending = '' self.name = front + ending
def choose_target_building(self, target_building): ''' Pick a building to move into ''' if target_building: return target_building # Else do some magic to look at nearby buildings, pick one if empty, or construct a new one else: entity_region = g.WORLD.tiles[self.entity.wx][self.entity.wy] nearby_chunks = g.WORLD.get_nearby_chunks( chunk=entity_region.chunk, distance=3) # Find some nearby non-city non-village sites, and then find any empty buildings within these nearby_sites = [ site for chunk in nearby_chunks for site in chunk.get_all_sites() if site.type_ not in ('city', 'village') ] nearby_empty_buildings = [ building for site in nearby_sites for building in site.buildings if not building.inhabitants ] # If there are nearby empty buildings, choose one at random if nearby_empty_buildings and roll(0, 1): building = random.choice(nearby_empty_buildings) # If not, make a building object to send to the parent (but this doesn't actually exist yet - it will be added to a site later) else: building = building_info.Building( zone='residential', type_='hideout', template='TEST', construction_material='stone cons materials', site=None, professions=[], inhabitants=[], tax_status='commoner', wx=None, wy=None, constructed=0) return building
def choose_target_building(self, target_building): ''' Pick a building to move into ''' if target_building: return target_building # Else do some magic to look at nearby buildings, pick one if empty, or construct a new one else: entity_region = g.WORLD.tiles[self.entity.wx][self.entity.wy] nearby_chunks = g.WORLD.get_nearby_chunks(chunk=entity_region.chunk, distance=3) # Find some nearby non-city non-village sites, and then find any empty buildings within these nearby_sites = [site for chunk in nearby_chunks for site in chunk.get_all_sites() if site.type_ not in ('city', 'village')] nearby_empty_buildings = [building for site in nearby_sites for building in site.buildings if not building.inhabitants] # If there are nearby empty buildings, choose one at random if nearby_empty_buildings and roll(0, 1): building = random.choice(nearby_empty_buildings) # If not, make a building object to send to the parent (but this doesn't actually exist yet - it will be added to a site later) else: building = building_info.Building(zone='residential', type_='hideout', template='TEST', construction_material='stone cons materials', site=None, professions=[], inhabitants=[], tax_status='commoner', wx=None, wy=None, constructed=0) return building
def fill_position(self, profession): # Give temples and nobles and stuff an initial dynasty to begin with potential_employees = [ figure for figure in g.WORLD.tiles[self.site.x][self.site.y].entities if figure.creature.profession is None and figure.creature.sex == 1 and figure.creature.get_age() > g.MIN_MARRIAGE_AGE ] # Mostly try to use existing folks to fill the position if not profession.name in ( 'Assassin', ) and len(potential_employees) > 0: human = random.choice(potential_employees) # Otherwise, create a new person else: born = g.WORLD.time_cycle.years_ago(roll(18, 40)) human = self.site.create_inhabitant(sex=1, born=born, dynasty=None, important=0, house=None) ## Actually give profession to the person ## profession.give_profession_to(human)
def create_myth(self): creation_type = r(['ex nihilo', 'diver', 'chaos'])#, #'iteration', 'dismember']) opening = r(['In a time before time, ', 'In the beginning, ', 'Ages ago, ', 'Eons ago, ']) ctitle = r(['He Who Has Always Been', 'The One', 'The Creator', 'The First', 'God of gods', 'The Prime Being', 'The Mover']) c_fullname = r([self.creator.name + ', ' + ctitle + ',', self.creator.name + ', ' + ctitle + ',', ctitle + ', ' + self.creator.name + ',' ]) if creation_type == 'ex nihilo': #### giants/titans cverb = r([' created ', ' summoned ', ' brought forth ', ' willed there to be ']) s1 = r([self.creator.name + ', ' + ctitle + ',' + cverb + self.astrology.list_celestial_bodies() + '.', c_fullname + cverb + self.astrology.list_celestial_bodies() + '.', c_fullname + cverb + self.earth_name + '; the earth.', c_fullname + cverb + r(['the world, and named it ', 'the earth, and named it ', 'the world, calling it ', 'the earth, naming it ', 'all that is. The center of creation was the world, ' ]) + self.earth_name + '.', c_fullname + cverb + self.astrology.list_celestial_bodies() + '.' ]) s2 = r([self.creator.name + r([' looked upon ', ' looked down upon ']) + self.earth_name + ' and created the oceans, the peaks and the valleys, the hills and the plains.', self.creator.name + ' flooded ' + self.earth_name + ', creating oceans where the water settled and the land where it did not.', self.creator.name + ' then shaped ' + self.earth_name + ' and formed its surface. Next, ' + ctitle + ' created the oceans, lakes, and rivers.']) ########### self.story_text.append(' '.join([opening + s1, s2 ]) ) ########## s3 = r([self.creator.name + ' saw the earth, and, feeling it empty, created the all the flora, trees, and plants. ' \ 'Thus the first living things were made. Even so, ' + ctitle + ' still felt it empty. '\ 'All manner of creatures thus came to be. But ' + self.creator.name + 'still felt it empty. '\ 'Thus was the race of Man created, so that others could appreciate the earth.', self.creator.name + ' created Man in ' + self.creator.get_pronoun(s=0) + ' image. So that Man was not alone, '\ 'all manner of beasts were created to populate ' + self.earth_name + ', along with various flora '\ 'to sustain both man and beast alike.', self.creator.name + ' then created all living things; trees, insects, fish, and animals. Man alone received the '\ 'gift of Knowledge, and this elevated him above all other creatures.' ]) self.story_text.append(' '.join([s3])) elif creation_type == 'diver': ### Covered story l_adj = ['inundated with', 'covered in', 'only'] liq = r(['water']) s1 = self.earth_name + ', the earth, was ' + r(l_adj) + ' ' + liq + '.' s2 = '' s3 = '' #method = r(['raised', 'animal']) method = r(['animal']) if method == 'raised': fl_action = r([' saw the emptiness and ']) action = r(['raised mountains from the deep.', 'formed the continents.', 'formed land.', 'bombarded the ' + liq + ' with great boulders until land had formed.', ]) s2 = c_fullname + r([' ', fl_action]) + action elif method == 'animal': land = r(['sand', 'mud']) a_type = r(['bird', 'amphibian']) a_name = self.language.gen_word(syllables=roll(1, 2), num_phonemes=(3, 20)) a_name = lang.spec_cap(a_name) expand_phrase = r(['which expanded into ' + r(['land.', 'the earth.']), 'which became ' + r(['land.', 'the earth.', 'the continent.']), 'which grew into ' + r(['land.', 'the earth.', 'the continent.']), ' which begat ' + r(['land.', 'the earth.', 'the continent.']) ]) if a_type == 'bird': animal = r(['sparrow', 'lark', 'eagle', 'hawk', 'vulture']) a_method = r(['traveled to ' + self.earth_name + ' from the heavens. It', 'descended to ' + self.earth_name + ' on a rope. It', 'glided to ' + self.earth_name + '. It', 'came upon ' + self.earth_name + '. It', 'fell to ' + self.earth_name + '. Confused, it']) a_action = r(['flapped its wings until the ocean gave way to land.', 'splashed the water aside and packed the '+land+' into earth.', 'dove into the waters to find ' + land + '. Slowly the ' +land+ ' was piled together to form land.', 'dove into the waters and brought ' +land+ ' to the surface, ' + expand_phrase, 'had nowhere to rest and dove into the waters in search of ' + land + '. ' + a_name + ' brought ' +land+ ' to the surface, ' + expand_phrase]) elif a_type == 'amphibian': animal = r(['toad', 'salamander', 'frog']) a_method = r(['traveled to ' + self.earth_name + ' from the heavens. It', 'descended to ' + self.earth_name + ' on a rope. It', 'was cast down to ' + self.earth_name + '. It', 'fell to ' + self.earth_name + '. Confused, it']) a_action = r(['dove into the waters to find ' + land + '. Slowly the ' + land + ' was piled together to form land.', 'had nowhere to rest, and dove into the waters in search of ' + land + '. ' + a_name + ' brought ' +land+ ' to the surface, ' + expand_phrase]) s2 = r([a_name + ', the ' + animal + ', ' + a_method + ' ' + a_action, self.creator.name + ' sent ' + a_name + ', the ' + animal + ', to ' + self.earth_name + '. It ' + a_action]) animal_follow_up = roll(0, 1) if animal_follow_up: a_name = self.language.gen_word(syllables=roll(1, 2), num_phonemes=(3, 20)) a_name = lang.spec_cap(a_name) animal = r(['sparrow', 'lark', 'eagle', 'hawk', 'vulture']) s3 = r([a_name + ', the ' + animal + ', was sent to see if the landmass was dry. It was still soft, and ' + a_name + '\'s wings grazed the earth, creating the mountains and the valleys.', a_name + ', the ' + animal + ', was sent to see if the landmass was dry. It was still soft, and ' + a_name + '\'s claws scraped the earth, creating the valleys and the mountains.']) else: s3 = r([c_fullname + ' saw the earth, and shaped the land.', c_fullname + ' saw the earth, and formed the land into mountains, and hills, and valleys.']) self.story_text.append( opening + ' '.join([s1, s2, s3]) ) elif creation_type == 'chaos': cosmos = r(['universe ', 'cosmos ', 'entirety of existence ', 'world ']) v_name = self.language.gen_word(syllables=roll(1, 2), num_phonemes=(3, 20)) v_name = lang.spec_cap(v_name) v_adj = r(['Expanse', 'Void']) form = r(['formless.', 'without form.', 'an endless expanse.', 'formless and shapeless.', 'devoid of form.', 'void.', 'a void.', 'an abyss.', 'darkness.', 'shrouded in darkness.']) s1 = r(['the ' + cosmos + 'was ' + form]) s2 = r([v_name + ', the ' + v_adj + ', was ' + r(['filled with ', 'composed of ', 'made up of ']) + r(['a thick, foggy vapor.', 'dense, obscuring fog.', 'swirling, gaseous matter.']), 'The ' + v_adj + ' seethed freely with ' + r(['a thick, foggy vapor.', 'dense, obscuring fog.', 'gaseous matter.']) ]) ###### prep = r(['From this state, ', 'From the chaos, ', 'Using this material, ', '']) cverb = r([' brought order to the unformed void and fashioned ', ' created ', ' brought forth ']) s3 = r([ prep + c_fullname + cverb + self.earth_name + '; the earth.', prep + c_fullname + cverb + r(['the world, and named it ', 'the earth, and named it ', 'the world, calling it ', 'the earth, naming it ', 'all that is. The center of this creation was the world, ' ]) + self.earth_name + '.', prep + c_fullname + cverb + self.astrology.list_celestial_bodies() + '.' ]) s4 = r([self.creator.name + r([' then looked upon ', ' looked down upon ']) + self.earth_name + ' and created the oceans, the peaks and the valleys, the hills and the plains.', self.creator.name + ' then flooded ' + self.earth_name + ', creating oceans ' + r([' in the basins', ' where the water settled']) + ' and dry land elsewhere.', self.creator.name + ' then shaped ' + self.earth_name + ' and formed its surface. Next, ' + ctitle + ' created the oceans, lakes, and rivers.']) ######### self.story_text.append(opening + ' '.join([s1, s2, s3, s4]) ) ######### s5 = r([self.creator.name + ' saw the earth, and, feeling it empty, created the all the flora, trees, and plants. ' \ 'Thus the first living things were made. Even so, ' + ctitle + ' still felt it empty. '\ 'All manner of creatures thus came to be. But ' + self.creator.name + 'still felt it empty. '\ 'Thus was the race of Man created, so that others could appreciate the earth.', self.creator.name + ' created Man in ' + self.creator.get_pronoun(s=0) + ' image. So that Man was not alone, '\ 'all manner of beasts were created to populate ' + self.earth_name + ', along with various flora '\ 'to sustain both man and beast alike.', self.creator.name + ' then created all living things; trees, insects, fish, and animals. Man alone received the '\ 'gift of Knowledge, and this elevated him above all other creatures.' ]) self.story_text.append(' '.join([s5]))
def set_name(self): if roll(1, 2) == 1: self.name = 'Pantheon of {0}'.format(self.gods[0].name) else: self.name = '{0}mites'.format(lang.spec_cap(self.astrology.language.gen_word(syllables=roll(1, 2), num_phonemes=(3, 20))))
def get_behavior_location(self, current_location): return roll(0, 10), roll(0, 10)
def chance(number, top=100): ''' A simple function for automating a chance (out of 100) of something happening ''' return roll(1, top) <= number