def test_load_random_map(self): """Test loading a few random maps.""" all_maps = maps.get_maps() run_config = run_configs.get() with run_config.start() as controller: # Test only a few random maps when run locally to minimize time. count = 5 map_sample = random.sample(all_maps.items(), min(count, len(all_maps))) for _, map_class in sorted(map_sample): m = map_class() logging.info("Loading map: %s", m.name) create = sc_pb.RequestCreateGame(local_map=sc_pb.LocalMap( map_path=m.path, map_data=m.data(run_config))) create.player_setup.add(type=sc_pb.Participant) create.player_setup.add(type=sc_pb.Computer, race=sc_pb.Random, difficulty=sc_pb.VeryEasy) join = sc_pb.RequestJoinGame(race=sc_pb.Random, options=sc_pb.InterfaceOptions(raw=True)) controller.create_game(create) controller.join_game(join) # Verify it has the right mods and isn't running into licensing issues. info = controller.game_info() logging.info("Mods for %s: %s", m.name, info.mod_names) self.assertIn("Mods/Void.SC2Mod", info.mod_names) self.assertIn("Mods/VoidMulti.SC2Mod", info.mod_names) # Verify it can be played without making actions. for _ in range(3): controller.step() controller.observe()
def test_list_all_maps(self): """Make sure all maps can be read.""" all_maps = maps.get_maps() run_config = run_configs.get() for _, map_class in sorted(all_maps.items()): map_inst = map_class() logging.info("map: %s", map_inst.name) self.assertTrue(map_inst.data(run_config), msg="Failed on %s" % map_inst)
def get_maps(count=None, filter_fn=None): """Test only a few random maps to minimize time.""" all_maps = { k: v for k, v in maps.get_maps().items() if filter_fn is None or filter_fn(v) } count = count or len(all_maps) return sorted(random.sample(all_maps.keys(), min(count, len(all_maps))))
def main(): smac_map_registry = smac_maps.get_smac_map_registry() all_maps = pysc2_maps.get_maps() print("{:<15} {:7} {:7} {:7}".format("Name", "Agents", "Enemies", "Limit")) for map_name, map_params in smac_map_registry.items(): map_class = all_maps[map_name] if map_class.path: print("{:<15} {:<7} {:<7} {:<7}".format( map_name, map_params["n_agents"], map_params["n_enemies"], map_params["limit"], ))
def main(): mm_map_registry = mm_maps.get_scmm_map_registry() all_maps = pysc2_maps.get_maps() print("{:^23} {:^7} {:^7} {:^7} {:^20} {:^7}".format("Name", "Agents", "Enemies", "Limit","Type", "Symmetry")) for map_name, map_params in mm_map_registry.items(): map_class = all_maps[map_name] if map_class.path: print( "{:^23} {:^7} {:^7} {:^7} {:^20} {:^7}".format( map_name, map_params["n_agents"], map_params["n_enemies"], map_params["limit"], map_params["map_type"][0], map_params["map_type"][1], ) )
def main(unused_argv): for _, map_class in sorted(maps.get_maps().items()): mp = map_class() if mp.path: print(mp, "\n")
from smac.env.starcraft2.maps import smac_maps from pysc2 import maps as pysc2_maps from smac.env.pettingzoo import StarCraft2PZEnv as sc2 import pytest from pettingzoo import test import pickle smac_map_registry = smac_maps.get_smac_map_registry() all_maps = pysc2_maps.get_maps() map_names = [] for map_name in smac_map_registry.keys(): map_class = all_maps[map_name] if map_class.path: map_names.append(map_name) @pytest.mark.parametrize(("map_name"), map_names) def test_env(map_name): env = sc2.env(map_name=map_name) test.api_test(env) # test.parallel_api_test(sc2_v0.parallel_env()) # does not pass it due to # illegal actions test.seed_test(sc2.env, 50) # not required, sc2 env only # allows reseeding at initialization test.render_test(env) recreated_env = pickle.loads(pickle.dumps(env)) test.api_test(recreated_env)
def get_maps(count=None): """Test only a few random maps to minimize time.""" all_maps = maps.get_maps() count = count or len(all_maps) return sorted(random.sample(all_maps.keys(), min(count, len(all_maps))))