⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 worldmodel.cpp

📁 根据 trilearn_base_sources-3.3 (一般称做UVA底层)修改的robocup球队代码,对某些模块进行了详细的注释(例如BasicPlayer,WorldMode模块),并且进行
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  //仅仅对动态物体检测  DynamicObject *object = (DynamicObject*)getObjectPtrFromType( o );  if( object != NULL )    return object->getTimeChangeInformation(  );  return Time( -1, 0);}/*! This method returns the last global position derived from a see message.    The time corresponds to the method 'getTimeGlobalPositionLastSee'.     \param object type of object that should be checked    \return global position related to the last see message. *///返回最后一次看见对象O在球场的位置VecPosition WorldModel::getGlobalPositionLastSee( ObjectT o ){  //仅仅对动态物体检测  DynamicObject *object = (DynamicObject*)getObjectPtrFromType( o );  if( object != NULL )    return object->getGlobalPositionLastSee(  );  return VecPosition( UnknownDoubleValue, UnknownDoubleValue);}/*! This method returns the last server cycle the global position     the specified object has been calculated.    \param object type of object that should be checked    \return server time global position of this object was last           derived (from a see message). *///返回最后一次看见对象O位置时的时间Time WorldModel::getTimeGlobalPositionLastSee( ObjectT o ){  //仅仅对动态物体检测  DynamicObject *object = (DynamicObject*)getObjectPtrFromType( o );  if( object != NULL )    return object->getTimeGlobalPosDerivedFromSee(  );  return UnknownTime;}/*! This method returns the last global velocity derived from a see message.    The time corresponds to the method 'getTimeChangeInformation'.     \param object type of object that should be checked    \return global velocity related to the last see message. *///返回最后一次看见对象o的绝对速度VecPosition WorldModel::getGlobalVelocityLastSee( ObjectT o ){  DynamicObject *object = (DynamicObject*)getObjectPtrFromType( o );  if( object != NULL )    return object->getGlobalVelocityLastSee(  );  return VecPosition( UnknownDoubleValue, UnknownDoubleValue);}/*! This method returns the last global body angle derived from a see message.    The time corresponds to the method 'getTimeChangeInformation'.     \param object type of object that should be checked    \return global body angle related to the last see message. *///返回最后一次看见对象o的身体绝对角度AngDeg WorldModel::getGlobalBodyAngleLastSee( ObjectT o ){  PlayerObject *object = (PlayerObject*)getObjectPtrFromType( o );  if( object != NULL )    return object->getGlobalBodyAngleLastSee(  );  return UnknownAngleValue;}/*! This method returns the number of cycles it will take the tackle to expire.    In case of the argument OBJECT_ILLEGAL, the number of cycles for the     agentObject is returned. *///返回结束一次铲球的周期数,默认是返回当前球员的信息int WorldModel::getTackleExpires( ObjectT o ){  if( o == OBJECT_ILLEGAL || o == getAgentObjectType() )    return agentObject.getTackleExpires();  PlayerObject *object = (PlayerObject*)getObjectPtrFromType( o );  if( object == NULL )    return 0;    return max(0, object->getTimeTackle( ) -                getCurrentTime()         +                SS->getTackleCycles());}/*! This method returns the arm direction of object 'o'. It does not keep track    of how relevant this information is. When the pointing agent stops pointing    the angle is set to UnknownAngleValue. *///返回对象O的胳膊指向的绝对方向//当对象的胳膊停止指向的时候,返回方向为未知AngDeg WorldModel::getGlobalArmDirection( ObjectT o ){  PlayerObject *object = (PlayerObject*)getObjectPtrFromType( o );  if( object == NULL )    return UnknownAngleValue;  return object->getGlobalArm();}/*! This method returns the time related to the global arm direction of object    'o'. When the pointing agent stops pointing the angle is set to     UnknownAngleValue and the returned time is not relevant. *///返回对象O在获得Arm指向时的时间,当球员指向不存在时,返回无效的值(开球前时间)Time  WorldModel::getTimeGlobalArmDirection( ObjectT o ){  PlayerObject *object = (PlayerObject*)getObjectPtrFromType( o );  if( object == NULL )    //对象不存在的时候,返回开球前时间    return Time(-1,0);  //返回做该动作的时间  return object->getTimeGlobalArm();}/*! This method returns the probability that a tackle performed by object o    will succeed. This probability depends on the relative distance to the    ball in both the x and y direction and various server parameters. In the     case that o equals OBJECT_ILLEGAL, the returned probability corresponds    to that of the agent object. *///返回铲球是否成功的预测可能性//这种可能性的大小取决于对象O相对于球坐标(x,y)的距离,还有服务器各种参数//如果O为无效对象,默认设定为当前球员double WorldModel::getProbTackleSucceeds( ObjectT o, int iExtraCycles,                                          VecPosition *pos){  //如果O为非法对象,设定为当前球员  if( o == OBJECT_ILLEGAL )    o = getAgentObjectType();  VecPosition posObject   = getGlobalPosition( o ); //取O的绝对位置  VecPosition posBall     = (pos == NULL ) ? getBallPos() : *pos ;//球的位置  AngDeg      angBody     = getGlobalBodyAngle( o );  //取O的绝对角度  int         iExtra      = 0;  double      dTackleDist, dDist=0;  //断球距离  // if opponent goalie is within 3 metres he can probably catch in next cycle  // RC2003 HACK  // 如果对方守门员在3米以内,守门员可能在下个周期扑到球  if( o == getOppGoalieType() &&            //o对象是对方守门员      posBall.getDistanceTo( o ) < 3.0  )   //距离球3米内    //成功可能指数为1.0    return 1.0;  if( o != getAgentObjectType() )   //如果O不和Agent的类型相同时  {    // get the number of cycles object was not seen and assume he moves 0.6    // in every cycle. Only in case of bad body direction subtract one.    // then move object position closer to the ball    // 获得对象没被看见的周期数并假设他每个周期移动0.6米    // 只有在身体的角度差时在周期上减一,然后继续移动对象去接近球    dDist  = posBall.getDistanceTo( posObject );    //iExtra = (当前周期 - 上次Seen(O)的周期 + 额外周期(可能是延迟周期))    iExtra = getCurrentTime() - getTimeLastSeen( o ) + iExtraCycles;    //计算角度(球相对于对象的方向)    AngDeg ang    = (posBall - posObject).getDirection();    // if body angle ok,     // 当前周期与得到角度的周期之差小于2    if( getCurrentTime() - getTimeGlobalAngles( o ) < 2 )    {      //如果相对于身体的标准化角度>35时      if( fabs( VecPosition::normalizeAngle( ang - angBody ) ) > 35 )         iExtra --;      //当前O的速度模小于0.2的时候      if( getGlobalVelocity( o ).getMagnitude() < 0.2 )         iExtra --;    }    double dExtra = 0.7*max( 0, iExtra );    // if object was not seen in last see message, he stood further away    // then the visible_distance.    // 如果对象在上次的see_message没有被看见,那么他在可视距离更远处    if( getTimeLastSeen( o ) != getTimeLastSeeMessage() &&        getCurrentTime() == getTimeLastSeeMessage() &&        dDist - dExtra < SS->getVisibleDistance() )    {      Log.log( 560, "prob tackle succeeds: opp not seen raise dExtra" );      dExtra = dDist - SS->getVisibleDistance();    }    // now incorporate that to kick the ball we may need more cycles             //    dExtra = max( 0, dExtra + iExtraCycles );    // 总结起来我们踢到球还需要更多的周期    // do not move object more than 4.0 metres.    // 不要移动物体超过4.0米    posObject += VecPosition( min(4.0,min(dDist - 0.2, dExtra )), ang, POLAR );    // object is directed towards ball    // 身体角度指向球    angBody = ang;  }  //球相对于对象的位置  VecPosition posBallRel  = posBall - posObject;  //将球的位置按照逆时针方向旋转angBody角度  posBallRel.rotate( - angBody );  //如果球的相对位置的X坐标大于0.0时,接收服务器返回的前方断球距离  if ( posBallRel.getX() > 0.0 )      // ball in front -> tackle_dist parameter    dTackleDist = SS->getTackleDist();  //否则接收后方的断球距离  else    dTackleDist = SS->getTackleBackDist();  //铲球可能性的计算方法  double dProb =     pow(fabs(posBallRel.getX())/dTackleDist         ,SS->getTackleExponent())+     pow(fabs(posBallRel.getY())/SS->getTackleWidth(),SS->getTackleExponent());  //日志记录  Log.log( 556,            "tackle relpos o %d: (%f,%f) dist %f body %f extra %d %d: prob %f",           o, posBallRel.getX(),posBallRel.getY(), dDist, angBody, iExtra,            iExtraCycles, max(0,1-dProb) );    return max( 0, 1 - dProb );}/*! This method returns a list with all the opponents that are location within  distance of 'dDist' of position 'pos'. *///接收和点pos距离在dDist以内的敌方球员列表list<ObjectT> WorldModel::getListCloseOpponents( VecPosition pos,double dDist ){  int iIndex;  list<ObjectT> listOpp;  //循环寻找所有可信度较高的点  for( ObjectT o = iterateObjectStart( iIndex, OBJECT_SET_OPPONENTS );       o != OBJECT_ILLEGAL;       o = iterateObjectNext ( iIndex, OBJECT_SET_OPPONENTS  ) )  {    //符合区域条件的话,该对象记录于表中    if( getGlobalPosition( o ).getDistanceTo( pos ) < dDist )      listOpp.push_back( o );  }  //将索引iIndex的值置-1  iterateObjectDone( iIndex );  return listOpp;}/*! This method returns the tackle probability of the closest opponent to the    ball. *///返回最近的敌方队员铲球的可能性double WorldModel::getProbTackleClosestOpp( int iExtraCycles ){  //设置离球最近的敌方球员  ObjectT obj = getClosestInSetTo( OBJECT_SET_OPPONENTS, OBJECT_BALL );  //如果是非法对象,返回-1.0  if( obj == OBJECT_ILLEGAL )    return -1.0;  //否则返回该对象的铲球成功指数  return getProbTackleSucceeds( obj, iExtraCycles );}/*! This method sets the value of the specified object to a known    player or not.  A known player is a player of which the exact team    name and player number are known. If the player number is not    known, information about the object is stored at an empty position    in the player array and the value of isKnownPlayer is set to    'false'.    \param o object type of which known player information should be set    \param isKnownPlayer new known player value    \return boolean indicating whether update was successful *///设置对象O是否为可知球员bool WorldModel::setIsKnownPlayer( ObjectT o, bool isKnownPlayer ){   //设置队员对象的指针  PlayerObject *object = (PlayerObject*) getObjectPtrFromType( o );  return object->setIsKnownPlayer( isKnownPlayer );}/*! This method sets the time the object 'o' has last been seen.    \param o object of which the time should be changed      \param time new time for this object    \return bool indicating whether update was successful. *///设置上次看见对象的时间bool WorldModel::setTimeLastSeen( ObjectT o, Time time ){  PlayerObject *object = (PlayerObject*) getObjectPtrFromType( o );  return object->setTimeLastSeen( time );}/*! This method sets the heterogeneous(不同种类组成的) player type of the object      that is passed as the first argument.    \param o object type of which the heterogeneous player type should be set    \param iPlayer new heterogeneous player type of this object. *///设置异构(PS:暂译)球员的类型,把对象O的类型设置成异构球员iPlayerType的类型]/*PS by 席浩洋:我关于异构类型的理解。这应该是教练所使用的标记球员的一种手段,也就是说教练在球员设定的基础上增设一个标记,然后在以后的调用中方便使用。大概是的......*/bool WorldModel::setHeteroPlayerType( ObjectT  o, int iPlayerType ){  PlayerObject *object = (PlayerObject*) getObjectPtrFromType( o );  if( o == getAgentObjectType() )    updateSSToHeteroPlayerType( iPlayerType );  return object->setHeteroPlayerType( iPlayerType );}/*! This method returns the player type of the object 'o' in the  current formation. *///返回对象O在当前阵形中的类型PlayerT WorldModel::getPlayerType ( ObjectT o ){  //如果是非法球员,设置O为Agent  if( o == OBJECT_ILLEGAL )     o = getAgentObjectType();  //否则,返回其类型  return formations->getPlayerType( SoccerTypes::getIndex( o ) );}/*! This method returns whether the object 'o' is located in the set of    player types 'ps'. *///判断对象O是否在本地球员设定的ps类型中bool WorldModel::isInPlayerSet( ObjectT o, PlayerSetT ps ){  return SoccerTypes::isPlayerTypeInSet( getPlayerType( o ), ps );}/*! This methods returns the heterogeneous player type of object 'obj'.     Initially, the player types of all players are set to the type of the agent    itself. After new information from the coach, they are set correctly. *///返回obj的异构球员类型int WorldModel::getHeteroPlayerType( ObjectT obj ){  PlayerObject *object = (PlayerObject*) getObjectPtrFromType( obj );  return object->getHeteroPlayerType( );}/*! This method returns the global position of the opponent goal.    \return VecPosition containing the position of the opponent goal. *///返回对方球门的位置坐标VecPosition WorldModel::getPosOpponentGoal( ){   //定义并设置对方球门  ObjectT objGoal = SoccerTypes::getGoalOpponent( getSide() );  //我方禁区或者是敌方禁区  if( isPenaltyUs() 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -