예제 #1
0
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)
예제 #2
0
def _find_applicable_strat_player(state: PlayerState) -> _StrategyGenerator:
    # Matches the current state of the game to a uppaal model, if applicable

    # Check if dribble strategy model can be applied
    if state.team_name in DRIBBLE_OR_PASS_TEAMS and state.needs_dribble_or_pass_strat(
    ):
        print(state.now(), " DRIBBLE STRAT - Player : ", state.num)

        possession_dir = Path(__file__).parent / "models" / "possessionmodel"
        if not possession_dir.exists():
            os.makedirs(possession_dir)

        original_pos_model = Path(
            possession_dir).parent / "PassOrDribbleModel.xml"
        model_name = "possessionmodel{0}{1}.xml".format(
            state.world_view.side, state.num)
        new_pos_file = possession_dir / model_name

        if not new_pos_file.exists():
            f = open(new_pos_file, "x")
            copyfile(original_pos_model, new_pos_file)
            f.close()

        return _StrategyGenerator(
            "/possessionmodel/possessionmodel{0}{1}".format(
                state.world_view.side, state.num),
            _update_dribble_or_pass_model, _extract_pass_or_dribble_strategy)

    # Check if stamina strategy model can be applied
    if state.team_name in STAMINA_MODEL_TEAMS and (
            state.now() % 121) == (state.num + 1) * 10:
        print(state.num, state.team_name)
        return _StrategyGenerator(
            "/staminamodel/staminamodel{0}{1}".format(state.world_view.side,
                                                      state.num),
            _update_stamina_model_simple, _extract_stamina_solution_simple)

    # Check if the goalie defence model can be applied
    if state.team_name in GOALIE_MODEL_TEAMS and state.player_type == "goalie":
        ball_possessor = state.get_ball_possessor()

        if ball_possessor is not None and ball_possessor.coord is not None:
            side = 1 if state.world_view.side == "r" else -1
            steps_per_meter = goalie_strategy.STEPS_PER_METER
            # Convert coordinate to fit the squares from the strategy
            possessor_new_x = math.floor(ball_possessor.coord.pos_x * side /
                                         steps_per_meter) * steps_per_meter
            possessor_new_y = math.floor(
                ball_possessor.coord.pos_y / steps_per_meter) * steps_per_meter
            goalie_new_x = math.floor(state.position.get_value().pos_x * side /
                                      steps_per_meter) * steps_per_meter
            goalie_new_y = math.floor(state.position.get_value().pos_y /
                                      steps_per_meter) * steps_per_meter

            if abs(state.position.get_value().pos_x) > 52.5:
                goalie_new_x = 52 * side

            # Example: "(36.5, -19.5),(47.5, -8.5)" -> "(goalie_x, goalie_y),(player_x, player_y)"
            key = "({0}.0, {1}.0),({2}.0, {3}.0)".format(
                str(goalie_new_x), str(goalie_new_y), str(possessor_new_x),
                str(possessor_new_y))
            if key in state.goalie_position_dict.keys():
                result = state.goalie_position_dict[key]
                optimal_x = int(goalie_new_x * side + result[0] * side)
                optimal_y = int(goalie_new_y + result[1])
                optimal_coord = Coordinate(optimal_x, optimal_y)
                state.goalie_position_strategy = optimal_coord

    return None