14.9 isClosestTeam
This method determines whether or not among your teammates are you the closest agent to the ball.
This first approach used the vector<pair<double,int > > TeamDistToBall
obtained from using GenerateTeamToTargetDistanceVector
, since that vector is sorted we merely need to check if the second
component of the pair<double,int >
at the first index ie 0
is equal to _playerNumber
. If it is then that means the agent with _playerNumber
is closest to the ball on your team.
bool NaoBehavior::isClosestTeam(int _playerNumber, vector<pair<double,int > > TeamDistToBall){
if(_playerNumber == TeamDistToBall[0].second){
return true;
}
return false;
}
The second approach requires iterating through an array which stores all the distances of our teammates to the ball.
bool NaoBehavior::isClosestTeam(int _playerNumber, double* _teamMateDistances){
//return T/F if is the closest teammate to the ball
double minTeamDis = MAXFLOAT;
int id = -1;
for(int z=0;z<NUM_AGENTS;z++){
if((_teamMateDistances[z]) < minTeamDis){
minTeamDis = _teamMateDistances[z];
id = z+1;
}
}
if(_playerNumber == id){
return true;
}
return false;
}