def _boost_filled(self) -> bool: minimum_boost_level = self.MINIMUM_BOOST_LEVEL if self.agent.me.boost >= minimum_boost_level: self.agent.pop() defaultThrottle(self.agent, 0) return True return False
def _drive_to_post(self): car_to_target = self.target - self.agent.me.location distance_remaining = car_to_target.flatten().magnitude() # See commends for adjustment in jump_shot or aerial for explanation side_of_vector = sign( self.dir_to_goal.cross((0, 0, 1)).dot(car_to_target)) car_to_target_perp = car_to_target.cross( (0, 0, side_of_vector)).normalize() adjustment = car_to_target.angle( self.dir_to_goal) * distance_remaining / 3.14 final_target = self.target + (car_to_target_perp * adjustment) # Some adjustment to the final target to ensure it's inside the field and we dont try to drive through # any goalposts to reach it if abs(self.agent.me.location[1]) > GameConstants.FIELD_LENGTH: final_target[0] = cap(final_target[0], -GameConstants.CAP_X_IN_GOAL_LENGTH, GameConstants.CAP_X_IN_GOAL_LENGTH) local_target = self.agent.me.local(final_target - self.agent.me.location) angles = defaultPD(self.agent, local_target) defaultThrottle(self.agent, GameConstants.MAX_SPEED_BOOST) self.agent.controller.boost = False self.agent.controller.handbrake = True if abs( angles[1]) > 2.3 else self.agent.controller.handbrake
def _face_ball(self): vec_to_ball = self.agent.ball.location - self.agent.me.location angle = self.agent.me.local(vec_to_ball).angle(Vector3(1, 0, 0)) if angle > math.radians(self.ANGLE_CORRECTION_ALLOWED_DIFF): if self.agent.time - self.start_time > self.ANGLE_CORRECTION_DRIVE_DURATION: self.toggle *= -1 self.start_time = self.agent.time defaultPD(self.agent, self.toggle * self.agent.me.local(vec_to_ball), self.toggle) defaultThrottle(self.agent, self.ANGLE_CORRECTION_SPEED, self.toggle)
def _drive_to_boost_pad(self, boost_pad: boost_object, brake_upon_destination: bool): # Driving towards selected boost target = self.agent.boosts[ boost_pad].location # dont forget to remove this! local_target = self.agent.me.local(target - self.agent.me.location) defaultPD(self.agent, local_target) if brake_upon_destination: speed = min(GameConstants.MAX_SPEED_BOOST, (self.agent.me.location - target).magnitude()) else: speed = GameConstants.MAX_SPEED_BOOST defaultThrottle(self.agent, speed)
def _correct_car_angle(self): angle = self.agent.me.local(self.dir_to_goal).angle(Vector3(1, 0, 0)) if angle < math.radians(self.ANGLE_CORRECTION_ALLOWED_DIFF): self.agent.pop() if self.agent.time - self.start_time > self.ANGLE_CORRECTION_DRIVE_DURATION: self.toggle *= -1 self.start_time = self.agent.time defaultPD(self.agent, self.toggle * self.agent.me.local(self.dir_to_goal), self.toggle) defaultThrottle(self.agent, self.ANGLE_CORRECTION_SPEED, self.toggle)
def step(self): """Run step behaviour returns whether the current entity is finished. :return: Controller for the corresponding car and a flag indicating whether it is finished. :rtype: (SimpleControllerState, bool) """ target = self.world.ball.physics.location + Vector3( 0, 200 * side(self.world.teams[self.index]), 0) local_target = self.world.me.local(target - self.world.me.location) defaultPD(self.world, local_target) defaultThrottle(self.world, 2300) # I think you need self.drone.physics.location return SimpleControllerState(), False
def run(self, agent: GoslingAgent): """Wait forever :param agent: Gosling agent. :type agent: GoslingAgent """ self.agent = agent if self.state == State.INITIALIZE: self._initialize_wait() if self._waiting_done(): agent.pop() defaultThrottle(agent, 0) if self.face_ball: self._face_ball()
def _goto_target(self, agent: GoslingAgent, target: Vector3): """"Drives the agent to a particular target. """ # Some adjustment to the final target to ensure it's inside the field and we dont try to drive through # any goalposts to reach it if abs(agent.me.location[1]) > GameConstants.FIELD_LENGTH: target[0] = cap(target[0], -GameConstants.CAP_X_IN_GOAL_LENGTH, GameConstants.CAP_X_IN_GOAL_LENGTH) local_target = agent.me.local(target - agent.me.location) angles = defaultPD(agent, local_target) defaultThrottle(agent, GameConstants.MAX_SPEED) agent.controller.boost = False agent.controller.handbrake = True if abs( angles[1]) > 2.3 else agent.controller.handbrake
def _go_to_target(self, target: Vector3): # Control our car defaultPD(self.agent, self.agent.me.local(target - self.agent.me.location)) dist_to_target = (target - self.agent.me.location).magnitude() if dist_to_target < self.FINISH_DIST: self.agent.pop() # Quickly compensate if far away if dist_to_target > self.QUICK_COMPENSATION_RANGE: defaultThrottle(self.agent, GameConstants.max_speed_boost) else: defaultThrottle( self.agent, min(GameConstants.max_speed_no_boost, self._get_controlled_velocity(target)))
def run(self, agent: GoslingAgent): """ Run kickoff routine. :param agent: Gosling agent. """ target = agent.ball.location + Vector3( 0, self.TARGET_OFFSET_FROM_CENTER * side(agent.team), 0) local_target = agent.me.local(target - agent.me.location) defaultPD(agent, local_target) defaultThrottle(agent, GameConstants.MAX_SPEED_BOOST) if local_target.magnitude() < self.FLIP_DISTANCE: agent.pop() agent.push( flip( agent.me.local(agent.foe_goal.location - agent.me.location)))
def _approach_ball_control(self): defaultPD(self.agent, self._get_approach_local_target()) defaultThrottle(self.agent, self._get_approach_throttle())
def _close_ball_control(self): defaultPD(self.agent, self._get_close_local_target()) defaultThrottle(self.agent, self._get_close_throttle())
def _control_agent_throttle(self, target: Vector3): use_boost = self._get_dist_to_target(target) > self.QUICK_COMPENSATION_RANGE if use_boost: defaultThrottle(self.agent, GameConstants.MAX_SPEED_BOOST) else: defaultThrottle(self.agent, min(GameConstants.MAX_SPEED_NO_BOOST, self._get_control_velocity(target)))