lab_dice/yahtzee_goals.py

100 lines
2.5 KiB
Python

class GoalOnes:
"One point for each one"
used = False
def prompt(self, dice):
potential_score = self.score(dice)
return f"Ones ({potential_score})"
def score(self, dice):
total = 0
for die in dice:
if die.face == 1:
total += 1
return total
class GoalTwos:
"Two points for each two"
used = False
def prompt(self, dice):
potential_score = self.score(dice)
return f"Twos ({potential_score})"
def score(self, dice):
total = 0
for die in dice:
if die.face == 2:
total += 2
return total
class GoalThrees:
"Three points for each three"
used = False
def prompt(self, dice):
potential_score = self.score(dice)
return f"Threes ({potential_score})"
def score(self, dice):
total = 0
for die in dice:
if die.face == 3:
total += 3
return total
class GoalFours:
"Four points for each four"
used = False
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 GoalThreeOfAKind:
"add all dice, if all three dice have the same number"
used = False
def is_three_of_a_kind(self, dice):
if sum([d.face == dice[0].face for d in dice]) == 3:
return True
if sum([d.face == dice[1].face for d in dice]) == 3:
return True
if sum([d.face == dice[2].face for d in dice]) == 3:
return True
return False
def prompt(self, dice):
potential_score = self.score(dice)
return f"Three of a kind ({potential_score})"
def score(self, dice):
total = 0
if self.is_three_of_a_kind(dice):
total = sum([d.face for d in dice])
return total
class GoalYahtzee:
"""50 points if all the dice are all the same numbers"""
used = False
def is_Yahtzee(self, dice):
if sum([d.face == dice[0].face for d in dice]) == 5:
return True
return False
def prompt(self, dice):
potential_score = self.score(dice)
return f"Yahtzee ({potential_score})"
def score(self, dice):
total = 0
if self.is_Yahtzee(dice):
total = 50
return total