From aac1a39b2005b3bd3046cc6085216b13c985a0a8 Mon Sep 17 00:00:00 2001 From: Danielle Tear Date: Fri, 9 Feb 2024 10:02:42 -0500 Subject: [PATCH] Completed Lab Dice --- __pycache__/dice_stats.cpython-310.pyc | Bin 0 -> 1990 bytes __pycache__/die.cpython-310.pyc | Bin 0 -> 725 bytes __pycache__/yahtzee.cpython-310.pyc | Bin 0 -> 7617 bytes __pycache__/yahtzee_goals.cpython-310.pyc | Bin 0 -> 5890 bytes dice_stats.py | 41 ++++- play.py | 20 +++ pyproject.toml | 1 - yahtzee.py | 46 +++++- yahtzee_goals.py | 190 ++++++++++++++++++++++ 9 files changed, 290 insertions(+), 8 deletions(-) create mode 100644 __pycache__/dice_stats.cpython-310.pyc create mode 100644 __pycache__/die.cpython-310.pyc create mode 100644 __pycache__/yahtzee.cpython-310.pyc create mode 100644 __pycache__/yahtzee_goals.cpython-310.pyc diff --git a/__pycache__/dice_stats.cpython-310.pyc b/__pycache__/dice_stats.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c30e8411b3bd6e86c382fe81507f89099ca8f367 GIT binary patch literal 1990 zcma)7OK%%D5GJ_~t=^WLv}s)wP0$wA#Y$=ey%?_1xbDpt=d?gTY?idW@vhb)S9u5u zP(b+s?LUx@{v-VfJ@DF-&%X82&Tu1Ha$KM*a5#L-%r`G8Z#HWLzTem%@_Ubvzi_eq zIk4D+q5lLTh@dISXhKB9(m>U;FZOe+N`~Y`{-^!+}$Y6s^t);L9(rqip6F zO1FkTgLF%_OKFRsBVE~Hey%n$_O!|aKQ2w?U_Rn%avh`MON9Ec{E zZkga9c_sIgSjH5T%|GNZ^iN^v2S7^g1rZJgZ%QYGgH_Pr9*Fv?y?r7Eyx$=^TrPxDOnMOMg2^|RxLHS^k=$Uh96GMBnJ}mtD=Z)Z4V=Kk(Fp8WviDP)s88YW zuy?<#bxejrM@>D3u9I<**?AHc!+3MP74LJW7MCh3Q literal 0 HcmV?d00001 diff --git a/__pycache__/die.cpython-310.pyc b/__pycache__/die.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..769543755ad17c7e9b1b5c238a945d98ccc892f0 GIT binary patch literal 725 zcmZ`%y^hpC47O*IY*?~Fx)zB7U6bY_L_>klNg&Z}v)wjUi08OKeqfT-iPd#`4|0_I z7!~oD(pmeT8TSL_Ke4lzt48s#bOR3FMs`Z&k^8{I>%zgIT!6-h+$x?pvE;K zd;~UZZ-DL2tPKY%NW+8VK#If6=M9%lU#Nd9Mx1le?o^C}H8RMz$mRytmMsTz1{`uE zXUH?D84vbD=?bBCFM8KP??t;r%r)G?Pe7r!f;}#UK;YY|+RNFw>S7N*maM;Tvdgx1 z8P~nbeOBjR%jPp(mHj0ZExW9~DqdxqrtDv5RsM;%EF`ydXWxDdF;OW2q9+Qe*a>bE z;dOQwc$}b)w-<_EaEB}Kfw-v|Y}flCxX26VBY7DKPDUYy8IdFqX?G*u9Jfy=yz%`% zI9<~?j}y7{vL-e=a}9(FEMv6GgO2T>V5#xig4f~?q5Dt*&qO;Vn_z_7Sh01c%QVty zG^Na#EZdTW6;vwst(hrLch~q< z^-QMJmXL;QB4rUNQWglwUPaz!on55-h*FeIl!ezUBC&vc-?`OQ-8~(`BHgN6kG^&9 zx#xWMJC9D5mpc|de?R`W=r`vq>z}-t{!j6T*QyKpbZQIFTt9|t$@;YfdtCbDkZ%EEj0ZP$!*+f$xud}`fpsHSS+ z+*ECK4Cj{WsN*=d)skAq`IuT!CvfhlRdo{Q<7!Qv!g)!ZR!`u(te#X);k=^GsIxeq zQ0LUsIIpT_Amg(|`=hY8o#j!K-+ABfC4)gYR4@1AVdQ@l%5#4!97NrYkI&8RIQ91; zoyN(~Pd2L_cp4AmEDrl|9w~o6&bIx~@5gDzURz1nPt5>5u6pv}HT8K3NBTS(Wsj}E z8nd;H7BXn^(7tRP@|mj|khq!u@q=ov6w^?=DPg*hGMb3vr@chuF7;nI?_*(p*zX&8 z{1DH>y)f>Fclzb>xWxDSY2x>E6lPK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4@Tqm*+LGWp79i>nM5>cWd6GRw3or>H*&Z(8=a6?xWp&14QmB~J zTg?nrI5X{`p?8zYGCN}w$r;T4C@sQ_miA&rM85@XEli6D?-35+G0!s*V!2&vLLeY! z?K-nzxLK+Va|Jhbn5f__>#dTW!!HsZW~d8K|Du;om3%BIFG&QZYKE%-=HfsQ^~$IR z-y)euX^IGyKM7eT;Ytbc+HSL6TJ{5tCqc=SPcnWBKC1E-;x5a)rZN~hm>}QmDAx0k z)tHnQK1Oor%?VB@9KbP!jasY;$JfM2sbp2jC>Vz{!bxf`qcgUfd$&7dT4u}KbIidt|0)r-MHP{*@{!56i-z%@%oGe6v!Wpx z_iuUOqscd_oqd#D7Ny;wc@}Rp6Pe=7EE@$V%9((1;tbwo*PpSO6XFd#`viw6&om6x zp#5sag+rJ{`0OPAoqB$W@unk1^AAUbTq)a_4E!!|3_^MqwN28Kafho&bbx*3?GWRQ z@B}bE%ScCpvXWe-Vp3unksKf(b5D!uzs0EFXX5a88s$vGGd!Z!fYU7 z4kV*ZxvryxSLYaMC6{m={@=KVqC0W-@{wW6LK4c52xPifz6Ay~|5MQKu$i+tOFe(! zb01CqMg_cC`_>>@1V4!lk%|16Ey02evDck$ZqaFi(Y z>=n2>=HkvLOLqR;|CI3R`bqu|GsGWcK~QvpV34R$pVv!4aBmd$%U@bSppsq?Xci;& z6Kqbgsj3T_Ig@7asu}*7;E?WE(-COy7ENKNR4U4q4NV>(&C6e=ZOgOUZoAb!)?P(> ss(k`quib8U+Q*lcHTz!0?i6kCC3&)F*rI*GtmYzv5GjK#S!>RJ020jkzW@LL 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..4a73b11dc8dfb39ce9f4dd93c2fe4250dc33558c GIT binary patch literal 5890 zcmb7IO>Er86(+gl{z$9UpKV!I(ri+@wfbXOaa^^in>tnM1W=$9kO3hAT7uc3q>Xo%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ek=NSy!^2WiQ)m`mk;76W)I1s^vk_HG_&lHb=)I6d)oyu@M4 zS+3SMs4hq660dGij3^!YyuSj`n;)^h8(BR56q;QQAz4I}$>Rj=+}m%p-Vade^(t@P zuK$LWdzgdAD)s83m@8lY$f*g3lDnr?N3q9EdXOmLIslR+uA$3F77IyIh?C@@jnuG^ z4mMK5er75Ywe>ZH)M1)DGH`9CuJKBtY*gFMx_+J0xe9S4Wf|-4MMvM{-BjkZ{EmJT z_YR#@+PuY1QcB8cKEjiKLXVKuF{|+!+SNEgByN+HXL*zd`5$OZJW7=5Q7Owd+SvX! zy4q{*;B}^Q>t=qhPKj=Ppq$IIf8i9xvzHl9L)J6B`)??p!@G{&NqKi!!RsfUURHMM zI`R6la^Ur(-&(5QS}Ho$RPj`QO>~m+{8T?b)z4R@QypJ)%CLpDSXtNKCoMA+NvwT` zaFODN6!NzB?Wof~$D_!8;6DxZ9rhX#V1LE^@Cw8rz^dj=gxH|j7Ix#gv(Cs0xL;tz z&uCHtjwoNiec{!2O+5OagAmdS<|V3FUJI+()T^TS*1dN-B_6 zlye#gE2&^vQN^L)+f3uKZ-xN^eVT{5i^w&tz5g)zc?!imYI~n zQDMUB_Vm2u$NysS#Yf3c*mFd>e~tSg z*N`~uq~wzQ{)CRq3Sku^{F5fcNko}WlJ5+wyI!Z^=Pj^GarZpmWB$v@h;L*avEnG# zuplU)an4~KVyJR1p>k%mY{b>Fd{DFEFE;Y3hl8CTr{qJL6umk*!bhc;%Wrg>K_`^DT)vR$Iy=5Wag9RKm~TLug|KE7 zr{#T~o3UnIX>y=BYARA>6)ZTS@}2mj-rGD|!dD=wMy*hrO#NS~U98R2=4*2^v;PPG CN*$m8 literal 0 HcmV?d00001 diff --git a/dice_stats.py b/dice_stats.py index 83a99cb..6343f77 100644 --- a/dice_stats.py +++ b/dice_stats.py @@ -1,5 +1,6 @@ from die import Die from tqdm import tqdm +from collections import Counter class FiveDice: def __init__(self): @@ -18,16 +19,44 @@ class FiveDice: if face != 1: return False return True + def is_three_of_a_kind(self): + c = Counter(self.faces()) + of_a_kind = max(c.values()) + if (of_a_kind >= 3): + return True + else: + return False + + def is_four_of_a_kind(self): + c = Counter(self.faces()) + of_a_kind = max(c.values()) + if (of_a_kind >= 4): + return True + else: + return False dice = FiveDice() -successes = 0 -trials = 1000000 -for trial in tqdm(range(trials)): +successes_3 = 0 +trials_3 = 1000000 +for trial in tqdm(range(trials_3)): dice.roll() - if dice.all_ones(): - successes += 1 + if dice.is_three_of_a_kind(): + successes_3 += 1 -print(successes/trials) +print(successes_3/trials_3) + +successes_4 = 0 +trials_4 = 1000000 +for trial in tqdm(range(trials_4)): + dice.roll() + if dice.is_four_of_a_kind(): + successes_4 += 1 + +print(successes_4/trials_4) + +test_dice = FiveDice() +counter = Counter(test_dice.faces()) +print(counter.keys()) diff --git a/play.py b/play.py index a8e683c..6feacef 100644 --- a/play.py +++ b/play.py @@ -3,12 +3,32 @@ from yahtzee_goals import ( GoalOnes, GoalTwos, GoalThrees, + GoalFours, + GoalFives, + GoalSixes, + Goal_Three_of_a_Kind, + Goal_Four_of_a_Kind, + GoalFullHouse, + GoalSmallStraight, + GoalLargeStraight, + GoalYahtzee, + GoalChance ) goals = [ GoalOnes(), GoalTwos(), GoalThrees(), + GoalFours(), + GoalFives(), + GoalSixes(), + Goal_Three_of_a_Kind(), + Goal_Four_of_a_Kind(), + GoalFullHouse(), + GoalSmallStraight(), + GoalLargeStraight(), + GoalYahtzee(), + GoalChance() ] game = Yachtzee(goals) diff --git a/pyproject.toml b/pyproject.toml index 1934113..aff548f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,6 @@ name = "lab-dice" version = "0.1.0" description = "" authors = ["Chris Proctor "] -readme = "README.md" [tool.poetry.dependencies] python = "^3.10" diff --git a/yahtzee.py b/yahtzee.py index 8ae2b41..93c9424 100644 --- a/yahtzee.py +++ b/yahtzee.py @@ -5,17 +5,28 @@ class Yachtzee: This version of Yahtzee is initialized with a list of goals. """ def __init__(self, goals): + '''Initializes a game of Yahtzee. The initial score is 0, and all goals are available. + Also creates the five dice that will be used for this game.''' self.score = 0 self.goals = goals self.dice = [Die() for num in range(5)] def play(self): - print("Welcome to Yachtzee!") + '''Plays a game of Yahtzee. + Starts by welcoming the player and will continue playing rounds until all goals have been used. + Once all goals have been used, the game ends and the final score is presented to the player.''' + print("Welcome to Yahtzee!") while self.count_unused_goals() > 0: self.play_round() print(f"Your final score was {self.score}") def play_round(self): + '''Plays a single round of Yahtzee. + Prints a line to divide this round from the previous round. + The five dice are rolled to start, and the player is shown the current game status. + The player can choose to re-roll up to three times with the ultimate end choosing a goal. + The round concludes when a player chooses a goal to apply their dice toward. + This goal is marked as used, and the appropriate score from that round is added to the total.''' print("=" * 80) self.rolls_left = 3 for die in self.dice: @@ -26,10 +37,16 @@ class Yachtzee: self.score += goal.score(self.dice) def show_status(self): + '''Shows the player their current status. + Displays the currrent values on the faces of the five dice, the current score and + the number of re-rolls remaining for this round.''' dice = ', '.join([str(die) for die in self.dice]) print(f"Score: {self.score}. Rolls left: {self.rolls_left}. Dice: {dice}.") def choose_goal(self): + '''Finds which goals the player can choose from and whether or not the player can re-roll. + If the player has re-rolls remaining and chooses to re-roll, they can. + Otherwise, they choose a goal and this function returns the goal chosen.''' options = [] unused_goals = self.get_unused_goals() for goal in unused_goals: @@ -46,6 +63,11 @@ class Yachtzee: return unused_goals[choice] def get_choice(self, options): + '''Prompts the player to choose an option, either a goal or to re-roll + depending on whether the player has re-rolls remaining. + Each option is assigned a number. Checks to see if the player's response is + valid. Informs the player if their choice is invalid. When the player chooses + a valid option, the number corresponding to that option is returned''' print("What would you like to do?") for i, option in enumerate(options): print(f"{i}. {option}") @@ -56,6 +78,12 @@ class Yachtzee: return int(choice) def option_choice_is_valid(self, choice, options): + '''Checks to see if the option a player chose was valid. + First checks to see if the option chosen was presented in the form of a number. + If the choice was a number, then checks to see if that number was one of the + possible options presented to the player. If it was then the choice is valid. + If the choice was not a number or if the number was not a possible option, + then the choice is not valid.''' if not choice.isdigit(): return False if int(choice) < 0: @@ -65,9 +93,11 @@ class Yachtzee: return True def count_unused_goals(self): + '''Returns the number of goals the player has not yet used.''' return len(self.get_unused_goals()) def get_unused_goals(self): + '''Creates a list of goals the player has not yet used.''' unused_goals = [] for goal in self.goals: if not goal.used: @@ -75,6 +105,9 @@ class Yachtzee: return unused_goals def reroll(self): + '''Re-rolls the dice chosen by the player. + Decreases the number of re-rolls remaining for this round by 1 and + and rolls the dice that need to be re-rolled''' self.rolls_left -= 1 choices = self.get_reroll_choices() dice_to_reroll = self.get_dice_to_reroll(choices) @@ -82,6 +115,9 @@ class Yachtzee: die.roll() def get_dice_to_reroll(self, choice_ints): + '''This function returns the dice that need to be re-rolled. + The dice that the player wants to re-roll are removed and placed into a list + and this list of dice to re-roll is returned''' dice_to_reroll = [] for die in self.dice: if die.face in choice_ints: @@ -90,6 +126,10 @@ class Yachtzee: return dice_to_reroll def get_reroll_choices(self): + '''Prompts the player to select which dice they would like to re-roll. + Checks to see that the input is valid. If it is not valid, the player + is prompted to enter number values of dice they want to re-roll. + Returns a list of the dice values to re-roll.''' print("Which dice do you want to re-roll?") choices = input("> ") while not self.reroll_choices_are_valid(choices): @@ -99,6 +139,10 @@ class Yachtzee: return choice_ints def reroll_choices_are_valid(self, choices_str): + '''This function checks to see if choices for re-rolls are valid. + First checks if the values the player wants to re-roll are numbers. + Then checks that each value the player wants to re-roll corresponds + to a unique dice-value the player currently has.''' if not choices_str.isdigit(): return False choice_ints = [int(digit) for digit in choices_str] diff --git a/yahtzee_goals.py b/yahtzee_goals.py index fce4e5a..9755ff1 100644 --- a/yahtzee_goals.py +++ b/yahtzee_goals.py @@ -1,3 +1,5 @@ +from collections import Counter + class GoalOnes: "One point for each one" @@ -43,3 +45,191 @@ 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 Goal_Three_of_a_Kind: + "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 score(self, dice): + total = 0 + faces = [] + for die in dice: + faces.append(die.face) + total += die.face + c = Counter(faces) + of_a_kind = max(c.values()) + if (of_a_kind >= 3): + return total + else: + return 0 + + +class Goal_Four_of_a_Kind: + "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 score(self, dice): + total = 0 + faces = [] + for die in dice: + faces.append(die.face) + total += die.face + c = Counter(faces) + of_a_kind = max(c.values()) + if (of_a_kind >= 4): + return total + else: + return 0 + +class GoalFullHouse: + "25 Points" + used = False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Full House ({potential_score})" + + def score(self, dice): + faces = [] + for die in dice: + faces.append(die.face) + c = Counter(faces) + if len(c) == 2 and (3 in c.values()) and (2 in c.values()): + return 25 + else: + return 0 + +class GoalSmallStraight: + "30 Points" + used = False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Small Straight ({potential_score})" + + def score(self, dice): + faces = [] + for die in dice: + faces.append(die.face) + c = Counter(faces) + if (len(c) >= 4): + if (1 in c.keys()) and (2 in c.keys()) and (3 in c.keys()) and (4 in c.keys()): + return 30 + elif (2 in c.keys()) and (3 in c.keys()) and (4 in c.keys()) and (5 in c.keys()): + return 30 + elif (3 in c.keys()) and (4 in c.keys()) and (5 in c.keys()) and (6 in c.keys()): + return 30 + else: + return 0 + else: + return 0 + +class GoalLargeStraight: + "40 Points" + used = False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Large Straight ({potential_score})" + + def score(self, dice): + faces = [] + for die in dice: + faces.append(die.face) + c = Counter(faces) + if (len(c) >= 5): + if (1 in c.keys()) and (2 in c.keys()) and (3 in c.keys()) and (4 in c.keys()) and (5 in c.keys()): + return 40 + elif (2 in c.keys()) and (3 in c.keys()) and (4 in c.keys()) and (5 in c.keys()) and (6 in c.keys()): + return 40 + else: + return 0 + else: + return 0 + +class GoalYahtzee: + "50 Points" + used = False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Yahtzee ({potential_score})" + + def score(self, dice): + faces = [] + for die in dice: + faces.append(die.face) + c = Counter(faces) + of_a_kind = max(c.values()) + if (of_a_kind == 5): + return 50 + else: + return 0 + +class GoalChance: + "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 + faces = [] + for die in dice: + total += die.face + return total