Beispiel #1
0
    def testFeatureUnitsAreAdded(self):
        feature_units = [
            dummy_observation.FeatureUnit(units.Protoss.Probe,
                                          features.PlayerRelative.SELF,
                                          owner=1,
                                          pos=common_pb2.Point(x=10, y=10,
                                                               z=0),
                                          radius=1.0,
                                          health=10,
                                          health_max=20,
                                          is_on_screen=True,
                                          shield=0,
                                          shield_max=20),
            dummy_observation.FeatureUnit(units.Terran.Marine,
                                          features.PlayerRelative.SELF,
                                          owner=1,
                                          pos=common_pb2.Point(x=11, y=12,
                                                               z=0),
                                          radius=1.0,
                                          health=35,
                                          health_max=45,
                                          is_on_screen=True,
                                          shield=0,
                                          shield_max=0)
        ]

        self._builder.feature_units(feature_units)

        obs = self._get_obs()
        for proto, builder in zip(obs.raw_data.units, feature_units):
            self._check_feature_unit(proto, builder)
Beispiel #2
0
    def _default_observation(self, obs_spec, agent_index):
        """Returns a mock observation from an SC2Env."""

        builder = dummy_observation.Builder(obs_spec).game_loop(0)
        aif = self._agent_interface_formats[agent_index]
        if aif.use_feature_units or aif.use_raw_units:
            feature_units = [
                dummy_observation.FeatureUnit(
                    units.Neutral.LabBot,
                    features.PlayerRelative.NEUTRAL,
                    owner=16,
                    pos=common_pb2.Point(x=10, y=10, z=0),
                    radius=1.0,
                    health=5,
                    health_max=5,
                    is_on_screen=True,
                )
            ]

            builder.feature_units(feature_units)

        response_observation = builder.build()
        features_ = self._features[agent_index]
        observation = features_.transform_obs(response_observation)

        # Add bounding box for the minimap camera in top left of feature screen.
        if 'feature_minimap' in observation:
            minimap_camera = observation.feature_minimap.camera
            minimap_camera.fill(0)
            height, width = [dim // 2 for dim in minimap_camera.shape]
            minimap_camera[:height, :width].fill(1)

        return observation