def run(self, agent: VirxERLU): if self.start_time == -1: self.start_time = agent.time T = agent.time - self.start_time agent.controller.boost = True agent.controller.throttle = 1 agent.controller.roll = -1 if T > 1.295 and not agent.me.airborne: agent.pop() return if T < .11: agent.controller.steer = 1 agent.controller.yaw = 1 if T >= .1 and not self.have_jumped: agent.controller.jump = True self.have_jumped = True if T > .175 and not self.have_flipped: agent.controller.jump = True agent.controller.pitch = -1 self.have_flipped = True if .195 < T < .845: agent.controller.pitch = 1 if .795 < T < 1.295: agent.controller.yaw = -1
def send_comm(agent: VirxERLU, msg): message = {"index": agent.index, "team": agent.team} msg.update(message) try: agent.matchcomms.outgoing_broadcast.put_nowait({"VirxERLU": msg}) except Full: agent.print("Outgoing broadcast is full; couldn't send message")
def valid_ceiling_shot(agent: VirxERLU, cap_=5): struct = agent.ball_prediction_struct if struct is None: return end_slice = math.ceil(cap_ * 60) slices = struct.slices[30:end_slice:2] if agent.me.location.x * side(agent.team) > 0: quadrilateral = (round(agent.foe_goal.right_post.flatten()), round(agent.foe_goal.left_post.flatten())) else: quadrilateral = (round(agent.foe_goal.left_post.flatten()), round(agent.foe_goal.right_post.flatten())) quadrilateral += ( Vector(0, 640), Vector(round(agent.me.location.x - (200 * sign(agent.me.location.x))), round(agent.me.location.y - (200 * side(agent.team)))), ) agent.polyline(quadrilateral + (quadrilateral[0], ), agent.renderer.team_color(alt_color=True)) for ball_slice in slices: intercept_time = ball_slice.game_seconds time_remaining = intercept_time - agent.time if time_remaining <= 0: return ball_location = Vector(ball_slice.physics.location.x, ball_slice.physics.location.y, ball_slice.physics.location.z) if ball_location.z < 642: continue if not point_inside_quadrilateral_2d(round(ball_location.flatten()), quadrilateral): continue return ball_location
def run(self, agent: VirxERLU): if self.stage == 0: agent.controller.boost = True if agent.me.boost > self.old_boost: self.stage = 1 else: self.old_boost = agent.me.boost elif self.stage == 1: angles = defaultPD( agent, agent.me.local_location(Vector(110 * sign(agent.me.location.x)))) if abs(angles[1]) < 0.1: self.stage = 2 elif self.stage == 2: agent.push(speed_flip()) self.stage = 3 elif self.stage == 3: # TODO do a second flip is the opponent is speedflipping as well if False: agent.push( flip( agent.me.local_location( Vector(120 * sign(agent.me.location.x))))) self.stage = 4 elif self.stage == 4: agent.pop()
def defaultThrottle(agent: VirxERLU, target_speed, target_angles=None, local_target=None): # accelerates the car to a desired speed using throttle and boost car_speed = agent.me.forward.dot(agent.me.velocity) if agent.me.airborne: return car_speed if target_angles is not None and local_target is not None: turn_rad = turn_radius(abs(car_speed)) agent.controller.handbrake = not agent.me.airborne and agent.me.velocity.magnitude( ) > 600 and (is_inside_turn_radius(turn_rad, local_target, sign(agent.controller.steer)) if abs(local_target.y) < turn_rad or car_speed > 1410 else abs(local_target.x) < turn_rad) angle_to_target = abs(target_angles[1]) if target_speed < 0: angle_to_target = math.pi - angle_to_target if agent.controller.handbrake: if angle_to_target > 2.6: agent.controller.steer = sign(agent.controller.steer) agent.controller.handbrake = False else: agent.controller.steer = agent.controller.yaw # Thanks to Chip's RLU speed controller for this # https://github.com/samuelpmish/RLUtilities/blob/develop/src/mechanics/drive.cc#L182 # I had to make a few changes because it didn't play very nice with driving backwards t = target_speed - car_speed acceleration = t / REACTION_TIME if car_speed < 0: acceleration *= -1 # if we're going backwards, flip it so it thinks we're driving forwards brake_coast_transition = BRAKE_COAST_TRANSITION coasting_throttle_transition = COASTING_THROTTLE_TRANSITION throttle_accel = throttle_acceleration(car_speed) throttle_boost_transition = 1 * throttle_accel + 0.5 * agent.boost_accel if agent.me.up.z < 0.7: brake_coast_transition = coasting_throttle_transition = MIN_WALL_SPEED # apply brakes when the desired acceleration is negative and large enough if acceleration <= brake_coast_transition: agent.controller.throttle = -1 # let the car coast when the acceleration is negative and small elif brake_coast_transition < acceleration and acceleration < coasting_throttle_transition: pass # for small positive accelerations, use throttle only elif coasting_throttle_transition <= acceleration and acceleration <= throttle_boost_transition: agent.controller.throttle = 1 if throttle_accel == 0 else cap( acceleration / throttle_accel, 0.02, 1) # if the desired acceleration is big enough, use boost elif throttle_boost_transition < acceleration: agent.controller.throttle = 1 if not agent.controller.handbrake: if t > 0 and angle_to_target < 1: agent.controller.boost = True # don't boost when we need to lose speed, we we're using handbrake, or when we aren't facing the target if agent.cheating and agent.odd_tick == 0 and angle_to_target < 0.5: velocity = agent.me.velocity.flatten() if velocity.magnitude() > 100: if sign(target_speed) != sign(car_speed): velocity *= -1 new_velocity = velocity.scale(abs(target_speed)) cars = { agent.index: CarState( Physics(velocity=Vector3(new_velocity.x, new_velocity.y))) } agent.set_game_state(GameState(cars=cars)) if car_speed < 0: agent.controller.throttle *= -1 # earlier we flipped the sign of the acceleration, so we have to flip the sign of the throttle for it to be correct return car_speed