151 | 151 |
|
152 | 152 |
"""
|
153 | 153 |
def __init__(self, **kwargs):
|
154 | |
self.alice = kwargs.get('alice')
|
155 | |
self.bob = kwargs.get('bob')
|
156 | |
self.house = kwargs.get('house')
|
|
154 |
self.characters = kwargs.get('characters')
|
|
155 |
self.setting = kwargs.get('setting')
|
157 | 156 |
self.friffery = kwargs.get('friffery', False)
|
158 | 157 |
self.debug = kwargs.get('debug', False)
|
159 | 158 |
self.title = kwargs.get('title', "Untitled")
|
|
165 | 164 |
print "=" * len(self.title)
|
166 | 165 |
print
|
167 | 166 |
|
168 | |
alice = self.alice
|
169 | |
bob = self.bob
|
170 | |
house = self.house
|
171 | |
|
172 | 167 |
for chapter in range(1, self.chapters+1):
|
173 | 168 |
print "Chapter %d." % chapter
|
174 | 169 |
print "-----------"
|
175 | 170 |
print
|
176 | |
|
177 | |
alice_collector = EventCollector()
|
178 | |
bob_collector = EventCollector()
|
179 | |
# don't continue a conversation from the previous chapter, please
|
180 | |
alice.topic = None
|
181 | |
bob.topic = None
|
182 | |
alice.location = None
|
183 | |
bob.location = None
|
|
171 |
|
|
172 |
for character in self.characters:
|
|
173 |
# don't continue a conversation from the previous chapter, please
|
|
174 |
character.topic = None
|
|
175 |
character.location = None
|
184 | 176 |
|
185 | 177 |
for paragraph in range(1, self.paragraphs_per_chapter+1):
|
186 | |
alice.collector = alice_collector
|
187 | |
bob.collector = bob_collector
|
188 | |
|
189 | |
# we could do this randomly...
|
190 | |
#pov_actor = pick([alice, bob])
|
191 | |
# but, we could also alternate. They ARE Alice and Bob, after all.
|
192 | |
pov_actor = (alice, bob)[(paragraph - 1) % 2]
|
193 | |
|
194 | |
for actor in (alice, bob):
|
|
178 |
for character in self.characters:
|
|
179 |
character.collector = EventCollector()
|
|
180 |
|
|
181 |
# we alternate pov like so:
|
|
182 |
pov_actor = (self.characters)[(paragraph - 1) % len(self.characters)]
|
|
183 |
|
|
184 |
for actor in self.characters:
|
195 | 185 |
if actor.location is None:
|
196 | |
actor.place_in(pick(house))
|
|
186 |
actor.place_in(pick(self.setting))
|
197 | 187 |
else:
|
198 | 188 |
# this is hacky & won't work for >2 characters:
|
199 | |
if not (alice.location == bob.location):
|
|
189 |
if self.characters[0].location is not self.characters[1].location:
|
200 | 190 |
actor.emit("<1> was in <2>", [actor, actor.location])
|
201 | |
|
202 | |
actor_order = (alice, bob)
|
203 | |
# this leads to continuity problems:
|
204 | |
#if random.randint(0, 1) == 0:
|
205 | |
# actor_order = (bob, alice)
|
|
191 |
|
206 | 192 |
while len(pov_actor.collector.events) < 20:
|
207 | |
for actor in actor_order:
|
|
193 |
for actor in self.characters:
|
208 | 194 |
actor.live()
|
209 | |
|
|
195 |
|
210 | 196 |
if self.friffery:
|
211 | 197 |
if paragraph == 1:
|
212 | 198 |
choice = random.randint(0, 3)
|
|
230 | 216 |
sys.stdout.write("Feeling anxious, ")
|
231 | 217 |
|
232 | 218 |
if self.debug:
|
233 | |
print "ALICE'S POV:"
|
234 | |
for event in alice_collector.events:
|
235 | |
print str(event)
|
236 | |
print
|
237 | |
alice.dump_memory()
|
238 | |
print
|
239 | |
print "BOB'S POV:"
|
240 | |
for event in bob_collector.events:
|
241 | |
print str(event)
|
242 | |
print
|
243 | |
bob.dump_memory()
|
244 | |
print
|
|
219 |
for character in self.characters:
|
|
220 |
print "%s'S POV:" % character.name.upper()
|
|
221 |
for event in character.collector.events:
|
|
222 |
print str(event)
|
|
223 |
print
|
|
224 |
character.dump_memory()
|
|
225 |
print
|
245 | 226 |
print "- - - - -"
|
246 | 227 |
print
|
247 | 228 |
|
|
254 | 235 |
#sys.stdout.write("\n")
|
255 | 236 |
print
|
256 | 237 |
print
|
257 | |
|
258 | |
alice_collector.events = []
|
259 | |
bob_collector.events = []
|