本文整理汇总了Python中helper.Helper.euclidian_distance方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.euclidian_distance方法的具体用法?Python Helper.euclidian_distance怎么用?Python Helper.euclidian_distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helper.Helper
的用法示例。
在下文中一共展示了Helper.euclidian_distance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: move
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import euclidian_distance [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()
示例2: __find_best_state
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import euclidian_distance [as 别名]
def __find_best_state(self, state, states):
'''Find the best state out of states array to match
the given state.
'''
best_d = Helper.euclidian_distance(state, states[0])
best_state = states[0]
for state2 in states[1:]:
d = Helper.euclidian_distance(state, state2)
if best_d > d:
best_d = d
best_state = state2
return best_d, best_state