Exemple #1
0
 async def query_pathings(
     self, zipped_list: List[List[Union[Unit, Point2, Point3]]]
 ) -> List[Union[float, int]]:
     """ Usage: await self.query_pathings([[unit1, target2], [unit2, target2]])
     -> returns [distance1, distance2]
     Caution: returns 0 when path not found
     Might merge this function with the function above
     """
     assert isinstance(zipped_list, list)
     assert len(zipped_list) > 0
     assert isinstance(zipped_list[0], list)
     assert len(zipped_list[0]) == 2
     assert isinstance(zipped_list[0][0], (Point2, Unit))
     assert isinstance(zipped_list[0][1], Point2)
     if isinstance(zipped_list[0][0], Point2):
         results = await self._execute(query=query_pb.RequestQuery(pathing=[
             query_pb.RequestQueryPathing(
                 start_pos=common_pb.Point2D(x=p1.x, y=p1.y),
                 end_pos=common_pb.Point2D(x=p2.x, y=p2.y))
             for p1, p2 in zipped_list
         ]))
     else:
         results = await self._execute(query=query_pb.RequestQuery(pathing=[
             query_pb.RequestQueryPathing(
                 unit_tag=p1.tag, end_pos=common_pb.Point2D(x=p2.x, y=p2.y))
             for p1, p2 in zipped_list
         ]))
     results = [float(d.distance) for d in results.query.pathing]
     return results
Exemple #2
0
    async def query_pathings(
        self, zipped_list: List[List[Union[Unit, Point2, Point3]]]
    ) -> List[Union[float, int]]:
        """ Usage: await self.query_pathings([[unit1, target2], [unit2, target2]])
        -> returns [distance1, distance2]
        Caution: returns 0 when path not found

        :param zipped_list:
        """
        assert zipped_list, "No zipped_list"
        assert isinstance(zipped_list, list), f"{type(zipped_list)}"
        assert isinstance(zipped_list[0], list), f"{type(zipped_list[0])}"
        assert len(zipped_list[0]) == 2, f"{len(zipped_list[0])}"
        assert isinstance(zipped_list[0][0],
                          (Point2, Unit)), f"{type(zipped_list[0][0])}"
        assert isinstance(zipped_list[0][1],
                          Point2), f"{type(zipped_list[0][1])}"
        if isinstance(zipped_list[0][0], Point2):
            results = await self._execute(query=query_pb.RequestQuery(
                pathing=(query_pb.RequestQueryPathing(
                    start_pos=common_pb.Point2D(x=p1.x, y=p1.y),
                    end_pos=common_pb.Point2D(x=p2.x, y=p2.y))
                         for p1, p2 in zipped_list)))
        else:
            results = await self._execute(query=query_pb.RequestQuery(
                pathing=(query_pb.RequestQueryPathing(
                    unit_tag=p1.tag, end_pos=common_pb.Point2D(x=p2.x, y=p2.y))
                         for p1, p2 in zipped_list)))
        return [float(d.distance) for d in results.query.pathing]
Exemple #3
0
 async def query_pathing(
     self, start: Union[Unit, Point2, Point3], end: Union[Point2, Point3]
 ) -> Optional[Union[int, float]]:
     """ Caution: returns 0 when path not found """
     assert isinstance(start, (Point2, Unit))
     assert isinstance(end, Point2)
     if isinstance(start, Point2):
         result = await self._execute(
             query=query_pb.RequestQuery(
                 pathing=[
                     query_pb.RequestQueryPathing(
                         start_pos=common_pb.Point2D(x=start.x, y=start.y),
                         end_pos=common_pb.Point2D(x=end.x, y=end.y),
                     )
                 ]
             )
         )
     else:
         result = await self._execute(
             query=query_pb.RequestQuery(
                 pathing=[
                     query_pb.RequestQueryPathing(unit_tag=start.tag, end_pos=common_pb.Point2D(x=end.x, y=end.y))
                 ]
             )
         )
     distance = float(result.query.pathing[0].distance)
     if distance <= 0.0:
         return None
     return distance
Exemple #4
0
    async def query_pathing(
            self, start: Union[Unit, Point2, Point3],
            end: Union[Point2, Point3]) -> Optional[Union[int, float]]:
        """ Caution: returns "None" when path not found
        Try to combine queries with the function below because the pathing query is generally slow.

        :param start:
        :param end: """
        assert isinstance(start, (Point2, Unit))
        assert isinstance(end, Point2)
        if isinstance(start, Point2):
            result = await self._execute(query=query_pb.RequestQuery(pathing=[
                query_pb.RequestQueryPathing(
                    start_pos=common_pb.Point2D(x=start.x, y=start.y),
                    end_pos=common_pb.Point2D(x=end.x, y=end.y),
                )
            ]))
        else:
            result = await self._execute(query=query_pb.RequestQuery(pathing=[
                query_pb.RequestQueryPathing(unit_tag=start.tag,
                                             end_pos=common_pb.Point2D(
                                                 x=end.x, y=end.y))
            ]))
        distance = float(result.query.pathing[0].distance)
        if distance <= 0.0:
            return None
        return distance
Exemple #5
0
 async def query_pathing(self, start, end):
     assert isinstance(start, (Point2, Unit))
     assert isinstance(end, Point2)
     if isinstance(start, Point2):
         result = await self._execute(query=query_pb.RequestQuery(pathing=[
             query_pb.RequestQueryPathing(
                 start_pos=common_pb.Point2D(x=start.x, y=start.y),
                 end_pos=common_pb.Point2D(x=end.x, y=end.y))
         ]))
     else:
         result = await self._execute(query=query_pb.RequestQuery(pathing=[
             query_pb.RequestQueryPathing(unit_tag=start.tag,
                                          end_pos=common_pb.Point2D(
                                              x=end.x, y=end.y))
         ]))
     distance = float(result.query.pathing[0].distance)
     if distance <= 0.0:
         return None
     return distance