diff --git a/__pycache__/yahtzee.cpython-310.pyc b/__pycache__/yahtzee.cpython-310.pyc index bb12e89..3aed1ee 100644 Binary files a/__pycache__/yahtzee.cpython-310.pyc and b/__pycache__/yahtzee.cpython-310.pyc differ diff --git a/__pycache__/yahtzee_goals.cpython-310.pyc b/__pycache__/yahtzee_goals.cpython-310.pyc index c8b0b1f..e281c45 100644 Binary files a/__pycache__/yahtzee_goals.cpython-310.pyc and b/__pycache__/yahtzee_goals.cpython-310.pyc differ diff --git a/play.py b/play.py index a8e683c..9e47524 100644 --- a/play.py +++ b/play.py @@ -3,12 +3,32 @@ from yahtzee_goals import ( GoalOnes, GoalTwos, GoalThrees, + GoalFours, + GoalFives, + GoalSixes, + ThreeOfAKind, + FourOfAKind, + FullHouse, + SmallStraight, + LargeStraight, + Yahtzee, + Chance ) goals = [ GoalOnes(), GoalTwos(), GoalThrees(), + GoalFours(), + GoalFives(), + GoalSixes(), + ThreeOfAKind(), + FourOfAKind(), + FullHouse(), + SmallStraight(), + LargeStraight(), + Yahtzee(), + Chance() ] game = Yachtzee(goals) diff --git a/yahtzee_goals.py b/yahtzee_goals.py index fce4e5a..6838fc1 100644 --- a/yahtzee_goals.py +++ b/yahtzee_goals.py @@ -43,3 +43,238 @@ 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"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 \ No newline at end of file