14.18 DangerClose
This was a function first utilised by Public School Heroes in the Pairs 2v2 tournament in order to identify situation where they were at risk of conceding possession. Firstly we required the position of the closest opponent to the ball. In a similar fashion as other functions we utilise vector<pair<double,int > > OppDistToBall
to check the realation of the opponents positions to the ball. This vector is generated using GenerateOppToTargetDistanceVector
. The logic dictates if the closest opponent player is not within 1 unit of the ball then we are not in immediate danger. If the case is that the closest opponent is indeed within 1 unit of the ball we check which side of the ball that opponent is. The idea here is that if the opponent is in between our goal and the ball then they are on the wrong side of the ball to be a threat as they would need to walk around the ball in order to target our goal. This is achieved by checking who is closer to our goal, the closest opponent or the ball. If the ball is closer then we return true
meaning we are in danger else we return false
meaning the closest opponent is on the wrong side of the ball.
bool NaoBehavior::DangerClose(vector<pair<double,int > > OppDistToBall){
double minOppDis = OppDistToBall[0].first;
int id = OppDistToBall[0].second;
id = id + WO_OPPONENT1;
if(minOppDis<1){
WorldObject* closestopponent = worldModel->getWorldObject(id);
VecPosition closestopponentpos = closestopponent->pos;
double distogoal1 = closestopponentpos.getDistanceTo(VecPosition(-HALF_FIELD_X, 0, 0));
double distogoal2 = ball.getDistanceTo(VecPosition(-HALF_FIELD_X, 0, 0));
if(distogoal1>distogoal2){ //opponent on the right side of the ball to be a threat
return true;
}
else{
return false;
}
}
else{
return false;
}
}
This, in the same fashion as in many of the other functions, is generated from the initial for
which loops over all opponent WorldObject
’s. This was the older implementation which utilised pointers to achieve the same goal.
bool NaoBehavior::DangerClose(double* _opponentDistances){
double minOppDis = MAXFLOAT;
int id = -1;
for(int z=0;z<NUM_AGENTS;++z){
if(_opponentDistances[z]< minOppDis){
minOppDis = _opponentDistances[z];
id = z;
}
}
id = id + WO_OPPONENT1;
if(minOppDis<1){
WorldObject* closestopponent = worldModel->getWorldObject(id);
VecPosition closestopponentpos = closestopponent->pos;
double distogoal1 = closestopponentpos.getDistanceTo(VecPosition(-HALF_FIELD_X, 0, 0));
double distogoal2 = ball.getDistanceTo(VecPosition(-HALF_FIELD_X, 0, 0));
if(distogoal1>distogoal2){ //opponent on the right side of the ball to be a threat
return true;
}
else{
return false;
}
}
else{
return false;
}
}