def goal_scored_for(self): if self.out_of_play(): if self.ball.x > self.field.length / 2: ball_angle_to_goal_post_se = ray_angle( self.ball.x_just_now, self.ball.y_just_now, self.field.markings_xy.ix['GoalPostSE'].x, self.field.markings_xy.ix['GoalPostSE'].y) ball_angle_to_goal_post_ne = ray_angle( self.ball.x_just_now, self.ball.y_just_now, self.field.markings_xy.ix['GoalPostNE'].x, self.field.markings_xy.ix['GoalPostNE'].y) ball_angle_between_goal_posts_e = angular_difference( ball_angle_to_goal_post_se, ball_angle_to_goal_post_ne) ball_angle_between_goal_post_se_and_direction = angular_difference( ball_angle_to_goal_post_se, self.ball.angle) if within_range(ball_angle_between_goal_post_se_and_direction, 0., ball_angle_between_goal_posts_e): return 'West' elif self.ball.x < -self.field.length / 2: ball_angle_to_goal_post_nw = ray_angle( self.ball.x_just_now, self.ball.y_just_now, self.field.markings_xy.ix['GoalPostNW'].x, self.field.markings_xy.ix['GoalPostNW'].y) ball_angle_to_goal_post_sw = ray_angle( self.ball.x_just_now, self.ball.y_just_now, self.field.markings_xy.ix['GoalPostSW'].x, self.field.markings_xy.ix['GoalPostSW'].y) ball_angle_between_goal_posts_w = angular_difference( ball_angle_to_goal_post_nw, ball_angle_to_goal_post_sw) ball_angle_between_goal_post_nw_and_direction = angular_difference( ball_angle_to_goal_post_nw, self.ball.angle) if within_range(ball_angle_between_goal_post_nw_and_direction, 0., ball_angle_between_goal_posts_w): return 'East'
def goal_scored_for(self): if self.out_of_play(): if self.ball.x > self.field.length / 2: ball_angle_to_goal_post_se = ray_angle(self.ball.x_just_now, self.ball.y_just_now, self.field.markings_xy.ix['GoalPostSE'].x, self.field.markings_xy.ix['GoalPostSE'].y) ball_angle_to_goal_post_ne = ray_angle(self.ball.x_just_now, self.ball.y_just_now, self.field.markings_xy.ix['GoalPostNE'].x, self.field.markings_xy.ix['GoalPostNE'].y) ball_angle_between_goal_posts_e = angular_difference(ball_angle_to_goal_post_se, ball_angle_to_goal_post_ne) ball_angle_between_goal_post_se_and_direction = angular_difference(ball_angle_to_goal_post_se, self.ball.angle) if within_range(ball_angle_between_goal_post_se_and_direction, 0., ball_angle_between_goal_posts_e): return 'West' elif self.ball.x < - self.field.length / 2: ball_angle_to_goal_post_nw = ray_angle(self.ball.x_just_now, self.ball.y_just_now, self.field.markings_xy.ix['GoalPostNW'].x, self.field.markings_xy.ix['GoalPostNW'].y) ball_angle_to_goal_post_sw = ray_angle(self.ball.x_just_now, self.ball.y_just_now, self.field.markings_xy.ix['GoalPostSW'].x, self.field.markings_xy.ix['GoalPostSW'].y) ball_angle_between_goal_posts_w = angular_difference(ball_angle_to_goal_post_nw, ball_angle_to_goal_post_sw) ball_angle_between_goal_post_nw_and_direction = angular_difference(ball_angle_to_goal_post_nw, self.ball.angle) if within_range(ball_angle_between_goal_post_nw_and_direction, 0., ball_angle_between_goal_posts_w): return 'East'
def observe_marking_in_front(self, field, min_distance_over_distance_sigma_ratio=6.): min_angle = pi marking_in_front = None for marking in field.markings: a = abs(angular_difference(self.angle, ray_angle(self.x, self.y, marking.x, marking.y))) d = euclidean_distance(self.x, self.y, marking.x, marking.y) if (a < min_angle) and (d >= min_distance_over_distance_sigma_ratio * self.distance_sigma): min_angle = a marking_in_front = marking self.observe((marking_in_front,))
def observe_marking_in_front(self, field, min_distance_over_distance_sigma_ratio=6.): min_angle = pi marking_in_front = None for marking in field.markings: a = abs( angular_difference( self.angle, ray_angle(self.x, self.y, marking.x, marking.y))) d = euclidean_distance(self.x, self.y, marking.x, marking.y) if (a < min_angle) and (d >= min_distance_over_distance_sigma_ratio * self.distance_sigma): min_angle = a marking_in_front = marking self.observe((marking_in_front, ))