generated from mwc/lab_dice
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.
This commit is contained in:
parent
29154778d4
commit
a6b4a1aadd
Binary file not shown.
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue