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"Six ({potential_score})" def score(self, dice): total = 0 for die in dice: if die.face == 6: total += 6 return total class ThreeOfAKind: "Total of all 5 dice" used = False def prompt(self, dice): potential_score = self.score(dice) return f"Three of a kind ({potential_score})" def faces(self, dice): #print([die.face for die in dice]) return [die.face for die in dice] def is_three_of_a_kind(self,dice): sorted = self.faces(dice) sorted.sort() #print(sorted) if sorted[0] == sorted[1] and sorted[0] == sorted[2] and sorted[0] != sorted[3]: return True elif sorted[1] == sorted[2] and sorted[1] == sorted[3] and sorted[1] != sorted[4]: return True elif sorted[2] == sorted[3] and sorted[2] == sorted[4]: return True else: return False # if self.faces(dice)[0] == self.faces(dice)[1] and self.faces(dice)[0] == self.faces(dice)[2] and self.faces(dice)[0] != self.faces(dice)[3]: # return True # elif self.faces(dice)[1] == self.faces(dice)[2] and self.faces(dice)[1] == self.faces(dice)[3] and self.faces(dice)[1] != self.faces(dice)[4]: # return True # elif self.faces(dice)[2] == self.faces(dice)[3] and self.faces(dice)[2] == self.faces(dice)[4]: # return True # else: # return False def score(self, dice): if self.is_three_of_a_kind(dice): total = 0 for die in dice: total += die.face return total else: return 0 class FourOfAKind: "Total of all 5 dice" used = False def prompt(self, dice): potential_score = self.score(dice) return f"Four of a kind ({potential_score})" def faces(self,dice): return [die.face for die in dice] def is_four_of_a_kind(self,dice): sorted = self.faces(dice) sorted.sort() if sorted[0] != sorted[4] and sorted[0] == sorted[1] and sorted[0] == sorted[2] and sorted[0] == sorted[3]: return True elif sorted[0] != sorted[1] and sorted[1] == sorted[2] and sorted[1] == sorted[3] and sorted[1] == sorted[4]: return True else: return False def score(self, dice): if self.is_four_of_a_kind(dice): total = 0 for die in dice: total += die.face return total else: return 0 class FullHouse: "25 points for three of one number and two of another" used = False def prompt(self, dice): potential_score = self.score(dice) return f"Full House ({potential_score})" def faces(self,dice): return [die.face for die in dice] def is_full_house(self,dice): counts = [] for i in range(1,7): counts.append(self.faces(dice).count(i)) if 2 in counts and 3 in counts: return True else: return False def score(self,dice): if self.is_full_house(dice): return 25 else: return 0 class SmallStraight: "Score 30 points if 4 of 5 dice show a sequence" used = False def prompt(self, dice): potential_score = self.score(dice) return f"Small Straight ({potential_score})" def faces(self,dice): return [die.face for die in dice] def is_small_straight(self,dice): small_straights = [[1,2,3,4], [2,3,4,5], [3,4,5,6], [1,2,3,4,5], [2,3,4,5,6]] ss_list = self.faces(dice) check = list(set(ss_list)) check.sort() if check in small_straights: return True else: return False def score(self,dice): if self.is_small_straight(dice): return 30 else: return 0 class LargeStraight: "Score 40 points if all 5 dice show a sequence" used = False def prompt(self, dice): potential_score = self.score(dice) return f"Large Straight ({potential_score})" def faces(self,dice): return [die.face for die in dice] def is_large_straight(self,dice): lorge_straights = [[1,2,3,4,5], [2,3,4,5,6]] ls_list = self.faces(dice) check = list(set(ls_list)) check.sort() if check in lorge_straights: return True else: return False def score(self,dice): if self.is_large_straight(dice): return 40 else: return 0 class Yahtzee: "Score 50 points if all 5 dice are the same value" used = False def prompt(self, dice): potential_score = self.score(dice) return f"Yahtzee ({potential_score})" def faces(self,dice): return [die.face for die in dice] def is_yahtzee(self,dice): check = set(self.faces(dice)) if len(check) == 1: return True else: return False def score(self,dice): if self.is_yahtzee(dice): return 50 else: return 0 class Chance: "Scores total of all 5 dice" used = False def prompt(self, dice): potential_score = self.score(dice) return f"Chance ({potential_score})" def score(self, dice): total = 0 for die in dice: total += die.face return total