generated from mwc/lab_dice
did the code for three and four of a kind
This commit is contained in:
@@ -21,6 +21,7 @@ class FiveDice:
|
||||
|
||||
def value_count(self):
|
||||
|
||||
counts = {}
|
||||
count_ones = 0
|
||||
count_twos = 0
|
||||
count_threes = 0
|
||||
@@ -28,49 +29,63 @@ class FiveDice:
|
||||
count_fives = 0
|
||||
count_sixes = 0
|
||||
|
||||
for face in self.faces():
|
||||
count_ones+=1
|
||||
if face == 2:
|
||||
count_twos+=1
|
||||
if face == 3:
|
||||
count_threes+=1
|
||||
if face == 4:
|
||||
count_fours+=1
|
||||
if face == 5:
|
||||
count_fives+=1
|
||||
if face == 6:
|
||||
count_sixes+=1
|
||||
counts=
|
||||
'ones':count_ones,
|
||||
'twos':count_twos,
|
||||
'threes':count_threes,
|
||||
'fours':count_fours,
|
||||
'fives':count_fives,
|
||||
'sixes':count_sixes,
|
||||
for face in self.faces():
|
||||
if face == 1:
|
||||
count_ones+=1
|
||||
if face == 2:
|
||||
count_twos+=1
|
||||
if face == 3:
|
||||
count_threes+=1
|
||||
if face == 4:
|
||||
count_fours+=1
|
||||
if face == 5:
|
||||
count_fives+=1
|
||||
if face == 6:
|
||||
count_sixes+=1
|
||||
|
||||
counts = {
|
||||
"ones":count_ones,
|
||||
"twos":count_twos,
|
||||
"threes":count_threes,
|
||||
"fours":count_fours,
|
||||
"fives":count_fives,
|
||||
"sixes":count_sixes
|
||||
}
|
||||
|
||||
return counts
|
||||
|
||||
|
||||
|
||||
def all_ones(self):
|
||||
value_count = None
|
||||
value_count = self.value_count()
|
||||
|
||||
if value_count['ones'] < 5:
|
||||
return False
|
||||
return True
|
||||
if value_count["ones"] == 5:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def is_three_of_a_kind(self):
|
||||
|
||||
value_count = None
|
||||
value_count = self.value.count()
|
||||
"""take the return of false out of the if statement.
|
||||
We want to check all of the counts first and return true if any one of them is greater than or equal to 3.
|
||||
We only return false if we've already gone through all of the counts."""
|
||||
|
||||
value_count = self.value_count()
|
||||
for value in value_count.values():
|
||||
if value >= 3:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
def is_four_of_a_kind(self):
|
||||
value_count = None
|
||||
value_count = self.value_count()
|
||||
for value in value_count.values():
|
||||
if value >= 4:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
dice = FiveDice()
|
||||
@@ -81,7 +96,28 @@ for trial in tqdm(range(trials)):
|
||||
if dice.all_ones():
|
||||
successes += 1
|
||||
|
||||
print(successes/trials)
|
||||
|
||||
print("Odds of rolling all ones:" + str(successes/trials))
|
||||
|
||||
"""Create a new trial here to test for three of a kind. Repeat the code above, but make it for three of a kind."""
|
||||
"""create another for four of a kind."""
|
||||
|
||||
dice = FiveDice()
|
||||
successes1 = 0
|
||||
trials = 1000000
|
||||
for trial in tqdm(range(trials)):
|
||||
dice.roll()
|
||||
if dice.is_three_of_a_kind():
|
||||
successes1 += 1
|
||||
print("Odds of rolling three of a kind:" + str(successes1/trials))
|
||||
|
||||
dice = FiveDice()
|
||||
successes2 = 0
|
||||
trials = 1000000
|
||||
for trial in tqdm(range(trials)):
|
||||
dice.roll()
|
||||
if dice.is_four_of_a_kind():
|
||||
successes2 += 1
|
||||
|
||||
|
||||
print("Odds of rolling four of a kind:" + str(successes2/trials))
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class Yahtzee:
|
||||
goal.used = False
|
||||
while self.count_unused_goals() > 0:
|
||||
self.play_round()
|
||||
print(f"Your final score was {self.score}"
|
||||
print(f"Your final score was {self.score}")
|
||||
#says your final score
|
||||
|
||||
def play_round(self):
|
||||
|
||||
Reference in New Issue
Block a user