From 2bdc10b999a8b63e993882d300c6eebbeaa1ad6b Mon Sep 17 00:00:00 2001 From: aalfaro5 <98926113+aalfaro5@users.noreply.github.com> Date: Mon, 20 Feb 2023 11:19:45 -0800 Subject: [PATCH 1/5] Create main.yml --- .github/workflows/main.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..e4de889 --- /dev/null +++ b/.github/workflows/main.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 -Wall -Wextra -Werror -o test From 1d91a5528f4dc3210a52a0b90994ea5b153020b2 Mon Sep 17 00:00:00 2001 From: aalfaro5 <98926113+aalfaro5@users.noreply.github.com> Date: Mon, 20 Feb 2023 11:21:19 -0800 Subject: [PATCH 2/5] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a8fe2c..2c43cb6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +Status Badge: [![Build C++](https://github.com/aalfaro5/GameDie/actions/workflows/main.yml/badge.svg)](https://github.com/aalfaro5/GameDie/actions/workflows/main.yml) + # GameDie This repository provides a class that represents a game die, such as the @@ -23,4 +25,4 @@ 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` From ed09a6c1f5be9efe010e033f79ae70bab664ddbe Mon Sep 17 00:00:00 2001 From: aalfaro5 <98926113+aalfaro5@users.noreply.github.com> Date: Mon, 20 Feb 2023 11:24:15 -0800 Subject: [PATCH 3/5] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e4de889..0ef5aef 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,4 +20,4 @@ jobs: steps: - uses: actions/checkout@v3 - name: Build project - run: g++ main.cpp -std=c++17 -Wall -Wextra -Werror -o test + run: g++ GameDie.cpp -std=c++17 -Wall -Wextra -Werror -o test From 91b3d56bf730a93f08538cb72609731f80b05111 Mon Sep 17 00:00:00 2001 From: aalfaro5 <98926113+aalfaro5@users.noreply.github.com> Date: Mon, 20 Feb 2023 11:40:57 -0800 Subject: [PATCH 4/5] Update GameDie.cpp implement percentage function --- GameDie.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/GameDie.cpp b/GameDie.cpp index d512405..7361a1b 100644 --- a/GameDie.cpp +++ b/GameDie.cpp @@ -44,3 +44,26 @@ int GameDie::roll() vector GameDie::get_distribution(){ return counter; } +vector GameDie::get_percentages(){ + int rolls = 0; + vector pVector; + for (int i = 0; i < (int)counter.size(); i++) + { + rolls += counter[i]; + } + //check if rolls is 0, fill vector with 0s if true + if( rolls == 0) + { + for(int i = 0; i < FACES; i++){ + pVector.push_back(0);} + }//otherwise get percentage and pushback onto pVector + else + { + for(int i = 0; i < FACES; i++) + { + pVector.push_back((double)counter[i] / (double)rolls); + } + } + + return pVector; +} From 2ab1df2eff19cb6daa65a5c4a374d95715d99e38 Mon Sep 17 00:00:00 2001 From: aalfaro5 <98926113+aalfaro5@users.noreply.github.com> Date: Mon, 20 Feb 2023 11:42:15 -0800 Subject: [PATCH 5/5] Update GameDie.h added in get percentages function and added pVector to private --- GameDie.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/GameDie.h b/GameDie.h index 54d69ba..3cb5d6b 100644 --- a/GameDie.h +++ b/GameDie.h @@ -11,9 +11,11 @@ class GameDie GameDie(unsigned int); int roll(); vector get_distribution(); + vector get_percentages(); private: vector counter; + vector pVector; const static int FACES = 6; };