From 3c9116087bd93a39f8e334e641e57d82ae131fab Mon Sep 17 00:00:00 2001 From: njmason2 Date: Wed, 12 Nov 2025 19:01:36 -0500 Subject: [PATCH] play.py yahtzee.py yahtzee_goals.py --- play.py | 12 ++++++ yahtzee.py | 5 ++- yahtzee_goals.py | 107 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 2 deletions(-) diff --git a/play.py b/play.py index 773f7f3..f8ba240 100644 --- a/play.py +++ b/play.py @@ -3,12 +3,24 @@ from yahtzee_goals import ( GoalOnes, GoalTwos, GoalThrees, + GoalFours, + GoalFives, + GoalSixes, + Goal_is_three_of_a_kind, + Goal_is_four_of_a_kind, + Goal_is_full_house, ) goals = [ GoalOnes(), GoalTwos(), GoalThrees(), + GoalFours(), + GoalFives(), + GoalSixes(), + Goal_is_three_of_a_kind(), + Goal_is_four_of_a_kind(), + Goal_is_full_house(), ] game = Yahtzee(goals) diff --git a/yahtzee.py b/yahtzee.py index 61c9416..0e553f7 100644 --- a/yahtzee.py +++ b/yahtzee.py @@ -97,7 +97,7 @@ class Yahtzee: def get_unused_goals(self): """ - Conditional appending of the list of unused_goals. + Conditional appending of the list of unused_goals, displayed in the menu. """ unused_goals = [] for goal in self.goals: @@ -120,7 +120,8 @@ class Yahtzee: def get_dice_to_reroll(self, choice_ints): """Conditional logic to append dice to the dice_to_reroll list, - and removes dice that weren't chosen from the choice_ints list. + and removes dice that weren't chosen from the choice_ints list + (the Dice: displayed in the show_status function) """ dice_to_reroll = [] for die in self.dice: diff --git a/yahtzee_goals.py b/yahtzee_goals.py index 10af574..98f0786 100644 --- a/yahtzee_goals.py +++ b/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 +