#include #include #include #include std::string slurp(std::ifstream& in) { std::ostringstream sstr; sstr << in.rdbuf(); return sstr.str(); } struct ScoreData{ int difficulty=0; std::string song; int totalEX=0; int ex1=0,ex2=0,ex3=0; std::string str()const{ return "["+std::to_string(difficulty)+"] "+song+": "+std::to_string(totalEX)+" total, "+" EX1: "+std::to_string(ex1)+" EX2: "+std::to_string(ex2)+" EX3: "+std::to_string(ex3); } friend std::ostream&operator<<(std::ostream&os,const ScoreData&data){ os<>selectedScore; int totalEX=0; }; std::string GetNext(int&marker,std::string str){ int originalMarker=marker; marker=str.find_first_of(',',originalMarker)+1; return str.substr(originalMarker,marker-1); }; int main(){ std::vectordataA,dataB; std::ifstream file("team.csv"); std::string line; //First two lines are garbage data. std::getline(file,line); std::getline(file,line); for(int i=0;i<12;i++){ std::getline(file,line); int marker=0; dataA.emplace_back(ScoreData{ stoi(GetNext(marker,line)), GetNext(marker,line), stoi(GetNext(marker,line)), stoi(GetNext(marker,line)), stoi(GetNext(marker,line)), stoi(GetNext(marker,line))} ); } //Two more lines of garbage data. std::getline(file,line); std::getline(file,line); for(int i=0;i<12;i++){ std::getline(file,line); int marker=0; dataB.emplace_back(ScoreData{ stoi(GetNext(marker,line)), GetNext(marker,line), stoi(GetNext(marker,line)), stoi(GetNext(marker,line)), stoi(GetNext(marker,line)), stoi(GetNext(marker,line))} ); } std::cout<<"File Contents:"<bestSelections; while(true){ int Aselections=6,Bselections=6; Selection selection; int totalEX=0; int hash=0; std::vectorrandomChoice={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; for(int iSel=0;iSel<4;iSel++){ int arrInd=rand()%randomChoice.size(); int randSongIndex=randomChoice[arrInd]; randomChoice.erase(randomChoice.begin()+arrInd); ScoreData*dataRef; if(randSongIndex<12){ Aselections--; dataRef=&dataA[randSongIndex]; }else{ Bselections--; dataRef=&dataB[randSongIndex-12]; } selection.selectedScore.push_back({0,randSongIndex}); selection.totalEX+=dataRef->ex1; totalEX+=dataRef->ex1; } for(int iSel=0;iSel<4;iSel++){ int arrInd=rand()%randomChoice.size(); int randSongIndex=randomChoice[arrInd]; while(Aselections==0&&randSongIndex<12||Bselections==0&&randSongIndex>=12){ arrInd=rand()%randomChoice.size(); randSongIndex=randomChoice[arrInd]; } randomChoice.erase(randomChoice.begin()+arrInd); ScoreData*dataRef; if(randSongIndex<12){ Aselections--; dataRef=&dataA[randSongIndex]; }else{ Bselections--; dataRef=&dataB[randSongIndex-12]; } selection.selectedScore.push_back({1,randSongIndex}); selection.totalEX+=dataRef->ex2; totalEX+=dataRef->ex2; } for(int iSel=0;iSel<4;iSel++){ int arrInd=rand()%randomChoice.size(); int randSongIndex=randomChoice[arrInd]; while(Aselections==0&&randSongIndex<12||Bselections==0&&randSongIndex>=12){ arrInd=rand()%randomChoice.size(); randSongIndex=randomChoice[arrInd]; } randomChoice.erase(randomChoice.begin()+arrInd); ScoreData*dataRef; if(randSongIndex<12){ Aselections--; dataRef=&dataA[randSongIndex]; }else{ Bselections--; dataRef=&dataB[randSongIndex-12]; } selection.selectedScore.push_back({2,randSongIndex}); selection.totalEX+=dataRef->ex3; totalEX+=dataRef->ex3; } if(bestSelections.size()>0){ int bestEX=bestSelections.back().totalEX; if(totalEX>bestEX){ std::cout<<"New best EX combination found: "+std::to_string(totalEX)+". Selections are:"<&song:selection.selectedScore){ std::cout<<"P"<