Esempio n. 1
0
    def __init__(self,
                 match_time: int,
                 match_id: int,
                 half_id: int,
                 progress_check_steps: int,
                 progress_check_threshold: int,
                 ball_progress_check_steps: int,
                 ball_progress_check_threshold: int,
                 team_name_blue: str,
                 team_name_yellow: str,
                 initial_score_blue: int,
                 initial_score_yellow: int,
                 penalty_area_allowed_time: int,
                 penalty_area_reset_after: int,
                 post_goal_wait_time: int = 3,
                 initial_position_noise: float = 0.15):

        super().__init__()

        self.match_time = match_time
        self.match_id = match_id
        self.half_id = half_id
        self.post_goal_wait_time = post_goal_wait_time
        self.initial_position_noise = initial_position_noise

        self.time = match_time

        # Event message queue to be drawn
        # List of Tuples of int (time) and string (message)
        self.event_messages_to_draw: List[Tuple[int, str]] = []

        self.eventer = Eventer()

        self.team_name_blue = team_name_blue
        self.team_name_yellow = team_name_yellow

        self.emitter = self.getDevice("emitter")

        self.ball_stop = 2

        self.robot_translation = ROBOT_INITIAL_TRANSLATION.copy()
        self.robot_rotation = ROBOT_INITIAL_ROTATION.copy()

        self.robot_nodes = {}
        self.robot_translation_fields = {}
        self.robot_rotation_fields = {}

        self.robot_in_penalty_counter = {}

        self.progress_chck = {}
        self.penalty_area_chck = {}

        for robot in ROBOT_NAMES:
            robot_node = self.getFromDef(robot)
            self.robot_nodes[robot] = robot_node
            field = robot_node.getField('translation')

            self.robot_translation_fields[robot] = field

            field = robot_node.getField('rotation')
            self.robot_rotation_fields[robot] = field

            self.robot_in_penalty_counter[robot] = 0

            self.progress_chck[robot] = ProgressChecker(
                progress_check_steps, progress_check_threshold)

            self.penalty_area_chck[robot] = PenaltyAreaChecker(
                penalty_area_allowed_time,
                penalty_area_reset_after,
            )

        self.ball = self.getFromDef("BALL")
        self.ball_translation_field = self.ball.getField("translation")

        bpc = ProgressChecker(ball_progress_check_steps,
                              ball_progress_check_threshold)
        self.progress_chck['ball'] = bpc

        self.reset_positions()

        self._update_positions()

        self.ball_reset_timer = 0

        self.score_blue = initial_score_blue
        self.score_yellow = initial_score_yellow
        # The team that ought to have the kickoff at the next restart
        self.team_to_kickoff = None

        self.draw_team_names()
        self.draw_scores(self.score_blue, self.score_yellow)
Esempio n. 2
0
def eventer() -> Eventer:
    return Eventer()