Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions GameDie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,46 @@
GameDie::GameDie()
{
srand(time(NULL));
counter.resize(FACES);
roll_counter.resize(FACES);

for(int i=0; i<FACES; i++)
counter[i] = 0;
roll_counter[i] = 0;
}

//overloaded constructor
GameDie::GameDie(unsigned int num)
{
if( num == 0 )
{
counter.resize(FACES);
roll_counter.resize(FACES);
}
else{
counter.resize(num);
roll_counter.resize(num);
}
for(int i=0; i<FACES; i++)
{
counter[i] = 0;
roll_counter[i] = 0;
}

}


//generate a random number between 1-n where n is the counter size
// (inclusive) and return it
int GameDie::roll()
{
int roll = rand() % counter.size();
counter[roll]++;
int roll = rand() % roll_counter.size();
roll_counter[roll]++;
return roll + 1;
}

// return the count of how many times each face has been rolled, as a vector
// where each face's count is at index face-1 (i.e. Face 1 is at index 0)
vector <int> GameDie::get_distribution(){
return roll_counter;
}

//Percentage function
vector<double> GameDie::getpercentage(){
return counter;
}
2 changes: 1 addition & 1 deletion GameDie.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GameDie
vector <int> get_distribution();

private:
vector <int> counter;
vector <int> roll_counter;
const static int FACES = 6;
};

Expand Down