?? basicplayer.c
字號(hào):
dAngle = VecPosition::normalizeAngle( dAngle ); return SoccerCommand( CMD_KICK, dPower, dAngle );}/*! This skill enables an agent to kick the ball close to his body. It receives an angle 'ang' as its only argument and returns a kick command that causes the ball to move to a point at a relative angle of 'ang' degrees and at a close distance (kickable margin/6 to be precise) from the agent's body. To this end the ball has to be kicked from its current position to the desired point relative to the predicted position of the agent in the next cycle. In general, this skill will be used when the agent wants to kick the ball to a certain position on the field which cannot be reached with a single kick. Since the efficiency of a kick is highest when the ball is positioned just in front of the agent's body, calling this skill with 'ang = 0' will have the effect that the agent can kick the ball with more power after it is executed. Note that this skill will only be executed if it is possible to actually reach the desired ball position with a single kick. If the required power does exceed the maximum then the ball is frozen at its current position using the freezeBall skill. In general, it will then always be possible to shoot the motionless ball to the desired point in the next cycle. \param 'ang' relative angle to body to which the ball should be kicked \return SoccerCommand to kick the ball close to the body */SoccerCommand BasicPlayer::kickBallCloseToBody( AngDeg ang ){ AngDeg angBody = WM->getAgentGlobalBodyAngle(); VecPosition posAgent = WM->predictAgentPos( 1, 0 ); double dDist = SS->getPlayerSize() + SS->getBallSize() + SS->getKickableMargin()/6.0; VecPosition posDesBall = posAgent + VecPosition( dDist, angGlobal, POLAR ); VecPosition vecDesired = posDesBall - WM->getBallPos(); VecPosition vecShoot = vecDesired - WM->getGlobalVelocity( OBJECT_BALL ); double dPower = WM->getKickPowerForSpeed( vecShoot.getMagnitude() ); AngDeg angActual = vecShoot.getDirection() - angBody; angActual = VecPosition::normalizeAngle( angActual ); if( dPower > SS->getMaxPower() && WM->getBallSpeed() > 0.1 ) { Log.log( 500, "kickBallCloseToBody: cannot compensate for ball speed, freeze"); Log.log( 101, "kickBallCloseToBody: cannot compensate for ball speed, freeze"); return freezeBall(); } else if( dPower > SS->getMaxPower() ) { Log.log( 101, "kickBallCloseToBody: ball has no speed, but far away" ); dPower = 100; } else Log.log( 101, "(kick %f %f), vecDesired (%f,%f)", dPower, angActual, vecDesired.getX(), vecDesired.getY() ); return SoccerCommand( CMD_KICK, dPower, angActual );}/*! This skill enables an agent to accelerate the ball in such a way that it gets a certain velocity after the kick. It receives the desired velocity 'vecDes' as its only argument and returns a kick command that causes the ball to be accelerated to this velocity. If the power that must be supplied to the kick command to get the desired result does not exceed the maximum kick power then the desired velocity can be realized with a single kick. The kick direction should then be equal to the direction of the acceleration vector relative to the agent's global body angle. However, if the desired velocity is too great or if the current ball velocity is too high then the required acceleration cannot be realized with a single kick. In this case, the ball is kicked in such a way that the acceleration vector has the maximum possible length and a direction that aligns the resulting ball movement with 'vecDes'. This means that after the kick the ball will move in the same direction as 'vecDes' but at a lower speed. To this end the acceleration vector has to compensate for the current ball velocity in the `wrong' direction (y-component). \param velDes desired ball velocity \return SoccerCommand that accelerates the ball to 'vecDes' */SoccerCommand BasicPlayer::accelerateBallToVelocity( VecPosition velDes ){ AngDeg angBody = WM->getAgentGlobalBodyAngle(); VecPosition velBall = WM->getGlobalVelocity( OBJECT_BALL ); VecPosition accDes = velDes - velBall; double dPower; double angActual; // if acceleration can be reached, create shooting vector if( accDes.getMagnitude() < SS->getBallAccelMax() ) { dPower = WM->getKickPowerForSpeed ( accDes.getMagnitude() ); angActual = VecPosition::normalizeAngle( accDes.getDirection() - angBody ); if( dPower <= SS->getMaxPower() ) return SoccerCommand( CMD_KICK, dPower, angActual ); } // else determine vector that is in direction 'velDes' (magnitude is lower) dPower = SS->getMaxPower(); double dSpeed = WM->getActualKickPowerRate() * dPower; double tmp = velBall.rotate(-velDes.getDirection()).getY(); angActual = velDes.getDirection() - asinDeg( tmp / dSpeed ); angActual = VecPosition::normalizeAngle( angActual - angBody ); return SoccerCommand( CMD_KICK, dPower, angActual );}/*! This skill enables an agent to catch the ball and can only be executed when the agent is a goalkeeper. It returns a catch command that takes the angle of the ball relative to the body of the agent as its only argument. The correct value for this argument is computed by determining the global direction between the current ball position and the agent's current position and by making this direction relative to the agent's global body angle. \return SoccerCommand to catch the ball */SoccerCommand BasicPlayer::catchBall(){ // true means returned angle is relative to body instead of neck return SoccerCommand( CMD_CATCH, WM->getRelativeAngle( OBJECT_BALL, true ));}/*! This skill enables an agent to communicate with other players on the field. It receives a string message as its only argument and returns a say command that causes the message to be broadcast to all players within a certain distance from the speaker. \return SoccerCommand to say the specified string 'str' */SoccerCommand BasicPlayer::communicate( char *str ){ return SoccerCommand( CMD_SAY, str );}/*! This method returns a 'move' command to teleport the agent directly to the specified global position. \param pos global position to which should be moved. \return SoccerCommand to move directly to 'pos'. */SoccerCommand BasicPlayer::teleportToPos( VecPosition pos ){ return SoccerCommand( CMD_MOVE, pos.getX(), pos.getY() );}/********************** INTERMEDIATE LEVEL SKILLS ****************************//*! This skill enables an agent to turn his body towards an object o which is supplied to it as an argument. To this end the object's global position o in the next cycle is predicted based on its current velocity. This predicted position is passed as an argument to the turnBodyToPoint skill which generates a turn command that causes the agent to turn his body towards the object. \param o object to which agent wants to turn \return SoccerCommand that turns to this object */SoccerCommand BasicPlayer::turnBodyToObject( ObjectT o ){ return turnBodyToPoint( WM->predictPosAfterNrCycles(o, 1) );}/*! This skill enables an agent to turn his neck towards an object. It receives as arguments this object o as well as a primary action command 'soc' that will be executed by the agent at the end of the current cycle. Turning the neck towards an object amounts to predicting the object's global position in the next cycle and passing this predicted position together with the 'soc' command as arguments to the turnNeckToPoint skill. This low-level skill will then generate a turn neck command that causes the agent to turn his neck towards the given object. Note that the 'soc' command is supplied as an argument for predicting the agent's global position and neck angle after executing the command. This is necessary because a turn neck command can be executed in the same cycle as a kick, dash, turn , move or catch command. \param o object to which the agent wants to turn his neck \param soc SoccerCommand that is performed in this cycle. \return SoccerCommand that turns the neck of the agent to this object */SoccerCommand BasicPlayer::turnNeckToObject( ObjectT o, SoccerCommand soc ){ return turnNeckToPoint( WM->predictPosAfterNrCycles(o, 1), soc );}/*! This skill enables an agent to move to a global position 'pos' on the field which is supplied to it as an argument. Since the agent can only move forwards or backwards into the direction of his body, the crucial decision in the execution of this skill is whether he should perform a turn or a dash. Turning has the advantage that in the next cycle the agent will be orientated correctly towards the point he wants to reach. However, it has the disadvantage that performing the turn will cost a cycle and will reduce the agent's velocity since no acceleration vector is added in that cycle. Apart from the target position 'pos', this skill receives several additional arguments for determining whether a turn or dash should be performed in the current situation. If the target point is in front of the agent then a dash is performed when the relative angle to this point is smaller than a given angle 'angWhenToTurn'. However, if the target point is behind the agent then a dash is only performed if the distance to point is less than a given value 'dDistBack' and if the angle relative to the back direction of the agent is smaller than 'angWhenToTurn'. In all other cases a turn is performed. Note that in the case of the goalkeeper it is sometimes desirable that he moves backwards towards his goal in order to keep sight of the rest of the field. To this end an additional boolean argument 'bMoveBack' is supplied to this skill that indicates whether the agent should always move backwards to the target point. If this value equals true then the agent will turn his back towards the target point if the angle relative to his back direction is larger than 'angToTurn'. In all other cases he will perform a (backward) dash towards 'posTo' regardless of whether the distance to this point is larger than 'dDistBack'. \param posTo global target position to which the agent wants to move \param angWhenToTurn angle determining when turn command is returned \param dDistBack when posTo lies closer than this value to the back of the agent (and within angWhenToTurn) a backward dash is returned \param bMoveBack boolean determing whether to move backwards to 'posTo' \return SoccerCommand that determines next action to move to 'posTo' */SoccerCommand BasicPlayer::moveToPos( VecPosition posTo, AngDeg angWhenToTurn, double dDistBack, bool bMoveBack ){ VecPosition posPred = WM->predictAgentPos( 1, 0 ); AngDeg angBody = WM->getAgentGlobalBodyAngle(); VecPosition posAgent = WM->getAgentGlobalPosition(); AngDeg angTo = ( posTo - posPred ).getDirection(); angTo = VecPosition::normalizeAngle( angTo - angBody ); AngDeg angBackTo = VecPosition::normalizeAngle( angTo + 180 ); double dDist = posAgent.getDistanceTo( posTo ); if( bMoveBack ) { if( fabs( angBackTo ) < angWhenToTurn ) return dashToPoint( posTo ); else return turnBackToPoint( posTo ); } else if( fabs( angTo ) < angWhenToTurn || (fabs( angBackTo ) < angWhenToTurn && dDist < dDistBack ) ) return dashToPoint( posTo ); else return turnBodyToPoint( posTo );}/*! This skill enables an agent to intercept a ball which is close to him. The objective is to move in such a way that the ball will come within the kickable distance from the agent in one or two cycles. To this end the prediction methods from the world model are used to predict the ball position in the next cycle and two cycles into the future. It is then determined whether it is possible to move the agent within kickable distance from one of these positions using all logical combinations of turn and dash commands. If it is not possible to intercept the ball within two cycles then this skill returns an illegal command to indicate that it cannot be performed. First it is determined whether the agent can intercept the ball in one cycle. To this end the position of the ball in the next cycle is predicted and a calculation is performed to decide whether a single dash can move the agent within the kickable distance from this position. In order to be able to kick the ball efficiently after intercepting it, it is important that the agent moves to a good position relative to the ball (i.e. the ball must be in front of him). At the same time the agent must make sure that he does not collide with the ball when trying to intercept it. Let l be a line that runs forwards and backwards from the predicted position of the agent in the next cycle into the direction of his body. This line thus denotes the possible movement direction of the agent. Note that we have to use the agent's predicted position in the next cycle since his current velocity must be taken into account. In addition, let c be a circle which is centered on the predicted
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -