Commits

Lars Yencken committed 8098f0e

Minor improvements to the helper script.

Comments (0)

Files changed (1)

                         
     def time_remaining(self):
         return self.turntime - int(1000 * (time.clock() - self.turn_start_time))
+
+    def time_taken(self):
+        return int(1000 * (time.clock() - self.turn_start_time))
     
     def issue_order(self, order):
         'issue an order by writing the proper ant location and direction'
     # static methods are not tied to a class and don't have self passed in
     # this is a python decorator
     @staticmethod
-    def run(bot):
+    def run(bot, istream=sys.stdin):
         'parse input, update game state and call the bot classes do_turn method'
         ants = Ants()
         map_data = ''
         while(True):
             try:
-                current_line = sys.stdin.readline().rstrip('\r\n') # string new line char
+                current_line = istream.readline().rstrip('\r\n') # string new line char
                 if current_line.lower() == 'ready':
                     ants.setup(map_data)
                     bot.do_setup(ants)
             except:
                 # don't raise error or return so that bot attempts to stay alive
                 traceback.print_exc(file=sys.stderr)
-                sys.stderr.flush()
+                sys.stderr.flush()