Hello hello hello!
I made Yahtzee! (Kinda)
So what is Yahtzee?
Yahtzee is a popular dice game where you have 5 dice (each dice having 6 sides, and the numbers 1 - 6 written on the sides. Just normal dice). The aim of the game is to roll those dice and to try to get at least 3 dice of the same value. The full game has a few more stuff, what I have done is a bit more simplified. Rolling all five dice with the same number (like all of them have the number 2) gets you the most points possible. That is called Yahtzee. (I think you’re supposed to shout that out loud if you get it xDD)
So like I said earlier, what I did is a simplified version of the game. Mine is kinda a simulation.
You will be able to either roll the dice manually (by pressing enter) or by doing it automatically for a number of times set by you (careful not to put a value too big or it’ll crash!).
At the end of the simulations, you will be given a summary with how many rolls you did, how much times you got 3 Of A Kinds/4 Of A Kinds/Yahtzees, and your total points. In this version, I put 3 Of A Kinds at 6 pts, 4 Of A Kinds at 12 pts, and Yahtzees at 50 pts.
How this was made
Ok, so first of all, I have my list containing 5 dice. I then rolled a random number from 1 to 6 for each of the 5 dice. remember that lists start at index 0.
Next, instead of using loads and loads of
if statements to check if the numbers are the same, I just used the
sort(). This sorts the dice from smallest to largest.
So for example, if I rolled
    , the
sort() will sort them like this:
    . As you can see, I have a 3 Of A Kind.
Next, I use a bit of conditionals to determine if I scored anything. Like if I scored a Yahtzee, that would mean that all the dice are the same. So I can just do
if dice == dice: which checks if the 1st dice equals the last dice. Since the dice are already arranged from smallest to largest, then it sees that I got a Yahtzee!
Lets go back to my 1st example.
These are my dice:
     and they are sorted from smallest to largest. The first
ifstatement checks if there is Yahtzee. Is the first index equal to the last one? No, so no Yahtzee.
Then, it checks if its a 4 Of A Kind like this:
elif dice == dice or dice == dice:
Again, that condition isn’t verified.
Last conditional, it checks if there is a 3 Of A Kind:
elif dice == dice or dice == dice or dice == dice:
Aha! So we can see that
dice == dice which means that the dice at index 1 = the dice at the index 3. This means that I have scored a 3 Of A Kind!
(I hope that wasn’t too long/unnecessarily boring or complicated ;)
Chances of getting a Yahtzee
Planning on getting those 50 points? You’ll have to be very, very, very, very lucky. Lets do the math:
There are 5 dice, each with 6 sides. This means there are 6 x 6 x 6 x 6 x 6 = 6^5 = 7776 possible different combinations. A lot.
So if you want all the dice to have the same numbers; you have 6 possibilities (five 1s, five 2s, five 3s, etc.).
Next, we divide the number of possible Yahtzees (6) by the total possible rolls (7776), you get 6/7776 = 1/1296.
Yep, the odds of getting a Yahtzee is 1 chance over 1296. That’s about 0.08 percent.
As you can see, I’ve rolled 10 times, and only gotten one 3 Of A Kind, no Yahtzee (duh).
I roll 100 times, and I’ve gotten six 4 Of A Kinds and nineteen 3 Of A Kinds, still no Yahtzee.
I roll 1000 times, twenty-two 4 Of A Kinds and one hundred and eighty eight 3 Of A Kinds, and still no Yahtzees again.
Well, that’s all I think. Try this out and tell me what you think. I find it mind boggling how many possibilities there are in only 5 dice, and how hard it is to get a Yahtzee.
So if y’all every play the actual game, just know that you’ll have to throw dice a few thousand times to get some Yahtzees!
Everyone have an amazing day! =)
PS: Fun Fact Because Why Not!
from Godbwye which is a contraction of the phrase
God Be With Ye. So yea good bye!
(Source: I think I read it in the NYT but here is where I looked it up from: https://www.todayifoundout.com/index.php/2012/01/where-the-term-goodbye-comes-from/#:~:text=%E2%80%9CGoodbye%E2%80%9D%20comes%20from%20the%20term,Gabriel%20Harvey%20wrote%20in%201573.)
So good! I really like this game. Good Job!
I find it mind boggling how many possibilities there are in only 5 dice, and how hard it is to get a Yahtzee.
So I did the math and the answer kinda angers me. There are 6 faces on a die, and there are 5 dice, so the answer is 6^5
Which is 7776
Which is soooo close to 7777, but isn't.
Good work on this btw.