From a6b4a1aadde36b051ea0f7e5cc8b4f10cdeda42e Mon Sep 17 00:00:00 2001 From: Justin Toombs Date: Sun, 4 Feb 2024 18:14:38 -0500 Subject: [PATCH] There were changes made specifically to develop the three and four of a kind definitions, and was accomplished using a comparison between each of the presented integers upon each roll. A situation where a class would come in handy would actually be working with my Dungeons and Dragons Club after school with students to help them with character creation as a class could be made to help with the generation of characters with their specific race, character class, background, inventory, and stats. This would actually be quite the helpful tool. --- __pycache__/die.cpython-310.pyc | Bin 0 -> 727 bytes dice_stats.py | 28 ++++++++++++++++++++++++---- pyproject.toml | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 __pycache__/die.cpython-310.pyc diff --git a/__pycache__/die.cpython-310.pyc b/__pycache__/die.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..433e7f0cf550a8cef83913e58faf5a36cca8aab8 GIT binary patch literal 727 zcmZ`%y>8n;3?}a+S#@O;$XXy%7cCKrZbeZ9Xn}5Cym=uM@zN;OPkWLP)X3&MLLVR< z{YvWC$*+(pq=Xg*ni3%Ic%=A!B-Jh!a}as>@rz#~z;AVq#foz-+MSAFV633VH6nZh zHf-;J?ar(X2P;U!gXBPp!_4OmmrY-&e=J6vbJ6aV7zb-)kZ+OA9jq-|4&)3t5>?GiD!a1TELh29GGxD*0`Z>wrAXXmQRJ@{C%9^PhGZSAsa z-?wdj(Pef1rEEUaP1#>j(Xz|xo8oo0Y0CahR^=DOW#KX|-PzagLrhdkfasZmDtdz3 zM3|lZ3H+a;4!9SR*SNzK_(0s$47Th25M1Vk^O3xa6ept)!;DB0h_t^EZ;spN6W;j# z51cM)oXCk>dRY{kow)@<1(reDiwQIjnqs5Ne(_MJ&(JN*3IyEuG7~8~-ugla9k^V$& WJu%hPr)muGy9xijHaF1?Ps}5My@*Kw literal 0 HcmV?d00001 diff --git a/dice_stats.py b/dice_stats.py index 83a99cb..d051195 100644 --- a/dice_stats.py +++ b/dice_stats.py @@ -1,5 +1,6 @@ from die import Die from tqdm import tqdm +from collections import Counter class FiveDice: def __init__(self): @@ -19,15 +20,34 @@ class FiveDice: return False return True + def is_three_of_a_kind(self): + listOfFaces = self.faces() + listOfFaces.sort() + if listOfFaces[0] == listOfFaces[1] and listOfFaces[0] == listOfFaces[2]: + return True + elif listOfFaces[1] == listOfFaces[2] and listOfFaces[1] == listOfFaces[3]: + return True + elif listOfFaces[2] == listOfFaces[3] and listOfFaces[2] == listOfFaces[4]: + return True + else: + return False + + def is_four_of_a_kind(self): + listOfFaces = self.faces() + listOfFaces.sort() + if listOfFaces[0] == listOfFaces[3]: + return True + elif listOfFaces[1] == listOfFaces[4]: + return True + else: + return False + dice = FiveDice() successes = 0 trials = 1000000 for trial in tqdm(range(trials)): dice.roll() - if dice.all_ones(): + if dice.is_three_of_a_kind(): successes += 1 print(successes/trials) - - - diff --git a/pyproject.toml b/pyproject.toml index c873876..c54d940 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ readme = "README.md" packages = [{include = "lab_dice"}] [tool.poetry.dependencies] -python = "^3.11" +python = "^3.10" click = "^8.1.6" tqdm = "^4.66.1"