Phoenix2D-Library  0.10
Flag.cpp
Go to the documentation of this file.
1 /*
2  * Phoenix2D (RoboCup Soccer Simulation 2D League)
3  * Copyright (c) 2013 Ivan Gonzalez
4  *
5  * This file is part of Phoenix2D.
6  *
7  * Phoenix2D is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * Phoenix2D is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Phoenix2D. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <sstream>
22 #include <cstdlib>
23 #include <cmath>
24 #include "Flag.h"
25 #include "Self.h"
26 #include "Server.h"
27 namespace Phoenix
28 {
29 _coordinate makeCoordinate(double x, double y) {
30  if (Self::SIDE.compare("r") == 0) {
31  x *= -1.0;
32  y *= -1.0;
33  }
34  _coordinate c = {x , y};
35  return c;
36 }
37 
38 std::map<std::string, _coordinate> Flag::FIELD;
39 
40 Flag::Flag(std::string name, std::string position, int simulation_time) {
41  this->name = name;
42  this->simulation_time = simulation_time;
43  std::stringstream ss(position);
44  std::string token;
45  std::getline(ss, token, ' ');
46  distance = atof(token.c_str());
47  if (distance > 0.1) {
49  minDistance = exp(log(distance - 0.1) - Server::QUANTIZE_STEP_L);
50  //distance = (minDistance + maxDistance) / 2.0;
51  } else {
54  }
56  std::getline(ss, token, ' ');
57  direction = atof(token.c_str());
58  x = Flag::FIELD[name].x;
59  y = Flag::FIELD[name].y;
60 }
61 
63 
64 }
65 
67  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f t 0" , makeCoordinate( 0.0, -39.0)));
68  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f t r 10", makeCoordinate( 10.0, -39.0)));
69  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f t r 20", makeCoordinate( 20.0, -39.0)));
70  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f t r 30", makeCoordinate( 30.0, -39.0)));
71  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f t r 40", makeCoordinate( 40.0, -39.0)));
72  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f t r 50", makeCoordinate( 50.0, -39.0)));
73  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f r t 30", makeCoordinate( 57.5, -30.0)));
74  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f r t 20", makeCoordinate( 57.5, -20.0)));
75  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f r t 10", makeCoordinate( 57.5, -10.0)));
76  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f r 0" , makeCoordinate( 57.5, 0.0)));
77  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f r b 10", makeCoordinate( 57.5, 10.0)));
78  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f r b 20", makeCoordinate( 57.5, 20.0)));
79  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f r b 30", makeCoordinate( 57.5, 30.0)));
80  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f b r 50", makeCoordinate( 50.0, 39.0)));
81  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f b r 40", makeCoordinate( 40.0, 39.0)));
82  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f b r 30", makeCoordinate( 30.0, 39.0)));
83  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f b r 20", makeCoordinate( 20.0, 39.0)));
84  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f b r 10", makeCoordinate( 10.0, 39.0)));
85  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f b 0" , makeCoordinate( 0.0, 39.0)));
86  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f b l 10", makeCoordinate(-10.0, 39.0)));
87  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f b l 20", makeCoordinate(-20.0, 39.0)));
88  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f b l 30", makeCoordinate(-30.0, 39.0)));
89  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f b l 40", makeCoordinate(-40.0, 39.0)));
90  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f b l 50", makeCoordinate(-50.0, 39.0)));
91  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f l b 30", makeCoordinate(-57.5, 30.0)));
92  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f l b 20", makeCoordinate(-57.5, 20.0)));
93  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f l b 10", makeCoordinate(-57.5, 10.0)));
94  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f l 0" , makeCoordinate(-57.5, 0.0)));
95  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f l t 10", makeCoordinate(-57.5, -10.0)));
96  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f l t 20", makeCoordinate(-57.5, -20.0)));
97  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f l t 30", makeCoordinate(-57.5, -30.0)));
98  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f t l 50", makeCoordinate(-50.0, -39.0)));
99  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f t l 40", makeCoordinate(-40.0, -39.0)));
100  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f t l 30", makeCoordinate(-30.0, -39.0)));
101  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f t l 20", makeCoordinate(-20.0, -39.0)));
102  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f t l 10", makeCoordinate(-10.0, -39.0)));
103  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f c" , makeCoordinate( 0.0, 0.0)));
104  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f c t" , makeCoordinate( 0.0, -34.0)));
105  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f r t" , makeCoordinate( 52.5, -34.0)));
106  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f r b" , makeCoordinate( 52.5, 34.0)));
107  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f c b" , makeCoordinate( 0.0, 34.0)));
108  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f l b" , makeCoordinate(-52.5, 34.0)));
109  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f l t" , makeCoordinate(-52.5, -34.0)));
110  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("g l" , makeCoordinate(-52.5, 0.0)));
111  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f g l t" , makeCoordinate(-52.5, -7.0)));
112  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f p l t" , makeCoordinate(-36.0, -20.0)));
113  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f p l c" , makeCoordinate(-36.0, 0.0)));
114  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f p l b" , makeCoordinate(-36.0, 20.0)));
115  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f g l b" , makeCoordinate(-52.5, 7.0)));
116  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("g r" , makeCoordinate( 52.5, 0.0)));
117  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f g r t" , makeCoordinate( 52.5, -7.0)));
118  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f p r t" , makeCoordinate( 36.0, -20.0)));
119  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f p r c" , makeCoordinate( 36.0, 0.0)));
120  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f p r b" , makeCoordinate( 36.0, 20.0)));
121  Flag::FIELD.insert(std::map<std::string, _coordinate>::value_type("f g r b" , makeCoordinate( 52.5, 7.0)));
122 }
123 
124 std::string Flag::getName() {
125  return name;
126 }
127 
129  return distance;
130 }
131 
133  return direction;
134 }
135 
136 double Flag::getX() {
137  return x;
138 }
139 
140 double Flag::getY() {
141  return y;
142 }
143 
145  return minDistance;
146 }
147 
149  return maxDistance;
150 }
151 
152 double Flag::getError() {
153  return error;
154 }
155 }
double getDistance()
Definition: Flag.cpp:128
double error
Definition: Flag.h:53
double getError()
Definition: Flag.cpp:152
_coordinate The Coordinate is just a holder for coordinates
Definition: Flag.h:36
static void initializeField()
Definition: Flag.cpp:66
std::string getName()
Definition: Flag.cpp:124
static double QUANTIZE_STEP_L
Definition: Server.h:174
double minDistance
Definition: Flag.h:51
double getY()
Definition: Flag.cpp:140
double distance
Definition: Flag.h:47
double getDirection()
Definition: Flag.cpp:132
std::string name
Definition: Flag.h:46
static double x
Definition: Self.cpp:89
double y
Definition: Flag.h:50
double direction
Definition: Flag.h:48
int simulation_time
Definition: Flag.h:54
static std::string SIDE
Definition: Self.h:50
double getX()
Definition: Flag.cpp:136
Flag(std::string name, std::string position, int simulation_time)
Definition: Flag.cpp:40
static std::map< std::string, _coordinate > FIELD
Definition: Flag.h:55
static double y
Definition: Self.cpp:90
double maxDistance
Definition: Flag.h:52
_coordinate makeCoordinate(double x, double y)
Definition: Flag.cpp:29
double getMinDistance()
Definition: Flag.cpp:144
double getMaxDistance()
Definition: Flag.cpp:148
double x
Definition: Flag.h:49