You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
5.2 KiB
156 lines
5.2 KiB
#include <iostream>
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include <vector>
|
|
|
|
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<<data.str();
|
|
return os;
|
|
}
|
|
};
|
|
|
|
struct Selection{
|
|
std::vector<std::pair<int,int>>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::vector<ScoreData>dataA,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:"<<std::endl<<std::endl;
|
|
for(auto&list:{dataA,dataB}){
|
|
for(auto&dat:list){
|
|
std::cout<<dat<<std::endl;
|
|
}
|
|
}
|
|
std::cout<<"==================="<<std::endl;
|
|
std::vector<Selection>bestSelections;
|
|
while(true){
|
|
int Aselections=6,Bselections=6;
|
|
Selection selection;
|
|
int totalEX=0;
|
|
int hash=0;
|
|
std::vector<int>randomChoice={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:"<<std::endl<<"\t";
|
|
for(std::pair<int,int>&song:selection.selectedScore){
|
|
std::cout<<"P"<<song.first<<"|"<<song.second<<",";
|
|
}
|
|
std::cout<<std::endl;
|
|
bestSelections.push_back(selection);
|
|
}
|
|
}else{
|
|
bestSelections.push_back(selection);
|
|
}
|
|
}
|
|
std::cout<<"Done"<<std::endl;
|
|
} |