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

📄 worldmodel.cpp

📁 自己写的robocup-2d程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  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. */
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() || isPenaltyThem() )
    objGoal = ( getSidePenalty() == SIDE_LEFT ) ?OBJECT_GOAL_L:OBJECT_GOAL_R ;
  return SoccerTypes::getGlobalPositionFlag(
                        objGoal,
                        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( )
{
  SideT sideGoal = getSide();
  ObjectT objGoal = SoccerTypes::getOwnGoal( sideGoal );
  if( isPenaltyUs() || isPenaltyThem() ) 
    objGoal = (getSidePenalty() == SIDE_LEFT ) ? OBJECT_GOAL_L : OBJECT_GOAL_R;

  return SoccerTypes::getGlobalPositionFlag(
                        objGoal,
                        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 = getPosOpponentGoal();
  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 returns the heterogeneous player information of the object
    'obj'. This information consists of a subset of the ServerSettings
    values that fully specify the information of the heterogeneous player. */
HeteroPlayerSettings WorldModel::getHeteroInfoPlayer( ObjectT obj )
{
//  if( obj == getAgentObjectType() || SoccerTypes::isOpponent( obj ) )
//    return getInfoHeteroPlayer( agentObject.getHeteroPlayerType() );    
  if( ! SoccerTypes::isKnownPlayer( obj ) )
    obj = getAgentObjectType();

  PlayerObject *object = (PlayerObject*) getObjectPtrFromType( obj );
  int          iType   = object->getHeteroPlayerType();
  // default iType in Object = 0
  return getInfoHeteroPlayer( iType );
}


/*! This method inserts a substituted opponent player in the set of substituted
    opponent players. This can then be detected by the coach, who then can
    figure out to which new type this opponent player is changed. */
bool WorldModel::setSubstitutedOpp( ObjectT obj )
{
  m_setSubstitutedOpp.insert( obj );
  return true;
}

/*! This method returns the first substituted opponent player in the set of 
    substituted opponent players and then erases this opponent from the set. */
ObjectT WorldModel::getSubstitutedOpp( )
{
  if( m_setSubstitutedOpp.empty() == true )
    return OBJECT_ILLEGAL;
  
  ObjectT obj = *m_setSubstitutedOpp.begin();
  m_setSubstitutedOpp.erase( obj );
  return obj;
}


/*! This method returns the dash power rate of the object 'obj'. */
double WorldModel::getDashPowerRate( ObjectT obj )
{
  return getHeteroInfoPlayer( obj ).dDashPowerRate ;
}

/*! This method returns the maximum speed of the object 'obj'. */
double WorldModel::getPlayerSpeedMax( ObjectT obj )
{
  return getHeteroInfoPlayer( obj ).dPlayerSpeedMax ;
}

/*! This method returns the decay of the object 'obj'. */
double WorldModel::getPlayerDecay( ObjectT obj )
{
  return getHeteroInfoPlayer( obj ).dPlayerDecay ;
}

/*! This method returns the maximal kick distance of the object 'obj'. */
double WorldModel::getMaximalKickDist( ObjectT obj )
{
  return getHeteroInfoPlayer( obj ).dMaximalKickDist ;
}

/*! This method returns the stamina increase of the object 'obj'. */
double WorldModel::getStaminaIncMax( ObjectT obj )
{
  return getHeteroInfoPlayer( obj ).dStaminaIncMax ;
}

/*! This method returns the size of the object 'obj'. */
double WorldModel::getPlayerSize( ObjectT obj )
{
  return getHeteroInfoPlayer( obj ).dPlayerSize ;
}

/*! This method returns the inertia moment of the object 'obj'. */
double WorldModel::getInertiaMoment( ObjectT obj )
{
  return getHeteroInfoPlayer( obj ).dInertiaMoment;
}

/*! This method returns the maximum effort of the object 'obj'. */
double WorldModel::getEffortMax( ObjectT obj )
{
  return getHeteroInfoPlayer( obj ).dEffortMax;
}

/*! This method returns the effective max speed of the object 'obj'. */
double WorldModel::getEffectiveMaxSpeed( ObjectT obj, bool bWithNoise )
{
  double dSpeed = 0.0;
  HeteroPlayerSettings pt = getHeteroInfoPlayer( obj );

  for( int j = 0; j < 15 ; j ++ )
  {
    dSpeed *= pt.dPlayerDecay;
    dSpeed += SS->getMaxPower()*pt.dEffortMax*pt.dDashPowerRate;
    if( dSpeed > pt.dPlayerSpeedMax )
      dSpeed = pt.dPlayerSpeedMax;
    if( bWithNoise )
      dSpeed += sqrt(2*(pow(dSpeed * SS->getPlayerRand(), 2)));
  }
  return dSpeed;
}

/*! 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 < CMD_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();

  bool bLeftKick = (pm==PM_FREE_KICK_LEFT  || pm==PM_INDIRECT_FREE_KICK_LEFT );
  bool bRightKick= (pm==PM_FREE_KICK_RIGHT || pm==PM_INDIRECT_FREE_KICK_RIGHT);

  return ( bLeftKick   && getSide() == SIDE_LEFT  ) ||
         ( bRightKick  && getSide() == SIDE_RIGHT ) ;
}

/*! This method checks whether the play mode indicates that the other
    team has 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 the other team has a free kick. */
bool WorldModel::isFreeKickThem( PlayModeT pm )
{
  if( pm == PM_ILLEGAL )
    pm = getPlayMode();

  bool bLeftKick = (pm==PM_FREE_KICK_LEFT  || pm==PM_INDIRECT_FREE_KICK_LEFT );
  bool bRightKick= (pm==PM_FREE_KICK_RIGHT || pm==PM_INDIRECT_FREE_KICK_RIGHT);

  return ( bRightKick  && getSide() == SIDE_LEFT  ) ||
         ( bLeftKick   && getSide() == SIDE_RIGHT ) ;
}

/*! This method checks whether the play mode indicates that there is (or
    will be) a before kick off situation. This is the case when the play mode
    equals PM_BEFORE_KICK_OFF or either PM_GOAL_LEFT or PM_GOAL_RIGHT since
    after the goal the play mode will go to PM_BEFORE_KICK_OFF.
    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 there is a before kick off situation. */
bool WorldModel::isBeforeKickOff( PlayModeT pm )
{
  if( pm == PM_ILLEGAL )
    pm = getPlayMode();

  return pm == PM_BEFORE_KICK_OFF  || pm == PM_GOAL_LEFT  ||
         pm == PM_GOAL_RIGHT || isKickOffUs( pm ) || isKickOffThem( pm );
}

/*! This method checks whether the play mode indicates that there is
    a dead ball situation and our team is allowed to perform the action.
    That is our team has either a free kick, kick in, corner kick or a kick in.
    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 dead ball situation. */
bool WorldModel::isDeadBallUs( PlayModeT pm )
{
  if( pm == PM_ILLEGAL )
    pm = getPlayMode();

  return isKickInUs  ( pm ) || isFreeKickUs  ( pm ) || isCornerKickUs     ( pm)
      || isKickOffUs ( pm ) || isOffsideThem ( pm ) || isFreeKickFaultThem( pm)
      || isGoalKickUs( pm ) || isBackPassThem( pm ) ;
}


/*! This method checks whether the current play mode indicates that there is
    a dead ball situation and their team is allowed to perform the action.
    That is their team has either a free kick, kick in, corner kick or a kick
    in. 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 they have a dead ball situation. */
bool WorldModel::isDeadBallThem( PlayModeT pm )
{
  if( pm == PM_ILLEGAL )
    pm = getPlayMode();

  return isFreeKickThem( pm ) || isKickInThem  ( pm ) || isCornerKickThem ( pm)
     ||  isKickOffThem ( pm ) || isGoalKickThem( pm ) || isFreeKickFaultUs( pm)
     || isOffsideUs    ( pm ) || isBackPassUs  ( pm ) ;
}

bool WorldModel::setChangeViewCommand( SoccerCommand soc )
{
  m_changeViewCommand = soc;
  return true;
}

SoccerCommand WorldModel::getChangeViewCommand( )
{
  return m_changeViewCommand;
}

/*! This method returns the side the penalty kick is taken. */
SideT WorldModel::getSidePenalty( )
{
  return m_sidePenalty;
}

/*! This method sets the side the penalty kick is taken. */
bool WorldModel::setSidePenalty( SideT side )
{
  m_sidePenalty = side;
  return true;
}


/*! This method checks whether the current play mode indicates that we have
    a corner 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 corner kick. */
bool WorldModel::isCornerKickUs( PlayModeT pm )
{
  if( pm == PM_ILLEGAL )
    pm = getPlayMode();

  return ( pm == PM_CORNER_KICK_LEFT  && getSide() == SIDE_LEFT  ) ||
         ( pm == PM_CORNER_KICK_RIGHT && getSide() == SIDE_RIGHT ) ;
}

/*! This method checks whether the current play mode indicates that the other
    team has a corner 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 the other team has a corner kick. */
bool WorldModel::isCornerKickThem( PlayModeT pm )
{
  if( pm == PM_ILLEGAL )
    pm = getPlayMode();

  return ( pm == PM_CORNER_KICK_RIGHT  && getSide() == SIDE_LEFT  ) ||
         ( pm == PM_CORNER_KICK_LEFT   && getSide() == SIDE_RIGHT ) ;
}

/*! This method checks whether the current play mode indicates that we stood
    offside. 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 stood offside. */
bool WorldModel::isOffsideUs( PlayModeT pm )
{
  if( pm == PM_ILLEGAL )
    pm =

⌨️ 快捷键说明

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