📄 worldmodelhighlevel.c
字号:
for( ObjectT o = iterateObjectStart( iIndex, set, dConfThr ); o != OBJECT_ILLEGAL; o = iterateObjectNext ( iIndex, set, dConfThr ) ) { if( o != obj ) { v = getGlobalPosition( obj ) - getGlobalPosition( o ); if( v.getMagnitude() < dMinMag ) // closer then first { dSecondMinMag = dMinMag; // put first to second secondClosestObject = closestObject; dMinMag = v.getMagnitude(); // and this to first closestObject = o; } else if( v.getMagnitude() < dSecondMinMag ) // between first and 2nd { dSecondMinMag = v.getMagnitude(); // put this to second secondClosestObject = o; } } } iterateObjectDone( iIndex ); if( dDist != NULL ) *dDist = dSecondMinMag; return secondClosestObject;}/*! This method returns the object type of the second closest object relative to the agent. Only objects are taken into account within set 'set' and which where seen in the last see message. \param set ObjectSetT which denotes objects taken into consideration \param dDist will be filled with the distance to this this object \return ObjectType that is second closest to the agent */ObjectT WorldModel::getSecondClosestRelativeInSet( ObjectSetT set, double *dDist ){ ObjectT closestObject = OBJECT_ILLEGAL; ObjectT secondClosestObject = OBJECT_ILLEGAL; double dMinMag = 1000.0; double dSecondMinMag = 1000.0; double d; int iIndex; for( ObjectT o = iterateObjectStart( iIndex, set, 1.0 ); o != OBJECT_ILLEGAL; o = iterateObjectNext ( iIndex, set, 1.0 ) ) { d = getRelativeDistance( o ); if( d < dMinMag ) // closer then first { dSecondMinMag = dMinMag; // put first to second secondClosestObject = closestObject; dMinMag = d; // and this to first closestObject = o; } else if( d < dSecondMinMag ) // between first and 2nd { dSecondMinMag = d; // put this to second secondClosestObject = o; } } iterateObjectDone( iIndex ); if( dDist != NULL ) *dDist = dSecondMinMag; return secondClosestObject;}/*! This method returns the object type of the furthest object to the ObjectT that is supplied as the second argument. Only objects are taken into account that are part of the set 'set' and have a confidence higher than the supplied threshold. If no threshold is supplied, the threshold defined in 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 */ObjectT WorldModel::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 */ObjectT WorldModel::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. */double WorldModel::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 */ObjectT WorldModel::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 */ObjectT WorldModel::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*/ObjectT WorldModel::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 */bool WorldModel::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. */bool WorldModel::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. */bool WorldModel::isBallCatchable(){ return getTimeSinceLastCatch() > SS->getCatchBanCycle() &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -