From 1d8878f10ada9969f5b0983bf71aaecf98663b23 Mon Sep 17 00:00:00 2001 From: Justin Toombs Date: Sun, 4 Feb 2024 22:31:56 -0500 Subject: [PATCH] I made several changes to the yahtzee_goals python file in order to provide the various tasks needed to win the game of Yahtzee. This style of problem solving has some similarities to our earlier assignments from the summer, but had a significant number of layers to it not seen in prior labs. While I certainly understand this method of thinking and workflow, I do not believe this is how my thinking process best understands coding. During much of the process, I needed a significant amount of help to work through and understand even the smallest of details. --- __pycache__/yahtzee.cpython-310.pyc | Bin 0 -> 4519 bytes __pycache__/yahtzee_goals.cpython-310.pyc | Bin 0 -> 8665 bytes play.py | 20 ++ yahtzee_goals.py | 259 ++++++++++++++++++++++ 4 files changed, 279 insertions(+) create mode 100644 __pycache__/yahtzee.cpython-310.pyc create mode 100644 __pycache__/yahtzee_goals.cpython-310.pyc diff --git a/__pycache__/yahtzee.cpython-310.pyc b/__pycache__/yahtzee.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b92919573513af2785ed4e1cbbf28f01aa44bef9 GIT binary patch literal 4519 zcmb_f&u<&Y6`t8$k}Hb(VOh3iId0dDU5BkhrFB!MuA?}x;q*iVmI2p7jm4U?5?5Ms zrJ1D#Emmky+Ef|Du1#UVHL6w*X1{y%~}sDHiRaOU&cj*_qjS-+S+Sv&r0C zmEn5-?mxpHE;05mx*5G}+&o58KZ6iV@R)V@Cg>JnZF0ddk8j#$olR$k2}hK^W}78wWl@1vhUSVHXccHxF$>Lw zRugm3W}wZB1!z@hi{cWrS!he*GPD}BWpM@C9JH(A8nk(6E8;q|1!$|{2DC--9`=5- za9;(jcAAA@_U3c1m2^5mS9};p-Ozg#=zecI=!A``hwDWZ6`sj%mOV!V{nm9I6pyCw;=@2na^^P+@O;J;bZ=k9aEnz z7@^&i9AjG~2G?Mv4Roj_h;5d$*QFz#vSaoSYv0;nXH3$lx>Z<>j|#in>&O!BwfKI0 zt(|njwH=uzN#~7P>jb+|ciSgB{8l2uwa!87H)}nZc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h|U^D4edPL3@C zhg562b`MxsGq6jiB-<*vmQ}`o70rRZh*m|LL9@{+{pM0%&62c66CtWmA~MiD(_UA& RkBpV;MA`btTVqSszX4$!&KCdx literal 0 HcmV?d00001 diff --git a/__pycache__/yahtzee_goals.cpython-310.pyc b/__pycache__/yahtzee_goals.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e3e8b6ad29c380bd714c47f121f58aa315adf61d GIT binary patch literal 8665 zcmcgx&2JmW72gkjiTai-%koFFj_t;DY{{|XxF3!!*RIm0i5yr$fC>l*ibF}1DXuk3 z)iEIzMQxym6a{(fI7KgWKQKV|Hz*OX%=Pg zJgS1RWGZ9HQs$DaFh^yp*mGkkuHq_zU#tZ>Qnl1OZm#s8T=1&LQ9F;_V!7h1xY{Y? z@@tM;F3jbrw(&>sSni?h9Y?iod}eH$pPM@vXxsV)0Q{v5#rAwPL9NckFU`!ZS&Msl zR~L5eTFfhyR%$U-%ol3IkKIb4Tq)*CS-;uP{ZRSk{h2j)qcF3sE3Uh-?9FWC9u>>0 z*(b%yS~l;h!pz2#{2Mb{K-=r?tdm?QT4-BskL; zs}`7;i+g10;cZJ@`c@)PC?XtsA}o^`n?s9coTg zpqbxI)>7GQIk!>BW^3tecEeR$C0-9?vzuGFQoSXa%_=vK+p#ULp!8s4kkG({Sj*_# zSe89bA%*cV18X3rc`uI=`Qy!56wP%u3}^9)>s2RF`-bBMmQ#7+cD5W%l*LA*wp1ivphe?7+P7^{6la3fCg{v;|Nd>O(A zU!RC}38wZ68bm2PjiD)Z1uo5DDe_9}1!Ob2JOp1=40DOxx6aZyy z((!QkiIpE{g5Tg6f}c1le~fPMokOQ<>?rV2>Jh%;4`6~*bNFe64>x;)k2-pSZ;mqz z!N-n=gHQa!f$+V{F+%Xk7~SBzfKK0HM}d!0Z}2S?KL&i0_-R4UD}LMyc%q>v@IK`H z0`R2c;lQJVJD9smd?EnPAEO(1uc6aJb`mEjNmBKxG=5X69}#w- z7I>2fD|f$FEUW6x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&O{+=Vf8!~S2N)zSNlVHmK-q+8{Wta>pQKShK+>p=2smv? zdXaOflk|OFw|kEvr7WDqgh(14_%I}uQ96?JJq+~^lva`sYPNMHX+Oi)_x%rH)oDif z8=dKS_=B+#IVuj)^NAw2vM897F6!br)e>PSzwhI1Rc z#Ufn1go{=#?n{s5U6y>y#Ov>^=h5w;d|2LA;b()lRRnj#OQT!kZ53(gneeii4M%!( z=ZM7TI!8W$>W&;aLu|O-Y6P3ZutW5BWXA(pSUYy4G~4nhkw0>N7NzmUQa-%hTg%}M zvpUiC@TZ5v;gqkSr{wk`AradbNc^7dOrNg1X)Zh)YdNelf)CDec5v`f{$&~hKR`DQ z=c;mmUY~%!C7r)%K19d!oVp}2l;$&o@=;hmaO$(TqtCJ8#}ds$e>sAaqXKy$k(5GQ smh6nCj*!!DrX{u1E&n_AZ4764JRck~heksGXNO)HIz4oG$Qe8NKb|!r@&Et; literal 0 HcmV?d00001 diff --git a/play.py b/play.py index a8e683c..c65213e 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..9281cd7 100644 --- a/yahtzee_goals.py +++ b/yahtzee_goals.py @@ -14,6 +14,7 @@ class GoalOnes: total += 1 return total + class GoalTwos: "Two points for each two" used = False @@ -29,6 +30,7 @@ class GoalTwos: total += 2 return total + class GoalThrees: "Three points for each three" used = False @@ -43,3 +45,260 @@ 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: + """Add total of all dice for getting three identical rolls""" + used = False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Three of a kind ({potential_score})" + + def faces(self, dice): + return[die.face for die in dice] + + def is_three_of_a_kind(self, dice): + listOfFaces = self.faces(dice) + listOfFaces.sort() + if listOfFaces[0] == listOfFaces[1] and listOfFaces[0] == listOfFaces[2]: + return True + elif listOfFaces[1] == listOfFaces[2] and listOfFaces[1] == listOfFaces[3]: + return True + elif listOfFaces[2] == listOfFaces[3] and listOfFaces[2] == listOfFaces[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 GoalFourOfAKind: + """Add total of all dice for getting four identical rolls""" + 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): + listOfFaces = self.faces(dice) + listOfFaces.sort() + if listOfFaces[0] == listOfFaces[3]: + return True + elif listOfFaces[1] == listOfFaces[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 GoalFullHouse: + """Add 25 points for getting both two and three of a kind at once""" + 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): + listOfFaces = self.faces(dice) + listOfFaces.sort() + if listOfFaces[0] == listOfFaces[1] and listOfFaces[0] == listOfFaces[2] and listOfFaces[3] == listOfFaces[4]: + return True + elif listOfFaces[2] == listOfFaces[3] and listOfFaces[2] == listOfFaces[4] and listOfFaces[0] == listOfFaces[1]: + return True + else: + return False + + def score(self, dice): + if self.is_full_house(dice): + return 25 + else: + return 0 + + +class GoalSmallStraight: + """Add 30 points for getting four numbers in order""" + 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): + listOfFaces = self.faces(dice) + listOfFaces.sort() + foundSmallStraight = False + for i in range (2): + for j in range(3): + if i == 0: + if j != 2: + if listOfFaces[j] == listOfFaces[j+1] - 1: + continue + else: + break + else: + if listOfFaces[j] == listOfFaces[j+1] - 1: + foundSmallStraight = True + else: + if j != 2: + if listOfFaces[j+1] == listOfFaces[j+2] - 1: + continue + else: + break + else: + if listOfFaces[j+1] == listOfFaces[j+2] - 1: + foundSmallStraight = True + return foundSmallStraight + + def score(self, dice): + if self.is_small_straight(dice): + return 30 + else: + return 0 + + +class GoalLargeStraight: + """Add 40 points for getting five numbers in order""" + 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): + listOfFaces = self.faces(dice) + listOfFaces.sort() + for j in range(4): + if j != 3: + if listOfFaces[j] == listOfFaces[j+1] - 1: + continue + else: + return False + else: + if listOfFaces[j] == listOfFaces[j+1] - 1: + return True + + def score(self, dice): + if self.is_large_straight(dice): + return 40 + else: + return 0 + + + +class GoalYahtzee: + """Add 50 points for getting five identical rolls""" + used = False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Five of a kind ({potential_score})" + + def faces(self, dice): + return[die.face for die in dice] + + def is_five_of_a_kind(self, dice): + listOfFaces = self.faces(dice) + listOfFaces.sort() + if listOfFaces[0] == listOfFaces[4]: + return True + else: + return False + + def score(self, dice): + if self.is_five_of_a_kind(dice): + return 50 + else: + return 0 + + +class GoalChance: + """Add total of all 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