?? sensehandler.c
字號(hào):
\param strMsg message that should be parsed \return bool indicating whether the message was parsed correctly. */bool SenseHandler::analyzeSeeGlobalMessage( char *strMsg ){ Log.logWithTime( 2, " incoming see global message" ); strcpy( WM->strLastSeeMessage, strMsg ); ObjectT o; bool isGoalie; double dX, dY, dVelX, dVelY; int iTime; AngDeg angBody, angNeck; Time time = WM->getCurrentTime(); iTime = Parse::parseFirstInt( &strMsg ); // get the time time.updateTime( iTime ); while( *strMsg != ')' ) // " ((objname.." or ")" { dX = dY = dVelX = dVelY = UnknownDoubleValue; angBody = angNeck = UnknownAngleValue; strMsg += 2; // go the start of the object name // get the object type at the current position in the string o = SoccerTypes::getObjectFromStr( &strMsg, &isGoalie, WM->getTeamName() ); if( o == OBJECT_ILLEGAL ) { Log.log( 4, "Illegal object" ); Log.log( 4, "total messages: %s", WM->strLastSeeMessage ); Log.log( 4, "rest of message: %s", strMsg ); } dX = Parse::parseFirstDouble( &strMsg ); // parse first value dY = Parse::parseFirstDouble( &strMsg ); // parse second value if ( *strMsg != ')' ) // if it was no flag { dVelX = Parse::parseFirstDouble( &strMsg ); // parse delta x dVelY = Parse::parseFirstDouble( &strMsg ); // parse delta y if( *strMsg != ')' ) // stil not finished { // get body and neck angle angBody = Parse::parseFirstDouble( &strMsg ); angNeck = Parse::parseFirstDouble( &strMsg ); } } // skip ending bracket of object information. strMsg++; // process the parsed information (unread values are Unknown...) WM->processSeeGlobalInfo( o, time, VecPosition(dX,dY), VecPosition(dVelX,dVelY), angBody, angNeck ); } WM->setTimeLastSeeGlobalMessage( time ); // set time last see global message return true;}/*! This method analyzes a sense message. All information from the player is parsed and updated in the WorldModel. A sense message looks like (sense_body 0 (view_mode high normal) (stamina 2000 1) (speed 0 0) (head_angle 0) (kick 0) (dash 0) (turn 0) (say 0) (turn_neck 0) (catch 0) (move 0) (change_view 0)) \param strMsg message that should be parsed \return bool indicating whether the message was parsed correctly. */bool SenseHandler::analyzeSenseMessage( char *strMsg ){ setTimeSignal(); // set signal when to send action strcpy( WM->strLastSenseMessage, strMsg ); if( WM->getRelativeDistance( OBJECT_BALL ) < SS->getVisibleDistance() ) Log.logWithTime( 560, "%s", WM->strLastSenseMessage ); int iTime = Parse::parseFirstInt( &strMsg );// get time Time timeOld = WM->getCurrentTime(); Time timeNew = timeOld; timeNew.updateTime( iTime ); if( timeNew.getTimeDifference( timeOld ) > 1 ) Log.log( 1, "Missed a sense!!" ); Log.logWithTime ( 2, "\n\nSENSE (%d, %d)", timeNew.getTime(), timeNew.getTimeStopped() ); Log.restartTimer( ); Log.logWithTime ( 2, " alarm after %d", iTimeSignal ); strMsg++; // go to ( before view_mode Parse::gotoFirstOccurenceOf( ' ', &strMsg ); // skip view_mode strMsg++; // skip space ViewQualityT vq = SoccerTypes::getViewQualityFromStr( strMsg ); // get quality Parse::gotoFirstOccurenceOf( ' ', &strMsg ); strMsg++; // skip space; get view_angle ViewAngleT va = SoccerTypes::getViewAngleFromStr( strMsg ); double dStamina = Parse::parseFirstDouble( &strMsg ); // get stamina double dEffort = Parse::parseFirstDouble( &strMsg ); // get effort double dSpeed = Parse::parseFirstDouble( &strMsg ); // get speed AngDeg angSpeed = Parse::parseFirstDouble( &strMsg ); // get speed ang // minus sign since we store angle between neck and body and not vice versa int iHeadAngle = - Parse::parseFirstInt( &strMsg ); // get head_angle WM->processNewAgentInfo( vq, va, dStamina, dEffort, dSpeed, (AngDeg) angSpeed, (AngDeg)iHeadAngle ); // set all number of performed commands WM->setNrOfCommands( CMD_KICK , Parse::parseFirstInt( &strMsg ) ); WM->setNrOfCommands( CMD_DASH , Parse::parseFirstInt( &strMsg ) ); WM->setNrOfCommands( CMD_TURN , Parse::parseFirstInt( &strMsg ) ); WM->setNrOfCommands( CMD_SAY , Parse::parseFirstInt( &strMsg ) ); WM->setNrOfCommands( CMD_TURNNECK , Parse::parseFirstInt( &strMsg ) ); WM->setNrOfCommands( CMD_CATCH , Parse::parseFirstInt( &strMsg ) ); WM->setNrOfCommands( CMD_MOVE , Parse::parseFirstInt( &strMsg ) ); WM->setNrOfCommands( CMD_CHANGEVIEW , Parse::parseFirstInt( &strMsg ) ); WM->setTimeLastSenseMessage( timeNew ); // set the time Log.logWithTime( 2, " end analyzing sense" ); return true;}/*! This method analyzes an init message. All information from the initialization is parsed and updated in the WorldModel. An init message looks like (init [l|r] 10 before_kick_off) \param strMsg message that should be parsed \return bool indicating whether the message was parsed correctly. */bool SenseHandler::analyzeInitMessage( char *strMsg ){ strMsg += 6; // go to Side WM->setSide( SoccerTypes::getSideFromStr( strMsg ) ); // get and set Side int nr = Parse::parseFirstInt( &strMsg ); // get and set number if( nr == 0 ) // coach { WM->setPlayerNumber( nr ); return true; } WM->setAgentObjectType( SoccerTypes::getTeammateObjectFromIndex( nr - 1 ) ); WM->setPlayerNumber( nr ); strMsg++; // skip space to pm WM->setPlayMode( SoccerTypes::getPlayModeFromStr( strMsg ) ); // get playmode return true;}/*! This method analyzes a hear message. When the message is from the referee the message is parsed and the new play mode is set or the goal difference is adjusted. When the message comes from another player the method analyzePlayerMessage is called A hear message looks like (hear 0 self|referee|dir message) \param strMsg message that should be parsed \return bool indicating whether the message was parsed correctly. */bool SenseHandler::analyzeHearMessage( char *strMsg ){ RefereeMessageT rm; PlayModeT pm; strcpy( WM->strLastHearMessage, strMsg); Parse::parseFirstInt( &strMsg ); // ignore time Time time = WM->getCurrentTime(); switch( Parse::gotoFirstNonSpace( &strMsg ) ) { case 'r': // referee WM->setTimeLastRefereeMessage( time ); Parse::gotoFirstOccurenceOf( ' ', &strMsg ); // go to start Parse::gotoFirstNonSpace ( &strMsg ); // and first part rm = SoccerTypes::getRefereeMessageFromStr( strMsg ); // get the ref msg Log.logWithTime( 2, " referee message: %s %s", SoccerTypes::getRefereeMessageStr(rm), WM->strLastHearMessage); pm = SoccerTypes::getPlayModeFromRefereeMessage( rm );// get play mode if( pm != PM_ILLEGAL ) // from ref msg WM->setPlayMode( pm ); // if was pm, set it switch( rm ) { case REFC_GOAL_LEFT: // goal left if( WM->getSide() == SIDE_LEFT ) WM->addOneToGoalDiff(); else WM->subtractOneFromGoalDiff(); WM->processSeeGlobalInfo( OBJECT_BALL, time, VecPosition( 0, 0 ), VecPosition( 0, 0 ), 0, 0 ); break; case REFC_GOAL_RIGHT: // goal right if( WM->getSide() == SIDE_RIGHT ) WM->addOneToGoalDiff(); else WM->subtractOneFromGoalDiff(); WM->processSeeGlobalInfo( OBJECT_BALL, time, VecPosition( 0, 0 ), VecPosition( 0, 0 ), 0, 0 ); break; case REFC_GOALIE_CATCH_BALL_LEFT: // catch ball case REFC_GOALIE_CATCH_BALL_RIGHT: WM->processCatchedBall( rm, time ); break; case REFC_PENALTY_ONFIELD_LEFT: WM->setSidePenalty( SIDE_LEFT ); break; case REFC_PENALTY_ONFIELD_RIGHT: WM->setSidePenalty( SIDE_RIGHT ); break; case REFC_PENALTY_MISS_LEFT: case REFC_PENALTY_SCORE_LEFT: WM->setPlayMode( PM_FROZEN ); break; case REFC_PENALTY_MISS_RIGHT: case REFC_PENALTY_SCORE_RIGHT: WM->setPlayMode( PM_FROZEN ); break; case REFC_PENALTY_FOUL_LEFT: case REFC_PENALTY_FOUL_RIGHT: default: break; } break; case 'o': // online_coach_ break; case 's': // self break; // do nothing default: // from direction Log.logWithTime( 600, "incoming hear: %s", WM->strLastHearMessage ); analyzePlayerMessage( strMsg ); // from player break; } return true;}/*! This message analyzes an incoming communication message. Messages from opponents are discarded. First it is checked whether the message arrived from a teammate using a specific encoding string and then the contents are parsed and stored in the world model, which will process it when it updates the world model. */bool SenseHandler::analyzePlayerMessage( char *strMsg ){ Parse::gotoFirstNonSpace( &strMsg ); // skip space if( WM->getPlayerNumber() == 0 ) // if i am coach return false; // skip message if( strlen( strMsg ) < 2 || strMsg[0] == 'o' ) // skip message since no dir. return false; // thus no content Parse::parseFirstInt( &strMsg ); // skip direction Parse::gotoFirstNonSpace( &strMsg ); // skip space if( strlen( strMsg ) < 2 || strMsg[1] == 'p' ) // skip message when from opp return false; int iPlayer = Parse::parseFirstInt( &strMsg ); // get player number Parse::gotoFirstNonSpace( &strMsg ); // skip space strMsg++; // skip " (=quote) if( strlen( strMsg ) < 4 ) // < 2 + two ending charactres ") return false; WM->storePlayerMessage( iPlayer, strMsg, WM->getCurrentCycle() ); return true;}/*! This method analyzes the check_ball message that is only received by the
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -