def simulate(self, robots, locs1, next_locs1, locs2, next_locs2): players = [game.Player(robots={'Robot': robot()}) for robot in robots] map['start1'], map['start2'] = locs1, locs2 game.init_settings(map) self._game = game.Game(*players, unit_testing=True) 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_game(code1, code2): rgkit_dir = path.dirname(rg.__file__) with open(path.join(rgkit_dir, 'maps/default.py')) as mapfile: game.init_settings(ast.literal_eval(mapfile.read())) g = MyGame( MyPlayer(code=code1), MyPlayer(code=code2), record_actions=True) return g
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 main(): map_data = ast.literal_eval(args.map.read()) game.init_settings(map_data) players = [make_player(args.usercode1), make_player(args.usercode2)] g = game.Game(*players, record_turns=True) for i in range(settings.max_turns): print (' running turn %d ' % (g.turns + 1)).center(70, '-') g.run_turn() if not args.headless: render.Render(g, game.settings) print g.history
def main(): args = parser.parse_args() if args.quiet >= 3: mute_all() game.init_settings(args.map) print('Game seed: {0}'.format(args.game_seed)) runner = test_runs_sequentially if _is_multiprocessing_supported and args.count > 1: runner = test_runs_concurrently scores = runner(args) if args.count > 1: p1won = sum(p1 > p2 for p1, p2 in scores) p2won = sum(p2 > p1 for p1, p2 in scores) print [p1won, p2won, args.count - p1won - p2won]
def comparison_worker(identity, input, output): logfile = open(__file__+"."+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()) game.init_settings(map_data) players = [game.Player(open(x).read()) 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)
import ast import pkg_resources import unittest from rgkit import game, rg map_data = ast.literal_eval( open(pkg_resources.resource_filename('rgkit', 'maps/default.py')).read()) settings = game.init_settings(map_data) class TestRG(unittest.TestCase): def test_center(self): self.assertEqual(rg.CENTER_POINT, (9, 9)) def test_types_invalid(self): self.assertEqual(rg.loc_types((-1, 9)), set(['invalid'])) def test_types_spawn(self): self.assertEqual(rg.loc_types((3, 4)), set(['normal', 'spawn'])) def test_types_obstacle(self): self.assertEqual(rg.loc_types((16, 4)), set(['normal', 'obstacle'])) def test_types_normal(self): self.assertEqual(rg.loc_types((7, 2)), set(['normal'])) def test_around(self): filtered = set(rg.locs_around((3, 3))) self.assertEqual(filtered, set([(3, 2), (4, 3), (3, 4), (2, 3)])) def test_around_filter(self):