Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4b73b25
added github workflows and fixed rand_s error
AbhinavReddy-Dev Feb 22, 2023
fed019b
probable fix for build error
AbhinavReddy-Dev Feb 22, 2023
636854f
fix rand_r error
AbhinavReddy-Dev Feb 22, 2023
07cebe7
fix unsigned int argument rand_r error
AbhinavReddy-Dev Feb 22, 2023
8299fa5
fix unsigned int argument rand_r error
AbhinavReddy-Dev Feb 22, 2023
0bdf594
added github actions workflow badge
AbhinavReddy-Dev Feb 22, 2023
65af542
added lint and cleared all lint errors
AbhinavReddy-Dev Feb 22, 2023
fd442cb
fixed rand_r pointer issue
AbhinavReddy-Dev Feb 22, 2023
9eac2a3
cpplint not found error fix
AbhinavReddy-Dev Feb 22, 2023
e190e6b
cpplint not found error fix
AbhinavReddy-Dev Feb 22, 2023
ee2170d
cpplint not found error fix v3
AbhinavReddy-Dev Feb 22, 2023
19db7dd
cpplint not found error fix v4
AbhinavReddy-Dev Feb 22, 2023
e84ec1e
cpplint not found error fix v5
AbhinavReddy-Dev Feb 22, 2023
4ef1883
cpplint not found error fix v6
AbhinavReddy-Dev Feb 22, 2023
03a7806
cpplint not found error fix v7
AbhinavReddy-Dev Feb 22, 2023
216fd8c
cpplint not found error fix v8
AbhinavReddy-Dev Feb 22, 2023
7e87318
cpplint not found error fix v9
AbhinavReddy-Dev Feb 22, 2023
07ac3b8
cpplint not found error fix v10
AbhinavReddy-Dev Feb 22, 2023
b62a07e
cpplint not found error fix v11
AbhinavReddy-Dev Feb 22, 2023
7980392
cpplint not found error fix v12
AbhinavReddy-Dev Feb 22, 2023
77ec314
cpplint not found error fix v13
AbhinavReddy-Dev Feb 22, 2023
d7c773d
not tty error fix v14
AbhinavReddy-Dev Feb 22, 2023
ffa0b8e
not tty error fix v15
AbhinavReddy-Dev Feb 22, 2023
1b31787
removing exec file
AbhinavReddy-Dev Feb 22, 2023
04b8544
added seperate lint yml for correction
AbhinavReddy-Dev Feb 24, 2023
85ffe12
added seperate lint yml for correction
AbhinavReddy-Dev Feb 24, 2023
d1bac77
added seperate lint yml for correction v3
AbhinavReddy-Dev Feb 24, 2023
e4655ec
added seperate lint yml for correction v4
AbhinavReddy-Dev Feb 24, 2023
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
31 changes: 31 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: C++ Build

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

# make:
# needs: build
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Build project
# run: docker run -it cpp-container
# lint:
# needs: make
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - run: docker run -it cpp-container cpplint *.cpp *.h
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: C++ Lint

on:
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Docker run & Lint
run: |
docker build -t cpp-container .
docker run -i cpp-container cpplint *.cpp *.h
14 changes: 7 additions & 7 deletions GameDie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

// class constructor that seeds the random number generator
GameDie::GameDie() {
srand(time(NULL));
r_seed = (unsigned int *) 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 ) {
r_seed = (unsigned int *) time(NULL);
if (num == 0) {
roll_counter.resize(FACES);
} else {
roll_counter.resize(num);
Expand All @@ -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(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 <int> GameDie::get_distribution() {
vector<int> GameDie::get_distribution() {
return roll_counter;
}
7 changes: 4 additions & 3 deletions GameDie.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@

using std::vector;

class GameDie{
class GameDie {
public:
GameDie();
explicit GameDie(unsigned int);
int roll();
vector <int> get_distribution();
vector<int> get_distribution();

private:
vector <int> roll_counter;
vector<int> roll_counter;
static const int FACES = 6;
unsigned int *r_seed;
};

#endif // GAMEDIE_H_
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Roller

[![C++ Build](https://github.com/AbhinavReddy-Dev/Roller/actions/workflows/actions.yml/badge.svg)](https://github.com/AbhinavReddy-Dev/Roller/actions/workflows/actions.yml)

This repository provides a program that rolls a game die, such as the
six-sided dice used in traditional dice game.

Expand Down
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