diff --git a/play.py b/play.py index 773f7f3..93b3603 100644 --- a/play.py +++ b/play.py @@ -3,12 +3,32 @@ from yahtzee_goals import ( GoalOnes, GoalTwos, GoalThrees, + GoalFours, + GoalFives, + GoalSixes, + GoalFourofaKind, + GoalThreeofaKind, + GoalFullHouse, + GoalSmallStraight, + GoalLargeStraight, + GoalYahtzee, + GoalChance, ) goals = [ GoalOnes(), GoalTwos(), GoalThrees(), + GoalFours(), + GoalFives(), + GoalSixes(), + GoalFourofaKind(), + GoalThreeofaKind(), + GoalFullHouse(), + GoalSmallStraight(), + GoalLargeStraight(), + GoalYahtzee(), + GoalChance(), ] game = Yahtzee(goals) diff --git a/yahtzee_goals.py b/yahtzee_goals.py index 10af574..90eed73 100644 --- a/yahtzee_goals.py +++ b/yahtzee_goals.py @@ -1,3 +1,4 @@ +from collections import Counter class GoalOnes: "One point for each one" @@ -40,3 +41,147 @@ class GoalThrees: if die.face == 3: total += 3 return total + +class GoalFours: + + 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: + + 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: + + 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: + + def prompt(self, dice): + potential_score = self.score(dice) + return f"ThreeofaKind ({potential_score})" + + def score(self, dice): + total = 0 + for die in dice: + counts = Counter(self.dice) + for count in counts.value(): + if count >= 3: + return True + return False + if True: + total += sum(self.dice) + return total + + +class GoalFourofaKind: + + def prompt(self, dice): + potential_score = self.score(dice) + return f"FourofaKind ({potential_score})" + + def score(self, dice): + total = 0 + for die in dice: + counts = Counter(self.dice) + for count in counts.value(): + if count >= 4: + return True + return False + if True: + total += sum(self.dice) + return total + +class GoalFullHouse: + + def prompt(self, dice): + potential_score = self.score(dice) + return f"FullHouse ({potential_score}" + + def score(self, dice): + total = 0 + for die in dice: + if + total +=25 + return total + +class GoalSmallStraight: + def prompt(self, dice): + potential_score = self.score(dice) + return f"SmallStraight ({potential_score}" + + def score(self, dice): + total = 0 + for die in dice: + if + total +=30 + return total + +class GoalLargeStraight: + def prompt(self, dice): + potential_score = self.score(dice) + return f"LargeStraight ({potential_score}" + + def score(self, dice): + total = 0 + for die in dice: + if + total +=40 + return total + +class GoalYahtzee: + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Yahtzee ({potential_score})" + + def score(self, dice): + total = 0 + for die in dice: + counts = Counter(self.dice) + for count in counts.value(): + if count >= 5: + return True + return False + if True: + total += 50 + return total + +class GoalChance: + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Yahtzee ({potential_score})" + + def score(self, dice): + total = 0 + for die in dice: + if + total +=sum(self.dice) + return total \ No newline at end of file