diff --git a/play.py b/play.py index a8e683c..fa5e710 100644 --- a/play.py +++ b/play.py @@ -3,12 +3,38 @@ from yahtzee_goals import ( GoalOnes, GoalTwos, GoalThrees, + GoalFours, + GoalFives, + GoalSixes, + GoalThreeofakind, + GoalFourofakind, + GoalFullHouse, + GoalSmallStraight, + GoalLargeStraight, + GoalYahtzee, + GoalChance + + + ) goals = [ GoalOnes(), GoalTwos(), GoalThrees(), + GoalFours(), + GoalFives(), + GoalSixes(), + GoalThreeofakind(), + GoalFourofakind(), + GoalFullHouse(), + GoalSmallStraight(), + GoalLargeStraight(), + GoalYahtzee(), + GoalChance() + + + ] game = Yachtzee(goals) diff --git a/yahtzee.py b/yahtzee.py index 336131a..55328dc 100644 --- a/yahtzee.py +++ b/yahtzee.py @@ -153,3 +153,4 @@ class Yachtzee: if die.face in choice_ints: choice_ints.remove(die.face) return len(choice_ints) == 0 + \ No newline at end of file diff --git a/yahtzee_goals.py b/yahtzee_goals.py index fce4e5a..c4b7f38 100644 --- a/yahtzee_goals.py +++ b/yahtzee_goals.py @@ -43,3 +43,162 @@ class GoalThrees: 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 +