Пример #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)
Пример #2
0
    async def debug_text(self,
                         texts: Union[str, list],
                         positions: Union[list, set],
                         color=(0, 255, 0),
                         size_px=16):
        """ Deprecated, may be removed soon """
        if isinstance(positions, (set, list)):
            if not positions:
                return

            if isinstance(texts, str):
                texts = [texts] * len(positions)
            assert len(texts) == len(positions)

            await self._execute(debug=sc_pb.RequestDebug(debug=[
                debug_pb.DebugCommand(draw=debug_pb.DebugDraw(text=[
                    debug_pb.DebugText(
                        text=t,
                        color=debug_pb.Color(
                            r=color[0], g=color[1], b=color[2]),
                        world_pos=common_pb.Point(
                            x=p.x, y=p.y, z=getattr(p, "z", 10)),
                        size=size_px) for t, p in zip(texts, positions)
                ]))
            ]))
        else:
            await self.debug_text([texts], [positions], color)
Пример #3
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
Пример #4
0
 async def move_camera(self, position: Union[Unit, Point2, Point3]):
     """ Moves camera to the target position """
     assert isinstance(position, (Unit, Point2, Point3))
     if isinstance(position, Unit):
         position = position.position
     await self._execute(action=sc_pb.RequestAction(action=[
         sc_pb.Action(action_raw=raw_pb.ActionRaw(
             camera_move=raw_pb.ActionRawCameraMove(
                 center_world_space=common_pb.Point(x=position.x,
                                                    y=position.y))))
     ]))
Пример #5
0
    async def debug_text(self, texts, positions, color=(0, 255, 0)):
        if isinstance(positions, list):
            if not positions:
                return

            if isinstance(texts, str):
                texts = [texts] * len(positions)
            assert len(texts) == len(positions)

            await self._execute(debug=sc_pb.RequestDebug(
                debug=[debug_pb.DebugCommand(draw=debug_pb.DebugDraw(
                    text=[debug_pb.DebugText(
                        text=t,
                        color=debug_pb.Color(r=color[0], g=color[1], b=color[2]),
                        world_pos=common_pb.Point(x=p.x, y=p.y, z=p.z)
                    ) for t, p in zip(texts, positions)]
                ))]
            ))
        else:
            await self.debug_text([texts], [positions], color)
Пример #6
0
 def to_debug_point(self, point: Union[Unit, Point2,
                                       Point3]) -> common_pb.Point:
     """ Helper function for point conversion """
     if isinstance(point, Unit):
         point = point.position3d
     return common_pb.Point(x=point.x, y=point.y, z=getattr(point, "z", 0))
Пример #7
0
 def as_Point(self) -> common_pb.Point:
     return common_pb.Point(x=self.x, y=self.y, z=self.z)