diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml new file mode 100644 index 0000000..d80524b --- /dev/null +++ b/.github/workflows/super-linter.yml @@ -0,0 +1,23 @@ +# This workflow executes several linters on changed files based on languages used in your code base whenever +# you push a code or open a pull request. +# +# You can adjust the behavior by modifying this file. +# For more information, see: +# https://github.com/github/super-linter +name: Lint Code Base + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Docker build + run: | + docker build -t cpp-container . + docker run -i cpp-container cpplint *.cpp *.h diff --git a/GameDie.cpp b/GameDie.cpp index d8ecb3a..1c3e833 100644 --- a/GameDie.cpp +++ b/GameDie.cpp @@ -9,8 +9,8 @@ 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 @@ -29,13 +29,13 @@ 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(); + int roll = rand_r(seed) % 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 GameDie::get_distribution() { +vector GameDie::get_distribution() { return roll_counter; } diff --git a/GameDie.h b/GameDie.h index 888c05c..7167166 100644 --- a/GameDie.h +++ b/GameDie.h @@ -6,16 +6,18 @@ using std::vector; -class GameDie{ +class GameDie { public: GameDie(); explicit GameDie(unsigned int); int roll(); - vector get_distribution(); + vector get_distribution(); private: - vector roll_counter; + vector roll_counter; static const int FACES = 6; + unsigned int a = 6; + unsigned int *seed = &a; }; #endif // GAMEDIE_H_ diff --git a/README.md b/README.md index d46f7c6..7d979fb 100644 --- a/README.md +++ b/README.md @@ -41,3 +41,5 @@ To check for your program's adoption of the style guide, within the docker container (see above), run **cpplint**: `cpplint *.cpp *.h` + +[![Lint Code Base](https://github.com/hamsaraj7106/Roller/actions/workflows/super-linter.yml/badge.svg)](https://github.com/hamsaraj7106/Roller/actions/workflows/super-linter.yml) diff --git a/main.cpp b/main.cpp index 65055f9..39efd65 100644 --- a/main.cpp +++ b/main.cpp @@ -7,7 +7,7 @@ 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" @@ -15,8 +15,7 @@ int main(int argc, char *argv[]) { << "--------------------\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;