def _position_optimally_objective_goalie(state: PlayerState): if "kick_off" in state.world_view.game_state: # If already close to starting position, do idle orientation if state.position.get_value().euclidean_distance_from( state.get_global_start_pos()) < 2: return Objective(state, lambda: actions.idle_orientation(state), lambda: True) return Objective( state, lambda: actions.jog_to(state, state.get_global_start_pos()), lambda: True) optimal_position = _optimal_goalie_pos(state) current_position: Coordinate = state.position.get_value() dist = current_position.euclidean_distance_from(optimal_position) if dist > 6.0: target = optimal_position return Objective(state, lambda: actions.rush_to(state, target), lambda: True) if dist > 0.6: difference = optimal_position - current_position return Objective( state, lambda: actions.positional_adjustment(state, difference), lambda: True) else: return Objective(state, lambda: actions.idle_orientation(state), lambda: True)
def _optimal_goalie_pos(state: PlayerState): if state.team_name in configurations.GOALIE_MODEL_TEAMS: if state.goalie_position_strategy is not None: optimal_coord = Coordinate(state.goalie_position_strategy.pos_x, state.goalie_position_strategy.pos_y) state.goalie_position_strategy = None return optimal_coord else: ball: Ball = state.world_view.ball.get_value() y_value = clamp(ball.coord.pos_y * 0.8, -5, 5) return Coordinate(state.get_global_start_pos().pos_x, y_value) else: ball: Ball = state.world_view.ball.get_value() y_value = clamp(ball.coord.pos_y * 0.8, -5, 5) return Coordinate(state.get_global_start_pos().pos_x, y_value)
def _position_optimally_objective(state: PlayerState): if "kick_off" in state.world_view.game_state: # If already close to starting position, do idle orientation if state.position.get_value().euclidean_distance_from( state.get_global_start_pos()) < 2: return Objective(state, lambda: actions.idle_orientation(state), lambda: True) return Objective( state, lambda: actions.jog_to(state, state.get_global_start_pos()), lambda: True) if state.player_type == "defender": optimal_position = _optimal_defender_pos(state) elif state.player_type == "midfield": optimal_position = _optimal_midfielder_pos(state) elif state.player_type == "goalie": optimal_position = _optimal_goalie_pos(state) else: # Striker optimal_position = _optimal_striker_pos( state) # _optimal_attacker_pos(state) current_position: Coordinate = state.position.get_value() dist = current_position.euclidean_distance_from(optimal_position) if dist > 6.0: # todo: Should they sprint if dist > 10? target = optimal_position return Objective(state, lambda: actions.rush_to(state, target), lambda: True) if dist > 2.0: difference = optimal_position - current_position return Objective( state, lambda: actions.positional_adjustment(state, difference), lambda: True) else: return Objective(state, lambda: actions.idle_orientation(state), lambda: True)