本文整理汇总了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)
示例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()