From 50eb761422f37cd2abe75d1a764228d7333369ca Mon Sep 17 00:00:00 2001 From: Peter Menzies Date: Mon, 20 Feb 2023 11:24:31 -0800 Subject: [PATCH 1/3] Added percentage distribution function Resolves #106 --- GameDie.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/GameDie.cpp b/GameDie.cpp index d512405..7744d7b 100644 --- a/GameDie.cpp +++ b/GameDie.cpp @@ -44,3 +44,26 @@ int GameDie::roll() vector GameDie::get_distribution(){ return counter; } + +// 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. +vector GameDie::get_percentages(){ + vector result; + int total = 0; + result.resize(counter.size()); + for(unsigned int i = 0; i < counter.size(); i++) { + total += counter[i]; + } + if(total == 0) { + return result; + } + for(unsigned int i = 0; i < counter.size(); i++) { + result[i] = counter[i]/(double)total; + } +} \ No newline at end of file From eeeae58b26d578ff9ac63832aa0e010a29afe5f5 Mon Sep 17 00:00:00 2001 From: Peter Menzies Date: Mon, 20 Feb 2023 11:24:31 -0800 Subject: [PATCH 2/3] Added percentage distribution function Resolves #106 --- GameDie.cpp | 1 + GameDie.h | 1 + 2 files changed, 2 insertions(+) diff --git a/GameDie.cpp b/GameDie.cpp index 7744d7b..75eefba 100644 --- a/GameDie.cpp +++ b/GameDie.cpp @@ -66,4 +66,5 @@ vector GameDie::get_percentages(){ for(unsigned int i = 0; i < counter.size(); i++) { result[i] = counter[i]/(double)total; } + return result; } \ No newline at end of file diff --git a/GameDie.h b/GameDie.h index 54d69ba..e5bec0b 100644 --- a/GameDie.h +++ b/GameDie.h @@ -11,6 +11,7 @@ class GameDie GameDie(unsigned int); int roll(); vector get_distribution(); + vector get_percentages(); private: vector counter; From 8dc87eb0d00e4c661c2c301068ea06b9423d77b5 Mon Sep 17 00:00:00 2001 From: Peter Menzies Date: Mon, 20 Feb 2023 11:49:54 -0800 Subject: [PATCH 3/3] Added CI/CD resolves #107 --- .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..7f2ec8b --- /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++ GameDie.cpp -std=c++17 -Wall -Werror \ No newline at end of file