I was able to do the code of 4's, 5's, 6's, three of a kind, four of a kind, and yahtzee. The full house, straights, and chance hung me up.

I didnt mind writting classes for each problem, it was nice to think of one thing at a time instead of the whole checkpoint all together, which sometimes it has felt like that in the past. That being said, I like jupyter notebook the best still, adds more guidence which i feel I need.
This commit is contained in:
mollychi
2025-11-09 21:17:54 -05:00
parent 90c88b4385
commit f2c01b2c98
2 changed files with 165 additions and 0 deletions

20
play.py
View File

@@ -3,12 +3,32 @@ from yahtzee_goals import (
GoalOnes, GoalOnes,
GoalTwos, GoalTwos,
GoalThrees, GoalThrees,
GoalFours,
GoalFives,
GoalSixes,
GoalFourofaKind,
GoalThreeofaKind,
GoalFullHouse,
GoalSmallStraight,
GoalLargeStraight,
GoalYahtzee,
GoalChance,
) )
goals = [ goals = [
GoalOnes(), GoalOnes(),
GoalTwos(), GoalTwos(),
GoalThrees(), GoalThrees(),
GoalFours(),
GoalFives(),
GoalSixes(),
GoalFourofaKind(),
GoalThreeofaKind(),
GoalFullHouse(),
GoalSmallStraight(),
GoalLargeStraight(),
GoalYahtzee(),
GoalChance(),
] ]
game = Yahtzee(goals) game = Yahtzee(goals)

View File

@@ -1,3 +1,4 @@
from collections import Counter
class GoalOnes: class GoalOnes:
"One point for each one" "One point for each one"
@@ -40,3 +41,147 @@ class GoalThrees:
if die.face == 3: if die.face == 3:
total += 3 total += 3
return total return total
class GoalFours:
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:
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:
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:
def prompt(self, dice):
potential_score = self.score(dice)
return f"ThreeofaKind ({potential_score})"
def score(self, dice):
total = 0
for die in dice:
counts = Counter(self.dice)
for count in counts.value():
if count >= 3:
return True
return False
if True:
total += sum(self.dice)
return total
class GoalFourofaKind:
def prompt(self, dice):
potential_score = self.score(dice)
return f"FourofaKind ({potential_score})"
def score(self, dice):
total = 0
for die in dice:
counts = Counter(self.dice)
for count in counts.value():
if count >= 4:
return True
return False
if True:
total += sum(self.dice)
return total
class GoalFullHouse:
def prompt(self, dice):
potential_score = self.score(dice)
return f"FullHouse ({potential_score}"
def score(self, dice):
total = 0
for die in dice:
if
total +=25
return total
class GoalSmallStraight:
def prompt(self, dice):
potential_score = self.score(dice)
return f"SmallStraight ({potential_score}"
def score(self, dice):
total = 0
for die in dice:
if
total +=30
return total
class GoalLargeStraight:
def prompt(self, dice):
potential_score = self.score(dice)
return f"LargeStraight ({potential_score}"
def score(self, dice):
total = 0
for die in dice:
if
total +=40
return total
class GoalYahtzee:
def prompt(self, dice):
potential_score = self.score(dice)
return f"Yahtzee ({potential_score})"
def score(self, dice):
total = 0
for die in dice:
counts = Counter(self.dice)
for count in counts.value():
if count >= 5:
return True
return False
if True:
total += 50
return total
class GoalChance:
def prompt(self, dice):
potential_score = self.score(dice)
return f"Yahtzee ({potential_score})"
def score(self, dice):
total = 0
for die in dice:
if
total +=sum(self.dice)
return total