forked from mattfister/nanogenmo2015
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setting_paragraph.py
66 lines (58 loc) · 3.26 KB
/
setting_paragraph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import generate_concept_sentence
import random
from wordtools import wordLists
from wordtools import md_writer
from says_sentence import says_sentence
from paragraph import Paragraph
lore_fail_exclamations = ['I have never heard of this place',
'This place is frightening me',
'We should leave this place at once',
'I am horrified at the thought of being here',
'I have never seen a place like this',
'I hate this place',
"Let's get out of here",
"I don't like the looks of this place",
"Let's move on",
"I don't think we should stick around here",
"This place is a mystery to me",
"Let's keep moving"]
class SettingParagraph(Paragraph):
def __init__(self, state):
super(SettingParagraph, self).__init__(state)
def setting_sentence(self, state):
sentence = ''
cs = self.state.get_characters()
random.shuffle(cs)
for i in range(len(cs)):
sentence += cs[i].get_name()
if i < len(cs) - 2:
sentence += ', '
elif i == len(cs) - 2:
sentence += ', and '
else:
sentence += ' traveled to a ' + self.state.get_current_setting().get_description() + '.'
return sentence
def generate_lore_sentence(self, state):
c = random.choice(self.state.get_characters())
if c.challenge('lore'):
return says_sentence(c, self.state.get_current_setting().discover_lore())
else:
return says_sentence(c, random.choice(lore_fail_exclamations))
def generate_sentences(self):
md_writer.print_chapter_sentence(self.setting_sentence(self.state))
for i in range(10):
r = random.random()
if r < 0.2 and self.state.get_current_setting().has_more_lore():
md_writer.print_chapter_sentence(self.generate_lore_sentence(self.state))
elif r < 0.3:
md_writer.print_chapter_sentence(self.state.generate_status_sentence())
elif r < 0.5:
md_writer.print_chapter_sentence(generate_concept_sentence.generate_concept_sentence(random.choice((random.choice(self.state.get_characters()).first_name, None)), self.state.get_current_setting().get_name()))
else:
if len(self.state.get_current_setting().get_props()) > 0:
md_writer.print_chapter_sentence(self.state.get_current_setting().discover_prop(random.choice((random.choice(self.state.get_characters()).first_name, None)), random.choice(self.state.get_current_setting().get_props()), self.state.get_current_setting().get_description()))
elif len(self.state.get_current_setting().get_known_props()) > 0:
try:
print md_writer.print_chapter_sentence(generate_concept_sentence.generate_concept_sentence(random.choice((random.choice(self.state.get_characters()).first_name, None)), random.choice(self.state.get_current_setting().get_known_props())))
except Exception:
continue