1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#ifndef ROLEDECISIONDYNAMIC_H
#define ROLEDECISIONDYNAMIC_H

#include <functional>
#include <ModuleFramework/Module.h>

#include "Representations/Infrastructure/FrameInfo.h"
#include "Representations/Infrastructure/FieldInfo.h"
#include "Representations/Infrastructure/GameData.h"
#include "Representations/Infrastructure/Roles.h"

#include "Representations/Modeling/TeamMessage.h"
#include "Representations/Modeling/TeamMessageData.h"
#include "Representations/Modeling/TeamMessagePlayersState.h"
#include "Representations/Modeling/PlayerInfo.h"
#include "Representations/Modeling/RoleDecisionModel.h"

#include <Tools/DataStructures/ParameterList.h>
#include "Tools/Debug/DebugParameterList.h"
#include "Tools/Debug/DebugPlot.h"
#include "Tools/Debug/DebugRequest.h"
#include "Tools/Debug/DebugDrawings.h"


BEGIN_DECLARE_MODULE(RoleDecisionDynamic)
  PROVIDE(DebugPlot)
  PROVIDE(DebugRequest)
  PROVIDE(DebugParameterList)
  PROVIDE(DebugDrawings)

  REQUIRE(FrameInfo)
  REQUIRE(FieldInfo)
  REQUIRE(GameData)
  REQUIRE(PlayerInfo)
//  REQUIRE(SoccerStrategy)
  REQUIRE(TeamMessage)
  REQUIRE(TeamMessagePlayersState)

  REQUIRE(TeamMessageData)

  PROVIDE(RoleDecisionModel)
END_DECLARE_MODULE(RoleDecisionDynamic);


class RoleDecisionDynamic : public RoleDecisionDynamicBase
{
public:
    RoleDecisionDynamic();

    virtual ~RoleDecisionDynamic();

    virtual void execute();

private:
    struct Striker {
        unsigned int playerNumber;
        double indicator;
        Vector2d ball;
        double sameBallRadius;
    };

    class Parameters: public ParameterList
    {
    public:
        Parameters(): ParameterList("RoleDecisionDynamic")<--- Member variable 'Parameters::strikerIndicatorFn' is not initialized in the constructor.<--- Member variable 'Parameters::strikerBallDifferenceFn' is not initialized in the constructor.<--- Member variable 'Parameters::strikerGoalieDecisionFn' is not initialized in the constructor.<--- Member variable 'Parameters::step_speed' is not initialized in the constructor.<--- Member variable 'Parameters::turn_speed' is not initialized in the constructor.
        {
            PARAMETER_REGISTER(strikerIndicator, &Parameters::setStrikerIndicatorFunction) = "time"; // "distance"

            PARAMETER_REGISTER(striker_ball_lost_time) = 1000.0;
            PARAMETER_REGISTER(striker_ball_bonus_time) = 4000.0;
            PARAMETER_REGISTER(striker_indicator_bonus) = 300.0;

            PARAMETER_REGISTER(striker_ball_difference, &Parameters::setStrikerBallDifferenceFunction) = "constlinear"; // "const", "linear", "constlinear"
            PARAMETER_REGISTER(striker_ball_difference_distance) = 500.0;
            PARAMETER_REGISTER(striker_ball_difference_distance_m) = 0.35;
            PARAMETER_REGISTER(striker_ball_difference_distance_n) = -40.0;

            PARAMETER_REGISTER(goalie_striker_decision, &Parameters::setStrikerGoalieDecisionFunction) = "condition"; // "wants"
            PARAMETER_REGISTER(goalie_striker_ball_distance) = 1500.0;
            PARAMETER_REGISTER(goalie_striker_min_x_pos) = -2700.0;
            PARAMETER_REGISTER(goalie_striker_decision_distance) = 500.0;

            PARAMETER_REGISTER(step_time, &Parameters::setStepTime) = 250;
            PARAMETER_REGISTER(step_distance, &Parameters::setStepDistance) = 80;
            PARAMETER_REGISTER(turn_angle, &Parameters::setTurnAngle) = 30;

            // load from the file after registering all parameters
            syncWithConfig();
        }

        // striker function, returns an indicator who's fastest
        std::string strikerIndicator;
        double (RoleDecisionDynamic::*strikerIndicatorFn)(const TeamMessageData&);

        double striker_ball_lost_time;
        double striker_ball_bonus_time;
        double striker_indicator_bonus;

        // ball difference function returns, how similiar two balls should be
        std::string striker_ball_difference;
        double (RoleDecisionDynamic::*strikerBallDifferenceFn)(double);

        double striker_ball_difference_distance;
        double striker_ball_difference_distance_m;
        double striker_ball_difference_distance_n;

        // decides, whether the goalie gets striker or not
        std::string goalie_striker_decision;
        bool (RoleDecisionDynamic::*strikerGoalieDecisionFn)(const TeamMessageData*, std::vector<RoleDecisionDynamic::Striker>&);

        double goalie_striker_ball_distance;
        double goalie_striker_min_x_pos;
        double goalie_striker_decision_distance;

        // params for the time-to-ball striker function
        double step_time;
        double step_distance;
        double turn_angle;
        // the calculated speeds
        double step_speed;
        double turn_speed;

    private:
        void setStrikerBallDifferenceFunction(std::string variant) {
            if(variant.compare("const") == 0) { // constant
                strikerBallDifferenceFn = &RoleDecisionDynamic::ballDifferenceRadiusConstant;
            } else if(variant.compare("linear") == 0) { // linear
                strikerBallDifferenceFn = &RoleDecisionDynamic::ballDifferenceRadiusLinear;
            } else if(variant.compare("constlinear") == 0) { // constlinear
                strikerBallDifferenceFn = &RoleDecisionDynamic::ballDifferenceRadiusConstantLinear;
            } else {
                // backup, in case something went wrong
                strikerBallDifferenceFn = &RoleDecisionDynamic::ballDifferenceRadiusConstant;
            }
        }
        void setStrikerIndicatorFunction(std::string variant) {
            if(variant.compare("distance") == 0) { // distance
                strikerIndicatorFn = &RoleDecisionDynamic::strikerIndicatorDistance;
            } else if(variant.compare("time") == 0) { // time
                strikerIndicatorFn = &RoleDecisionDynamic::strikerIndicatorTimeToBall;
            } else {
                // backup, in case something went wrong
                strikerIndicatorFn = &RoleDecisionDynamic::strikerIndicatorDistance;
            }
        }
        void setStrikerGoalieDecisionFunction(std::string variant) {
            if(variant.compare("wants") == 0) { // wants
                strikerGoalieDecisionFn = &RoleDecisionDynamic::goalieStrikerDecisionWants;
            } else if(variant.compare("condition") == 0) { // condition
                strikerGoalieDecisionFn = &RoleDecisionDynamic::goalieStrikerDecisionCondition;
            } else {
                // backup, in case something went wrong
                strikerGoalieDecisionFn = &RoleDecisionDynamic::goalieStrikerDecisionCondition;
            }
        }

        void setStepTime(double t) { setSpeed(t, step_distance, turn_angle); }
        void setStepDistance(double d) { setSpeed(step_time, d, turn_angle); }
        void setTurnAngle(double a) { setSpeed(step_time, step_distance, a); }
        void setSpeed(double t, double d, double a) {
            step_speed = d / t;
            turn_speed = Math::fromDegrees(a) / step_time;
        }
    } params;

    void decideStriker(std::map<unsigned int, Roles::Dynamic>& roles);
    void decideGoalieSupporter(std::map<unsigned int, Roles::Dynamic>& roles);
    void decideSupporter(std::map<unsigned int, Roles::Dynamic>& roles);

    void checkStriker(const TeamMessageData& msg, const double& indicator, const Vector2d& ball, std::vector<Striker>& striker, bool force = false);
    bool checkSameBall(const Striker &s, const Vector2d& ball, double r);<--- Function 'checkSameBall' argument 3 names different: declaration 'r' definition 'radius'.

    bool goalieStrikerDecisionWants(const TeamMessageData *goalie, std::vector<Striker>& striker);
    bool goalieStrikerDecisionCondition(const TeamMessageData *goalie, std::vector<Striker>& striker);

    /* Different radius methods for the same ball check. */
    double ballDifferenceRadiusConstant(double /*d*/) { return params.striker_ball_difference_distance; }
    double ballDifferenceRadiusLinear(double d) { return d * params.striker_ball_difference_distance_m + params.striker_ball_difference_distance_n; }
    double ballDifferenceRadiusConstantLinear(double d) { return std::max(ballDifferenceRadiusConstant(d), ballDifferenceRadiusLinear(d)); }

    /* Various evaluation functions who is faster to the ball for the striker decision. */
    double strikerIndicatorDistance(const TeamMessageData& msg);
    double strikerIndicatorTimeToBall(const TeamMessageData& msg);

    /* Various evaluation functions, if another striker is already defending the goal. */
    bool defendingGoalDirectLine(const Vector2d& ball, const Vector2d& player_pos) const;
    bool defendingGoalCircle(const Vector2d& ball, const Vector2d& player_pos) const;
};

#endif // ROLEDECISIONDYNAMIC_H