From 4c6128b3ff7cfd8d773455a8d7d274924df8d569 Mon Sep 17 00:00:00 2001 From: SloaneTribble Date: Mon, 20 Feb 2023 11:25:25 -0800 Subject: [PATCH 1/3] Add YAML folder for continuous integration workflow --- .github/workflows/actions.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/actions.yml diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml new file mode 100644 index 0000000..e52e4c4 --- /dev/null +++ b/.github/workflows/actions.yml @@ -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++ main.cpp -std=c++17 -o firstIO \ No newline at end of file From 445144d3239c2c02e8d8aeec422bf0f99ddb9027 Mon Sep 17 00:00:00 2001 From: SloaneTribble Date: Mon, 20 Feb 2023 11:35:14 -0800 Subject: [PATCH 2/3] Add status badge to README, resolves #107 --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a8fe2c..51e0c1b 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/SloaneTribble/GameDie/actions/workflows/actions.yml/badge.svg)](https://github.com/SloaneTribble/GameDie/actions/workflows/actions.yml) \ No newline at end of file From c58f597a92321df496ddf31794c32abc62aefbfd Mon Sep 17 00:00:00 2001 From: SloaneTribble Date: Mon, 20 Feb 2023 11:50:24 -0800 Subject: [PATCH 3/3] Add feature to report distribution as percentages. Resolve #106 --- GameDie.cpp | 32 ++++++++++++++++++++++++++++++++ GameDie.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/GameDie.cpp b/GameDie.cpp index d512405..a87a77b 100644 --- a/GameDie.cpp +++ b/GameDie.cpp @@ -3,6 +3,23 @@ #include #include +/* + * get_distribution() keeps a tally of how many times each face has been rolled, but some users are reporting that + * they want this same information as a percentage of total rolls. + +Add a public member function vector GameDie::get_percentages() that returns + the percentage of rolls for each face relative to the number of total rolls. + Each percentage should be a double between 0 and 1 inclusively. + For example, if we have a 4-sided die that has rolled each face 1 time and has the get_distribution() of: +{1,1,1,1} +then the get_percentages() function should return: +{0.25,0.25,0.25,0.25} + +If there are no rolls yet, percentages should report 0 for each face in the vector. + Otherwise, the percentage should be calculated by face rolls / total rolls. + */ + + //class constructor that seeds the random number generator GameDie::GameDie() { @@ -30,6 +47,21 @@ GameDie::GameDie(unsigned int num) } +GameDie::vector get_percentages(){ + vector percentages; + vector distribution = get_distribution(); + + int totalRolls = 0; + for (int i = 0; i < FACES; i++){ + totalRolls += distribution[i]; + } + for (int i = 0; i < FACES ; ++){ + percentages[i] = distribution / totalRolls; + } + + return percentages; +} + //generate a random number between 1-n where n is the counter size // (inclusive) and return it int GameDie::roll() diff --git a/GameDie.h b/GameDie.h index 54d69ba..13d8a2a 100644 --- a/GameDie.h +++ b/GameDie.h @@ -11,8 +11,10 @@ class GameDie GameDie(unsigned int); int roll(); vector get_distribution(); + vector get_percentages(); private: + vector counter; const static int FACES = 6; };