Added is_three_of_a_kind and is_four_of_a_kind

Checkpoint 1: The first thing that comes to my mind, along the same vein
as the Die objects, is a deck of cards. You could create a deck of Card
objects and deal hands to simulate poker or blackjack.
This commit is contained in:
Pat Wick 2024-01-31 20:13:01 -05:00
parent 50a2f11499
commit 35a8bd78ae
4 changed files with 27 additions and 7 deletions

Binary file not shown.

View File

@ -18,13 +18,33 @@ class FiveDice:
if face != 1:
return False
return True
def is_three_of_a_kind(self):
self.faces().sort()
if self.faces()[0] == self.faces()[1] and self.faces()[0] == self.faces()[2] and self.faces()[0] != self.faces()[3]:
return True
elif self.faces()[1] == self.faces()[2] and self.faces()[1] == self.faces()[3] and self.faces()[1] != self.faces()[4]:
return True
elif self.faces()[2] == self.faces()[3] and self.faces()[2] == self.faces()[4]:
return True
else:
return False
def is_four_of_a_kind(self):
self.faces().sort()
if self.faces()[0] != self.faces()[4] and self.faces()[0] == self.faces()[1] and self.faces()[0] == self.faces()[2] and self.faces()[0] == self.faces()[3]:
return True
elif self.faces()[0] != self.faces()[1] and self.faces()[1] == self.faces()[2] and self.faces()[1] == self.faces()[3] and self.faces()[1] == self.faces()[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_four_of_a_kind():
successes += 1
print(successes/trials)

10
poetry.lock generated
View File

@ -2,13 +2,13 @@
[[package]]
name = "click"
version = "8.1.6"
version = "8.1.7"
description = "Composable command line interface toolkit"
optional = false
python-versions = ">=3.7"
files = [
{file = "click-8.1.6-py3-none-any.whl", hash = "sha256:fa244bb30b3b5ee2cae3da8f55c9e5e0c0e86093306301fb418eb9dc40fbded5"},
{file = "click-8.1.6.tar.gz", hash = "sha256:48ee849951919527a045bfe3bf7baa8a959c423134e1a5b98c05c20ba75a1cbd"},
{file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"},
{file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"},
]
[package.dependencies]
@ -47,5 +47,5 @@ telegram = ["requests"]
[metadata]
lock-version = "2.0"
python-versions = "^3.11"
content-hash = "e78479d542c88ba0a220d425c59162a0f8c7ecfef5c42eb296d1431c0ab05b87"
python-versions = "^3.10"
content-hash = "20affb522c68abead0ebbdc99087c61d83c1efa06367c5a707a0153e8581679c"

View File

@ -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"