本文整理汇总了C++中Pair::getY方法的典型用法代码示例。如果您正苦于以下问题:C++ Pair::getY方法的具体用法?C++ Pair::getY怎么用?C++ Pair::getY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pair
的用法示例。
在下文中一共展示了Pair::getY方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: laneHalfWidth
// Find the width of a clear lane between the two locations passed as pairs.
// Returns 0.0 if the lane is blocked by any other robot.
float laneHalfWidth (
Pair passerLoc, // Position of the passing robot.
Pair passDestination, // location of the pass destination
const VisionData &field, // where everyone else is now
const SystemParameters &rp,// contains necessary game parameters
bool checkOurRobots) //to see if we check for our robots or not...
{
float minPassBuffer = 10000.0f; //Distance from pass line to nearest enemy robot
float tempPassBuffer; //Used when comparing buffer from one robot to min buffer
Pair closestPoint; //Point on pass line closest to robot
bool onSegment; //true if closestPoint is on pass line segment
Pair originalDest(passDestination.getX(),passDestination.getY());
//extend the pass destination point so an enemy a little behind will be considered
float lineLength = dist(passerLoc,passDestination);
passDestination.setX(passDestination.getX() + 2*rp.general.PLAYER_RADIUS*( (passDestination.getX() - passerLoc.getX()) / lineLength));
passDestination.setY(passDestination.getY() + 2*rp.general.PLAYER_RADIUS*( (passDestination.getY() - passerLoc.getY()) / lineLength));
//Check to make sure no enemy robots are in the way
for(RobotIndex i=ROBOT0; i<NUM_ROBOTS; i++) {
//If enemy robot is found, check to see if it is in the way
if(theirRobotFound(i, field, rp)) {
tempPassBuffer = distFromPointToSegment(passerLoc, passDestination, getTheirRobotLocation(i, field, rp), &closestPoint, onSegment)-rp.general.OPPONENT_RADIUS;
//If enemy is on segment, return 0. Pass is occluded
if(onSegment && tempPassBuffer <0.0f ) return 0.0f;
//Replace the min pass buffer if smaller buffer is found.
if (tempPassBuffer < minPassBuffer && onSegment)
minPassBuffer = tempPassBuffer;
}
}
//CODE TO CHECK OUR ROBOTS ALSO. REMEMBER TO IGNORE PASSER & RECEIVER
if(checkOurRobots) {
//Check to make sure no enemy robots are in the way
for(RobotIndex i=ROBOT0; i<NUM_ROBOTS; i++) {
//If our robot is found, and he is not the passer or receiver => check to see if it is in the way
if(robotFound(i, field, rp)&&
(dist(i,passerLoc,field,rp)>rp.general.PLAYER_RADIUS)&&
(dist(i,originalDest,field,rp)>rp.general.PLAYER_RADIUS))
{
tempPassBuffer = distFromPointToSegment(passerLoc, passDestination, getLocation(i, field, rp), &closestPoint, onSegment)- rp.general.PLAYER_RADIUS;
//If robot is on segment, return 0. Pass is occluded
if(onSegment && tempPassBuffer <0.0f) return 0.0f;
//Replace the min pass buffer if smaller buffer is found.
if (tempPassBuffer < minPassBuffer && onSegment)
minPassBuffer = tempPassBuffer;
}
}
}
//Buffer = distance from pass line to edge (not center) of nearest enemy.
float buf = minPassBuffer;
if(buf <= 0.0f) return 0.001f; //to avoid divide-by-zero errors, and so dist>0
else return buf;
}
示例2: intersectFastMovingBall
//===============================================================
//===============================================================
//===============================================================
//===============================================================
void intersectFastMovingBall(const VisionData& field,
const SystemParameters& params,
float xValueOfDefendingLine,
Destination* command)
{
Line defenderLine, ballVelocityVector;
//-------------------------------
defenderLine.setAposX( xValueOfDefendingLine );
defenderLine.setBposX( xValueOfDefendingLine );
defenderLine.setAposY( -200.0f);
defenderLine.setAposY( 200.0f);
//-------------------------------
ballVelocityVector.setA( getRobocupBall(field).getPos() );
ballVelocityVector.setBposX(
getRobocupBall(field).getXPos() +
(5.0f*getRobocupBall(field).getXVel())
);
ballVelocityVector.setBposY(
getRobocupBall(field).getYPos() +
(5.0f*getRobocupBall(field).getYVel())
);
Pair intersection;
//find the intersection point for where we can best intercept the ball along our line
findLineIntersection(defenderLine,
ballVelocityVector,
&intersection);
//if we cannot find an intersection, just match the ball's position
if(
(intersection.getX() == NEVER_INTERSECT) ||
(intersection.getY() == NEVER_INTERSECT)
)
intersection.setY( getRobocupBall(field).getYPos() );
//always set our x to be the x line we sent in.
intersection.setX( xValueOfDefendingLine );
//---------------------------------------------
//If the interception point is off the field, or the ball is moving slowly,
//just follow the Y position of the ball
if( offField(params, intersection) )
{
if(intersection.getY() > (params.field.LEFT_SIDE_LINE - params.general.PLAYER_RADIUS))
intersection.setY( params.field.LEFT_SIDE_LINE - params.general.PLAYER_RADIUS );
if(intersection.getY() < (params.field.RIGHT_SIDE_LINE + params.general.PLAYER_RADIUS))
intersection.setY( params.field.RIGHT_SIDE_LINE + params.general.PLAYER_RADIUS );
}
//actually set the desination for good =-)
command->setPos( intersection );
//finally, set the rotation to look straight at the ball
command->setRotation( angleToBall( command->getPos(), field) );
}
示例3: singleAssistOffense
//----------------------------------------------------------------------------
void Defender::singleAssistOffense(RobotIndex ID,
BasePlay* play,
const VisionData& field,
RobocupStrategyData* sd)
{
Pair ballPos = getBallLocation(field);
//run tight defense skill
if(
(ballPos.getX() < (sd->getSystemParams().field.DEFENSE_ZONE_LINE - sd->getSystemParams().general.PLAY_TRANSITION_HISTORISIS)) &&
((ballPos.getY() > (sd->getSystemParams().field.LEFT_MIDDLE_SECTOR + sd->getSystemParams().general.PLAY_TRANSITION_HISTORISIS)) ||
(ballPos.getY() < (sd->getSystemParams().field.RIGHT_MIDDLE_SECTOR - sd->getSystemParams().general.PLAY_TRANSITION_HISTORISIS)))
)
tightDefense(ID, play, field, sd);
else
{
//-------------------
//Display message
//-------------------
sd->setMessage(ID, "DEFENDER Single Assist Offense");
//------------------- //get a handle on skillset for this robot
//-------------------
SkillSet* skills = sd->getStrategyModule().getSkillSet(ID);
//-------------------
//get a handle on loose defense defender skill
//-------------------
TandemDefenderSkill* skillHandle =
(TandemDefenderSkill*)skills->getSkill(TandemDefenderSkill::skillNum);
//-------------------
//initialize skill if it is not initialized
//-------------------
if(!skillHandle->isInitialized())
skillHandle->initialize();
//-------------------
//run skill
//-------------------
skillHandle->run();
}
}
示例4: distanceBetween2Points
float distanceBetween2Points(Pair A, Pair B)
{
float distance, x, y, bValueX, bValueY, aValueX, aValueY;
bValueX = B.getX();
bValueY = B.getY();
aValueX = A.getX();
aValueY = A.getY();
x = pow(bValueX - aValueX,2);
y = pow(bValueY - aValueY,2);
if (x == 0 && y == 0)
{
distance = 0;
}
else
{
distance = sqrt(x+y);
}
return distance;
}
示例5: execute
//===============================================================================
//Execute the skill. This is the main part of the skill, where you tell the
//robot how to perform the skill.
void LookForChipKickSkill::execute()
{
///If not active, dont do anything!
if(!initialized) return;
Pair ballLoc = getBallLocation(*currentVisionData);
float currentRot = angleToBall(robotID,*currentVisionData,*sp);
Pair dest((sp->field.HALF_LINE + sp->field.OUR_GOAL_LINE)/2.0f,
(sp->field.SPLIT_LINE + sp->field.LEFT_SIDE_LINE)/2.0f);
//setup on same side of field as ball
if(ballLoc.getY() < sp->field.SPLIT_LINE)
dest.setY(-dest.getY());
command->setPos(dest);
command->setRotation(currentRot);
}
示例6: executePlay
void SimpleKickTest::executePlay(VisionData* vision,
RobocupStrategyData* rsd)
{
Pair result;
result = getBallLocation((*vision));
rsd->getDestination(ID)->setPos(result.getX(),result.getY());
rsd->getDestination(ID)->setKick(KICK_SHOT);
}
示例7: execute
//===============================================================================
//Execute the skill. This is the main part of the skill, where you tell the
//robot how to perform the skill.
void SupplementThreeManSkill::execute()
{
///If not initialized, dont do anything!
if(!initialized)
{
return;
}
//if the ball is close enough to defenisve players, move next to
//the defensive player that is closer to the ball
//since he'll become the aggresor and move upfield.
//this way we can slide in and form the defensive wall immediately.
Pair ballLoc = getBallLocation(*currentVisionData);
Pair robotLoc = getLocation(robotID, *currentVisionData, *sp);
RobotIndex closeDefensiveID = NO_ROBOT;
float closestDistance;
RobotIndex tempID;
float tempDistance;
tempID = strategy->getCurrentRoboCupFrame()->getRobotByPosition(BLOCKER);
if(tempID != NO_ROBOT)
{
closestDistance = getLocation(tempID, *currentVisionData, *sp).distanceTo(ballLoc);
closeDefensiveID = tempID;
}
tempID = strategy->getCurrentRoboCupFrame()->getRobotByPosition(DEFENDER);
if(tempID != NO_ROBOT)
{
tempDistance = getLocation(tempID, *currentVisionData, *sp).distanceTo(ballLoc);
if(tempDistance < closestDistance)
{
closestDistance = tempDistance;
closeDefensiveID = tempID;
}
if(closeDefensiveID == strategy->getCurrentRoboCupFrame()->getRobotByPosition(BLOCKER))
closeDefensiveID = strategy->getCurrentRoboCupFrame()->getRobotByPosition(DEFENDER);
}
tempID = strategy->getCurrentRoboCupFrame()->getRobotByPosition(SPECIAL_OP_DEFENDER);
if(tempID != NO_ROBOT)
{
tempDistance = getLocation(tempID, *currentVisionData, *sp).distanceTo(ballLoc);
if(tempDistance < closestDistance)
{
closestDistance = tempDistance;
closeDefensiveID = tempID;
}
if(closeDefensiveID == strategy->getCurrentRoboCupFrame()->getRobotByPosition(BLOCKER))
closeDefensiveID = strategy->getCurrentRoboCupFrame()->getRobotByPosition(SPECIAL_OP_DEFENDER);
}
//if closest defensive player
//a.) exists
//b.) within tolerance, then go to side of him
if(closestDistance < 3.0f*sp->general.PLAYER_RADIUS)
{
Pair defensivePlayer = getLocation(closeDefensiveID, *currentVisionData, *sp);
if(defensivePlayer.getY() > sp->field.SPLIT_LINE)
{
command->setYPos(defensivePlayer.getY() + sp->general.PLAYER_RADIUS + 0.02f);
}
else
{
command->setYPos(defensivePlayer.getY() - sp->general.PLAYER_RADIUS - 0.02f);
}
command->setXPos(defensivePlayer.getX());
command->setRotation(angleBetween(robotLoc, ballLoc));
}
//else acquire the ball
else
{
Skill* skillHandle = skillSet->getSkill(AcquirePossessionSkill::skillNum);
if(!skillHandle->isInitialized())
skillHandle->initialize();
skillHandle->run();
}
}
示例8: executePlay
void PassingChallengePlay::executePlay(VisionData* vision, RobocupStrategyData* rsd)
{
RobotIndex r0=ROBOT0;
RobotIndex r1=ROBOT1;
Pair ballLoc=getBallLocation(*vision);
///----
for(RobotIndex robotID = r0; robotID < ROBOT2; robotID++){
Pair robotLoc=getLocation(robotID,*vision,rsd->getSystemParams());
Pair otherPos;
int side;
if(robotID == r0){
otherPos=getLocation(r1,*vision,rsd->getSystemParams());
side=side0;
}else{
otherPos=getLocation(r0,*vision,rsd->getSystemParams());
side=side1;
}
if((ballLoc.getX() > rsd->getSystemParams().field.HALF_LINE &&
robotID==r0) ||
(ballLoc.getX() < rsd->getSystemParams().field.HALF_LINE &&
robotID==r1))
{
//ball on our side
if(friendlyHasPossession(robotID,rsd->getSystemParams())){
//go kick
if(-robotLoc.getY()*side > (rsd->getSystemParams().field.SPLIT_LINE + .5f)){
//we're there, kick
rsd->getDestination(robotID)->setKick(KICK_PASS);
}else{
//not there yet.
rsd->getDestination(robotID)->setDribble(DRIBBLE_DEFAULT);
rsd->getDestination(robotID)->setVerticalDribble(V_DRIBBLE_DEFAULT);
//head across
float backup=.3f;
if(robotID == r1){
rsd->getDestination(robotID)->setPos(rsd->getSystemParams().field.HALF_LINE - backup,-side*1.0f);
rsd->getDestination(robotID)->setRotation(0.0f);
}else{
rsd->getDestination(robotID)->setPos(rsd->getSystemParams().field.HALF_LINE + backup,-side*1.0f);
rsd->getDestination(robotID)->setRotation(PI);
}
}
}else{
//go grab ball
if(!rsd->getStrategyModule().getSkillSet(robotID)->getSkill(AcquirePossessionSkill::skillNum)->isInitialized()){
rsd->getStrategyModule().getSkillSet(robotID)->getSkill(AcquirePossessionSkill::skillNum)->initialize();
}
rsd->getStrategyModule().getSkillSet(robotID)->getSkill(AcquirePossessionSkill::skillNum)->run();
rsd->getDestination(robotID)->setDribble(DRIBBLE_DEFAULT);
rsd->getDestination(robotID)->setVerticalDribble(V_DRIBBLE_DEFAULT);
rsd->getDestination(robotID)->setKick(NO_KICK);
rsd->getDestination(robotID)->setSpeed(GOALIE_SPEED);
}
}else{
int side;
if(ballLoc.getY() > rsd->getSystemParams().field.SPLIT_LINE){
side=1;
}else{
side=-1;
}
if(robotID == r0){
side0=side;
}else{
side1=side;
}
float backup=.5f;
if(robotID == r1){
rsd->getDestination(robotID)->setPos(rsd->getSystemParams().field.HALF_LINE - backup,otherPos.getY());
rsd->getDestination(robotID)->setRotation(0.0f);
}else{
rsd->getDestination(robotID)->setPos(rsd->getSystemParams().field.HALF_LINE + backup,otherPos.getY());
rsd->getDestination(robotID)->setRotation(PI);
}
}
}
/*
Pair aggressorPos(getLocation(robot1ID,*vision,rsd->getSystemParams()));
Pair creatorPos(getLocation(robot2ID,*vision,rsd->getSystemParams()));
Pair ballLoc(getBallLocation(*vision));
if(ballLoc.getX() > rsd->getSystemParams().field.HALF_LINE)
{
turn = LEFT;
}
else
{
turn = RIGHT;
}
if(state == KICK_RECEIVE && readTimer() > MAX_ELAPSED_TIME)
//.........这里部分代码省略.........