git @ Cat's Eye Technologies Nhohnhehr / da5b779
Give NhohnhehrIO object a close() method. Chris Pressey 7 months ago
1 changed file(s) with 13 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
1111 # nhohnhehr.py [bytes] filename (ASCII I/O)
1212
1313 import sys
14
15
16 DEBUG = False
1417
1518
1619 def addvec(v1, v2):
244247
245248 def step(self):
246249 command = self[self.ip]
250 if DEBUG:
251 sys.stderr.write('({}) @ {}\n'.format(command, self.ip))
247252 ccwrot = {
248253 self.LEFT: self.DOWN,
249254 self.RIGHT: self.UP,
296301 def units_out(self, unit):
297302 raise NotImplementedError('implement units_out please')
298303
304 def close(self):
305 pass
306
299307
300308 class BitsIO(NhohnhehrIO):
301309 def units_in(self):
308316
309317 def units_out(self, bit):
310318 sys.stdout.write(('0', '1')[bit])
319 sys.stdout.flush()
320
321 def close(self):
322 sys.stdout.write("\n")
311323 sys.stdout.flush()
312324
313325
365377 try:
366378 with open(fname, 'r') as f:
367379 Environment(Room(file=f), io_system).run()
368 if mode == 'bits':
369 print # newline
370
380 io_system.close()
371381 except Exception as e:
372382 print("Error: {}".format(e))
373383