Yahtzee Full House

0 views
Skip to first unread message

Mike Fowler

unread,
Aug 3, 2024, 3:32:35 PM8/3/24
to taicontlute

Hey guys this is my first post on here so take it easy on me! Apologies in advance for how basic this question is as I'm a beginner. I'm in the process of self learning and googling has been my best friend so far but I'm struggling to work out what's going wrong here. Maybe it is my approach altogether...

I am building a very simple game of Yahtzee with Javascript as my first project. Most of the program works smoothly however I can't seem to get the logic right for a full house. For anyone that doesn't know Yahtzee is played with 5 dice and a full house is a pair combined with 3 of a kind so for example [1, 1, 1, 6, 6] or [4, 4, 5, 5, 5]. I have a generated array with .sort() applied so my thinking is the logic should be if index 0 = index 2 and index 3 = index 4 OR index 0 = index 1 and index 2 = index 4. I have tried with multiple nested if statements and without nested parentheses but no luck there either. I understand it must be how I've used the logical operator as the first parentheses of code in each if statement works by itself.

It's more complicated than it needs to be to sort and then test. It's also slower. Try this, to count how many occurrences of each number, and check that you've got a 3 and a 2. You don't need to sort the array first.

Note that this will return false for a Yahtzee where all five are the same. It would be easy enough to add a check5 to allow for this if you want that to return true. (Really it ought to return true, since it's allowable to count a Yahtzee as a full house if you want to.) It would then become:

If you want to check the correctness of your code i would recommend Unit Tests (eg. with Junit). Try to test as many cases as possible, using Parameterized Tests might help. See: -java/junit/junit-parameterized-test-example/

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.

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

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?

Yahtzee is a dice game made by Milton Bradley (a company that has since been acquired and assimilated by Hasbro). It was first marketed under the name of Yahtzee by game entrepreneur Edwin S. Lowe in 1956. The game is a development of earlier dice games such as Poker Dice, Yacht and Generala. It is also similar to Yatzy, which is popular in Scandinavia.

The objective of the game is to score points by rolling five dice to make certain combinations. The dice can be rolled up to three times in a turn to try to make various scoring combinations and dice must remain in the box. A game consists of thirteen rounds. After each round, the player chooses which scoring category is to be used for that round. Once a category has been used in the game, it cannot be used again. The scoring categories have varying point values, some of which are fixed values and others for which the score depends on the value of the dice. A Yahtzee is five-of-a-kind and scores 50 points, the highest of any category. The winner is the player who scores the most points.

Yahtzee was marketed by the E.S. Lowe Company from 1956 until 1973. In 1973, the Milton Bradley Company purchased the E.S. Lowe Company and assumed the rights to produce and sell Yahtzee. During Lowe's ownership, over 40 million Yahtzee games were sold worldwide. According to the current owner, Hasbro, as of 2007, 50 million Yahtzee games are sold each year.[1] A classic edition is currently being marketed by Winning Moves Games USA.

The most important predecessor of Yahtzee is the dice game Yacht, which is an English cousin of Generala and dates back to at least 1938.[2] Wood[2] classifies Yacht, and a similar three-dice game called Crag, as sequence dice games. Yahtzee is similar to Yacht in both name and content. Although Yahtzee is clearly derived from Yacht, it differed from it in a number of significant ways:

The present-day commercial Yahtzee began when toy and game entrepreneur Edwin S. Lowe filed Yahtzee as a trademark with the U.S. Patent Office on April 19, 1956. The first commercial usage of the name Yahtzee was a few weeks earlier on April 3. Lowe classified his product as a Poker Dice Game. Lowe is also responsible for introducing Bingo to the U.S. market.[3]

According to Hasbro, the game was invented by an anonymous Canadian couple, who called it The Yacht Game because they played it on their yacht with their friends.[1] Later they asked Lowe if he would make up some sets to be given as gifts to their friends who enjoyed the game. Lowe perceived the possibility of marketing the game, and acquired the rights to the game from the couple in exchange for 1,000 gift sets. This story is expanded by Lowe in the 1973 book A Toy is Born by Marvin Kaye. According to Lowe, the game did not initially do well commercially, since the rules and appeal were not easily conveyed in an advertisement. Eventually, he had the idea of organizing Yahtzee parties at which people could play the game and thereby gain a first-hand appreciation of it. The idea was successful, and enthusiasts quickly popularized the game through word of mouth.

The game and its contents were copyrighted by Lowe in 1956, 1961, 1967, and 1972. In 1973, Milton Bradley purchased the E.S. Lowe Company and assumed the rights to produce and sell Yahtzee. During Lowe's ownership over 40 million Yahtzee games were sold in America and around the globe. The game has maintained its popularity. According to current owner Hasbro, as of 2007, 50 million Yahtzee games are sold each year.[1]

Over time, the Yahtzee logo has taken several forms. The original version of the logo was used throughout the entire period that the game was produced solely by the Lowe company. After 1973, the logo changed various times. This logo is found on the scorecards and the game box(es).

The game consists of 13 rounds. In each round, a player gets three rolls of the dice, although they can choose to end their turn after one or two rolls. After the first roll the player can save any dice they want and re-roll the other dice. This procedure is repeated after the second roll. The player has complete choice as to which dice to roll. It is possible to re-roll both dice that were or were not rolled before.[4]

The Yahtzee scorecard contains 13 different category boxes. After completing each round, a player must enter a score in one of these category boxes. The score entered in the box depends on how well the five dice match the scoring rule for the category. Once a score has been entered for a category, that category may not be used again by that player in that game. The game is completed after 13 rounds by each player, with each of the 13 boxes filled. The total score is calculated by summing all thirteen boxes, together with any bonuses.[4]

Details of the scoring rules for each category are given below. As an example, one of the categories is called Three of a Kind. The scoring rule for this category means that a player only scores if at least three of the five dice are the same value. If a player chooses to score a roll in this category even though they do not have at least three dice of the same value, their score will be 0.

If a player scores a total of 63 or more points in these six boxes, a bonus of 35 is added to the upper section score. Although 63 points corresponds to scoring exactly three-of-a-kind for each of the six boxes, a common way to get the bonus is by scoring four-of-a-kind for some numbers so that fewer of other numbers are needed. A player can earn the bonus even if they score a "0" in an upper section box.[4]

In order to gauge how well a player is doing in the upper section, they often refer to being "up" or "down" compared to the average of three required for each box. So that if a player scores four "sixes" they will be "6 up"; while if they then score just two "twos" they will then be only "4 up". Similarly, if a player starts with two "twos" they will be "2 down".[4]

Some players count five of the same number (called a "Yahtzee") as being a valid Full House. However, the official rule is that a Full House is "three of one number and two of another".[4] Small Straight and Large Straight are sometimes called Low and High, Short and Long Straight, or Little and Big Straights.[4]

If a category is chosen but the dice do not match the requirements of the category the player scores 0 in that category. Some combinations offer the player a choice as to which category to score them under; e.g., a full house could be scored in the Full House, the Three-Of-A-Kind, or the Chance categories. The Chance category is often used for a turn that will not score well in any other category.[4]

A Yahtzee occurs when all five dice are the same. If the player throws a Yahtzee and has already filled the Yahtzee box with a score of 50, they score a Yahtzee bonus and get an extra 100 points. However, if they throw a Yahtzee and have filled the Yahtzee category with a score of 0, they do not get a Yahtzee bonus.[4]

c80f0f1006
Reply all
Reply to author
Forward
0 new messages