Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNicole Buckenwolf
8,721 PointsYatzy Full House scoring help - object oriented python
This question refers to the Object Oriented Python course, the challenge posed by Kenneth at the end to build out additional Yatzy scoring.
This course really lost me but I'm trying to figure it out. I am trying some of the other scoring challenges but having trouble, as what is in Kenneth's repo is fairly different from the course.
I am looking to understand how to create the scoring for Full House. I was able to get the three of a kind, four of a kind, and yatzy scoring (5 of a kind, but worth 50 instead of the sum) by reusing the score_one_pair
code Kenneth provided like so, pretty similar
def score_three_of_a_kind(self, hand):
return self._score_set(hand, 3)
def score_four_of_a_kind(self, hand):
return self._score_set(hand, 4)
def score_yahtzee(self, hand):
if self._score_set(hand, 5):
return 50
else:
print('No yahtzee here')
but I'm stuck on Full House, where the way it works in the game is the player needs to have two of one number and 3 of another, and the total points for a Full House is 25 (not the sum of the dice) - so for example,
[1, 1, 3, 3, 3]
or [5, 5, 5, 2, 2]
would both be valid Full House hands, both worth 25 points.
I'm not necessarily looking for the answer but trying to understand if there would be a way to do this using what we have already (maybe using the score_one_pair
and score_three_of_a_kind
functions to look for existence of those combos together in a hand and then return 25
? Or is the way he did it best? Why or why not?
These are from Kenneth's dice.py
file - go to the link to see the whole thing
@property
def _of_a_kind(self):
return {
1: self._by_count(1),
2: self._by_count(2),
3: self._by_count(3),
4: self._by_count(4),
5: self._by_count(5)
}
def score_full_house(self):
try:
two = max(self._of_a_kind[2])
three = max(self._of_a_kind[3])
except ValueError:
return 0
else:
if two and three:
return (two * 2) + (three * 3)
Thanks for any insight you can provide.
1 Answer
Steven Parker
231,268 PointsKenneth's "yatzy" game seems to have different scoring rules from the traditional "yahtzee". In particular, from the code shown above:
return (two * 2) + (three * 3)
The value returned for a full house is clearly the sum of the face values and not 25.
But you already have the right basic idea to implement traditional yahtzee scoring for a full house. So if you have a two-of-a-kind, and you also have a three-of-a-kind, AND if they are from different values (ie two-of-a-kind_score * 3 != three-of-a-kind_score * 2), then you would return 25 and 0 otherwise.