/** pickIndex returns best location to move to Sorts vector of possible destinations and picks highest ranking one @param possibleDestinations :vector of possible destinations @returns index of first destination in sorted vector (the best) @exception none */ int AgentMoveClosest::pickIndex(std::vector<Location*> possibleDestinations) { int best=0; for (int i=0; i<possibleDestinations.size(); ++i) { if (myCompare(possibleDestinations[i], possibleDestinations[best])>0) { best=i; } else if (myCompare(possibleDestinations[i], possibleDestinations[best])==0) { if (sim->getRnd(0,10)>5) best=i;//if equal pick one by coin flip } } //std::sort(possibleDestinations.begin(),possibleDestinations.end(),myCompare); return best; }
/** pickIndex returns best location to move to Sorts vector of possible destinations and picks highest ranking one @param possibleDestinations :vector of possible destinations @returns index of first destination in sorted vector (the best) @exception none */ int AgentMove::pickIndex(std::vector<Location*> possibleDestinations) { int best=0; for (int i=0; i<possibleDestinations.size(); ++i) { if (myCompare(possibleDestinations[i], possibleDestinations[best])) { best=i; } } //std::sort(possibleDestinations.begin(),possibleDestinations.end(),myCompare); return best; }
int isInEnvpList(char *en, char **envp) { char **env; int index = 0; for(env=envp; *env; env++){ if(myCompare(en, *env)){ return index; } index++; } return -1; }