From: <pat...@us...> - 2015-02-07 20:31:20
|
Revision: 386 http://sourceforge.net/p/simspark/svn/386 Author: patmac369 Date: 2015-02-07 20:31:12 +0000 (Sat, 07 Feb 2015) Log Message: ----------- Adding new training command parser commands for setting the game time and score. They are the following commands: (time <time>) (score (left <score>) (right <score>)) Also removing a couple unecessary messages in the repos command that were being printed to stderr for debugging purposes. Modified Paths: -------------- trunk/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.cpp trunk/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.h Modified: trunk/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.cpp =================================================================== --- trunk/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.cpp 2015-02-06 04:28:44 UTC (rev 385) +++ trunk/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.cpp 2015-02-07 20:31:12 UTC (rev 386) @@ -52,6 +52,8 @@ mCommandMap["repos"] = CT_REPOS; mCommandMap["killsim"] = CT_KILLSIM; mCommandMap["reqfullstate"] = CT_REQFULLSTATE; + mCommandMap["time"] = CT_TIME; + mCommandMap["score"] = CT_SCORE; // setup team index map // Originally team sides were "L","R" and "N" @@ -235,6 +237,12 @@ case CT_REQFULLSTATE: mMonitorControl->RequestFullState(); break; + case CT_TIME: + ParseTimeCommand(predicate); + break; + case CT_SCORE: + ParseScoreCommand(predicate); + break; default: return false; @@ -661,7 +669,7 @@ void TrainerCommandParser::ParseReposCommand(const oxygen::Predicate & predicate) { - cerr << "repos 2" << endl; + //cerr << "repos 2" << endl; Predicate::Iterator unumParam(predicate); int unum; @@ -714,7 +722,7 @@ ballPos = ballBody->GetPosition(); SoccerBase::GetTransformParent(**iter, agent_aspect); - cerr << "repos 3" << endl; + //cerr << "repos 3" << endl; Vector3f new_pos = mSoccerRule->RepositionOutsidePos(ballPos, (*iter)->GetUniformNumber(), (*iter)->GetTeamIndex()); SoccerBase::MoveAgent(agent_aspect, new_pos); @@ -727,3 +735,91 @@ { mSimServer->Quit(); } + +void TrainerCommandParser::ParseTimeCommand(const oxygen::Predicate & predicate) +{ + Predicate::Iterator timeParam(predicate); + float time; + + if (predicate.GetValue(timeParam,time)) + { + if (time >= 0) + { + mGameState->SetTime(time); + } + else + { + GetLog()->Debug() + << "(TrainerCommandParser) ERROR: value of time " + << time << " cannot be a negative value\n"; + return; + } + } + else + { + GetLog()->Debug() + << "(TrainerCommandParser) ERROR: could not parse time " + << time << "\n"; + return; + } +} + +void TrainerCommandParser::ParseScoreCommand(const oxygen::Predicate & predicate) +{ + Predicate::Iterator leftScoreParam(predicate); + int scoreLeft; + if (predicate.FindParameter(leftScoreParam, "left")) + { + if (!predicate.GetValue(leftScoreParam, scoreLeft)) + { + GetLog()->Debug() + << "(TrainerCommandParser) ERROR: could not parse score left " + << scoreLeft << "\n"; + return; + } + } + else + { + GetLog()->Debug() + << "(TrainerCommandParser) ERROR: could not find score left\n"; + return; + } + + + Predicate::Iterator rightScoreParam(predicate); + int scoreRight; + if (predicate.FindParameter(rightScoreParam, "right")) + { + if (!predicate.GetValue(rightScoreParam, scoreRight)) + { + GetLog()->Debug() + << "(TrainerCommandParser) ERROR: could not parse score right " + << scoreRight << "\n"; + return; + } + } + else + { + GetLog()->Debug() + << "(TrainerCommandParser) ERROR: could not find score right\n"; + return; + } + + if (scoreLeft < 0) + { + GetLog()->Debug() + << "(TrainerCommandParser) ERROR: score left " + << scoreLeft << " cannot be negative\n"; + return; + } + + if (scoreRight < 0) + { + GetLog()->Debug() + << "(TrainerCommandParser) ERROR: score right " + << scoreRight << " cannot be negative\n"; + return; + } + + mGameState->SetScores(scoreLeft, scoreRight); +} Modified: trunk/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.h =================================================================== --- trunk/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.h 2015-02-06 04:28:44 UTC (rev 385) +++ trunk/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.h 2015-02-07 20:31:12 UTC (rev 386) @@ -56,7 +56,9 @@ CT_KILL, CT_REPOS, CT_KILLSIM, - CT_REQFULLSTATE + CT_REQFULLSTATE, + CT_TIME, + CT_SCORE }; typedef std::map<std::string, ECommandType> TCommandMap; @@ -132,7 +134,18 @@ predicate */ void ParseKillSimCommand(const oxygen::Predicate & predicate); + + /** parses and executes the time command contained in the given + predicate + */ + void ParseTimeCommand(const oxygen::Predicate & predicate); + + /** parses and executes the score command contained in the given + predicate + */ + void ParseScoreCommand(const oxygen::Predicate & predicate); + protected: TCommandMap mCommandMap; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |