From 77fd29ec711943662e4c8533149c0b7515e260a6 Mon Sep 17 00:00:00 2001 From: no-bugs-only-features Date: Mon, 20 Feb 2023 11:15:13 -0800 Subject: [PATCH 01/10] Add action for building --- .github/workflows/build.yml | 24 ++++++++++++++++++++++++ Makefile | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..d8b0d0f --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,24 @@ +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: make \ No newline at end of file diff --git a/Makefile b/Makefile index fc44534..2a8c6b8 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ CC=g++ all: - $(CC) -Wall *.cpp \ No newline at end of file + $(CC) -Wall -Werror *.cpp \ No newline at end of file From 0cdf99a68aae416a116bed20e0f98f02331af101 Mon Sep 17 00:00:00 2001 From: no-bugs-only-features Date: Mon, 20 Feb 2023 11:22:45 -0800 Subject: [PATCH 02/10] Revert "Add action for building" This reverts commit 77fd29ec711943662e4c8533149c0b7515e260a6. --- .github/workflows/build.yml | 24 ------------------------ Makefile | 2 +- 2 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index d8b0d0f..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,24 +0,0 @@ -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: make \ No newline at end of file diff --git a/Makefile b/Makefile index 2a8c6b8..fc44534 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ CC=g++ all: - $(CC) -Wall -Werror *.cpp \ No newline at end of file + $(CC) -Wall *.cpp \ No newline at end of file From 1ec22eb096d4e4d205817fbbcfc6eaeebfdb5388 Mon Sep 17 00:00:00 2001 From: no-bugs-only-features Date: Mon, 20 Feb 2023 11:37:38 -0800 Subject: [PATCH 03/10] Add int main() --- GameDie.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/GameDie.cpp b/GameDie.cpp index e9fb279..6a182e7 100644 --- a/GameDie.cpp +++ b/GameDie.cpp @@ -3,6 +3,10 @@ #include #include +int main() { + return 0; +} + //class constructor that seeds the random number generator GameDie::GameDie() { From cbfe5eff9c45ccb649fcc3e696f412df2fb61d73 Mon Sep 17 00:00:00 2001 From: no-bugs-only-features Date: Mon, 20 Feb 2023 11:41:09 -0800 Subject: [PATCH 04/10] Implement percentages. Closes #106 --- GameDie.cpp | 10 ++++++++++ GameDie.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/GameDie.cpp b/GameDie.cpp index 6a182e7..86f83a0 100644 --- a/GameDie.cpp +++ b/GameDie.cpp @@ -12,6 +12,7 @@ GameDie::GameDie() { srand(time(NULL)); roll_counter.resize(FACES); + roll_percentages.resize(FACES); for(int i=0; i GameDie::get_distribution(){ return roll_counter; } + +vector GameDie::get_percentages() { + for (int i = 0; i < roll_counter.size(); i++) { + roll_percentages[i] = roll_counter[i]/num_rolls; + } + return roll_percentages; +} + diff --git a/GameDie.h b/GameDie.h index 939e8f7..f02889c 100644 --- a/GameDie.h +++ b/GameDie.h @@ -11,10 +11,13 @@ class GameDie GameDie(unsigned int); int roll(); vector get_distribution(); + vector get_percentages(); private: vector roll_counter; + vector roll_percentages; const static int FACES = 6; + int num_rolls = 0; }; #endif From 0543debc6f13591b82c969b60097109b23c76970 Mon Sep 17 00:00:00 2001 From: no-bugs-only-features Date: Mon, 20 Feb 2023 11:43:39 -0800 Subject: [PATCH 05/10] Fix initialization for percentages vector --- GameDie.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/GameDie.cpp b/GameDie.cpp index 86f83a0..b4fdf9e 100644 --- a/GameDie.cpp +++ b/GameDie.cpp @@ -24,13 +24,16 @@ GameDie::GameDie(unsigned int num) if( num == 0 ) { roll_counter.resize(FACES); + roll_percentages.resize(FACES); } else{ roll_counter.resize(num); + roll_percentages.resize(num); } for(int i=0; i GameDie::get_distribution(){ } vector GameDie::get_percentages() { - for (int i = 0; i < roll_counter.size(); i++) { + for (int i = 0; i < (int) roll_counter.size(); i++) { roll_percentages[i] = roll_counter[i]/num_rolls; } return roll_percentages; From ea5993850227699826b86f52224cac726760dc37 Mon Sep 17 00:00:00 2001 From: no-bugs-only-features Date: Mon, 20 Feb 2023 11:46:21 -0800 Subject: [PATCH 06/10] Fixed percentages function --- GameDie.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GameDie.cpp b/GameDie.cpp index b4fdf9e..1fe3d57 100644 --- a/GameDie.cpp +++ b/GameDie.cpp @@ -2,6 +2,7 @@ #include #include #include +#include int main() { return 0; @@ -56,7 +57,7 @@ vector GameDie::get_distribution(){ vector GameDie::get_percentages() { for (int i = 0; i < (int) roll_counter.size(); i++) { - roll_percentages[i] = roll_counter[i]/num_rolls; + roll_percentages[i] = roll_counter[i]/(double) num_rolls; } return roll_percentages; } From b71e39ef7e5e55fb97fe0d80855ac9bd8aa7abbb Mon Sep 17 00:00:00 2001 From: no-bugs-only-features <98416162+no-bugs-only-features@users.noreply.github.com> Date: Mon, 20 Feb 2023 11:48:00 -0800 Subject: [PATCH 07/10] Add github action for building --- .github/workflows/build.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..791c1d1 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,24 @@ +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: make From 44eccb18183656be6d9d654999322b0e9c30a3c9 Mon Sep 17 00:00:00 2001 From: no-bugs-only-features <98416162+no-bugs-only-features@users.noreply.github.com> Date: Mon, 20 Feb 2023 11:49:26 -0800 Subject: [PATCH 08/10] Add status badge. Closes #107 --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a8fe2c..a5eaef2 100644 --- a/README.md +++ b/README.md @@ -23,4 +23,6 @@ Once built, run the image: ...or run it with a bind mount to the current source code: -`docker run --mount type=bind,source="$(pwd)",target=/usr/src -it cpp-container` \ No newline at end of file +`docker run --mount type=bind,source="$(pwd)",target=/usr/src -it cpp-container` + +[![Build C++](https://github.com/no-bugs-only-features/GameDie/actions/workflows/build.yml/badge.svg)](https://github.com/no-bugs-only-features/GameDie/actions/workflows/build.yml) From 3f94693dc754f3e24777e4a766d479c716b01316 Mon Sep 17 00:00:00 2001 From: no-bugs-only-features <98416162+no-bugs-only-features@users.noreply.github.com> Date: Mon, 20 Feb 2023 11:52:36 -0800 Subject: [PATCH 09/10] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a5eaef2..0651df7 100644 --- a/README.md +++ b/README.md @@ -26,3 +26,5 @@ Once built, run the image: `docker run --mount type=bind,source="$(pwd)",target=/usr/src -it cpp-container` [![Build C++](https://github.com/no-bugs-only-features/GameDie/actions/workflows/build.yml/badge.svg)](https://github.com/no-bugs-only-features/GameDie/actions/workflows/build.yml) + +[![Build C++](https://github.com/no-bugs-only-features/GameDie/actions/workflows/build.yml/badge.svg)](https://github.com/no-bugs-only-features/GameDie/actions/workflows/build.yml) From 35cf0a704aad9342d2267bb9a7a7cd37a63394c2 Mon Sep 17 00:00:00 2001 From: no-bugs-only-features <98416162+no-bugs-only-features@users.noreply.github.com> Date: Mon, 20 Feb 2023 11:52:49 -0800 Subject: [PATCH 10/10] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 0651df7..a5eaef2 100644 --- a/README.md +++ b/README.md @@ -26,5 +26,3 @@ Once built, run the image: `docker run --mount type=bind,source="$(pwd)",target=/usr/src -it cpp-container` [![Build C++](https://github.com/no-bugs-only-features/GameDie/actions/workflows/build.yml/badge.svg)](https://github.com/no-bugs-only-features/GameDie/actions/workflows/build.yml) - -[![Build C++](https://github.com/no-bugs-only-features/GameDie/actions/workflows/build.yml/badge.svg)](https://github.com/no-bugs-only-features/GameDie/actions/workflows/build.yml)