#include #include #include #include #include #include #include #include #include #include #include "common.h" //for NPLAYERS using namespace std; const int NMATCHES=10,TIMEOUT=30000; const char *ignoredfiles[]={"caiaio","caiaio.exe","manager","manager.exe","referee","referee.exe","competition.sh","playerlogs","refereelogs","javascript"}; const int nignoredfiles=sizeof(ignoredfiles)/sizeof(ignoredfiles[0]); vector findplayers(void){ vector fnames; DIR *dir; struct dirent *ent; int i; if((dir=opendir("."))==NULL){ perror("opendir"); exit(1); } while((ent=readdir(dir))!=NULL){ for(i=0;id_name)==0)break; } if(id_name); } closedir(dir); return fnames; } vector parseplayers(const char *arg){ vector fnames; const char *found; int idx,cursor=0; while(true){ found=strchr(arg+cursor,','); if(found==NULL){ if(arg[cursor]!='\0')fnames.push_back(arg+cursor); break; } idx=found-arg; fnames.push_back(string(arg+cursor,idx-cursor)); cursor=idx+1; } return fnames; } template class Combinations{ vector v; int N; public: template class Combination_it{ const vector v; const unsigned int vsz; int N; //-1 means end iterator vector indices; public: Combination_it(void):vsz(0),N(-1){} Combination_it(vector &_v,int _N):v(_v),vsz(v.size()),N(_N){ indices.resize(N); for(int i=0;i=0;i--){ if(++indices[i] operator*(void){ //dereference, get value of iterator vector res; if(N<0)throw invalid_argument("Combinations::end iterator dereference"); res.reserve(N); for(int idx : indices)res.push_back(v[idx]); return res; } }; Combinations(vector &_v,int _N):v(_v),N(_N){} Combination_it begin(void){return Combination_it(v,N);} Combination_it end(void){return Combination_it();} }; //returns {scores,statuses} pair,vector> playmatch(const vector &fnames,int matchidx){ const int np=fnames.size(); int i,j; cout<<"I number_players "< playeridcs; playeridcs.resize(nfn); iota(playeridcs.begin(),playeridcs.end(),0); int i,j; for(const vector indices : Combinations(playeridcs,NPLAYERS)){ vector players; players.reserve(NPLAYERS); for(i=0;i,vector> res=playmatch(players,i+1); for(j=0;j> ranking; ranking.reserve(nfn); for(i=0;i &a,const pair &b) ->bool{return a.second>b.second;}); for(i=0;i