diff --git a/play.py b/play.py index a8e683c..d96f80f 100644 --- a/play.py +++ b/play.py @@ -3,12 +3,26 @@ from yahtzee_goals import ( GoalOnes, GoalTwos, GoalThrees, + GoalFours, + GoalFives, + GoalSixes, + GoalThreeOfAKind, + GoalFourOfAKind, + GoalFullHouse, + GoalChance ) goals = [ GoalOnes(), GoalTwos(), GoalThrees(), + GoalFours(), + GoalFives(), + GoalSixes(), + GoalThreeOfAKind(), + GoalFourOfAKind(), + GoalFullHouse(), + GoalChance() ] game = Yachtzee(goals) diff --git a/yahtzee_goals.py b/yahtzee_goals.py index fce4e5a..b84808b 100644 --- a/yahtzee_goals.py +++ b/yahtzee_goals.py @@ -43,3 +43,147 @@ 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: + "Total of all dice if there is three of a kind" + used = False + + def prompt(self, dice): + potential_score=self.score(dice) + return f"Three of a kind ({potential_score})" + + def score(self, dice): + total = 0 + if self.threek(dice): + for die in dice: + total=total + die.face + return total + + def threek(self,dice): + nmuch = {} # create an empty dictionary to associate each face rolled with its frequency + for die in dice: # go through each dice rolled + if die.face in nmuch: # check if the dictionary already has the face included, and if so increase its frequency by 1 + nmuch[die.face] += 1 + else: + nmuch[die.face] = 1 # add the face to the dictionary with frequency 1 if it has not already been included + for die,face in nmuch.items(): # check if there is three of a kind for a given face, and if so, return True + if face==3: + return True + return False # otherwise return False + +class GoalFourOfAKind: + "Total of all dice if there is four of a kind" + used = False + + def prompt(self, dice): + potential_score=self.score(dice) + return f"Four of a kind ({potential_score})" + + def score(self, dice): + total = 0 + if self.fourk(dice): + for die in dice: + total=total + die.face + return total + + def fourk(self,dice): + nmuch = {} # create an empty dictionary to associate each face rolled with its frequency + for die in dice: # go through each dice rolled + if die.face in nmuch: # check if the dictionary already has the face included, and if so increase its frequency by 1 + nmuch[die.face] += 1 + else: + nmuch[die.face] = 1 # add the face to the dictionary with frequency 1 if it has not already been included + for die,face in nmuch.items(): # check if there is three of a kind for a given face, and if so, return True + if face==4: + return True + return False # otherwise return False + +class GoalFullHouse: + "25 points if there is full house" + used = False + + def prompt(self, dice): + potential_score=self.score(dice) + return f"Full house ({potential_score})" + + def score(self, dice): + if self.full(dice): + return 25 + return 0 + + def nofakind(self,dice,n): + nmuch = {} # create an empty dictionary to associate each face rolled with its frequency + for die in dice: # go through each dice rolled + if die.face in nmuch: # check if the dictionary already has the face included, and if so increase its frequency by 1 + nmuch[die.face] += 1 + else: + nmuch[die.face] = 1 # add the face to the dictionary with frequency 1 if it has not already been included + for die,face in nmuch.items(): # check if there is n of a kind for a given face, and if so, return True + if face==n: + return True + return False # otherwise return False + + def full(self,dice): + if self.nofakind(dice,3) and self.nofakind(dice,2): # check if there is a three of a kind and a two of a kind (both exact) + return True + else: + return False + +class GoalChance: + "Total of all dice by chance" + 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=total + die.face + return total \ No newline at end of file