23 #include <boost/regex.hpp>
53 static boost::regex
see_regex(
"\\(([^()]+)\\)\\s*([\\d\\.\\-etk\\s]*)");
55 boost::regex
hear_coach_regex(
"\\(hear\\s+(\\d+)\\s+(online_coach_left|online_coach_right)\\s+([\\\"\\w\\s]*)\\)");
57 boost::regex
hear_player_regex(
"\\(hear\\s+(\\d+)\\s+([\\d\\.\\-e]+)\\s+our\\s+(\\d+)\\s+([\\\"\\w\\s]+)\\)");
58 static pthread_cond_t
see_cond = PTHREAD_COND_INITIALIZER;
59 static pthread_mutex_t
see_mutex = PTHREAD_MUTEX_INITIALIZER;
73 std::cerr <<
"Parser::process_sense_body(void*) -> cannot lock sense body mutex" << std::endl;
80 std::cerr <<
"Parser::process_see(void*) -> cannot signal to blocked threads" << std::endl;
84 std::cerr <<
"Parser::process_sense_body(void*) -> cannot unlock sense body mutex" << std::endl;
90 std::cerr <<
"Parser::process_sense_body(void*) -> cannot lock mutex" << std::endl;
96 std::cerr <<
"Parser::process_sense_body(void*) -> cannot wait for condition" << std::endl;
100 success = pthread_mutex_unlock(&
see_mutex);
102 std::cerr <<
"Parser::process_sense_body(void*) -> cannot unlock mutex" << std::endl;
116 std::cerr <<
"Parser::process_sense_body(void*) -> cannot lock sense body mutex" << std::endl;
122 std::cerr <<
"Parser::process_sense_body(void*) -> cannot wait for condition" << std::endl;
128 std::cerr <<
"Parser::process_sense_body(void*) -> cannot unlock sense body mutex" << std::endl;
131 success = pthread_mutex_lock(&
see_mutex);
133 std::cerr <<
"Parser::process_see(void*) -> cannot lock mutex" << std::endl;
139 std::vector<Flag> flags;
142 std::string::const_iterator start, end;
145 boost::match_results<std::string::const_iterator> match;
146 boost::match_flag_type search_flags = boost::match_default;
147 while (boost::regex_search(start, end, match,
see_regex, search_flags)) {
148 std::string name = std::string() + match[1];
149 std::string data = std::string() + match[2];
154 flags.push_back(
Flag(name, data, simulation_time));
157 players.push_back(
Player(name, data, simulation_time, player_position, player_velocity));
160 ball =
Ball(data, simulation_time, player_position, player_velocity);
165 start = match[0].second;
166 search_flags |= boost::match_prev_avail;
167 search_flags |= boost::match_not_bob;
172 success = pthread_cond_signal(&
see_cond);
174 std::cerr <<
"Parser::process_see(void*) -> cannot signal to blocked threads" << std::endl;
176 success = pthread_mutex_unlock(&
see_mutex);
178 std::cerr <<
"Parser::process_see(void*) -> cannot unlock mutex" << std::endl;
187 pthread_attr_init(&
attr);
188 pthread_attr_setdetachstate(&
attr, PTHREAD_CREATE_DETACHED);
192 pthread_attr_destroy(&
attr);
198 size_t found = message.find_first_of(
" ");
199 std::string message_type = message.substr(1, found - 1);
206 std::cerr <<
"Parser::parseMessage(string) -> error creating sense_body thread" << std::endl;
214 std::cerr <<
"Parser::parseMessage(string) -> error creating see thread" << std::endl;
216 }
else if (message_type.compare(
"hear") == 0) {
221 int unum = atoi((std::string() + match[3]).c_str());
222 std::string message = std::string() + match[4];
225 std::string coach = std::string() + match[2];
234 }
else if (message_type.compare(
"change_player_type") == 0) {
236 }
else if (message_type.compare(
"see_global") == 0){
240 std::string::const_iterator start, end;
241 start = message.begin();
243 boost::match_results<std::string::const_iterator> match;
244 boost::match_flag_type search_flags = boost::match_default;
245 while (boost::regex_search(start, end, match,
see_regex, search_flags)) {
246 std::string name = std::string() + match[1];
247 std::string data = std::string() + match[2];
252 players.push_back(
Player(name, data, simulation_time));
255 ball =
Ball(data, simulation_time);
260 start = match[0].second;
261 search_flags |= boost::match_prev_avail;
262 search_flags |= boost::match_not_bob;
265 size_t found = message.find(
" ", 12);
267 }
else if (message_type.compare(
"ok") == 0) {
269 }
else if (message_type.compare(
"error") == 0) {
272 std::cerr <<
"Parse::parseMessage(string) -> message " << message <<
" not recognized" << std::endl;
void updatePlayMode(std::string play_mode)
Player The Player lorem Ipsum
Ball The Ball lorem Ipsum
static PlayMode * play_mode_ptr
Position The Position lorem Ipsum
void parseMessage(std::string message)
Trainer The Trainer lorem Ipsum
void * process_see(void *arg)
static Vector2D getVelocity()
static Position getPosition()
static pthread_mutex_t see_mutex
static bool processing_see
static pthread_cond_t sense_body_cond
bool compareFlags(Flag f0, Flag f1)
static pthread_cond_t see_cond
boost::regex hear_coach_regex("\\(hear\\s+(\\d+)\\s+(online_coach_left|online_coach_right)\\s+([\\\"\\w\\s]*)\\)")
void localize(std::vector< Flag > flags)
void updateObserverWorld(std::list< Player > players, Ball ball)
boost::regex hear_referee_regex("\\(hear\\s+(\\d+)\\s+referee\\s+([\\\"\\w\\s]*)\\)")
pthread_t thread_sense_body
static Trainer * trainer_ptr
Parser(Self *self, World *world)
Self The Self lorem Ipsum
boost::regex hear_trainer_regex("\\(hear\\s+(\\d+)\\s+coach\\s+([\\\"\\w\\s]*)\\)")
static int SYNCH_SEE_OFFSET
static std::string see_message
World The World lorem Ipsum
static void registerPlayMode(PlayMode *play_mode)
static std::string sense_body_message
Flag The Flag lorem Ipsum
void * process_sense_body(void *arg)
static bool processing_body
static pthread_mutex_t sense_body_mutex
static unsigned int SIMULATION_TIME
PlayMode The PlayMode lorem Ipsum
Game The Game lorem Ipsum
boost::regex hear_player_regex("\\(hear\\s+(\\d+)\\s+([\\d\\.\\-e]+)\\s+our\\s+(\\d+)\\s+([\\\"\\w\\s]+)\\)")
virtual void onMessageReceived(std::string message, int sender)=0
void updateTime(int game_time)
std::list< Player > players
static void registerTrainer(Trainer *trainer)
Vector2D The Vector2D lorem Ipsum
void processSenseBody(std::string sense_body)
static boost::regex see_regex("\\(([^()]+)\\)\\s*([\\d\\.\\-etk\\s]*)")