I am writing a tennis tournament simulator. I have two main classes to help me achieve this, a 'Player' class and a 'Tournament' class. Unsurprisingly the 'player' class contains details about each individual player, and the 'Tournament' class details of the tournament to be played (I am trying to simulate the entire ATP Tour).
I store each instance of the 'Tournament' class in a vector as below. For now I am doing just one tournament.
1 2
|
vector<unique_ptr<Tournament>> GrandSlams;
GrandSlams.emplace_back(new Tournament("Wimbledon","Grass",128,7,32,4,{10,45,90,180,360,720,1200,2000}));
|
I pass, and correct me if the terminology I use is wrong here as this is quite new to me and I am hacking it together by trial and error more than by understanding fully, the address of the pointer to each tournament to a 'PlayTournament' function as below.
1 2 3
|
for(auto &T: GrandSlams) {
PlayTournament(Players,T);
}
|
In the 'PlayTournament' function I am first wanting to resize the vector of vectors which will represent the tournament Draw. i.e. for a 128 person tournament I have this as vectors of Player objects of size 128,64,32,16,8,4, and 2.
I have so far only been able to do this looping over in the classic way as you can see below, but I want this to be 'good' code and use iterators or auto. You can see I have tried a number of different ways but none of them work. When I compile I get the error "no match for 'operator[]' (operand types are 'std::vector<std::vector<Player> >' and 'std::vector<std::vector<Player> >::iterator {aka __gnu_cxx::__normal_iterator<std::vector<Player>*, std::vector<std::vector<Player> > >}')|"
1 2 3 4 5 6 7 8 9 10 11
|
void PlayTournament(vector<Player> &Players,unique_ptr<Tournament> &T){
//Get size of initial draw and resize draws for each round.
int DrawSize = T->GetDrawSize();
int NoOfRounds = T->GetNoOfRounds();
// vector<vector<Player>>::iterator itr1;
// for(auto itr1=T->Draw.begin();itr1!=T->Draw.end();++itr1){
// for(itr1=T->Draw.begin();itr1!=T->Draw.end();++itr1){
for(int itr1=0;itr1<NoOfRounds;itr1++){
T->Draw[itr1].resize(DrawSize);
DrawSize/=2;
}
|
There are a number of places I wanted to use iterators so I would appreciate any help you might be able to give. If you need more information or code let me know.