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

📄 worldmodel.c

📁 机器足球2D比赛程序 对trlen_base_2002的改进
💻 C
📖 第 1 页 / 共 5 页
字号:
  \param ObjectT that represent the type of the object to check  \return VecPosition containing the global position. */VecPosition WorldModel::getGlobalVelocity( ObjectT o ){	DynamicObject *object = (DynamicObject*)getObjectPtrFromType( o );	if( object != NULL )		return object->getGlobalVelocity(  );	return VecPosition( UnknownDoubleValue, UnknownDoubleValue );}/*! This method returns the relative distance between the agent and the object  supplied as the first argument. No check is made whether this information  is up to date (use isVisible or getConfidence for that).  \param ObjectT that represent the type of the object to check  \return relative distance to this object */double WorldModel::getRelativeDistance( ObjectT o ){	Object *object = getObjectPtrFromType( o );	if( object != NULL )		return object->getRelativeDistance();	return UnknownDoubleValue;}/*! This method returns the relative position of the object to the agent.  No check is made whether this information is up to date (use isVisible or  getConfidence for that).  \param ObjectT that represent the type of the object to check  \return relative position to this object */VecPosition  WorldModel::getRelativePosition( ObjectT o ){	Object *object = getObjectPtrFromType( o );	if( object != NULL )		return object->getRelativePosition();	return VecPosition(UnknownDoubleValue, UnknownDoubleValue);}/*! This method returns the relative angle between the agent and the object  supplied as the first argument. No check is made whether this information  is up to date (use isVisible or getConfidence for that).  By default the returned angle is relative to the neck  of the agent. When the second argument 'bWithBody' is set to true, the  returned angle is relative to the body of the agent.  \param ObjectT that represent the type of the object to check  \param bWithBody when true angle is relative to body, otherwise to neck  (default false)  \return relative angle to this object */AngDeg WorldModel::getRelativeAngle( ObjectT o, bool bWithBody ){	Object *object = getObjectPtrFromType( o );	double dBody   = 0.0;	if( object != NULL )	{		if( bWithBody == true )			dBody = getAgentBodyAngleRelToNeck();		return VecPosition::normalizeAngle( object->getRelativeAngle() - dBody );	}	return UnknownDoubleValue;}/*! This method returns the time of the global angles (both body and neck angle)  of the specified object.  \param ObjectT that represent the type of the object to check  \return time corresponding to both the stored body and neck angle */Time WorldModel::getTimeGlobalAngles( ObjectT o ){	PlayerObject *object = (PlayerObject*) getObjectPtrFromType( o );	if( object != NULL )		return object->getTimeGlobalAngles();	return Time( -1, 0);}/*! This method returns the global body angle of the specified object.  No check is made whether this information is up to date (use  getTimeGlobalAngles).  \param ObjectT that represent the type of the object to check  \return last known global body angle of this object */AngDeg WorldModel::getGlobalBodyAngle( ObjectT o ){	PlayerObject *object = (PlayerObject*) getObjectPtrFromType( o );	if( object != NULL )		return object->getGlobalBodyAngle();	return UnknownAngleValue;}/*! This method returns the global neck angle of the specified object.  No check is made whether this information is up to date (use  getTimeGlobalAngles).  \param ObjectT that represent the type of the object to check  \return last known global neck angle of this object */AngDeg WorldModel::getGlobalNeckAngle( ObjectT o ){	PlayerObject *object = (PlayerObject*) getObjectPtrFromType( o );	if( object != NULL )		return object->getGlobalNeckAngle();	return UnknownAngleValue;}/*! This method returns the global angle of the specified object (this object  is normally a line).  \param ObjectT that represent the type of the object to check  \return global angle of this object in the field */AngDeg WorldModel::getGlobalAngle( ObjectT o ){	if( SoccerTypes::isLine( o ) )		return SoccerTypes::getGlobalAngleLine( o, getSide() );	return UnknownAngleValue;}/*! This method returns the confidence value of the object  supplied as the first argument. The confidence is calculated using the  current server cycle and the time the object was last seen.  \param ObjectT that represent the type of the object to check  \return confidence value [0.0, 1.0] that indicates the confidence value */double WorldModel::getConfidence( ObjectT o){	Object *object = getObjectPtrFromType( o );	if( object != NULL )		return object->getConfidence( getCurrentTime() );	return 0.0;}/*! This method returns wheter the specified object type is a known player.  A known player is a player of which we know for certain that the player  number is correct. If a player is seen without a number and it cannot be  mapped to a player, it is put on the first empty position in the  player list and the status of known player is set to false.  \param o object type of player that should be checked  \return bool indicating whether we are certain of number of player 'o'. */bool WorldModel::isKnownPlayer( ObjectT o ){	PlayerObject *object = (PlayerObject *)getObjectPtrFromType( o );	if( object != NULL  )		return object->getIsKnownPlayer();	return false;}/*! This method returns the object type of the opponent goalkeeper. Which object  type is the actual goalkeeper is checked in different ways. First of all  this information is can be available in a see message.  When no player is stored in the world model of which this is  is perceived, the opponent goalkeeper is assumed the player with the highest  x coordinate, but only if this player stands very close in front of the goal  \return ObjectT that represents the opponent goalkeeper, OBJECT_ILLEGAL if  it cannot be determined which object type is the opponent goalkeeper. */ObjectT WorldModel::getOppGoalieType(){	ObjectT objOppMaxX = OBJECT_ILLEGAL;	double  x = -100.0, y = UnknownDoubleValue;	for( int i = 0; i < MAX_OPPONENTS; i++ )	{		if( isConfidenceGood( Opponents[i].getType( ) ) )		{			if( Opponents[i].getIsGoalie() == true ) // &&				//           Opponents[i].getGlobalPosition().getX() > PENALTY_X - 2.0 )				return Opponents[i].getType();			if( Opponents[i].getGlobalPosition().getX() > x )			{				x          = Opponents[i].getGlobalPosition().getX();				y          = Opponents[i].getGlobalPosition().getY();				objOppMaxX = Opponents[i].getType();			}		}	}	// if opponent with highest x is nr 1, assume it is goalkeeper when standing	// in own penalty area, otherwise assume goalkeeper closest player to goal.	if(  objOppMaxX == OBJECT_OPPONENT_1 && x > PENALTY_X + 4.0 ||			(objOppMaxX != OBJECT_ILLEGAL    && x > PITCH_LENGTH/2.0 - 6.0 &&			 fabs( y ) < SS->getGoalWidth()/2.0 ))		return objOppMaxX;	return OBJECT_ILLEGAL;}/*! This method returns the object type of the own goalkeeper. Which object  type is the actual goalkeeper is checked in different ways. First of all  this information is available in the see, when (goalie) is behind the  perceived object. When no player is stored in the world model of which  this is perceived, the own goalkeeper is assumed the player with the lowest  x coordinate, but only if this player stands close in front of the goal.  \return ObjectT that represents the own goalkeeper, OBJECT_ILLEGAL if  it cannot be determined which object type is the own goalkeeper. */ObjectT WorldModel::getOwnGoalieType(){	ObjectT objOwnMinX = OBJECT_ILLEGAL;	double x = -100.0, y = UnknownDoubleValue;	for( int i = 0; i < MAX_TEAMMATES; i++ )	{		if( isConfidenceGood( Teammates[i].getType( ) ) )		{			if( Teammates[i].getIsGoalie() == true )				return Teammates[i].getType();			if( Teammates[i].getGlobalPosition().getX() < x )			{				x          = Teammates[i].getGlobalPosition().getX();				y          = Teammates[i].getGlobalPosition().getY();				objOwnMinX = Teammates[i].getType();			}		}	}	if(  objOwnMinX == OBJECT_TEAMMATE_1 && x < - ( PENALTY_X + 4.0 ) ||			(objOwnMinX != OBJECT_ILLEGAL    && x < - ( PITCH_LENGTH/2.0 - 6.0 ) &&			 fabs( y ) < SS->getGoalWidth()/2.0 ))		return objOwnMinX;	return OBJECT_ILLEGAL;}/*! This method returns the last server cycle the specified object has been  seen.  \param object type of object that should be checked  \return server time this object was last seen (in a see message). */Time WorldModel::getTimeLastSeen( ObjectT o ){	Object *object = getObjectPtrFromType( o );	if( object != NULL )		return object->getTimeLastSeen(  );	return Time( -1, 0);}/*! This method returns the last server cycle the relative distance change of  the specified object has been reported.  \param object type of object that should be checked  \return server time relative distance change of this object was last   seen (in a see message). */Time WorldModel::getTimeChangeInformation( ObjectT o ){	DynamicObject *object = (DynamicObject*)getObjectPtrFromType( o );	if( object != NULL )		return object->getTimeChangeInformation(  );	return Time( -1, 0);}/*! 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 */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 returns the global position of the opponent goal.  \return VecPosition containing the position of the opponent goal. */VecPosition WorldModel::getPosOpponentGoal( ){	return SoccerTypes::getGlobalPositionFlag(			SoccerTypes::getGoalOpponent( getSide() ),			getSide( ),			SS->getGoalWidth() );}/*! This method returns the global position of the own goal.  \return VecPosition containing the position of the own goal. */VecPosition WorldModel::getPosOwnGoal( ){	return SoccerTypes::getGlobalPositionFlag(			SoccerTypes::getOwnGoal( getSide() ),			getSide( ),			SS->getGoalWidth() );}/*! This method returns the relative distance to the opponent goal  \return relative distance from the agent to the opponent goal. */double  WorldModel::getRelDistanceOpponentGoal(){	VecPosition posGoal;	if( sideSide == SIDE_LEFT )		posGoal = SoccerTypes::getGlobalPositionFlag( OBJECT_GOAL_R, sideSide );	else		posGoal = SoccerTypes::getGlobalPositionFlag( OBJECT_GOAL_L, sideSide );	return getAgentGlobalPosition().getDistanceTo( posGoal );}/*! This method returns the relative angle to the opponent goal. This relative  angle is the relative angle between the opponent goal position and the agent  position. The neck and body angle of the agent are NOT taken into account.  \return relative angle between goal and agent position. */double  WorldModel::getRelAngleOpponentGoal(){	VecPosition posGoal;	if( sideSide == SIDE_LEFT )		posGoal = SoccerTypes::getGlobalPositionFlag( OBJECT_GOAL_R, sideSide );	else		posGoal = SoccerTypes::getGlobalPositionFlag( OBJECT_GOAL_L, sideSide );	return ( posGoal - getAgentGlobalPosition()).getDirection() ;}/*! This method returns information about the heterogeneous player at index  'iIndex'. This information consists of a subset of the ServerSettings  values that fully specify the information of the heterogeneous player. */HeteroPlayerSettings WorldModel::getInfoHeteroPlayer( int iIndex ){	return pt[iIndex];}/*! This method checks whether a queued action is performed. The commands in  QueuedCommands are the commands that are sent to the server by the  ActHandler. The performedCommands array contains the commands that are  performed in the last cycle (using the count information in the sense_body  message). Using these two array it is possible to check whether a command  is actually performed by the server. When there is an action that is sent  to the server and not performed, this method returns false, true otherwise.  \return true when all commands sent to the server are performed. */bool WorldModel::isQueuedActionPerformed(){	// for all possible commands check if it is sent in previous cycle,	// but not performed	for( int i = 0 ; i < MAX_COMMANDS ; i++ )		if( queuedCommands[i].time   == getTimeLastSenseMessage() - 1 &&				performedCommands[i]     == false )			return false;	return true;}/*! This method checks whether the play mode indicates that we have  a free kick. When the specified PlayModeT equals PM_ILLEGAL (default), the   current play mode is used.  \param pm play mode to check. In default case (PM_ILLEGAL) the current play  mode is used.   \return bool indicating whether we have a free kick. */bool WorldModel::isFreeKickUs( PlayModeT pm ){	if( pm == PM_ILLEGAL ) 		pm = getPlayMode();	return ( pm == PM_FREE_KICK_LEFT  && getSide() == SIDE_LEFT  ) ||		( pm == PM_FREE_KICK_RIGHT && getSide() == SIDE_RIGHT ) ;}/*! This method checks whether the play mode indicates that the other

⌨️ 快捷键说明

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