From 055f1634090d40d283307e8ec9759e3f132741f9 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 11 Feb 2024 15:06:46 -0500 Subject: [PATCH] completed checkpoint 3 by adding the yahtzee goals At first, I had lots of difficulty trying to get used to OOP. However, I do believe I am starting to understand it. It was not difficult to expand the code since OOP was used. This method of problem solving is more organized than how I would have written a Yahtzee program using my past experience. I would have had to use many more functions and it would be tougher to stay organized and expand as we had to do in this assignment. I like how it was structured in the different files. This made it easy to debug. This method of problem solving might be tougher to get started due to its more complex nature, but the coder will reap the benefits when trying to debug or expand the code. --- __pycache__/dice_stats.cpython-310.pyc | Bin 1403 -> 2238 bytes __pycache__/yahtzee_goals.cpython-310.pyc | Bin 1391 -> 5941 bytes dice_stats.py | 4 +- play.py | 20 +++ yahtzee_goals.py | 187 ++++++++++++++++++++++ 5 files changed, 209 insertions(+), 2 deletions(-) diff --git a/__pycache__/dice_stats.cpython-310.pyc b/__pycache__/dice_stats.cpython-310.pyc index 13353376d08b926550aef9aa036d729d6b24c0a4..b4edc1a58c82377982bed133c9282d81baa651d9 100644 GIT binary patch delta 938 zcmb_ZOK(y^6rP#;VBkJz3qA_OT!SnK+QgO7U}BV@aY352bwOfouFQ~JK1njcJ!G{R8e?`Umh%#)=qILc|WSg}ut+LMMbZ;__ae<&@H{0sf21N7*O-UE8- zJi4%UNZFpg-J;d$#~WFZdPSNEVF?=~7Y;bxcVC`pG(FqXOOqDG+P^OyWCG3uIE!rn zL02|=V~%M=j>!qBk*BFKi)h3)iO?<))T*TKMD&=(-sD(|G@&0Dsziw}c1XVpv)kP4W*aT5Sz}(74%|s2|Di5$*pEH#K<uL?J>9Fm~ptbL}!eQ@F zDs>?y^@h*=u&v@CF(lEv(HZ!M`$|gi`GJ4X>4_}Z7ZVJ%L2ZhMQp%8=9 zZT~;4JF789*?8z)*!BVshaM*yWw4XqjE%B8Tj-CIXYI_YM)6S%3bu(&U1na@HJz@( RC*fuG~H`xl!{zX3am%8UR2 delta 162 zcmdld_?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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