@ -24,6 +24,14 @@ class Agent(Base_Agent):
self . init_pos = ( [ - 14 , 0 ] , [ - 9 , - 5 ] , [ - 9 , 0 ] , [ - 9 , 5 ] , [ - 5 , - 5 ] , [ - 5 , 0 ] , [ - 5 , 5 ] , [ - 1 , - 6 ] , [ - 1 , - 2.5 ] , [ - 1 , 2.5 ] , [ - 1 , 6 ] ) [ unum - 1 ] # initial formation
def dribble ( self , target_2d = ( 15 , 0 ) , avoid_obstacles = True ) :
if avoid_obstacles :
next_pos , next_rel_ori = self . path_manager . get_dribble_path ( optional_2d_target = target_2d )
else :
distance_to_final_target = np . linalg . norm ( target_2d - self . loc_head_position [ : 2 ] )
return self . behavior . execute ( " Dribble " , next_rel_ori ,
False ) # Args: target, is_target_abs, ori, is_ori_abs, distance
def beam ( self , avoid_center_circle = False ) :
r = self . world . robot
@ -124,7 +132,7 @@ class Agent(Base_Agent):
def think_and_send ( self ) :
w = self . world
r = self . world . robot
r = self . world . robot
my_head_pos_2d = r . loc_head_position [ : 2 ]
my_ori = r . imu_torso_orientation
ball_2d = w . ball_abs_pos [ : 2 ]
@ -158,8 +166,10 @@ class Agent(Base_Agent):
min_teammate_ball_sq_dist = min ( teammates_ball_sq_dist )
self . min_teammate_ball_dist = math . sqrt ( min_teammate_ball_sq_dist ) # distance between ball and closest teammate
self . min_opponent_ball_dist = math . sqrt ( min ( opponents_ball_sq_dist ) ) # distance between ball and closest opponent
active_player_unum = teammates_ball_sq_dist . index ( min_teammate_ball_sq_dist ) + 1
if r . dribbling_state == " In " :
active_player_unum = r . unum
else :
active_player_unum = teammates_ball_sq_dist . index ( min_teammate_ball_sq_dist ) + 1
#--------------------------------------- 2. Decide action
@ -173,6 +183,7 @@ class Agent(Base_Agent):
elif PM_GROUP == w . MG_PASSIVE_BEAM :
self . beam ( True ) # avoid center circle
elif self . state == 1 or ( behavior . is_ready ( " Get_Up " ) and self . fat_proxy_cmd is None ) :
r . dribbling_state = " Out "
self . state = 0 if behavior . execute ( " Get_Up " ) else 1 # return to normal state if get up behavior has finished
elif PM == w . M_OUR_KICKOFF :
if r . unum == 9 :
@ -192,6 +203,7 @@ class Agent(Base_Agent):
self . move ( ( new_x , self . init_pos [ 1 ] ) , orientation = ball_dir , priority_unums = [ active_player_unum ] )
else : # I am the active player
path_draw_options ( enable_obstacles = True , enable_path = True , use_team_drawing_channel = True ) # enable path drawings for active player (ignored if self.enable_draw is False)
enable_pass_command = ( PM == w . M_PLAY_ON and ball_2d [ 0 ] < 6 )
@ -202,11 +214,15 @@ class Agent(Base_Agent):
# no need to change the state when PM is not Play On
elif self . min_opponent_ball_dist + 0.5 < self . min_teammate_ball_dist : # defend if opponent is considerably closer to the ball
if self . state == 2 : # commit to kick while aborting
self . state = 0 if self . kick ( abort = True ) else 2
self . dribble ( )
r . dribbling_state = " In "
else : # move towards ball, but position myself between ball and our goal
self . move ( slow_ball_pos + M . normalize_vec ( ( - 16 , 0 ) - slow_ball_pos ) * 0.2 , is_aggressive = True )
r . dribbling_state = " Out "
else :
self . state = 0 if self . kick ( goal_dir , 9 , False , enable_pass_command ) else 2
self . dribble ( )
r . dribbling_state = " In "
path_draw_options ( enable_obstacles = False , enable_path = False ) # disable path drawings