def run(options): random.seed(options.random_seed) world_map = terrain.TerrainMap(terrain.read_map(options.map), options.map) robots = robot_module.load_robots(options.robots, world_map) history = play_history.PlayHistory() master.Master(options, robots, world_map, history).run() return history, world_map
def test_two_plains(self): world = terrain.TerrainMap(' ', 'fred') self.assertEqual(world.width, 4) self.assertEqual(world.height, 3) self._assertWallBorder(world) self.assertEqual(world.get_xy(1, 1), terrain.PLAINS) self.assertEqual(world.get_xy(2, 1), terrain.PLAINS)
def test_right_padding(self): world = terrain.TerrainMap(' \n' ' \n', 'fred') self.assertEqual(world.width, 4) self.assertEqual(world.height, 4) self._assertWallBorder(world) self.assertEqual(world.get_xy(1, 1), terrain.PLAINS) self.assertEqual(world.get_xy(2, 1), terrain.PLAINS) self.assertEqual(world.get_xy(1, 2), terrain.PLAINS) self.assertEqual(world.get_xy(2, 2), terrain.WALL)
def setUp(self): # Pre-set random seed to get robot #0 at 1,1, and #1 at 1,2. This makes # it simpler to set up shot directions. random.seed(1) self._options = robotwar.parse_options([]) self._history = play_history.PlayHistory() self._world_map = terrain.TerrainMap(' ', '') self._r0 = robot_module.Robot(0, self._world_map) self._game = master.Master(self._options, [self._r0], self._world_map, self._history) self._round = self._game._prepare_round()
def test_two_spaces_two_robots(self): world_map = terrain.TerrainMap(' ', '') r0 = robot_module.Robot(0, world_map) r1 = robot_module.Robot(1, world_map) game = master.Master(self._options, [r0, r1], world_map, self._history)
def test_one_space_two_robots(self): world_map = terrain.TerrainMap(' ', '') r = robot_module.Robot(0, world_map) with self.assertRaises(RuntimeError): game = master.Master(self._options, [r, r], world_map, self._history)
def test_one_space_one_robot(self): world_map = terrain.TerrainMap(' ', '') r = robot_module.Robot(0, world_map) game = master.Master(self._options, [r], world_map, self._history) self.assertEquals(game._robot_data[r].position, position.Position(1, 1))
def test_impossible(self): world_map = terrain.TerrainMap('', '') r = robot_module.Robot(0, world_map) with self.assertRaises(ValueError): game = master.Master(self._options, [r], world_map, self._history)
def setUp(self): self._world_map = terrain.TerrainMap(' ', 'fred')
def test_illegal_terrain(self): with self.assertRaises(RuntimeError): terrain.TerrainMap('Q', 'fred')
def test_blank(self): world = terrain.TerrainMap('', 'fred') self.assertEqual(world.width, 2) self.assertEqual(world.height, 2) self._assertWallBorder(world)