def _make_player(file_name): try: return game.Player(file_name=file_name) except IOError, msg: if pkg_resources.resource_exists('rgkit', file_name): bot_filename = pkg_resources.resource_filename('rgkit', file_name) return game.Player(file_name=bot_filename) raise IOError(msg)
def simulate(self, robots, locs1, next_locs1, locs2, next_locs2, turns=1): players = [game.Player(robot=robot()) for robot in robots] map['start1'], map['start2'] = locs1, locs2 game.init_settings(map) self._game = game.Game(*players, unit_testing=True, record_turns=True) for i in range(turns): self._game.run_turn() pprint.pprint(self._game._robots) return [[self._game.robot_at_loc(loc) for loc in locs] for locs in (next_locs1, next_locs2)]
def make_player(proxy_proc, output_file): global settings robot = None try: result = proxy_proc.get_response({'query': 'Robot'}, MAX_MS_PER_CALL) if result['result']: robot = ProxyBot(proxy_proc, output_file) except Exception as e: traceback.print_exc(file=output_file) finally: output_file.write(proxy_proc.get_output()) output_file.flush() if robot is None: return None return game.Player(robot=robot)
def comparison_worker(identity, input, output): logfile = open( os.getcwd() + "/" + "rgcompare" + "." + str(identity) + ".log", 'w') if log else open(os.devnull, 'w') print "Starting worker {0} (logging to {1})".format(identity, logfile.name) try: with RedirectStdStreams(stdout=logfile, stderr=logfile): for match_id, player_fnames, map_fname, turns in iter( input.get, 'STOP'): map_data = ast.literal_eval(open(map_fname).read()) settings.init_map(map_data) players = [game.Player(x) for x in player_fnames] g = game.Game(players) t_start = time.clock() for i in range(turns): print(' running turn %d ' % g._state.turn).center(70, '-') g.run_turn() t_end = time.clock() output.put([g.get_scores(), t_end - t_start]) finally: print "Terminating worker {0}...".format(identity)