std::string toString() const { std::string res; for (int i=0;i<4;++i) { res+=anyToString(unsigned(((unsigned char *)(&(addr.sin_addr)))[i])); res+=(i!=3) ? "." : ":"; } res+=anyToString(unsigned(ntohs(addr.sin_port))); return res; }
Team * Server::getWeakestTeam() { unsigned maxTeams=4; DOPE_ASSERT(maxTeams>=4); unsigned numTeams=m_game.numTeams(); unsigned maxPlayers=4; const std::vector<Team> &teams(m_game.getTeams()); bool createTeam=false; // try to fill the first two teams first if (numTeams<2) createTeam=true; else { // hmm std::min did not work unsigned p0=teams[0].playerIDs.size(); unsigned p1=teams[1].playerIDs.size(); unsigned minp=(p0<=p1) ? p0 : p1; if (minp==maxPlayers) // team 0 and 1 are full - if team 2 does not exist create it if it is full create team 3 (if possible) if ((numTeams<3)||((numTeams==3)&&(teams[2].playerIDs.size()==maxPlayers))) createTeam=true; } if (createTeam) { // create team std::string tname("Team"); tname+=anyToString(numTeams+1); return m_game.addTeam(tname,numTeams); } // find team with fewest players unsigned minp=~0U; unsigned i=0; for (;i<numTeams;++i) { // std::min does not work minp=std::min(teams[i].playerIDs.size(),minp); unsigned tp=teams[i].playerIDs.size(); minp=(tp<minp) ? tp : minp; } if (minp>=maxPlayers) return NULL; for (i=0;i<numTeams;++i) if (teams[i].playerIDs.size()==minp) break; if (i>=numTeams) return NULL; return m_game.getTeam(i); }
//Show the Id (x y coordinates) of this Vertex in a string std::string getId() const { return anyToString(x) + "-" + anyToString(y); }