当前位置: 首页>>代码示例>>Python>>正文


Python Helper.get_direction_towards方法代码示例

本文整理汇总了Python中helper.Helper.get_direction_towards方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.get_direction_towards方法的具体用法?Python Helper.get_direction_towards怎么用?Python Helper.get_direction_towards使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在helper.Helper的用法示例。


在下文中一共展示了Helper.get_direction_towards方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_direction_towards

# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import get_direction_towards [as 别名]
    def test_get_direction_towards(self):
        direction = Helper.get_direction_towards((0,0), (0,10))
        self.assertEqual(90, direction)

        direction = Helper.get_direction_towards((0,0), (1,1))
        self.assertEqual(45, direction)

        direction = Helper.get_direction_towards((0,0), (-1,-1))
        eps = math.sin(math.radians(225)) - math.sin(math.radians(direction))
        self.assertTrue(eps < 0.001)
开发者ID:andreip,项目名称:t2-ml,代码行数:12,代码来源:test_helper.py

示例2: move

# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import get_direction_towards [as 别名]
    def move(self):
        '''Predator is pretty dumb: if it sees a pray, it follows it to
        autodestruction.
        '''
        # Can always do indexing on filtered instances, as it should be a pray
        # always, else the game should have finished (bug?).
        pray = filter(lambda x: isinstance(x, Pray), self.game.instances)[0]
        # In case it sees the pray, change direction to follow it.
        if BaseObject.object_sees_object(self, pray):
            self.direction = Helper.get_direction_towards(self.coord, pray.coord)

            # Try and find close predators and sync with them to arrive at the
            # prey in the same time.
            #
            # The sync works the following way:
            # - each predator finds the max speed and max distance to pray
            #   (from all predators visible from him that they follow the pray)
            # - they update their speed v' = v_max * d / d_max
            #   where d = own distance to pray
            max_speed = self.speed
            own_dist = max_dist = Helper.euclidian_distance(self.coord, pray.coord)
            for instance in self.game.instances:
                if instance == self or not isinstance(instance, Predator):
                    continue
                # Look only for visible predators other than myself.
                if BaseObject.object_sees_object(self, instance):
                    dist = Helper.euclidian_distance(instance.coord, pray.coord)
                    max_dist = max(max_dist, dist)
                    max_speed = max(max_speed, instance.speed)
            # Sync speed with other predators.
            self.speed = max_speed * own_dist / float(max_dist)
        super(Predator, self).move()
开发者ID:andreip,项目名称:t2-ml,代码行数:34,代码来源:objects.py


注:本文中的helper.Helper.get_direction_towards方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。