本文整理汇总了Python中Vector.Vector.mag方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.mag方法的具体用法?Python Vector.mag怎么用?Python Vector.mag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector.Vector
的用法示例。
在下文中一共展示了Vector.mag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: avoid_defenders
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import mag [as 别名]
def avoid_defenders(self):
"""
Avoid just the nearest defender by acc directly away from them.
Ignores anyone not goalward of us, even if they are close and faster than us.
"""
this=self.player
ignore_dist=self.avoid_defenders_ignore_dist
panic_dist=self.avoid_defenders_panic_dist
#
nearest=None
nearest_dist2 = 1e10
ignore_dist2=ignore_dist**2
this_end_zone_dist = this.dist_to_attack_end_zone
for p in self.avoid_defenders_team.players.values():
if not p.standing: continue
if this_end_zone_dist < p.dist_to_defend_end_zone : continue
dist2 = (this.pos - p.pos).mag2()
if dist2 < nearest_dist2:
nearest=p
nearest_dist2=dist2
if nearest == None:
return Vector(0,0)
if nearest_dist2 > ignore_dist2:
return Vector(0,0)
else:
# Calculate distance scaling
dist = np.sqrt(nearest_dist2)
if dist <= panic_dist:
fac=1.
else:
fac = 1.-(dist-panic_dist)/(ignore_dist-panic_dist)
desired_velocity = (this.pos-nearest.pos).norm()*this.top_speed*fac
desired_acc = desired_velocity - this.vel
# Don't permit accelerating backwards
if (desired_acc.x * this.direction) < 0.:
desired_acc = Vector(0.,desired_acc.mag()*np.sign(desired_acc.y))
return desired_acc
示例2: Player
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import mag [as 别名]
#.........这里部分代码省略.........
return (self.x - self.defend_end_zone_x)*self.team.direction
@property
def opposite_team(self):
return self.team.opposite_team
@property
def direction(self):
return self.team.direction
@property
def has_ball(self):
return self.pitch.ball.carrier == self
@property
def in_contact(self):
return self in self.pitch.contacts.keys()
@property
def team_name(self):
if self.team.direction > 0:
return('home')
else:
return('away')
@property
def team_in_possession(self):
return self.team.in_possession
def x_from_defend_end_zone(self,x):
if self.team.direction > 0:
return x
else:
return self.pitch.xsize-x
def move(self):
# NOTE: Ignores mass! (assumes m=1 I guess)
# Don't move if we are prone
if not self.standing:
# Prone players might still be moving, but they rapidly deccelerate!
# Magic numbers
prone_acc = 20.
prone_top_speed = 5.
desired_acc = self.vel.norm() * prone_acc * self.pitch.dt * -1.
if self.vel.mag() < desired_acc.mag():
self.vel=Vector(0,0)
else:
self.vel += desired_acc
self.vel = self.vel.truncate(prone_top_speed)
self.pos += self.vel * self.pitch.dt
return
elif self.in_contact:
# Push resolved seperately
return
acc = self.current_acc()
# Check current puff reduced acc
# NOTE HACK: Current states consider current vel in providing desired acc
# We undo this so that they return the actual desired velocity
state_vel = self.move_state.execute()
desired_vel = state_vel + self.vel
drag_limited_acc = acc * (1. - desired_vel.angle_factor(self.vel) * self.vel.mag() / self.top_speed)
desired_acc = (desired_vel - self.vel).truncate(drag_limited_acc)
self.vel += desired_acc * self.pitch.dt
self.vel = self.vel.truncate(self.top_speed)
self.pos += self.vel * self.pitch.dt
# It costs puff to move
self.puff -= desired_acc.mag() * self.pitch.dt * self.pitch.puff_fac
def push(self):
if not self.in_contact: return
# NOTE: Pushing forwards always, but we don't always want to do that. Need to have hook
# into state and define in states the push directions ( a parrallel steering behaviours).
def current_acc(self):
" Current puff reduced max accel."
cut_in=0.5
ability_floor=0.5
#NOTE: Turned off for now to allow easier state debugging
return self.top_acc
# Reduce ability linearily after cut in, down to floor
ratio = self.puff/self.stamina
if ratio < cut_in:
fac = ratio*(1.-ability_floor)/cut_in + ability_floor
else:
fac = 1.
return fac*self.top_acc
def standup(self):
"""
Check if player is prone and if so whether they can stand yet.
"""
# Done via property now (but is it working?)
#if self.prone > 0.:
self.prone -= self.pitch.dt
# if self.prone <= 0.:
# self.standing=True
def drop_ball(self):
self.send(self.pitch.ball,'ball_loose')