55
66from util .orientation import Orientation
77from util .vec import Vec3
8+ from util .sequence import Sequence , ControlStep
89
910
1011class MyBot (BaseAgent ):
1112
1213 def initialize_agent (self ):
1314 # This runs once before the bot starts up
1415 self .controller_state = SimpleControllerState ()
16+ self .active_sequence : Sequence = None
1517
1618 def get_output (self , packet : GameTickPacket ) -> SimpleControllerState :
17- ball_location = Vec3 (packet .game_ball .physics .location )
1819
20+ if self .active_sequence and not self .active_sequence .done :
21+ return self .active_sequence .tick (packet )
22+
23+ ball_location = Vec3 (packet .game_ball .physics .location )
1924 my_car = packet .game_cars [self .index ]
2025 car_location = Vec3 (my_car .physics .location )
26+ car_velocity = Vec3 (my_car .physics .velocity )
27+
28+ if 550 < car_velocity .length () < 600 :
29+ self .active_sequence = Sequence ([
30+ ControlStep (0.05 , SimpleControllerState (jump = True )),
31+ ControlStep (0.05 , SimpleControllerState (jump = False )),
32+ ControlStep (0.2 , SimpleControllerState (jump = True , pitch = - 1 )),
33+ ControlStep (0.8 , SimpleControllerState ()),
34+ ])
35+ return self .active_sequence .tick (packet )
2136
2237 car_to_ball = ball_location - car_location
2338
@@ -27,18 +42,8 @@ def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
2742
2843 steer_correction_radians = find_correction (car_direction , car_to_ball )
2944
30- if steer_correction_radians > 0 :
31- # Positive radians in the unit circle is a turn to the left.
32- turn = - 1.0 # Negative value for a turn to the left.
33- action_display = "turn left"
34- else :
35- turn = 1.0
36- action_display = "turn right"
37-
3845 self .controller_state .throttle = 1.0
39- self .controller_state .steer = turn
40-
41- draw_debug (self .renderer , my_car , packet .game_ball , action_display )
46+ self .controller_state .steer = - 1 if steer_correction_radians > 0 else 1.0
4247
4348 return self .controller_state
4449
@@ -60,12 +65,3 @@ def find_correction(current: Vec3, ideal: Vec3) -> float:
6065 diff -= 2 * math .pi
6166
6267 return diff
63-
64-
65- def draw_debug (renderer , car , ball , action_display ):
66- renderer .begin_rendering ()
67- # draw a line from the car to the ball
68- renderer .draw_line_3d (car .physics .location , ball .physics .location , renderer .white ())
69- # print the action that the bot is taking
70- renderer .draw_string_3d (car .physics .location , 2 , 2 , action_display , renderer .white ())
71- renderer .end_rendering ()
0 commit comments