diff --git a/__pycache__/dice_stats.cpython-310.pyc b/__pycache__/dice_stats.cpython-310.pyc index 1335337..b4edc1a 100644 Binary files a/__pycache__/dice_stats.cpython-310.pyc and b/__pycache__/dice_stats.cpython-310.pyc differ diff --git a/__pycache__/yahtzee_goals.cpython-310.pyc b/__pycache__/yahtzee_goals.cpython-310.pyc index 791e8e2..53cb84a 100644 Binary files a/__pycache__/yahtzee_goals.cpython-310.pyc and b/__pycache__/yahtzee_goals.cpython-310.pyc differ diff --git a/dice_stats.py b/dice_stats.py index e77caa3..7605add 100644 --- a/dice_stats.py +++ b/dice_stats.py @@ -36,7 +36,7 @@ class FiveDice: dice = FiveDice() - +''' successes = 0 trials = 1000000 for trial in tqdm(range(trials)): @@ -66,5 +66,5 @@ for trial in tqdm(range(trials)): print('four of a kind odds') print(successes/trials) print('_'*80) - +''' diff --git a/play.py b/play.py index a8e683c..153104a 100644 --- a/play.py +++ b/play.py @@ -3,12 +3,32 @@ 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_goals.py b/yahtzee_goals.py index fce4e5a..3aa41be 100644 --- a/yahtzee_goals.py +++ b/yahtzee_goals.py @@ -43,3 +43,190 @@ 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 for 3 of a kind" + used = False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"3 of a kind ({potential_score})" + + + def score(self, dice): + total = 0 + flag = False + of_each_counter={1:0, 2:0, 3:0, 4:0, 5:0, 6:0} + for die in dice: + + of_each_counter[die.face]=of_each_counter[die.face]+1 + for num_of in of_each_counter.values(): + if num_of>=3: + flag = True + if flag: + for die in dice: + total += die.face + return total + +class GoalFourOfAKind: + "Sum of all dice for 4 of a kind" + used = False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"4 of a kind ({potential_score})" + + + def score(self, dice): + total = 0 + flag = False + of_each_counter={1:0, 2:0, 3:0, 4:0, 5:0, 6:0} + for die in dice: + of_each_counter[die.face]=of_each_counter[die.face]+1 + for num_of in of_each_counter.values(): + if num_of>=4: + flag = True + if flag: + for die in dice: + total += die.face + return total + +class GoalFullHouse: + "25 points for full house" + used = False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Full House ({potential_score})" + + + def score(self, dice): + total = 0 + of_each_counter={1:0, 2:0, 3:0, 4:0, 5:0, 6:0} + for die in dice: + of_each_counter[die.face]=of_each_counter[die.face]+1 + if 3 in of_each_counter.values() and 2 in of_each_counter.values(): + total=25 + return total + +class GoalSmallStraight: + "30 points for small straight" + used = False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Small Straight ({potential_score})" + + + def score(self, dice): + total = 0 + nums=[] + for die in dice: + nums.append(die.face) + op1=(1 in nums and 2 in nums and 3 in nums and 4 in nums) + op2=(2 in nums and 3 in nums and 4 in nums and 5 in nums) + op3=(3 in nums and 4 in nums and 5 in nums and 6 in nums) + if op1 or op2 or op3: + total=30 + return total + +class GoalLargeStraight: + "40 points for Large straight" + used = False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Large Straight ({potential_score})" + + + def score(self, dice): + total = 0 + nums=[] + for die in dice: + nums.append(die.face) + op1=(1 in nums and 2 in nums and 3 in nums and 4 in nums and 5 in nums) + op2=(2 in nums and 3 in nums and 4 in nums and 5 in nums and 6 in nums) + if op1 or op2: + total=40 + return total + +class GoalYahtzee: + "50 points for Yahtzee" + used = False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Yahtzee ({potential_score})" + + + def score(self, dice): + total = 0 + flag=True + for die in dice: + if die!=dice[0].face: + flag=False + if flag: + total=50 + return total + +class GoalChance: + "Sum of all dice for 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 += die.face + return total