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
Binary file added .DS_Store
Binary file not shown.
Binary file added .github/.DS_Store
Binary file not shown.
Binary file added .github/workflows/.DS_Store
Binary file not shown.
23 changes: 23 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Build C++

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
install:
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y -f build-essential g++ cmake
build:
needs: install
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build project
run: g++ GameDie.cpp main.cpp -std=c++17 -o firstIO
18 changes: 18 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Docker Image CI

on:
pull_request:
branches: [ "main" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build -t cpp .
- name: Run the lint
run: docker run -i cpp cpplint *.cpp *.h
11 changes: 6 additions & 5 deletions GameDie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ GameDie::GameDie() {
srand(time(NULL));
roll_counter.resize(FACES);

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

// overloaded constructor
GameDie::GameDie(unsigned int num) {
srand(time(NULL));
if ( num == 0 ) {
if (num == 0) {
roll_counter.resize(FACES);
} else {
roll_counter.resize(num);
Expand All @@ -29,13 +29,14 @@ GameDie::GameDie(unsigned int num) {
// generate a random number between 1-n where n is the counter size
// (inclusive) and return it
int GameDie::roll() {
int roll = rand_r() % roll_counter.size();
unsigned int temp = 40;
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() {
vector<int> GameDie::get_distribution() {
return roll_counter;
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ To check for your program's adoption of the style guide, within the docker
container (see above), run **cpplint**:

`cpplint *.cpp *.h`


[![Build C++](https://github.com/sachinprasad1998mav/Roller/actions/workflows/actions.yml/badge.svg)](https://github.com/sachinprasad1998mav/Roller/actions/workflows/actions.yml)
Binary file added Roller
Binary file not shown.
5 changes: 2 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ using std::cout;
using std::endl;

int main(int argc, char *argv[]) {
if ( argc != 2 || std::atoi(argv[1]) < 1 ){
if ( argc != 2 || std::atoi(argv[1]) < 1 ) {
cout << "Incorrect command.\n"
<< "Format: ./Roller <n>\n"
<< "--------------------\n"
<< "Arguments\n"
<< "--------------------\n"
<< "<n> - Required; a number 1 or greater representing the number\n"
<< " of faces on the die being rolled\n";
}
else {
} else {
int faces = std::atoi(argv[1]);
GameDie die(faces);
cout << die.roll() << endl;
Expand Down