lab_dice/yahtzee_goals.py

205 lines
5.1 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 GoalFives:
"Five points for each five"
used = False
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"
used = False
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 GoalThreeofakind:
"sum of all dice if at least three dice have the same face"
used = False
def prompt(self, dice):
potential_score = self.score(dice)
return f"Three of a kind ({potential_score})"
def score(self, dice):
face_counts={}
for die in dice:
face_counts[die.face] = face_counts.get(die.face, 0)+1
if any(count >=3 for count in face_counts.values()):
return sum(die.face for die in dice)
return 0
class GoalFourofakind:
"sum of all dice if at least four dice have the same face"
used=False
def prompt(self, dice):
potential_score=self.score(dice)
return f"Four of a kind({potential_score})"
def score(self, dice):
face_counts={}
for die in dice:
face_counts[die.face]=face_counts.get(die.face, 0)+1
if any(count >= 4 for count in face_counts.values()):
return sum(die.face for die in dice)
return 0
class GoalFullHouse:
"25 points for a full house"
used = False
def prompt(self, dice):
potential_score = self.score(dice)
return f"Full House ({potential_score})"
def score(self, dice):
face_counts = {}
for die in dice:
face_counts[die.face] = face_counts.get(die.face, 0) + 1
if sorted(face_counts.values()) == [2, 3]:
return 25
return 0
class GoalSmallStraight:
"30 points for a small straight"
used = False
def prompt(self, dice):
potential_score = self.score(dice)
return f"Small Straight ({potential_score})"
def score(self, dice):
face_counts={}
for die in dice:
face_counts[die.face]=face_counts.get(die.face,0)+1
small_straights = [[1, 2, 3, 4],[2, 3, 4, 5],[3, 4, 5, 6]]
for straight in small_straights:
if all(face in face_counts for face in straight):
return 30
return 0
class GoalLargeStraight:
"40 points for a large straight"
used = False
def prompt(self, dice):
potential_score = self.score(dice)
return f"Large Straight ({potential_score})"
def score(self, dice):
face_counts = {}
for die in dice:
face_counts[die.face] = face_counts.get(die.face, 0) + 1
large_straights = [[1, 2, 3, 4, 5],[2, 3, 4, 5, 6]]
for straight in large_straights:
if all(face in face_counts for face in straight):
return 40
return 0
class GoalYahtzee:
"50 points for a Yahtzee"
used = False
def prompt(self, dice):
potential_score = self.score(dice)
return f"Yahtzee ({potential_score})"
def score(self, dice):
face_counts = {}
for die in dice:
face_counts[die.face] = face_counts.get(die.face, 0) + 1
if any(count == 5 for count in face_counts.values()):
return 50
return 0
class GoalChance:
"Sum of all dice"
used = False
def prompt(self, dice):
potential_score = self.score(dice)
return f"Chance ({potential_score})"
def score(self, dice):
total = sum(die.face for die in dice)
return total