def input(self): controller_input = SimpleControllerState() theta = self.current_state.rot.yaw correction_vector = self.target_state.pos - self.current_state.pos facing_vector = Vec3(cos(theta), sin(theta), 0) car_to_target = (self.target_state.pos - self.current_state.pos).normalize() #Rotated to the car's reference frame on the ground. rel_correction_vector = Vec3((correction_vector.x*cos(theta)) + (correction_vector.y * sin(theta)), (-(correction_vector.x*sin(theta))) + (correction_vector.y * cos(theta)), 0) if self.can_reverse and facing_vector.dot(car_to_target) < - 0.5: correction_angle = atan2(rel_correction_vector.y, rel_correction_vector.x) controller_input.throttle = - 1.0 if abs(correction_angle) > 1.25: controller_input.handbrake = 1 controller_input.steer = cap_magnitude(-5*correction_angle, 1) else: correction_angle = atan2(rel_correction_vector.y, rel_correction_vector.x) controller_input.throttle = 1.0 if abs(correction_angle) > 1.25: controller_input.handbrake = 1 controller_input.steer = cap_magnitude(5*correction_angle, 1) return controller_input
def controller(self, agent, angle): controller_state = SimpleControllerState() steer_value = steer(angle) controller_state.steer = steer_value controller_state.throttle = 1 controller_state.handbrake = True if self.level == PowerSlideLevel.NORMAL: balance_threshold = 0.25 * abs( agent.me.angular_velocity.data[2])**2 + 0.05 if balance_threshold * -1 <= angle <= balance_threshold: controller_state.handbrake = False controller_state.boost = True if abs(agent.me.angular_velocity.data[2]) >= 0.15: controller_state.steer = sign( agent.me.angular_velocity.data[2]) * -1 else: controller_state.steer = 0 elif self.level == PowerSlideLevel.U_TURN: if abs(angle) < 1.15: controller_state.steer = steer_value * -1 controller_state.throttle = -1 controller_state.handbrake = False controller_state.boost = False if abs(angle) < 0.15: controller_state.steer = 0 return controller_state
def exampleController(agent, target_object): #target_object es un objeto tipo obj location = target_object.local_location controller_state = SimpleControllerState() angle_to_target = math.atan2(location.data[1], location.data[0]) angle_velocity = math.atan2(agent.me.velocity.data[1], agent.me.velocity.data[1]) #draw_debug(agent.renderer,location.data) draw_debug(agent, agent.renderer, target_object.location.data) current_speed = velocity2D(agent.me) #steering if abs(angle_to_target) < math.pi / 4: if agent.me.has_wheel_contact == True: controller_state.boost = True controller_state.handbrake = False else: controller_state.boost = False controller_state.handbrake = True controller_state.steer = sign(angle_to_target) * min( 1, abs(2 * angle_to_target)) controller_state.throttle = 1 #dodging if abs(angle_to_target) < math.pi / 2 and abs( angle_velocity) < math.pi / 3: dodging(agent, target_object, controller_state, angle_to_target) return controller_state
def CeilingRushController( agent, target_object1, target_object2): #target_object es un objeto tipo obj controller_state = SimpleControllerState() '''if distance2D(agent.me,agent.pointA)<distance2D(agent.me,agent.pointB) and agent.me.location.data[2]>2800: target_object = target_object2 location = agent.pointB.local_location angle_to_target = math.atan2(location.data[1],location.data[0]) else: target_object = target_object1 location = agent.pointA.local_location angle_to_target = math.atan2(location.data[1],location.data[0])''' target_object = target_object1 location = agent.pointA.local_location angle_to_target = math.atan2(location.data[1], location.data[0]) draw_debug(agent, agent.renderer, target_object.location.data) angle_velocity = math.atan2(agent.me.velocity.data[1], agent.me.velocity.data[1]) #draw_debug(agent.renderer,target_object.location.data) current_speed = velocity2D(agent.me) #steering if abs(angle_to_target) < math.pi / 4: controller_state.handbrake = False elif abs(angle_to_target) < math.pi and abs(angle_to_target) > math.pi / 2: controller_state.handbrake = True if agent.me.location.data[2] < 1800: controller_state.steer = sign(angle_to_target) * min( 1, abs(2 * angle_to_target)) else: controller_state.steer = 0 #throttle controller_state.throttle = 1 return controller_state
def exampleController(self, target_object, target_speed): location = target_object.local_location controller_state = SimpleControllerState() angle_to_ball = math.atan2(location.data[1], location.data[0]) current_speed = velocity2D(self.me) #team team = sign(self.team) # if team<=0: #blue #try to get the ball to orange goal #else: #orange #try to get the ball to blue goal #steering if angle_to_ball > 0.1: controller_state.steer = controller_state.yaw = 1 elif angle_to_ball < -0.1: controller_state.steer = controller_state.yaw = -1 else: controller_state.steer = controller_state.yaw = 0 #powersliding if angle_to_ball > 0.8: controller_state.handbrake = True elif angle_to_ball < -0.8: controller_state.handbrake = True else: controller_state.handbrake = False #throttle if target_speed > current_speed: controller_state.throttle = 1.0 if target_speed > 1400 and self.start > 2.2 and current_speed < 2250: controller_state.boost = True elif target_speed < current_speed: controller_state.throttle = 0 #dodging front only time_difference = time.time() - self.start if time_difference > 2.2 and distance2D( target_object.location, self.me.location) > 1000 and abs(angle_to_ball) < 1.3: self.start = time.time() elif time_difference <= 0.1: controller_state.jump = True controller_state.pitch = -1 elif time_difference >= 0.1 and time_difference <= 0.15: controller_state.jump = False controller_state.pitch = -1 elif time_difference > 0.15 and time_difference < 1: controller_state.jump = True controller_state.yaw = controller_state.steer controller_state.pitch = -1 return controller_state
def Controller_output(agent, target, speed): Controller = SimpleControllerState() LocalTagret = agent.car.matrix.dot(target - agent.car.loc) angle_target = math.atan2(LocalTagret[1], LocalTagret[0]) Controller.steer = steer(angle_target) agentSpeed = velocity2D(agent.car) Controller.throttle, Controller.boost = throttle(speed, agentSpeed) if abs(angle_target) > 2: Controller.handbrake = True else: Controller.handbrake = False return Controller
def follow_controller(agent, target_object, target_speed): location = toLocal(target_object, agent.me) controller_state = SimpleControllerState() angle_to_ball = math.atan2(location.data[1], location.data[0]) current_speed = velocity2D(agent.me) pitch = agent.me.location.data[0] % math.pi roll = agent.me.location.data[2] % math.pi # Turn dem wheels controller_state.steer = cap(angle_to_ball * 5, -1, 1) print(velocity2D(agent.me)) if abs(angle_to_ball) > (math.pi / 3.): controller_state.handbrake = True else: controller_state.handbrake = False # throttle if target_speed > current_speed: controller_state.throttle = 1.0 if target_speed > 1400 and agent.start > 2.2 and current_speed < 2250 and abs( angle_to_ball) < (math.pi / 3.): controller_state.boost = True elif target_speed < current_speed: controller_state.throttle = 0 # doging time_difference = time.time() - agent.start if time_difference > 2.2 and distance2D( target_object, agent.me) > 1000 and abs(angle_to_ball) < 1.3 and velocity2D( agent.me) > 1200: agent.start = time.time() elif time_difference <= 0.1: controller_state.jump = True controller_state.pitch = -1 elif time_difference >= 0.1 and time_difference <= 0.15: controller_state.jump = False controller_state.pitch = -1 elif time_difference > 0.15 and time_difference < 1: controller_state.jump = True controller_state.yaw = controller_state.steer controller_state.pitch = -1 # print("target: " + str(target_speed) + ", current: " + str(current_speed)) return controller_state
def frugal_controller(agent, target, speed): controller_state = SimpleControllerState() location = return_local_location(target, agent.me) angle_to_target = math.atan2(location.data[1], location.data[0]) controller_state.steer = steer(angle_to_target) current_speed = velocity_2d(agent.me) if current_speed < speed: controller_state.throttle = 1.0 elif current_speed - 50 > speed: controller_state.throttle = -1.0 else: controller_state.throttle = 0 if distance_2d(agent.me.location.data, target) < 250: controller_state.handbrake = 1 # time_difference = time.time() - agent.start # if time_difference > 2.2 and distance_2d(target, agent.me) > (velocity_2d(agent.me) * 2.3) and abs( # angle_to_target) < 1 and current_speed < speed: # agent.start = time.time() # elif time_difference <= 0.1: # controller_state.jump = True # controller_state.pitch = -1 # elif time_difference >= 0.1 and time_difference <= 0.15: # controller_state.jump = False # controller_state.pitch = -1 # elif time_difference > 0.15 and time_difference < 1: # controller_state.jump = True # controller_state.yaw = controller_state.steer # controller_state.pitch = -1 return controller_state
def resolve(self, prev_status, car, packet: GameTickPacket): point = self.pointFunc(car, packet) car_location = Vec3(car.physics.location.x, car.physics.location.y) car_direction = rlmath.get_car_facing_vector(car) yaw_velocity = car.physics.angular_velocity.x car_velocity = Vec3(car.physics.velocity.x, car.physics.velocity.y) car_to_point = point - car_location steer_correction_radians = rlmath.fix_ang( car_direction.ang_to_flat(car_to_point) + yaw_velocity * 0.2) velocity_correction_radians = car_velocity.ang_to_flat(car_to_point) controller = SimpleControllerState() if abs(steer_correction_radians) > 0.5: controller.handbrake = True else: return (SUCCESS, self.parent, None) if steer_correction_radians > 0: controller.steer = 1 elif steer_correction_radians < 0: controller.steer = -1 controller.throttle = 0.3 # In these cases we want to brake instead if car_velocity.length() > 500: controller.throttle = 0 return (ACTION, self, controller)
def exampleController(agent, target_object,target_speed): distance = distance2D(agent.me.location,target_object.location) if distance > 400: #print("switching to efficient") agent.state = efficientMover return efficientMover(agent,target_object,target_speed) controller_state = SimpleControllerState() controller_state.handbrake = False car_direction = get_car_facing_vector(agent.me) car_to_ball = agent.me.location - target_object.location steer_correction_radians = steer(car_direction.correction_to(car_to_ball)) current_speed = getVelocity(agent.me.velocity) #steering controller_state.steer = steer(steer_correction_radians) #throttle if target_speed > current_speed: controller_state.throttle = 1.0 if target_speed > 1400 and current_speed < 2250: controller_state.boost = True elif target_speed < current_speed: controller_state.throttle = 0 return controller_state
def get_output(self, game_tick_packet: GameTickPacket) -> SimpleControllerState: # Get the direction to the ball car = game_tick_packet.game_cars[self.index] ball_pos = game_tick_packet.game_ball.physics.location to_ball_x = ball_pos.x - car.physics.location.x to_ball_y = ball_pos.y - car.physics.location.y dist_to_ball = math.sqrt(to_ball_x**2 + to_ball_y**2) if dist_to_ball == 0: return SimpleControllerState() to_ball_x /= dist_to_ball to_ball_y /= dist_to_ball # How is the car aligned with the direction to the ball? yaw = float(car.physics.rotation.yaw) car_left_x = -math.sin(yaw) car_left_y = math.cos(yaw) dot_product = to_ball_x * car_left_x + to_ball_y * car_left_y # Act on the information above. controller_state = SimpleControllerState() controller_state.throttle = 1.0 controller_state.steer = min( 1, max(-1, self.steering_coefficient * dot_product)) controller_state.boost = abs(dot_product) < .1 controller_state.handbrake = abs(dot_product) > .9 return controller_state
def get_output(self, game_tick_packet: GameTickPacket) -> SimpleControllerState: seconds = game_tick_packet.game_info.seconds_elapsed controller_state = SimpleControllerState() controller_state.steer = 0 controller_state.handbrake = 0 return controller_state
def input(self): controller_input = SimpleControllerState() controller_input.throttle = 1 if self.boost == 1: controller_input.boost = 1 controller_input.handbrake = 1 controller_input.steer = self.direction return controller_input
def WaitController(agent, target_object, target_speed): current_speed = velocity2D(agent.me) controller_state = SimpleControllerState() location = target_object.local_location angle_to_target = math.atan2(location.data[1], location.data[0]) draw_debug(agent, agent.renderer, target_object.location.data) if abs(angle_to_target) < math.pi / 4: controller_state.handbrake = False elif abs(angle_to_target) < math.pi and abs(angle_to_target) > math.pi / 2: controller_state.handbrake = True controller_state.yaw = controller_state.steer = sign( angle_to_target) * min(1, abs(2 * angle_to_target)) if distance2D(target_object, agent.me) < 100: controller_state.throttle = -1 else: controller_state.throttle = 1 return controller_state
def drive_to_target(car: Car, target: Vec3, controls=None, speed=MAX_BOOST_SPEED) -> SimpleControllerState: steer_direction = get_steer(car, target-car.location) if not controls: controls = SimpleControllerState() controls.steer = clamp(steer_direction) controls.throttle = clamp(speed/MAX_DRIVING_SPEED) # print("throttle: ", controls.throttle) controls.boost = speed > MAX_DRIVING_SPEED and car.boost > 0 if abs(steer_direction) > 2.8: controls.handbrake = True return controls
def getSensible_thingToCONTROL(magicWariable): ThisISTHE_controller = SimpleControllerState() ThisISTHE_controller.throttle = magicWariable[magicWariable[0][0]] ThisISTHE_controller.steer = magicWariable[magicWariable[0][1]] ThisISTHE_controller.pitch = magicWariable[magicWariable[0][2]] ThisISTHE_controller.yaw = magicWariable[magicWariable[0][3]] ThisISTHE_controller.roll = magicWariable[magicWariable[0][4]] ThisISTHE_controller.jump = magicWariable[magicWariable[0][5]] ThisISTHE_controller.boost = magicWariable[magicWariable[0][6]] ThisISTHE_controller.handbrake = magicWariable[magicWariable[0][7]] return ThisISTHE_controller
def get_output(self, packet: GameTickPacket) -> SimpleControllerState: """ This function will be called by the framework many times per second. This is where you can see the motion of the ball, etc. and return controls to drive your car. """ # Keep our boost pad info updated with which pads are currently active self.boost_pad_tracker.update_boost_status(packet) # This is good to keep at the beginning of get_output. It will allow you to continue # any sequences that you may have started during a previous call to get_output. if self.active_sequence is not None and not self.active_sequence.done: controls = self.active_sequence.tick(packet) if controls is not None: return controls # Gather some information about our car and the ball my_car = packet.game_cars[self.index] car_location = Vec3(my_car.physics.location) car_velocity = Vec3(my_car.physics.velocity) ball_location = Vec3(packet.game_ball.physics.location) nearest_boost_loc = self.get_nearest_boost(car_location) # By default we will chase the ball, but target_location can be changed later target_location = nearest_boost_loc # if car_location.dist(ball_location) > 1500: # # We're far away from the ball, let's try to lead it a little bit # ball_prediction = self.get_ball_prediction_struct() # This can predict bounces, etc # ball_in_future = find_slice_at_time(ball_prediction, packet.game_info.seconds_elapsed + 2) # # # ball_in_future might be None if we don't have an adequate ball prediction right now, like during # # replays, so check it to avoid errors. # if ball_in_future is not None: # target_location = Vec3(ball_in_future.physics.location) # self.renderer.draw_line_3d(ball_location, target_location, self.renderer.cyan()) # Draw some things to help understand what the bot is thinking self.renderer.draw_line_3d(car_location, target_location, self.renderer.white()) self.renderer.draw_string_3d(car_location, 1, 1, f'Speed: {car_velocity.length():.1f}', self.renderer.white()) self.renderer.draw_rect_3d(target_location, 8, 8, True, self.renderer.cyan(), centered=True) if 750 < car_velocity.length() < 800: # We'll do a front flip if the car is moving at a certain speed. return self.begin_front_flip(packet) controls = SimpleControllerState() controls.steer = steer_toward_target(my_car, target_location) controls.throttle = 1.0 controls.boost = True controls.handbrake = True # You can set more controls if you want, like controls.boost. return controls
def get_controls(game_info, sub_state_machine): controls = SimpleControllerState() controls.throttle = 1 controls.boost = 1 controls.handbrake = 1 controls.steer = 1 persistent = game_info.persistent return controls, persistent
def to_simple_controller_state(self): controls = SimpleControllerState() controls.throttle = self.throttle controls.steer = self.steer controls.yaw = self.yaw controls.pitch = self.pitch controls.roll = self.roll controls.boost = self.boost controls.jump = self.jump controls.handbrake = self.handbrake return controls
def copy_controls(obj_to: SimpleControllerState, obj_from: SimpleControllerState): """Copies the attribute of one SimpleControlerStates to another""" obj_to.steer = obj_from.steer obj_to.throttle = obj_from.throttle obj_to.pitch = obj_from.pitch obj_to.yaw = obj_from.yaw obj_to.roll = obj_from.roll obj_to.jump = obj_from.jump obj_to.boost = obj_from.boost obj_to.handbrake = obj_from.handbrake obj_to.use_item = obj_from.use_item
def decode_output(arr): s = SimpleControllerState() s.throttle = clamp1(n[0]) s.steer = clamp1(n[1]) s.boost = n[2] > 0.5 s.handbrake = n[3] > 0.5 # s.pitch = clamp1(n[2]) # s.yaw = clamp1(n[3]) # s.roll = clamp1(n[4]) # s.jump = n[6] > 0.5 # s.use_item = n[7] > 0.5 return s
def finalize_output(output): framework_output = SimpleControllerState() framework_output.throttle = output.throttle framework_output.steer = output.steer framework_output.yaw = output.yaw framework_output.pitch = output.pitch framework_output.roll = output.roll framework_output.boost = output.boost framework_output.handbrake = output.handbrake framework_output.jump = output.jump return framework_output
def get(self, data): c = SimpleControllerState() c.throttle = max(min(data[0], 1), -1) c.steer = max(min(data[1], 1), -1) c.pitch = max(min(data[2], 1), -1) c.yaw = max(min(data[3], 1), -1) c.roll = max(min(data[4], 1), -1) c.jump = data[5] c.boost = data[6] c.handbrake = data[7] c.use_item = data[8] return c
def get_output(self): output = SimpleControllerState() output.throttle = self.throttle output.steer = self.steer output.pitch = self.pitch output.yaw = self.yaw output.roll = self.roll output.jump = self.jump output.boost = self.boost output.handbrake = self.handbrake return output
def array_to_scs(a): scs = SimpleControllerState() scs.throttle = a[0] scs.steer = a[1] scs.pitch = a[2] scs.yaw = a[3] scs.roll = a[4] scs.jump = a[5] scs.boost = a[6] scs.handbrake = a[7] return scs
def RushController(agent, target_object): #target_object es un objeto tipo obj controller_state = SimpleControllerState() location = target_object.local_location angle_to_target = math.atan2(location.data[1], location.data[0]) angle_velocity = math.atan2(agent.me.velocity.data[1], agent.me.velocity.data[1]) draw_debug(agent, agent.renderer, target_object.location.data) #steering if abs(angle_to_target) < math.pi / 4: controller_state.handbrake = False elif abs(angle_to_target) < math.pi and abs(angle_to_target) > math.pi / 2: controller_state.handbrake = True controller_state.yaw = controller_state.steer = sign( angle_to_target) * min(1, abs(2 * angle_to_target)) #throttle controller_state.throttle = 1 #shot if True: #abs(angle_velocity) < math.pi/3: shot(agent, target_object, controller_state, angle_to_target) return controller_state
def greedyMover(agent,target_object): controller_state = SimpleControllerState() controller_state.handbrake = False location = toLocal(target_object, agent.me) angle = math.atan2(location.data[1], location.data[0]) controller_state.throttle = 1 if getVelocity(agent.me.velocity) < 2200: if agent.onSurface: controller_state.boost = True controller_state.jump = False controller_state.steer = Gsteer(angle) return controller_state
def get_controls(self, car_state: CarState, car: Car): controls = SimpleControllerState() target_Vec3 = Vec3(self.location[0], self.location[1], self.location[2]) if angle_between(self.location - to_vec3(car_state.physics.location), car.forward()) > pi / 2: controls.boost = False controls.handbrake = True elif angle_between(self.location - to_vec3(car_state.physics.location), car.forward()) > pi / 4: controls.boost = False controls.handbrake = False else: controls.boost = self.boost controls.handbrake = False # Be smart about not using boost at max speed # if Vec3(car.physics.velocity).length() > self.boost_analysis.frames[-1].speed - 10: # controls.boost = False controls.steer = steer_toward_target(car_state, target_Vec3) controls.throttle = 1 return controls
def act(self, action): controller_state = SimpleControllerState() controller_state.throttle = action[0] # controller_state.steer = action[1] # controller_state.pitch = action[2] # controller_state.yaw = action[3] # controller_state.roll = action[4] # controller_state.jump = True if action[5] > 0.5 else False # controller_state.boost = True if action[6] > 0.5 else False # controller_state.handbrake = True if action[7] > 0.5 else False controller_state.steer = 0 controller_state.pitch = 0 controller_state.yaw = 0 controller_state.roll = 0 controller_state.jump = 0 controller_state.boost = 0 controller_state.handbrake = 0 self.manager.agent_action_queue.put(controller_state)
def goto(target_location, target_speed, my_car, agent, packet): car_speed = Vec3(my_car.physics.velocity).length() distance = Vec3(my_car.physics.location).flat().dist( target_location.flat()) angle = Orientation( my_car.physics.rotation).forward.ang_to(target_location - Vec3(my_car.physics.location)) controls = SimpleControllerState() controls.steer = steer_toward_target(my_car, target_location, 0) controls.yaw = steer_toward_target(my_car, target_location, -my_car.physics.angular_velocity.z / 6) controls.throttle = cap(target_speed - car_speed, -1, 1) controls.boost = (target_speed > 1410 and abs(target_speed - car_speed) > 20 and angle < 0.3) controls.handbrake = angle > 2.3 controls.jump = (1 if my_car.physics.location.y >= 0 else -1) == ( 1 if agent.team == 1 else -1 ) and abs( my_car.physics.location.y) > 5000 and my_car.physics.location.z > 200 controls.use_item = Vec3(my_car.physics.location).dist( Vec3(packet.game_ball.physics.location)) < 200 and relative_location( Vec3(my_car.physics.location), Orientation( my_car.physics.rotation), Vec3(packet.game_ball.physics.location)).z < 75 if (abs(target_speed - car_speed) > 20 and angle < 0.3 and distance > 600) and ((target_speed > 1410 and my_car.boost == 0) or 700 < car_speed < 800): agent.stack.append(wavedash(target_location)) return controls