From 1fa5b5987f210446cba51b9dba8c809500994f61 Mon Sep 17 00:00:00 2001 From: mcbillings <99562545+mcbillings@users.noreply.github.com> Date: Mon, 20 Feb 2023 11:14:47 -0800 Subject: [PATCH 1/4] Setting up CI with new file --- .github/workflows/build.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 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..fed6709 --- /dev/null +++ b/.github/workflows/build.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 From 8b043e91d72cd6cf843460ac9a42a49ed79d748c Mon Sep 17 00:00:00 2001 From: mcbillings <99562545+mcbillings@users.noreply.github.com> Date: Mon, 20 Feb 2023 11:26:12 -0800 Subject: [PATCH 2/4] Add Status badge to Readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a8fe2c..f30dccc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # GameDie +[![Build C++](https://github.com/mcbillings/GameDie/actions/workflows/build.yml/badge.svg)](https://github.com/mcbillings/GameDie/actions/workflows/build.yml) + This repository provides a class that represents a game die, such as the six-sided dice used in traditional dice game. While the die defaults to six sides, the overloaded constructor allows the developer to customize @@ -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 8118fb3957025d076f6b8b9b1edf0715ec7a0a9b Mon Sep 17 00:00:00 2001 From: mcbillings <99562545+mcbillings@users.noreply.github.com> Date: Mon, 20 Feb 2023 11:36:56 -0800 Subject: [PATCH 3/4] Resolves #107 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f30dccc..b652a03 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Build C++](https://github.com/mcbillings/GameDie/actions/workflows/build.yml/badge.svg)](https://github.com/mcbillings/GameDie/actions/workflows/build.yml) + This repository provides a class that represents a game die, such as the six-sided dice used in traditional dice game. While the die defaults to six sides, the overloaded constructor allows the developer to customize From 23cef877171b150e18b7c96aec397a87c992e4ac Mon Sep 17 00:00:00 2001 From: Mikayla Billings-Alston Date: Mon, 20 Feb 2023 11:47:12 -0800 Subject: [PATCH 4/4] adds get-percentages, resolves #106 --- GameDie.cpp | 56 +++++++++++++++++++++++++++++++++++------------------ GameDie.h | 1 + 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/GameDie.cpp b/GameDie.cpp index d512405..4995e3e 100644 --- a/GameDie.cpp +++ b/GameDie.cpp @@ -6,27 +6,27 @@ //class constructor that seeds the random number generator GameDie::GameDie() { - srand(time(NULL)); - counter.resize(FACES); + srand(time(NULL)); + counter.resize(FACES); - for(int i=0; i GameDie::get_distribution(){ - return counter; + return counter; +} + +//returns percentage of rolls for each face relative to the number of total rolls +vector GameDie::get_percentages() { + vector rolls; + rolls = get_distribution(); + vector res; + int total = 0; + + for(int i = 0; i < rolls.size(); i++) { + total += rolls[i]; + } + + res.resize(rolls.size()); + + for(int i = 0; i < res.size(); i++) { + res[i] = (double)rolls[i]/(double)total; + } } 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;