26 #include <boost/regex.hpp>
27 #include <boost/circular_buffer.hpp>
52 double u[3] = {0.0, 0.0, 0.0};
55 "\\(view_mode\\s+(\\w+)\\s+(\\w+)\\)\\s*"
56 "\\(stamina\\s+([\\d\\.\\-e]+)\\s+([\\d\\.\\-e]+)\\s+([\\d\\.\\-e]+)\\)\\s*"
57 "\\(speed\\s+([\\d\\.\\-e]+)\\s+([\\d\\.\\-e]+)\\)\\s*"
58 "\\(head_angle\\s+([\\d\\.\\-e]+)\\)\\s*"
59 "\\(kick\\s+(\\d+)\\)\\s*"
60 "\\(dash\\s+(\\d+)\\)\\s*"
61 "\\(turn\\s+(\\d+)\\)\\s*"
62 "\\(say\\s+(\\d+)\\)\\s*"
63 "\\(turn_neck\\s+(\\d+)\\)\\s*"
64 "\\(catch\\s+(\\d+)\\)\\s*"
65 "\\(move\\s+(\\d+)\\)\\s*"
66 "\\(change_view\\s+(\\d+)\\)\\s*"
68 "\\(movable\\s+(\\d+)\\)\\s*"
69 "\\(expires\\s+(\\d+)\\)\\s*"
70 "\\(target\\s+([\\d\\.\\-e]+)\\s+([\\d\\.\\-e]+)\\)\\s*"
71 "\\(count\\s+(\\d+)\\)\\s*"
74 "\\(target\\s+(none|[lr]\\s+\\d+)\\)\\s*"
75 "\\(count\\s+(\\d+)\\)\\s*"
78 "\\(expires\\s+(\\d+)\\)\\s*"
79 "\\(count\\s+(\\d+)\\)\\s*"
81 "\\(collision\\s+(none|\\(ball\\)|\\(player\\)|\\(post\\)|\\s)+\\)\\s*"
83 "\\(charged\\s+(\\d+)\\)\\s*"
84 "\\(card\\s+(none|yellow|red)\\)\\s*"
89 static double x = 0.0;
90 static double y = 0.0;
202 boost::regex parameter_regex(
"\\(" + parameter +
"\\s+([\\w\\-\\.]+)\\)");
204 if (boost::regex_search(player_type.c_str(), match, parameter_regex)) {
205 std::string param = std::string() + match[1];
208 std::cerr <<
"Self::getParameter(string, string) -> search failed miserably for parameter " << parameter << std::endl;
214 boost::regex parameter_regex(
"\\(" + parameter +
"\\s+([\\w\\-\\.]+)\\)");
216 if (boost::regex_search(player_params.c_str(), match, parameter_regex)) {
217 std::string param = std::string() + match[1];
220 std::cerr <<
"Self::getParameter(string) -> search failed miserably for parameter " << parameter << std::endl;
225 Self::Self(std::string player_params, std::string team_name,
int unum, std::string side) {
273 if (side.compare(
"r")) {
318 u[0] =
u[1] =
u[2] = 0.0;
332 switch ((*it)->getCommandType()) {
355 change_view_ptr = *it;
377 Self::EFFORT = atof((std::string() + match[4]).c_str());
485 std::string stream = std::string() + match[26];
486 std::stringstream ss(stream);
488 std::list<std::string> collisions;
489 while(std::getline(ss, token,
' ')) {
490 collisions.push_back(token);
501 std::cerr <<
"Self::processSenseBody(string) -> failed to match " << sense_body << std::endl;
527 for (std::list<double>::iterator it = arcs.begin(); it != arcs.end(); ++it) {
533 return 180.0 * atan2(y_m, x_m) /
Self::PI;
543 bool triangular(
Flag* flag0,
Flag* flag1,
double &x_t,
double &y_t,
double &theta_t,
double &error_d) {
544 double k0 = pow(flag0->
getDistance(), 2.0) - pow(flag0->
getX(), 2.0) - pow(flag0->
getY(), 2.0);
545 double k1 = pow(flag1->
getDistance(), 2.0) - pow(flag1->
getX(), 2.0) - pow(flag1->
getY(), 2.0);
546 double x0, x1, y0, y1, B, C;
547 if (flag0->
getX() == flag1->
getX()) {
548 double y = (k0 - k1) / (2.0 * (flag1->
getY() - flag0->
getY()));
551 B = -2.0 * flag0->
getX();
552 C = pow(y, 2.0) - 2.0 * y * flag0->
getY() - k0;
553 if (pow(B, 2.0) - 4.0 * C > 0) {
554 x0 = (-B + sqrt(pow(B, 2.0) - 4.0 * C)) / 2.0;
555 x1 = (-B - sqrt(pow(B, 2.0) - 4.0 * C)) / 2.0;
559 }
else if (flag0->
getY() == flag1->
getY()) {
560 double x = (k0 - k1) / (2.0 * (flag1->
getX() - flag0->
getX()));
563 B = -2.0 * flag0->
getY();
564 C = pow(x, 2.0) - 2.0 * x * flag0->
getX() - k0;
565 if (pow(B, 2.0) - 4.0 * C > 0) {
566 y0 = (-B + sqrt(pow(B, 2.0) - 4.0 * C)) / 2.0;
567 y1 = (-B - sqrt(pow(B, 2.0) - 4.0 * C)) / 2.0;
572 double M = (k1 - k0) / (2.0 * (flag0->
getX() - flag1->
getX()));
573 double N = (flag0->
getY() - flag1->
getY()) / (flag1->
getX() - flag0->
getX());
574 B = (2.0 * (M * N - N * flag0->
getX() - flag0->
getY())) / (pow(N, 2.0) + 1.0);
575 C = (pow(M, 2.0) - 2.0 * M * flag0->
getX() - k0) / (pow(N, 2.0) + 1.0);
576 if (pow(B, 2.0) - 4.0 * C > 0) {
577 y0 = (-B + sqrt(pow(B, 2.0) - 4.0 * C)) / 2.0;
579 y1 = (-B - sqrt(pow(B, 2.0) - 4.0 * C)) / 2.0;
585 double d0 = sqrt(pow(x0 -
x, 2.0) + pow(y0 -
y, 2.0));
586 double d1 = sqrt(pow(x1 -
x, 2.0) + pow(y1 -
y, 2.0));
587 double gamma0, gamma1;
597 if (gamma0 >= 180.0) {
599 }
else if (gamma0 < -180.0) {
602 if (gamma1 >= 180.0) {
604 }
else if (gamma1 < -180.0) {
607 double x_m = (cos(
Self::PI * gamma0 / 180.0) + cos(
Self::PI * gamma1 / 180.0)) / 2.0;
608 double y_m = (sin(
Self::PI * gamma0 / 180.0) + sin(
Self::PI * gamma1 / 180.0)) / 2.0;
609 theta_t = 180.0 * atan2(y_m, x_m) /
Self::PI;
614 bool areaCheck(
double x_min,
double x_max,
double rmax,
double x_c,
double y_c,
double error) {
615 double x_t = cos(
theta) * (x_c -
x) + sin(
theta) * (y_c -
y);
616 double y_t = sin(
theta) * (
x - x_c) + cos(
theta) * (y_c -
y);
617 if (((x_t > x_min - error) && (x_t < x_max + error)) && ((y_t > -1.0 * rmax - error) && (y_t < rmax + error))) {
626 if (flags.size() == 0) {
631 std::list<double> thetas;
657 switch (flags.size()) {
670 for (std::vector<Flag>::iterator it_flag = flags.begin(); it_flag != flags.end(); ++it_flag) {
671 double dir = atan2(y_e - it_flag->getY(), x_e - it_flag->getX());
672 double x_i = it_flag->getX() + cos(dir) * it_flag->getDistance();
673 double y_i = it_flag->getY() + sin(dir) * it_flag->getDistance();
674 x_e = tao * x_e + (1 - tao) * x_i;
675 y_e = tao * y_e + (1 - tao) * y_i;
676 double gamma = 180 * atan2(it_flag->getY() - y_e, it_flag->getX() - x_e) /
Self::PI - it_flag->getDirection();
679 }
else if (gamma < -180.0) {
682 thetas.push_back(gamma);
699 theta += effective_turn;
702 }
else if (
theta < -180.0) {
static double getArmDistAtTime(unsigned int time)
Used by Player and Goalie.
static int UNIFORM_NUMBER
Self(std::string player_params, std::string team_name, int unum, std::string side)
static double NEW_DASH_POWER_RATE_DELTA_MAX
void changePlayerType(int type)
static double getStaminaCapacityAtTime(unsigned int time)
static unsigned int BUFFER_MAX_HISTORY
static double DASH_POWER_RATE
static double PLAYER_DECAY
void addPlayerType(std::string player_type)
static boost::circular_buffer< double > effort_buffer(Config::BUFFER_MAX_HISTORY, 0.0)
static boost::circular_buffer< int > arm_count_buffer(Config::BUFFER_MAX_HISTORY, 0)
static double PLAYER_DECAY_DELTA_MIN
static double getEffortAtTime(unsigned int time)
std::string getPlayerParameter(const std::string &player_params, std::string parameter)
static std::string VIEW_MODE_QUALITY
Position The Position lorem Ipsum
static boost::circular_buffer< int > foul_charged_buffer(Config::BUFFER_MAX_HISTORY, 0)
static boost::circular_buffer< std::list< std::string > > collisions_buffer(Config::BUFFER_MAX_HISTORY, empty_vector)
static void initializeField()
static double EXTRA_STAMINA_DELTA_MIN
Used by Player and Goalie.
static int getArmMovableAtTime(unsigned int time)
static double DASH_POWER_RATE_DELTA_MAX
Used by Player and Goalie.
static int getTurnCountAtTime(unsigned int time)
static std::list< std::string > getCollisionsAtTime(unsigned int time)
static boost::circular_buffer< int > catch_count_buffer(Config::BUFFER_MAX_HISTORY, 0)
Used by Player and Goalie.
static double getArmDirAtTime(unsigned int time)
static Vector2D getVelocity()
static boost::circular_buffer< int > tackle_expires_buffer(Config::BUFFER_MAX_HISTORY, 0)
static Position getPosition()
static double STAMINA_INC_MAX_DELTA_FACTOR
static int getFoulChargedAtTime(unsigned int time)
static double KICK_POWER_RATE_DELTA_MAX
static double PLAYER_ACCEL_MAX
static int getArmExpiresAtTime(unsigned int time)
Used by Player and Goalie.
static double KICKABLE_MARGIN
static boost::circular_buffer< std::string > focus_target_buffer(Config::BUFFER_MAX_HISTORY,"none")
static boost::circular_buffer< int > arm_movable_buffer(Config::BUFFER_MAX_HISTORY, 0)
static double KICKABLE_MARGIN_DELTA_MIN
static double NEW_STAMINA_INC_MAX_DELTA_FACTOR
static boost::circular_buffer< int > arm_expires_buffer(Config::BUFFER_MAX_HISTORY, 0)
static double PLAYER_SIZE_DELTA_FACTOR
static int getChangeViewCountAtTime(unsigned int time)
double * catchable_area_l_stretch
static double KICK_RAND_DELTA_FACTOR
static double KICKABLE_MARGIN_DELTA_MAX
static boost::circular_buffer< double > amount_of_speed_buffer(Config::BUFFER_MAX_HISTORY, 0.0)
Used by Player and Goalie.
static double FOUL_DETECT_PROBABILITY
static double getStaminaAtTime(unsigned int time)
static int TURN_NECK_COUNT
static double EXTRA_STAMINA_DELTA_MAX
static double CATCHABLE_AREA_L_STRECH_MIN
double getDashDirection()
static double STAMINA_CAPACITY
static std::list< Command * > last_commands_sent
std::string getPlayerTypeParameter(const std::string &player_type, std::string parameter)
static int getFocusCountAtTime(unsigned int time)
static double AMOUNT_OF_SPEED
static double DIRECTION_OF_SPEED
static std::string TEAM_NAME
static int ALLOW_MULT_DEFAULT_TYPE
static int TACKLE_EXPIRES
static double KICK_POWER_RATE_DELTA_MIN
static Vector2D getVector2DWithMagnitudeAndDirection(double magnitude, double direction)
static boost::circular_buffer< int > say_count_buffer(Config::BUFFER_MAX_HISTORY, 0)
Used by Player and Goalie.
static double PLAYER_SIZE
static boost::circular_buffer< int > focus_count_buffer(Config::BUFFER_MAX_HISTORY, 0)
static std::string getFoulCardAtTime(unsigned int time)
static std::string getFocusTargetAtTime(unsigned int time)
static int getMoveCountAtTime(unsigned int time)
static boost::circular_buffer< std::string > view_mode_width_buffer(Config::BUFFER_MAX_HISTORY,"normal")
Command The Command lorem Ipsum
static double DASH_POWER_RATE
static double EFFORT_MAX_DELTA_FACTOR
static double NEW_DASH_POWER_RATE_DELTA_MIN
static double CATCHABLE_AREA_L_STRECH_MAX
static std::string FOUL_CARD
void changeStatusTo(COMMAND_STATUS status)
static double FOUL_DETECT_PROBABILITY_DELTA_FACTOR
static double CATCHABLE_AREA_L_STRETCH
static int getTackleExpiresAtTime(unsigned int time)
static int getKickCountAtTime(unsigned int time)
static boost::circular_buffer< double > stamina_buffer(Config::BUFFER_MAX_HISTORY, 0.0)
static boost::circular_buffer< int > dash_count_buffer(Config::BUFFER_MAX_HISTORY, 0)
static double DASH_POWER_RATE_DELTA_MIN
static int getArmCountAtTime(unsigned int time)
std::list< std::string > empty_vector
static std::string FOCUS_TARGET
static boost::circular_buffer< double > stamina_capacity_buffer(Config::BUFFER_MAX_HISTORY, 0.0)
static double KICK_POWER_RATE
Flag The Flag lorem Ipsum
double * player_speed_max
boost::regex sense_body_regex("^\\(sense_body\\s+\\d+\\s+""\\(view_mode\\s+(\\w+)\\s+(\\w+)\\)\\s*""\\(stamina\\s+([\\d\\.\\-e]+)\\s+([\\d\\.\\-e]+)\\s+([\\d\\.\\-e]+)\\)\\s*""\\(speed\\s+([\\d\\.\\-e]+)\\s+([\\d\\.\\-e]+)\\)\\s*""\\(head_angle\\s+([\\d\\.\\-e]+)\\)\\s*""\\(kick\\s+(\\d+)\\)\\s*""\\(dash\\s+(\\d+)\\)\\s*""\\(turn\\s+(\\d+)\\)\\s*""\\(say\\s+(\\d+)\\)\\s*""\\(turn_neck\\s+(\\d+)\\)\\s*""\\(catch\\s+(\\d+)\\)\\s*""\\(move\\s+(\\d+)\\)\\s*""\\(change_view\\s+(\\d+)\\)\\s*""\\(arm\\s+""\\(movable\\s+(\\d+)\\)\\s*""\\(expires\\s+(\\d+)\\)\\s*""\\(target\\s+([\\d\\.\\-e]+)\\s+([\\d\\.\\-e]+)\\)\\s*""\\(count\\s+(\\d+)\\)\\s*""\\)\\s*""\\(focus\\s+""\\(target\\s+(none|[lr]\\s+\\d+)\\)\\s*""\\(count\\s+(\\d+)\\)\\s*""\\)\\s*""\\(tackle\\s+""\\(expires\\s+(\\d+)\\)\\s*""\\(count\\s+(\\d+)\\)\\s*""\\)\\s*""\\(collision\\s+(none|\\(ball\\)|\\(player\\)|\\(post\\)|\\s)+\\)\\s*""\\(foul\\s+""\\(charged\\s+(\\d+)\\)\\s*""\\(card\\s+(none|yellow|red)\\)\\s*""\\)\\s*""\\)$")
static boost::circular_buffer< int > kick_count_buffer(Config::BUFFER_MAX_HISTORY, 0)
static double EXTRA_STAMINA
static boost::circular_buffer< std::string > foul_card_buffer(Config::BUFFER_MAX_HISTORY,"none")
static boost::circular_buffer< int > change_view_count_buffer(Config::BUFFER_MAX_HISTORY, 0)
static double INERTIA_MOMENT
static std::string VIEW_MODE_WIDTH
Used by Player and Goalie.
static boost::circular_buffer< double > head_angle_buffer(Config::BUFFER_MAX_HISTORY, 0.0)
static std::string getViewModeQualityAtTime(unsigned int time)
static double PLAYER_DECAY_DELTA_MAX
static double getAmountOfSpeedAtTime(unsigned int time)
Used by Player and Goalie.
Used by Player and Goalie.
static boost::circular_buffer< int > move_count_buffer(Config::BUFFER_MAX_HISTORY, 0)
static int getCatchCountAtTime(unsigned int time)
static int CHANGE_VIEW_COUNT
double * foul_detect_probability
bool areaCheck(double x_min, double x_max, double rmax, double x_c, double y_c, double error)
bool triangular(Flag *flag0, Flag *flag1, double &x_t, double &y_t, double &theta_t, double &error_d)
static double STAMINA_INC_MAX
static double EFFORT_MIN_DELTA_FACTOR
static std::string getViewModeWidthAtTime(unsigned int time)
double angleMean(std::list< double > arcs)
static double getDirectionOfSpeedAtTime(unsigned int time)
static boost::circular_buffer< double > arm_dist_buffer(Config::BUFFER_MAX_HISTORY, 0.0)
static void setLastCommandsSet(std::list< Command * > last_commands_sent)
static boost::circular_buffer< double > arm_dir_buffer(Config::BUFFER_MAX_HISTORY, 0.0)
static std::list< std::string > COLLISION
static double PLAYER_SPEED_MAX_DELTA_MIN
static boost::circular_buffer< int > turn_neck_count_buffer(Config::BUFFER_MAX_HISTORY, 0)
static int getSayCountAtTime(unsigned int time)
static boost::circular_buffer< int > tackle_count_buffer(Config::BUFFER_MAX_HISTORY, 0)
static boost::circular_buffer< int > turn_count_buffer(Config::BUFFER_MAX_HISTORY, 0)
static int getTackleCountAtTime(unsigned int time)
static double INERTIA_MOMENT_DELTA_FACTOR
static boost::circular_buffer< std::string > view_mode_quality_buffer(Config::BUFFER_MAX_HISTORY,"high")
static double PLAYER_SPEED_MAX_DELTA_MAX
Vector2D The Vector2D lorem Ipsum
void processSenseBody(std::string sense_body)
static int getTurnNeckCountAtTime(unsigned int time)
static int getDashCountAtTime(unsigned int time)
static double PLAYER_SPEED_MAX
static boost::circular_buffer< double > direction_of_speed_buffer(Config::BUFFER_MAX_HISTORY, 0.0)