generated from mwc/lab_dice
play.py yahtzee.py yahtzee_goals.py
This commit is contained in:
107
yahtzee_goals.py
107
yahtzee_goals.py
@@ -1,3 +1,6 @@
|
||||
from collections import Counter
|
||||
from die import Die
|
||||
|
||||
|
||||
class GoalOnes:
|
||||
"One point for each one"
|
||||
@@ -13,6 +16,7 @@ class GoalOnes:
|
||||
total += 1
|
||||
return total
|
||||
|
||||
|
||||
class GoalTwos:
|
||||
"Two points for each two"
|
||||
|
||||
@@ -27,6 +31,7 @@ class GoalTwos:
|
||||
total += 2
|
||||
return total
|
||||
|
||||
|
||||
class GoalThrees:
|
||||
"Three points for each three"
|
||||
|
||||
@@ -40,3 +45,105 @@ class GoalThrees:
|
||||
if die.face == 3:
|
||||
total += 3
|
||||
return total
|
||||
|
||||
|
||||
class GoalFours:
|
||||
"Four points for each four"
|
||||
|
||||
def prompt(self, dice):
|
||||
potential_score = self.score(dice)
|
||||
return f"Fours ({potential_score})"
|
||||
|
||||
def score(self, dice):
|
||||
total = 0
|
||||
for die in dice:
|
||||
if die.face == 4:
|
||||
total += 4
|
||||
return total
|
||||
|
||||
|
||||
class GoalFives:
|
||||
"Fives points for each five"
|
||||
|
||||
def prompt(self, dice):
|
||||
potential_score = self.score(dice)
|
||||
return f"Fives ({potential_score})"
|
||||
|
||||
def score(self, dice):
|
||||
total = 0
|
||||
for die in dice:
|
||||
if die.face == 5:
|
||||
total += 5
|
||||
return total
|
||||
|
||||
|
||||
class GoalSixes:
|
||||
"Six points for each six"
|
||||
|
||||
def prompt(self, dice):
|
||||
potential_score = self.score(dice)
|
||||
return f"Sixes ({potential_score})"
|
||||
|
||||
def score(self, dice):
|
||||
total = 0
|
||||
for die in dice:
|
||||
if die.face == 6:
|
||||
total += 6
|
||||
return total
|
||||
|
||||
|
||||
class Goal_is_three_of_a_kind:
|
||||
"Score is total all 5 dice for three-of-a-kind"
|
||||
|
||||
def prompt(self, dice):
|
||||
potential_score = self.score(dice)
|
||||
return f"3 of a kind ({potential_score})"
|
||||
|
||||
def score(self, dice):
|
||||
total=0
|
||||
for die in dice:
|
||||
counts = Counter([die.face for die in dice])
|
||||
my_dict=dict(counts)
|
||||
values = list(my_dict.values())
|
||||
for a in values:
|
||||
if a == 3:
|
||||
total += die.face
|
||||
return total
|
||||
|
||||
class Goal_is_four_of_a_kind:
|
||||
"Score is total all 5 dice for four-of-a-kind"
|
||||
|
||||
def prompt(self, dice):
|
||||
potential_score = self.score(dice)
|
||||
return f"4 of a kind ({potential_score})"
|
||||
|
||||
def score(self, dice):
|
||||
total=0
|
||||
for die in dice:
|
||||
counts = Counter([die.face for die in dice])
|
||||
my_dict=dict(counts)
|
||||
values = list(my_dict.values())
|
||||
for a in values:
|
||||
if a == 4:
|
||||
total += die.face
|
||||
return total
|
||||
|
||||
|
||||
class Goal_is_full_house:
|
||||
"25 points for a full house (three-of-a-kind plus a pair of a different number)"
|
||||
|
||||
def prompt(self, dice):
|
||||
potential_score = self.score(dice)
|
||||
return f"Full House ({potential_score})"
|
||||
|
||||
def score(self, dice):
|
||||
total=0
|
||||
for die in dice:
|
||||
counts = Counter([die.face for die in dice])
|
||||
my_dict=dict(counts)
|
||||
values = list(my_dict.values())
|
||||
for a in values:
|
||||
if (a == 3 and len(values) == 2):
|
||||
total = 25
|
||||
return total
|
||||
|
||||
|
||||
Reference in New Issue
Block a user