parent
d8bb3d6dd9
commit
c293288908
@ -1,265 +1,312 @@ |
|||||||
#include <iostream> |
#include "pixelGameEngine.h" |
||||||
#include <fstream> |
#include "olcPGEX_QuickGUI.h" |
||||||
#include <sstream> |
|
||||||
#include <vector> |
|
||||||
#include <algorithm> |
|
||||||
#include <set> |
#include <set> |
||||||
|
|
||||||
std::string slurp(std::ifstream& in) { |
using namespace olc; |
||||||
std::ostringstream sstr; |
|
||||||
sstr << in.rdbuf(); |
|
||||||
return sstr.str(); |
|
||||||
} |
|
||||||
|
|
||||||
struct ScoreData{ |
// Override base class with your custom functionality
|
||||||
int difficulty=0; |
class ChampionsLeaguePointSolver : public olc::PixelGameEngine |
||||||
std::string song; |
{ |
||||||
int totalEX=0; |
std::string slurp(std::ifstream& in) { |
||||||
int ex1=0,ex2=0,ex3=0; |
std::ostringstream sstr; |
||||||
std::string str()const{ |
sstr << in.rdbuf(); |
||||||
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); |
return sstr.str(); |
||||||
} |
} |
||||||
friend std::ostream&operator<<(std::ostream&os,const ScoreData&data){ |
|
||||||
os<<data.str(); |
|
||||||
return os; |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
std::string GetNext(int&marker,std::string str){ |
struct ScoreData{ |
||||||
int originalMarker=marker; |
int difficulty=0; |
||||||
marker=str.find_first_of(',',originalMarker)+1; |
std::string song; |
||||||
return str.substr(originalMarker,marker-1); |
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 TestCase{ |
std::string GetNext(int&marker,std::string str){ |
||||||
int p1Amt,p2Amt,p3Amt; |
int originalMarker=marker; |
||||||
}; |
marker=str.find_first_of(',',originalMarker)+1; |
||||||
|
return str.substr(originalMarker,marker-1); |
||||||
|
}; |
||||||
|
|
||||||
struct SongCombinations{ |
struct TestCase{ |
||||||
std::vector<std::pair<int,int>>p1; //Index to song followed by EX of song.
|
int p1Amt,p2Amt,p3Amt; |
||||||
std::vector<std::pair<int,int>>p2; |
}; |
||||||
std::vector<std::pair<int,int>>p3; |
|
||||||
std::set<int>p1Picked; |
|
||||||
std::set<int>p2Picked; |
|
||||||
std::set<int>p3Picked; |
|
||||||
int totalEX=0; |
|
||||||
int remainingA,remainingB,remainingC; |
|
||||||
}; |
|
||||||
|
|
||||||
int main(){ |
struct SongCombinations{ |
||||||
|
std::vector<std::pair<int,int>>p1; //Index to song followed by EX of song.
|
||||||
|
std::vector<std::pair<int,int>>p2; |
||||||
|
std::vector<std::pair<int,int>>p3; |
||||||
|
std::set<int>p1Picked; |
||||||
|
std::set<int>p2Picked; |
||||||
|
std::set<int>p3Picked; |
||||||
|
int totalEX=0; |
||||||
|
int remainingA,remainingB,remainingC; |
||||||
|
}; |
||||||
std::vector<ScoreData>dataA,dataB; |
std::vector<ScoreData>dataA,dataB; |
||||||
std::vector<std::pair<int,int>>player1Score,player2Score,player3Score; |
std::vector<std::pair<int,int>>player1Score,player2Score,player3Score; |
||||||
std::ifstream file("team2"); |
void Evaluate(){ |
||||||
std::string line; |
std::vector<TestCase>cases; |
||||||
//First two lines are garbage data.
|
for(int i=0;i<5;i++){ |
||||||
std::getline(file,line); |
for(int j=0;j<5;j++){ |
||||||
std::getline(file,line); |
for(int k=0;k<5;k++){ |
||||||
for(int i=0;i<12;i++){ |
if(i+j+k==6){ |
||||||
std::getline(file,line); |
cases.push_back(TestCase{i,j,k}); |
||||||
int marker=0; |
} |
||||||
ScoreData dat{ |
|
||||||
stoi(GetNext(marker,line)), |
|
||||||
GetNext(marker,line), |
|
||||||
stoi(GetNext(marker,line)), |
|
||||||
stoi(GetNext(marker,line)), |
|
||||||
stoi(GetNext(marker,line)), |
|
||||||
stoi(GetNext(marker,line))}; |
|
||||||
player1Score.push_back(std::pair<int,int>{dat.ex1,0}); |
|
||||||
player2Score.push_back(std::pair<int,int>{dat.ex2,0}); |
|
||||||
player3Score.push_back(std::pair<int,int>{dat.ex3,0}); |
|
||||||
dataA.push_back(dat); |
|
||||||
} |
|
||||||
//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; |
|
||||||
ScoreData dat{ |
|
||||||
stoi(GetNext(marker,line)), |
|
||||||
GetNext(marker,line), |
|
||||||
stoi(GetNext(marker,line)), |
|
||||||
stoi(GetNext(marker,line)), |
|
||||||
stoi(GetNext(marker,line)), |
|
||||||
stoi(GetNext(marker,line))}; |
|
||||||
player1Score[i].second=dat.ex1; |
|
||||||
player2Score[i].second=dat.ex2; |
|
||||||
player3Score[i].second=dat.ex3; |
|
||||||
dataB.push_back(dat); |
|
||||||
} |
|
||||||
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<TestCase>cases; |
|
||||||
for(int i=0;i<5;i++){ |
|
||||||
for(int j=0;j<5;j++){ |
|
||||||
for(int k=0;k<5;k++){ |
|
||||||
if(i+j+k==6){ |
|
||||||
cases.push_back(TestCase{i,j,k}); |
|
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
|
||||||
|
|
||||||
auto ChooseSong = [](SongCombinations&combinations,std::vector<ScoreData>&dat,int index){ |
auto ChooseSong = [](SongCombinations&combinations,std::vector<ScoreData>&dat,int index){ |
||||||
if(combinations.remainingA>0&&combinations.p1Picked.count(index)==0&&combinations.p2Picked.count(index)==0&&combinations.p3Picked.count(index)==0){ |
if(combinations.remainingA>0&&combinations.p1Picked.count(index)==0&&combinations.p2Picked.count(index)==0&&combinations.p3Picked.count(index)==0){ |
||||||
combinations.remainingA--; |
combinations.remainingA--; |
||||||
combinations.totalEX+=dat[index].ex1; |
combinations.totalEX+=dat[index].ex1; |
||||||
combinations.p1.push_back(std::pair<int,int>{index,dat[index].ex1}); |
combinations.p1.push_back(std::pair<int,int>{index,dat[index].ex1}); |
||||||
combinations.p1Picked.insert(index); |
combinations.p1Picked.insert(index); |
||||||
}else |
}else |
||||||
if(combinations.remainingB>0&&combinations.p1Picked.count(index)==0&&combinations.p2Picked.count(index)==0&&combinations.p3Picked.count(index)==0){ |
if(combinations.remainingB>0&&combinations.p1Picked.count(index)==0&&combinations.p2Picked.count(index)==0&&combinations.p3Picked.count(index)==0){ |
||||||
combinations.remainingB--; |
combinations.remainingB--; |
||||||
combinations.totalEX+=dat[index].ex2; |
combinations.totalEX+=dat[index].ex2; |
||||||
combinations.p2.push_back(std::pair<int,int>{index,dat[index].ex2}); |
combinations.p2.push_back(std::pair<int,int>{index,dat[index].ex2}); |
||||||
combinations.p2Picked.insert(index); |
combinations.p2Picked.insert(index); |
||||||
}else |
}else |
||||||
if(combinations.remainingC>0&&combinations.p1Picked.count(index)==0&&combinations.p2Picked.count(index)==0&&combinations.p3Picked.count(index)==0){ |
if(combinations.remainingC>0&&combinations.p1Picked.count(index)==0&&combinations.p2Picked.count(index)==0&&combinations.p3Picked.count(index)==0){ |
||||||
combinations.remainingC--; |
combinations.remainingC--; |
||||||
combinations.totalEX+=dat[index].ex3; |
combinations.totalEX+=dat[index].ex3; |
||||||
combinations.p3.push_back(std::pair<int,int>{index,dat[index].ex3}); |
combinations.p3.push_back(std::pair<int,int>{index,dat[index].ex3}); |
||||||
combinations.p3Picked.insert(index); |
combinations.p3Picked.insert(index); |
||||||
} |
} |
||||||
}; |
}; |
||||||
|
|
||||||
std::vector<SongCombinations> bestComboA,bestComboB; |
std::vector<SongCombinations> bestComboA,bestComboB; |
||||||
int caseInd=0; |
int caseInd=0; |
||||||
for(TestCase&_case:cases){ |
for(TestCase&_case:cases){ |
||||||
bestComboA.push_back({}); |
bestComboA.push_back({}); |
||||||
bestComboA[caseInd].remainingA=_case.p1Amt; |
bestComboA[caseInd].remainingA=_case.p1Amt; |
||||||
bestComboA[caseInd].remainingB=_case.p2Amt; |
bestComboA[caseInd].remainingB=_case.p2Amt; |
||||||
bestComboA[caseInd].remainingC=_case.p3Amt; |
bestComboA[caseInd].remainingC=_case.p3Amt; |
||||||
SongCombinations testCombo=bestComboA[caseInd]; |
SongCombinations testCombo=bestComboA[caseInd]; |
||||||
for(int i=0;i<12;i++){ |
for(int i=0;i<12;i++){ |
||||||
SongCombinations c1=testCombo; |
SongCombinations c1=testCombo; |
||||||
ChooseSong(c1,dataA,i); |
ChooseSong(c1,dataA,i); |
||||||
for(int j=0;j<12;j++){ |
for(int j=0;j<12;j++){ |
||||||
SongCombinations c2=c1; |
SongCombinations c2=c1; |
||||||
ChooseSong(c2,dataA,j); |
ChooseSong(c2,dataA,j); |
||||||
for(int k=0;k<12;k++){ |
for(int k=0;k<12;k++){ |
||||||
SongCombinations c3=c2; |
SongCombinations c3=c2; |
||||||
ChooseSong(c3,dataA,k); |
ChooseSong(c3,dataA,k); |
||||||
for(int l=0;l<12;l++){ |
for(int l=0;l<12;l++){ |
||||||
SongCombinations c4=c3; |
SongCombinations c4=c3; |
||||||
ChooseSong(c4,dataA,l); |
ChooseSong(c4,dataA,l); |
||||||
for(int m=0;m<12;m++){ |
for(int m=0;m<12;m++){ |
||||||
SongCombinations c5=c4; |
SongCombinations c5=c4; |
||||||
ChooseSong(c5,dataA,m); |
ChooseSong(c5,dataA,m); |
||||||
for(int n=0;n<12;n++){ |
for(int n=0;n<12;n++){ |
||||||
SongCombinations c6=c5; |
SongCombinations c6=c5; |
||||||
ChooseSong(c6,dataA,n); |
ChooseSong(c6,dataA,n); |
||||||
if(bestComboA[caseInd].totalEX<c6.totalEX){ |
if(bestComboA[caseInd].totalEX<c6.totalEX){ |
||||||
bestComboA[caseInd]=c6; |
bestComboA[caseInd]=c6; |
||||||
bestComboA[caseInd].totalEX=c6.totalEX; |
bestComboA[caseInd].totalEX=c6.totalEX; |
||||||
std::cout<<"New Best Song Combinations found for Case ("<<_case.p1Amt<<","<<_case.p2Amt<<","<<_case.p3Amt<<") - Total EX: "<<bestComboA[caseInd].totalEX<<":"<<std::endl; |
std::cout<<"New Best Song Combinations found for Case ("<<_case.p1Amt<<","<<_case.p2Amt<<","<<_case.p3Amt<<") - Total EX: "<<bestComboA[caseInd].totalEX<<":"<<std::endl; |
||||||
std::cout<<"\t"; |
std::cout<<"\t"; |
||||||
for(std::pair<int,int>&p1:bestComboA[caseInd].p1){ |
for(std::pair<int,int>&p1:bestComboA[caseInd].p1){ |
||||||
std::cout<<"P1["<<p1.first<<"]:"<<p1.second<<" "; |
std::cout<<"P1["<<p1.first<<"]:"<<p1.second<<" "; |
||||||
} |
} |
||||||
for(std::pair<int,int>&p2:bestComboA[caseInd].p2){ |
for(std::pair<int,int>&p2:bestComboA[caseInd].p2){ |
||||||
std::cout<<"P2["<<p2.first<<"]:"<<p2.second<<" "; |
std::cout<<"P2["<<p2.first<<"]:"<<p2.second<<" "; |
||||||
} |
} |
||||||
for(std::pair<int,int>&p3:bestComboA[caseInd].p3){ |
for(std::pair<int,int>&p3:bestComboA[caseInd].p3){ |
||||||
std::cout<<"P3["<<p3.first<<"]:"<<p3.second<<" "; |
std::cout<<"P3["<<p3.first<<"]:"<<p3.second<<" "; |
||||||
|
} |
||||||
|
std::cout<<std::endl; |
||||||
} |
} |
||||||
std::cout<<std::endl; |
|
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
caseInd++; |
||||||
} |
} |
||||||
caseInd++; |
|
||||||
} |
|
||||||
|
|
||||||
caseInd=0; |
caseInd=0; |
||||||
for(TestCase&_case:cases){ |
for(TestCase&_case:cases){ |
||||||
bestComboB.push_back({}); |
bestComboB.push_back({}); |
||||||
bestComboB[caseInd].remainingA=_case.p1Amt; |
bestComboB[caseInd].remainingA=_case.p1Amt; |
||||||
bestComboB[caseInd].remainingB=_case.p2Amt; |
bestComboB[caseInd].remainingB=_case.p2Amt; |
||||||
bestComboB[caseInd].remainingC=_case.p3Amt; |
bestComboB[caseInd].remainingC=_case.p3Amt; |
||||||
SongCombinations testCombo=bestComboB[caseInd]; |
SongCombinations testCombo=bestComboB[caseInd]; |
||||||
for(int i=0;i<12;i++){ |
for(int i=0;i<12;i++){ |
||||||
SongCombinations c1=testCombo; |
SongCombinations c1=testCombo; |
||||||
ChooseSong(c1,dataB,i); |
ChooseSong(c1,dataB,i); |
||||||
for(int j=0;j<12;j++){ |
for(int j=0;j<12;j++){ |
||||||
SongCombinations c2=c1; |
SongCombinations c2=c1; |
||||||
ChooseSong(c2,dataB,j); |
ChooseSong(c2,dataB,j); |
||||||
for(int k=0;k<12;k++){ |
for(int k=0;k<12;k++){ |
||||||
SongCombinations c3=c2; |
SongCombinations c3=c2; |
||||||
ChooseSong(c3,dataB,k); |
ChooseSong(c3,dataB,k); |
||||||
for(int l=0;l<12;l++){ |
for(int l=0;l<12;l++){ |
||||||
SongCombinations c4=c3; |
SongCombinations c4=c3; |
||||||
ChooseSong(c4,dataB,l); |
ChooseSong(c4,dataB,l); |
||||||
for(int m=0;m<12;m++){ |
for(int m=0;m<12;m++){ |
||||||
SongCombinations c5=c4; |
SongCombinations c5=c4; |
||||||
ChooseSong(c5,dataB,m); |
ChooseSong(c5,dataB,m); |
||||||
for(int n=0;n<12;n++){ |
for(int n=0;n<12;n++){ |
||||||
SongCombinations c6=c5; |
SongCombinations c6=c5; |
||||||
ChooseSong(c6,dataB,n); |
ChooseSong(c6,dataB,n); |
||||||
if(bestComboB[caseInd].totalEX<c6.totalEX){ |
if(bestComboB[caseInd].totalEX<c6.totalEX){ |
||||||
bestComboB[caseInd]=c6; |
bestComboB[caseInd]=c6; |
||||||
bestComboB[caseInd].totalEX=c6.totalEX; |
bestComboB[caseInd].totalEX=c6.totalEX; |
||||||
std::cout<<"New Best Song Combinations found for Case ("<<_case.p1Amt<<","<<_case.p2Amt<<","<<_case.p3Amt<<") - Total EX: "<<bestComboB[caseInd].totalEX<<":"<<std::endl; |
std::cout<<"New Best Song Combinations found for Case ("<<_case.p1Amt<<","<<_case.p2Amt<<","<<_case.p3Amt<<") - Total EX: "<<bestComboB[caseInd].totalEX<<":"<<std::endl; |
||||||
std::cout<<"\t"; |
std::cout<<"\t"; |
||||||
for(std::pair<int,int>&p1:bestComboB[caseInd].p1){ |
for(std::pair<int,int>&p1:bestComboB[caseInd].p1){ |
||||||
std::cout<<"P1["<<p1.first<<"]:"<<p1.second<<" "; |
std::cout<<"P1["<<p1.first<<"]:"<<p1.second<<" "; |
||||||
} |
} |
||||||
for(std::pair<int,int>&p2:bestComboB[caseInd].p2){ |
for(std::pair<int,int>&p2:bestComboB[caseInd].p2){ |
||||||
std::cout<<"P2["<<p2.first<<"]:"<<p2.second<<" "; |
std::cout<<"P2["<<p2.first<<"]:"<<p2.second<<" "; |
||||||
} |
} |
||||||
for(std::pair<int,int>&p3:bestComboB[caseInd].p3){ |
for(std::pair<int,int>&p3:bestComboB[caseInd].p3){ |
||||||
std::cout<<"P3["<<p3.first<<"]:"<<p3.second<<" "; |
std::cout<<"P3["<<p3.first<<"]:"<<p3.second<<" "; |
||||||
|
} |
||||||
|
std::cout<<std::endl; |
||||||
} |
} |
||||||
std::cout<<std::endl; |
|
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
caseInd++; |
||||||
} |
} |
||||||
caseInd++; |
|
||||||
} |
|
||||||
|
|
||||||
int highestEX=0; |
int highestEX=0; |
||||||
SongCombinations picked1,picked2; |
SongCombinations picked1,picked2; |
||||||
for(SongCombinations&A:bestComboA){ |
for(SongCombinations&A:bestComboA){ |
||||||
for(SongCombinations&B:bestComboB){ |
for(SongCombinations&B:bestComboB){ |
||||||
if(A.totalEX+B.totalEX>highestEX&&A.p1Picked.size()+B.p1Picked.size()==4&&A.p2Picked.size()+B.p2Picked.size()==4&&A.p3Picked.size()+B.p3Picked.size()==4){ |
if(A.totalEX+B.totalEX>highestEX&&A.p1Picked.size()+B.p1Picked.size()==4&&A.p2Picked.size()+B.p2Picked.size()==4&&A.p3Picked.size()+B.p3Picked.size()==4){ |
||||||
highestEX=A.totalEX+B.totalEX; |
highestEX=A.totalEX+B.totalEX; |
||||||
picked1=A; |
picked1=A; |
||||||
picked2=B; |
picked2=B; |
||||||
std::cout<<"New Best Song Combinations found for Final Picks - Total EX: "<<highestEX<<":"<<std::endl; |
std::cout<<"New Best Song Combinations found for Final Picks - Total EX: "<<highestEX<<":"<<std::endl; |
||||||
std::cout<<"\t Set A: "; |
std::cout<<"\t Set A: "; |
||||||
for(std::pair<int,int>&p1:picked1.p1){ |
for(std::pair<int,int>&p1:picked1.p1){ |
||||||
std::cout<<"P1["<<p1.first<<"]:"<<p1.second<<" "; |
std::cout<<"P1["<<p1.first<<"]:"<<p1.second<<" "; |
||||||
} |
} |
||||||
for(std::pair<int,int>&p2:picked1.p2){ |
for(std::pair<int,int>&p2:picked1.p2){ |
||||||
std::cout<<"P2["<<p2.first<<"]:"<<p2.second<<" "; |
std::cout<<"P2["<<p2.first<<"]:"<<p2.second<<" "; |
||||||
} |
} |
||||||
for(std::pair<int,int>&p3:picked1.p3){ |
for(std::pair<int,int>&p3:picked1.p3){ |
||||||
std::cout<<"P3["<<p3.first<<"]:"<<p3.second<<" "; |
std::cout<<"P3["<<p3.first<<"]:"<<p3.second<<" "; |
||||||
} |
} |
||||||
std::cout<<std::endl; |
std::cout<<std::endl; |
||||||
std::cout<<"\t Set B: "; |
std::cout<<"\t Set B: "; |
||||||
for(std::pair<int,int>&p1:picked2.p1){ |
for(std::pair<int,int>&p1:picked2.p1){ |
||||||
std::cout<<"P1["<<p1.first<<"]:"<<p1.second<<" "; |
std::cout<<"P1["<<p1.first<<"]:"<<p1.second<<" "; |
||||||
} |
} |
||||||
for(std::pair<int,int>&p2:picked2.p2){ |
for(std::pair<int,int>&p2:picked2.p2){ |
||||||
std::cout<<"P2["<<p2.first<<"]:"<<p2.second<<" "; |
std::cout<<"P2["<<p2.first<<"]:"<<p2.second<<" "; |
||||||
} |
} |
||||||
for(std::pair<int,int>&p3:picked2.p3){ |
for(std::pair<int,int>&p3:picked2.p3){ |
||||||
std::cout<<"P3["<<p3.first<<"]:"<<p3.second<<" "; |
std::cout<<"P3["<<p3.first<<"]:"<<p3.second<<" "; |
||||||
|
} |
||||||
|
std::cout<<std::endl; |
||||||
} |
} |
||||||
std::cout<<std::endl; |
|
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
public: |
||||||
|
struct SongElement{ |
||||||
|
SongElement(QuickGUI::Manager&manager,std::string songName,vf2d pos){ |
||||||
|
label=new QuickGUI::Label(manager,songName,pos,{164,12}); |
||||||
|
p1Score=new QuickGUI::TextBox(manager,"",pos+vf2d{192,0},{36,12}); |
||||||
|
p2Score=new QuickGUI::TextBox(manager,"",pos+vf2d{192+42*1,0},{36,12}); |
||||||
|
p3Score=new QuickGUI::TextBox(manager,"",pos+vf2d{192+42*2,0},{36,12}); |
||||||
|
} |
||||||
|
QuickGUI::Label*label; |
||||||
|
QuickGUI::TextBox*p1Score; |
||||||
|
QuickGUI::TextBox*p2Score; |
||||||
|
QuickGUI::TextBox*p3Score; |
||||||
|
}; |
||||||
|
QuickGUI::Manager gui; |
||||||
|
std::vector<SongElement>songs; |
||||||
|
|
||||||
|
ChampionsLeaguePointSolver() |
||||||
|
{ |
||||||
|
// Name your application
|
||||||
|
sAppName = "Champions League Point Solver"; |
||||||
|
} |
||||||
|
|
||||||
|
public: |
||||||
|
bool OnUserCreate() override |
||||||
|
{ |
||||||
|
std::ifstream file("assets/team2"); |
||||||
|
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; |
||||||
|
ScoreData dat{ |
||||||
|
stoi(GetNext(marker,line)), |
||||||
|
GetNext(marker,line), |
||||||
|
stoi(GetNext(marker,line)), |
||||||
|
stoi(GetNext(marker,line)), |
||||||
|
stoi(GetNext(marker,line)), |
||||||
|
stoi(GetNext(marker,line))}; |
||||||
|
player1Score.push_back(std::pair<int,int>{dat.ex1,0}); |
||||||
|
player2Score.push_back(std::pair<int,int>{dat.ex2,0}); |
||||||
|
player3Score.push_back(std::pair<int,int>{dat.ex3,0}); |
||||||
|
dataA.push_back(dat); |
||||||
|
songs.push_back(SongElement{gui,dat.song.substr(0,dat.song.find(',')),{4.f,2.f+12*i+16}}); |
||||||
|
} |
||||||
|
//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; |
||||||
|
ScoreData dat{ |
||||||
|
stoi(GetNext(marker,line)), |
||||||
|
GetNext(marker,line), |
||||||
|
stoi(GetNext(marker,line)), |
||||||
|
stoi(GetNext(marker,line)), |
||||||
|
stoi(GetNext(marker,line)), |
||||||
|
stoi(GetNext(marker,line))}; |
||||||
|
player1Score[i].second=dat.ex1; |
||||||
|
player2Score[i].second=dat.ex2; |
||||||
|
player3Score[i].second=dat.ex3; |
||||||
|
dataB.push_back(dat); |
||||||
|
songs.push_back(SongElement{gui,dat.song.substr(0,dat.song.find(',')),{4.f,2.f+12*(i+13)+16}}); |
||||||
|
} |
||||||
|
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; |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
bool OnUserUpdate(float fElapsedTime) override |
||||||
|
{ |
||||||
|
Clear(VERY_DARK_CYAN); |
||||||
|
gui.Update(this); |
||||||
|
gui.Draw(this); |
||||||
|
return true; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
int main() |
||||||
|
{ |
||||||
|
ChampionsLeaguePointSolver solver; |
||||||
|
if (solver.Construct(320, 320, 4, 4)) |
||||||
|
solver.Start(); |
||||||
|
return 0; |
||||||
} |
} |
@ -0,0 +1,28 @@ |
|||||||
|
"Scores due by September 24th, 23:59 PST",,,,,,, |
||||||
|
Set A,,Total EX,NICONII,SALSA,YONCETAI,, |
||||||
|
12,Sola,1287,1218,1155,980,,0 |
||||||
|
13,Deadball de homerun,1323,1225,1047,994,,0 |
||||||
|
13,Star Trail,1443,1339,1231,978,,0 |
||||||
|
14,Draw the Savage,1425,1298,1294,1039,,0 |
||||||
|
14,IMANOGUILTS,1719,1586,1336,993,,0 |
||||||
|
15,Astrogazer,1782,1618,0,0,,0 |
||||||
|
15,Kouen,1905,1772,0,0,,0 |
||||||
|
16,The World Ends Now,1917,1730,0,0,,0 |
||||||
|
16,S!ck,2118,1790,1563,0,,0 |
||||||
|
17,Magnetic,2193,1815,0,0,,0 |
||||||
|
17,Unfinished Steam Maiden,2262,1885,0,0,,0 |
||||||
|
18,Nageki no ki,2370,1978,0,0,,0 |
||||||
|
,,,,,,,0 |
||||||
|
Set B,,,,,,,0 |
||||||
|
12,Towards the TOWER,1104,1046,1023,879,,0 |
||||||
|
13,Xenon,1158,1088,1042,913,,0 |
||||||
|
13,DeStRuCtIvE FoRcE,1299,1218,1102,833,,0 |
||||||
|
14,Diamond Night,1359,1258,1169,919,,0 |
||||||
|
14,Nightbird lost wing,1539,1395,1220,674,,0 |
||||||
|
15,Sand Blow,1668,1466,0,0,,0 |
||||||
|
15,SILVER DREAM,1668,1500,1242,0,,0 |
||||||
|
16,Another Phase,1767,1547,0,0,,0 |
||||||
|
16,Blew My Mind,1803,1464,0,0,,0 |
||||||
|
17,Emera,1851,1531,0,0,,0 |
||||||
|
17,JOMANDA,2004,1556,0,0,,0 |
||||||
|
18,PARANOiA Revolution,2097,1582,0,0,,0 |
@ -0,0 +1,75 @@ |
|||||||
|
|
||||||
|
<!doctype html> |
||||||
|
<html lang="en-us"> |
||||||
|
<head> |
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||||
|
<meta charset="utf-8"> |
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
||||||
|
<title>Emscripten-Generated Code</title> |
||||||
|
<style> |
||||||
|
html,body { width: 100%; height: 100%; } |
||||||
|
body { font-family: arial; margin: 0; padding: 0; background: #000; } |
||||||
|
|
||||||
|
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; } |
||||||
|
div.emscripten_border { border: none; } |
||||||
|
|
||||||
|
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */ |
||||||
|
canvas.emscripten { border: 0px none; background-color: black; } |
||||||
|
</style> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas> |
||||||
|
<script type='text/javascript'> |
||||||
|
var Module = { |
||||||
|
preRun: [], |
||||||
|
postRun: [], |
||||||
|
canvas: (function() { |
||||||
|
var canvas = document.getElementById('canvas'); |
||||||
|
|
||||||
|
// As a default initial behavior, pop up an alert when webgl context is lost. To make your |
||||||
|
// application robust, you may want to override this behavior before shipping! |
||||||
|
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2 |
||||||
|
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false); |
||||||
|
|
||||||
|
return canvas; |
||||||
|
})(), |
||||||
|
}; |
||||||
|
</script> |
||||||
|
<script async type="text/javascript" src="ChampionsLeaguePointSolver.js"></script> |
||||||
|
<script type="text/javascript"> |
||||||
|
Module.canvas.addEventListener("resize", (e) => { |
||||||
|
|
||||||
|
var viewWidth = e.detail.width; |
||||||
|
var viewHeight = e.detail.width / Module._olc_WindowAspectRatio; |
||||||
|
|
||||||
|
if(viewHeight > e.detail.height) |
||||||
|
{ |
||||||
|
viewHeight = e.detail.height; |
||||||
|
viewWidth = e.detail.height * Module._olc_WindowAspectRatio; |
||||||
|
} |
||||||
|
|
||||||
|
// update dom attributes |
||||||
|
Module.canvas.setAttribute("width", viewWidth); |
||||||
|
Module.canvas.setAttribute("height", viewHeight); |
||||||
|
|
||||||
|
var top = (e.detail.height - viewHeight) / 2; |
||||||
|
var left = (e.detail.width - viewWidth) / 2; |
||||||
|
|
||||||
|
// update styles |
||||||
|
Module.canvas.style.position = "fixed"; |
||||||
|
Module.canvas.style.top = top.toString() + "px"; |
||||||
|
Module.canvas.style.left = left.toString() + "px"; |
||||||
|
Module.canvas.style.width = ""; |
||||||
|
Module.canvas.style.height = ""; |
||||||
|
|
||||||
|
// trigger PGE update |
||||||
|
Module._olc_PGE_UpdateWindowSize(viewWidth, viewHeight); |
||||||
|
|
||||||
|
// ensure canvas has focus |
||||||
|
Module.canvas.focus(); |
||||||
|
e.preventDefault(); |
||||||
|
}); |
||||||
|
</script> |
||||||
|
|
||||||
|
</body> |
||||||
|
</html> |
File diff suppressed because one or more lines are too long
Binary file not shown.
@ -1,211 +0,0 @@ |
|||||||
|
|
||||||
#include "pixelGameEngine.h" |
|
||||||
|
|
||||||
//THIS IS WRITTEN USING OLC GPE, CHECK OUT onelonecoder.com
|
|
||||||
//Or else
|
|
||||||
class Snake : public olc::PixelGameEngine { |
|
||||||
public: |
|
||||||
Snake() { |
|
||||||
sAppName = "Snake"; |
|
||||||
} |
|
||||||
|
|
||||||
enum direction { STOP, LEFT, RIGHT, DOWN, UP }; |
|
||||||
direction dir; |
|
||||||
//Game variables
|
|
||||||
int score; |
|
||||||
//Snake variables
|
|
||||||
float SnakeXPos, SnakeYPos; |
|
||||||
float tailUpdateTimer=0; |
|
||||||
int tailX[1000], tailY[1000], tailLength = 0; |
|
||||||
float x, y; |
|
||||||
//Target variables
|
|
||||||
int fruit1X, fruit1Y, fruit2X, fruit2Y; |
|
||||||
bool fruit1 = false, fruit2 = false; |
|
||||||
bool GameOver; |
|
||||||
|
|
||||||
void SnakeDead() { |
|
||||||
if (GameOver == true) { |
|
||||||
Clear(olc::BLACK); |
|
||||||
DrawString(ScreenWidth() - ((ScreenWidth() / 2) + (ScreenWidth() / 2.8)), ScreenHeight() / 2 - 5, "Game Over", olc::RED, 1); |
|
||||||
} |
|
||||||
} |
|
||||||
void BorderCollisionCheck() { |
|
||||||
if (SnakeXPos <= 3) { |
|
||||||
GameOver = true; |
|
||||||
SnakeDead(); |
|
||||||
} |
|
||||||
if (SnakeXPos >= ScreenWidth() - 3) { |
|
||||||
GameOver = true; |
|
||||||
SnakeDead(); |
|
||||||
} |
|
||||||
if (SnakeYPos <= 3) { |
|
||||||
GameOver = true; |
|
||||||
SnakeDead(); |
|
||||||
} |
|
||||||
if (SnakeYPos >= ScreenHeight() - 3) { |
|
||||||
GameOver = true; |
|
||||||
SnakeDead(); |
|
||||||
} |
|
||||||
} |
|
||||||
void userInput(float speed) { |
|
||||||
if (GetKey(olc::Key::UP).bPressed && dir != DOWN) { |
|
||||||
dir = UP; |
|
||||||
} |
|
||||||
if (GetKey(olc::Key::DOWN).bPressed && dir != UP) { |
|
||||||
dir = DOWN; |
|
||||||
} |
|
||||||
if (GetKey(olc::Key::LEFT).bPressed && dir != RIGHT) { |
|
||||||
dir = LEFT; |
|
||||||
} |
|
||||||
if (GetKey(olc::Key::RIGHT).bPressed && dir != LEFT) { |
|
||||||
dir = RIGHT; |
|
||||||
} |
|
||||||
|
|
||||||
//Move Snake
|
|
||||||
switch (dir) { |
|
||||||
case LEFT: |
|
||||||
SnakeXPos -= speed; |
|
||||||
break; |
|
||||||
case RIGHT: |
|
||||||
SnakeXPos += speed; |
|
||||||
break; |
|
||||||
case DOWN: |
|
||||||
SnakeYPos += speed; |
|
||||||
break; |
|
||||||
case UP: |
|
||||||
SnakeYPos -= speed; |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
void FruitCoordGen() { |
|
||||||
//Fruit1
|
|
||||||
if (fruit1 == false) { |
|
||||||
fruit1X = rand() & ScreenWidth(); |
|
||||||
fruit1Y = rand() & ScreenHeight(); |
|
||||||
fruit1 = true; |
|
||||||
} |
|
||||||
if (fruit1X <= 2 || fruit1X >= ScreenWidth() - 2) { |
|
||||||
fruit1X = rand() & ScreenWidth(); |
|
||||||
} |
|
||||||
if (fruit1Y <= 2 || fruit1Y >= ScreenHeight() - 2) { |
|
||||||
fruit1Y = rand() & ScreenHeight(); |
|
||||||
} |
|
||||||
//Fruit2
|
|
||||||
//if (fruit2 == false) {
|
|
||||||
//fruit2X = rand() & ScreenWidth();
|
|
||||||
//fruit2Y = rand() & ScreenHeight();
|
|
||||||
//fruit2 = true;
|
|
||||||
//}
|
|
||||||
//if (fruit2X <= 2 || fruit2X >= ScreenWidth() - 2) {
|
|
||||||
//fruit1X = rand() & ScreenWidth();
|
|
||||||
//}
|
|
||||||
//if (fruit2Y <= 2 || fruit2Y >= ScreenHeight() - 2) {
|
|
||||||
//fruit1Y = rand() & ScreenHeight();
|
|
||||||
//}
|
|
||||||
//if (fruit1X == fruit2X) {
|
|
||||||
//fruit1X = rand() & ScreenWidth();
|
|
||||||
//}
|
|
||||||
//if (fruit1Y == fruit2Y) {
|
|
||||||
//fruit1Y = rand() & ScreenWidth();
|
|
||||||
//}
|
|
||||||
} |
|
||||||
|
|
||||||
private: |
|
||||||
|
|
||||||
public: |
|
||||||
bool OnUserUpdate(float fElapsedTime) override { |
|
||||||
|
|
||||||
float speed = 20 * fElapsedTime; |
|
||||||
Clear(olc::BLACK); |
|
||||||
//Draw top border
|
|
||||||
DrawLine(2, 2, ScreenWidth() - 2, 2, olc::WHITE); |
|
||||||
//Draw left border
|
|
||||||
DrawLine(2, 2, 2, ScreenHeight() - 2, olc::WHITE); |
|
||||||
//Draw right border
|
|
||||||
DrawLine(ScreenWidth() - 2, 2, ScreenWidth() - 2, ScreenHeight() - 2, olc::WHITE); |
|
||||||
//Draw bottom border
|
|
||||||
DrawLine(2, ScreenHeight() - 2, ScreenWidth() - 2, ScreenHeight() - 2, olc::WHITE); |
|
||||||
|
|
||||||
olc::vi2d SnakeHead(SnakeXPos, SnakeYPos); |
|
||||||
olc::vi2d SnakeHeadSize(2, 2); |
|
||||||
|
|
||||||
olc::vi2d Fruit(fruit1X, fruit1Y); |
|
||||||
olc::vu2d FruitSize(2, 2); |
|
||||||
|
|
||||||
//Snake and fruit collision
|
|
||||||
if (SnakeHead.x < Fruit.x + FruitSize.x && |
|
||||||
SnakeHead.x + SnakeHeadSize.x > Fruit.x && |
|
||||||
SnakeHead.y < Fruit.y + FruitSize.y && |
|
||||||
SnakeHead.y + SnakeHeadSize.y > Fruit.y) { |
|
||||||
fruit1 = false; |
|
||||||
score++; |
|
||||||
tailLength++; |
|
||||||
} |
|
||||||
|
|
||||||
//Draw fruit
|
|
||||||
DrawRect(fruit1X, fruit1Y, 1, 1, olc::RED); |
|
||||||
|
|
||||||
//Fruit coord gen
|
|
||||||
FruitCoordGen(); |
|
||||||
|
|
||||||
//Border collision
|
|
||||||
BorderCollisionCheck(); |
|
||||||
|
|
||||||
tailUpdateTimer -= fElapsedTime; //Decrement the tail timer by the game elapsed time.
|
|
||||||
if ( tailUpdateTimer <= 0 ) { |
|
||||||
//In order to create a tail following trail, start from the back-most tail and work your way up to the front, setting the previous tail's position to the current tail index's position.
|
|
||||||
for (int i = tailLength - 1; i > 0; i--) { |
|
||||||
tailX[i]=tailX[i-1]; |
|
||||||
tailY[i]=tailY[i-1]; |
|
||||||
} |
|
||||||
//Now set the front-most tail to the current snake head's position.
|
|
||||||
tailX[0]=SnakeXPos; |
|
||||||
tailY[0]=SnakeYPos; |
|
||||||
tailUpdateTimer=0.05; //Every 0.05 seconds we will re-update the tail positions instead of doing it by frame-based timing.
|
|
||||||
} |
|
||||||
|
|
||||||
//Draw Snake tail
|
|
||||||
if (tailLength >= 1) { |
|
||||||
for (int i = 0; i < tailLength; i++) { |
|
||||||
DrawRect(tailX[i], tailY[i], 1, 1, olc::GREEN); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Snake position gets adjusted here.
|
|
||||||
userInput(speed); |
|
||||||
|
|
||||||
//Draw the Snake at its new position.
|
|
||||||
DrawRect(SnakeXPos, SnakeYPos, 1, 1, olc::DARK_GREEN); |
|
||||||
|
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
bool OnUserCreate() override { |
|
||||||
srand(time(NULL)); |
|
||||||
dir = STOP; |
|
||||||
//Snake X coord gen
|
|
||||||
SnakeXPos = rand() & ScreenWidth(); |
|
||||||
if (SnakeXPos <= 3 || SnakeXPos >= ScreenWidth() - 3) { |
|
||||||
SnakeXPos = rand() & ScreenWidth(); |
|
||||||
} |
|
||||||
if (SnakeXPos <= 3 || SnakeXPos >= ScreenHeight() - 3) { |
|
||||||
SnakeXPos = rand() & ScreenHeight(); |
|
||||||
} |
|
||||||
//Snake Y coord gen
|
|
||||||
SnakeYPos = rand() & ScreenWidth(); |
|
||||||
if (SnakeYPos <= 3 || SnakeYPos >= ScreenWidth() - 3) { |
|
||||||
SnakeYPos = rand() & ScreenWidth(); |
|
||||||
} |
|
||||||
if (SnakeYPos <= 3 || SnakeYPos >= ScreenHeight() - 3) { |
|
||||||
SnakeYPos = rand() & ScreenHeight(); |
|
||||||
} |
|
||||||
return true; |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
int main() { |
|
||||||
Snake demo; |
|
||||||
if (demo.Construct(100, 100, 10, 10)) |
|
||||||
demo.Start(); |
|
||||||
return 0; |
|
||||||
} |
|
File diff suppressed because it is too large
Load Diff
@ -1,2 +1,4 @@ |
|||||||
#define OLC_PGE_APPLICATION |
#define OLC_PGE_APPLICATION |
||||||
#include "pixelGameEngine.h" |
#include "pixelGameEngine.h" |
||||||
|
#define OLC_PGEX_QUICKGUI |
||||||
|
#include "olcPGEX_QuickGUI.h" |
Binary file not shown.
Loading…
Reference in new issue