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

📄 worldmodelhighlevel.c

📁 机器足球2D比赛程序 对trlen_base_2002的改进
💻 C
📖 第 1 页 / 共 5 页
字号:
  PlayerSettings is used.  \param set ObjectSetT which denotes objects taken into consideration  \param o ObjectT that represent the type of the object to compare to  \param dDist will be filled with the furthest distance  \param dConfThr minimum confidence threshold for the objects in 'set'  \return ObjectType that is furthest to o */ObjectTWorldModel::getFurthestInSetTo (ObjectSetT set, ObjectT objTarget,				double *dDist, double dConfThr){  if (dConfThr == -1.0)    dConfThr = PS->getPlayerConfThr ();  ObjectT furthestObject = OBJECT_ILLEGAL;  double dMaxMag = -1000.0;  VecPosition v;  int iIndex;  for (ObjectT o = iterateObjectStart (iIndex, set, dConfThr);       o != OBJECT_ILLEGAL; o = iterateObjectNext (iIndex, set, dConfThr))    {      if (o != objTarget)	{	  v = getGlobalPosition (objTarget) - getGlobalPosition (o);	  if (v.getMagnitude () > dMaxMag)	    {	      dMaxMag = v.getMagnitude ();	      furthestObject = o;	    }	}    }  iterateObjectDone (iIndex);  if (dDist != NULL)    *dDist = dMaxMag;  return furthestObject;}/*! This method returns the type of the object that is located furthest  relative to the agent. Only objects are taken into account  that are part of the set 'set'.  \param set ObjectSetT which denotes objects taken into consideration  \param dDist will be filled with the furthest relative distance  \return ObjectType that is furthest to the agent */ObjectTWorldModel::getFurthestRelativeInSet (ObjectSetT set, double *dDist){  ObjectT furthestObject = OBJECT_ILLEGAL;  double dMaxMag = -1000.0;  int iIndex;  for (ObjectT o = iterateObjectStart (iIndex, set, 1.0);       o != OBJECT_ILLEGAL; o = iterateObjectNext (iIndex, set, 1.0))    {      if (getRelativeDistance (o) > dMaxMag)	{	  dMaxMag = getRelativeDistance (o);	  furthestObject = o;	}    }  iterateObjectDone (iIndex);  if (dDist != NULL)    *dDist = dMaxMag;  return furthestObject;}/*! This method returns the maximum distance object 'o' could have traveled  since it was last seen.   \param o object type to check  \return distance which object 'o' could have maximal traveled. */doubleWorldModel::getMaxTraveledDistance (ObjectT o){  return (getCurrentTime () - getTimeLastSeen (o)) * SS->getPlayerSpeedMax ();}/*! This method returns the fastest object to a specified object and fills the  last argument with the predicted amount of cycles needed to intercept  this object. Only objects within the set 'set' are taken into  consideration and the objects have to have a confidence higher than the  player confidence threshold defined in PlayerSettings.  \param set ObjectSetT which denotes objects taken into consideration  \param obj object type of object that should be intercepted  \param iCyclesToIntercept will be filled with the amount of cycles needed  \returns object that can intercept object obj fastest */ObjectTWorldModel::getFastestInSetTo (ObjectSetT set, ObjectT obj,			       int *iCyclesToIntercept){  double dConfThr = PS->getPlayerConfThr ();  ObjectT fastestObject = OBJECT_ILLEGAL;  int iCycles = -1;  int iCyclesToObj = 100;  int iMinCycles = 100;  int iIndex;  VecPosition posObj;  while (iCycles < iMinCycles && iCycles < 100)    {      iCycles = iCycles + 1;      iMinCycles = 100;      posObj = predictPosAfterNrCycles (obj, iCycles);      for (ObjectT o = iterateObjectStart (iIndex, set, dConfThr);	   o != OBJECT_ILLEGAL; o = iterateObjectNext (iIndex, set, dConfThr))	{	  if (getGlobalPosition (o).getDistanceTo (posObj) /	      SS->getPlayerSpeedMax () < iMinCycles)	    {	      iCyclesToObj =		(int) rint (getGlobalPosition (o).getDistanceTo (posObj) /			    SS->getPlayerSpeedMax ());	      //        iCyclesToObj = predictNrCyclesToPoint( o, posObj,	      //                                               PS->getPlayerWhenToTurnAngle() );	      //        if( iCyclesToObj < iMinCycles )	      {		iMinCycles = iCyclesToObj;		fastestObject = o;	      }	    }	}      iterateObjectDone (iIndex);    }  if (iCyclesToIntercept != NULL)    *iCyclesToIntercept = iMinCycles;  return fastestObject;}/*! This method returns the fastest object to another object that is currently  located at position 'pos' and has velocity 'vel' that decays with a value  'dDecay'. The last argument will be filled with the predicted amount of  cycles needed to reach this object.  \param set ObjectSetT which denotes objects taken into consideration  \param pos current position of the object  \param vel current velocity of the object  \param dDecay decay value of the velocity of the object  \param iCyclesToIntercept will be filled with the amount of cycles needed  \returns object that can reach it fastest */ObjectTWorldModel::getFastestInSetTo (ObjectSetT set, VecPosition pos,			       VecPosition vel, double dDecay,			       int *iCyclesToIntercept){  double dConfThr = PS->getPlayerConfThr ();  ObjectT fastestObject = OBJECT_ILLEGAL;  int iCycles = 0;  int iCyclesToObj = 100;  int iMinCycles = 100;  int iIndex;  while (iCycles < iMinCycles && iCycles < 100)    {      iCycles = iCycles + 1;      iMinCycles = 100;      for (ObjectT o = iterateObjectStart (iIndex, set, dConfThr);	   o != OBJECT_ILLEGAL; o = iterateObjectNext (iIndex, set, dConfThr))	{	  if (getGlobalPosition (o).getDistanceTo (pos) /	      SS->getPlayerSpeedMax () < iMinCycles)	    {	      iCyclesToObj =		(int) rint (getGlobalPosition (o).getDistanceTo (pos) /			    SS->getPlayerSpeedMax ());	      //        iCyclesToObj = predictNrCyclesToPoint( o, pos,	      //                                               PS->getPlayerWhenToTurnAngle() );	      //        if( iCyclesToObj < iMinCycles )	      {		iMinCycles = iCyclesToObj;		fastestObject = o;	      }	    }	}      iterateObjectDone (iIndex);      pos += vel;      vel *= dDecay;    }  if (iCyclesToIntercept != NULL)    *iCyclesToIntercept = iMinCycles;  return fastestObject;}/*! This method returns the first empty spot in the set 'set'. The first empty  spot is returned as the object which has a lower confidence than the  threshold player_conf_thr defined in the PlayerSettings. This can be used  when information of an unknown object is perceived. It is set on the first  position where there is currently no information stored. If 'iUnknownPlayer'  is specified, the range that corresponds to this unknown player is used  to dermine the position.  \param set ObjectSetT consisting of the objects to check  \param iUnknownPlayer indicates the unknownplayer that has to be mapped  \return object type of which currently no up to date information is stored*/ObjectTWorldModel::getFirstEmptySpotInSet (ObjectSetT set, int iUnknownPlayer){  int iIndex;  for (ObjectT o = iterateObjectStart (iIndex, set, 0.0);       o != OBJECT_ILLEGAL; o = iterateObjectNext (iIndex, set, 0.0))    {      if (getConfidence (o) < PS->getPlayerConfThr () &&	  o != getAgentObjectType () &&	  (iUnknownPlayer == -1	   || UnknownPlayers[iUnknownPlayer].isInRange (o)))	return o;    }  return OBJECT_ILLEGAL;}/*! This method returns a truth value that represents whether the object  supplied as the first argument was seen in the last see message. If  "touch" information was received, i.e. the object was very close to the  agent but not in its view cone, false is also returned.  \param ObjectT that represent the type of the object to check  \return bool indicating whether o was seen in the last see message */boolWorldModel::isVisible (ObjectT o){  Object *object = getObjectPtrFromType (o);  if (object != NULL &&      object->getTimeLastSeen () == getTimeLastSeeMessage ())    return true;  return false;}/*! This method determines whether the ball is kicakble, i.e. the ball is in the  kickable range of the agent (see ServerSettings). This value can be  different for the different heterogeneous player types.  \return bool indicating whether ball can be kicked. */boolWorldModel::isBallKickable (){  return getRelativeDistance (OBJECT_BALL) < SS->getMaximalKickDist ();}/*! This method determines whether the ball is catchable. This only applies  to a goalie. Three things are tested:  - the ball hasn't been catched in catch_ban_cycles (see ServerSettings)  before the current cycle  - the relative distance to the ball is smaller than the length of the  catchable area length of the goalie (see also ServerSettings)  - the ball is in the (own) penalty area.  \return true when above three constraints are met, false otherwise. */boolWorldModel::isBallCatchable (){  return getTimeSinceLastCatch () > SS->getCatchBanCycle () &&    getRelativeDistance (OBJECT_BALL) < SS->getCatchableAreaL () &&    isInOwnPenaltyArea (getBallPos ());}/*! This method checks whether the ball is currently heading towards our own  goal. For the ball to be heading to our goal a few constraints must be met:  - ball must be located in our penalty area  - line of ball heading must intersect with goal line within goal width +  small constant.  - ball must pass goal line within 20 cycles.  If all these constraints are met true is returned, false otherwise  \return bool indicating whether the ball is heading towards our own goal */boolWorldModel::isBallHeadingToGoal (){  if (!isConfidenceGood (OBJECT_BALL) ||      getBallPos ().getX () > -PENALTY_X + 5.0)    return false;  // make line from ball heading and goal line  Line l =    Line::makeLineFromPositionAndAngle (getBallPos (), getBallDirection ());  Line l2 =    Line::makeLineFromTwoPoints (getPosOwnGoal (),				 getPosOwnGoal () + VecPosition (0, 10));  // if intersection is outside goalwidth, not heading to goal  VecPosition posIntersect = l.getIntersection (l2);  if (fabs (posIntersect.getY ()) > SS->getGoalWidth () / 2.0 + 3.0)    return false;  // check whether ball will be behind goal line within 20 cycles.  VecPosition pos = getBallPos ();  int iCycle = 1;  while (pos.getX () > -PITCH_LENGTH / 2.0 && iCycle < 20)    {      pos = predictPosAfterNrCycles (OBJECT_BALL, iCycle);      iCycle++;    }  return (iCycle == 20) ? false : true;}/*! This method returns whether the ball is in our possesion. This is defined  by the fact if the fastest player to the ball is a teammate or not.  \return bool indicating whether a teammate is the fastest player to the  ball. */boolWorldModel::isBallInOurPossesion (){  int iCyc;  ObjectT o = getFastestInSetTo (OBJECT_SET_PLAYERS, OBJECT_BALL, &iCyc);  if (o == OBJECT_ILLEGAL)    return false;  if (SoccerTypes::isTeammate (o))    return true;  else    return false;}/*! This method returns whether the ball lies in the own penalty area.  \return bool indicating whether ball lies in own penalty area.     */boolWorldModel::isBallInOwnPenaltyArea (){  return isInOwnPenaltyArea (getBallPos ());}/*! This method returns whether the specified position lies in the own penalty  area.  \param pos position which should be checked  \return bool indicating whether 'pos' lies in own penalty area. */boolWorldModel::isInOwnPenaltyArea (VecPosition pos){  ObjectT objFlag = (getSide () == SIDE_LEFT)    ? OBJECT_FLAG_P_L_C : OBJECT_FLAG_P_R_C;  VecPosition posFlag =    SoccerTypes::getGlobalPositionFlag (objFlag, getSide ());  if (pos.getX () < posFlag.getX ()      && fabs (pos.getY ()) < PENALTY_AREA_WIDTH / 2.0)    return true;  return false;}/*! This method returns whether the specified position lies in the opponent  penalty area.  \param pos position which should be checked  \return boolean indicating whether 'pos' lies in opponent penalty area. */boolWorldModel::isInTheirPenaltyArea (VecPosition pos){  ObjectT objFlag = (getSide () == SIDE_LEFT)    ? OBJECT_FLAG_P_R_C : OBJECT_FLAG_P_L_C;  VecPosition posFlag =    SoccerTypes::getGlobalPositionFlag (objFlag, getSide ());  if (pos.getX () > posFlag.getX () &&      fabs (pos.getY ()) < PENALTY_AREA_WIDTH / 2.0)    return true;  return false;}/*! This method determines whether the confidence for 'o' is good. The  confidence of the object is compared to the player_conf_thr defined in  PlayerSettings. When the confidence is higher than this value and the object  does not equal the agent object type true is returned, otherwise false.  \param o object of which confidence value should be returned  \return bool indicating whether object information has good confidence. */boolWorldModel::isConfidenceGood (ObjectT o){  return getConfidence (o) > PS->getPlayerConfThr () &&    o != getAgentObjectType ();}/*! This method determines whether the confidence for 'o' is very good. The  confidence of the object is compared to the player_high_conf_thr defined in  PlayerSettings. When the confidence is higher than this value and the object  does not equal the agent object type true is returned, otherwise false.  \param o object of which confidence value should be returned  \return bool indicating whether object information has good confidence. */boolWorldModel::isConfidenceVeryGood (ObjectT o){  return getConfidence (o) > PS->getPlayerHighConfThr () &&    o != getAgentObjectType ();}/*! This method checks whether the specified object stands onside. This is done  by comparing the x coordinate of the object to the offside line.  \return boolean indicating whether 'obj' stands onside. */boolWorldModel::isOnside (ObjectT obj){

⌨️ 快捷键说明

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