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

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)