14.8 isPossesion
This function determines if our team has a player which closer to the ball than any other of the opponents. Follows the same logic as isClosestPlayertoBall
but is only concerned with knowing a member of our team is closer than any opponent.
This implementation is more efficient and makes use of the vector<pair<double,int > >
vectors which store the distances to the ball for both our team and the opponent.
bool NaoBehavior::isPossesion(vector<pair<double,int > > TeamDistToBall, vector<pair<double,int > > OppDistToBall){
double minOppDis = OppDistToBall[0].first;
double minTeamDis = TeamDistToBall[0].first;
if(minOppDis < (minTeamDis*0.8)){ // this is important
return false;
}
return true;
}
This implementation was the less efficient approach of using pointers.
bool NaoBehavior::isPossesion(double* _opponentDistances, double* _teamMateDistances){
double minOppDis = MAXFLOAT;
for(int z =0; z<NUM_AGENTS; z++){
if(_opponentDistances[z]< minOppDis){
minOppDis = _opponentDistances[z];
}
}
double minTeamDis = MAXFLOAT;
for(int z=0;z<NUM_AGENTS;z++){
if((_teamMateDistances[z]) < minTeamDis){
minTeamDis = _teamMateDistances[z];
}
}
if(minOppDis < minTeamDis){
return false;
}
return true;
}