Share your repls and programming experiences

← Back to all posts
Yahtzee!!! 🎲🎲🎲🎲🎲
Bookie0

Yahtzee

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)


My version

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 [5] [6] [5] [5] [1], the sort() will sort them like this: [1] [5] [5] [5] [6]. 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[0] == dice[4]: 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: [1] [5] [5] [5] [6] 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[0] == dice[3] or dice[1] == dice[4]:
Again, that condition isn’t verified.

Last conditional, it checks if there is a 3 Of A Kind:
elif dice[0] == dice[2] or dice[1] == dice[3] or dice[2] == dice[4]:
Aha! So we can see that dice[1] == dice[3] 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.


Some gameplay

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.

But now I rolled 10000 times, and I’ve finally gotten 4 Yahtzees with almost two hundred 4 Of A Kinds and almost two thousand 3 Of A Kinds.


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!

Goodbyecomes 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.)

Voters
jayjay200
NDcoder
Dominicl645
user7865
DSADesmond
python88
DigitCommander
parmisss
AngelAyalaM
Name12
Comments
hotnewtop
[deleted]

Omg i so lucki :oooo

VulcanWM
potatojs
firefish

@behavingEffort Wow your die must be biased

firefish

@behavingEffort I must admire, that your photo lokks quite legitimate (jk)

Bookie0
Leroy01010
ChezTacoz
k9chelsea2

:OOOOO how did you dewit @behavingEffort ?????

codeitfast

@behavingEffort There must be a HUGE bug XD.

codeitfast
[deleted]

@k9chelsea2 lucky!!!!!

k9chelsea2

lol thx

Name12
JBloves27
Jakman

I feel your skill improving

Bookie0

thanks! ;) @Jakman

gibbsfreenergy

Really? @Jakman

Jakman

@JosephSanthosh he's growing. It might have been a slower start than usual but he is growing. I can tell

gibbsfreenergy

Oh that's cool! @Jakman

gibbsfreenergy

@Jakman I'm growing too ... sideways btw.

Jakman

@JosephSanthosh you should get that checked out. Sounds like a bad case of diabetes

gibbsfreenergy

Haha! i'm like 110 pounds, that's why u shud never be a runner for cross country or track n field. @Jakman

Jakman

@JosephSanthosh my advice for you is to not go to prison anytime soon. You are very small.

gibbsfreenergy

@Jakman Thx! I'm a freshham

gibbsfreenergy

*Freshman @Jakman

gibbsfreenergy

Freshfish @Jakman

Jakman
Alice688

I LOVE this game. Also, please check out my account and maybe follow me. UwU

Bookie0

thanks! :) @Alice688

NDcoder

You rolled: [3, 3, 3, 3, 3]
Yahtzee!!!

Cool, plus great logic explanation.

JasonLiu19

Bookie0

@JasonLiu19 lol nice! :)

Ironwolfyyy

I rolled 800 times and got 2 Yahtzees. Is that lucky?

Bookie0

i guess lol nice! @HEROBRATT

Brooks2009

You rolled: 1 times

You got:
[0] Yahtzees (0 points)
[0] 4 Of A Kinds (0 points)
[1] 3 Of A Kinds (6 points)

Total points: 6

LUCKY!!!

Bookie0
Ironwolfyyy

Lmao 🤣🤣🤣🤣🤣🤣🤣🤣

Bookie0

great @HEROBRATT

Ironwolfyyy

🤣🤣🤣🤣🤣

Ironwolfyyy

@HEROBRATT I rolled 1000000000 times

Bookie0

lmao nice @HEROBRATT

python88

out of 10 i got 1 four of a kind ond 3 3of a kinds

python88

out of 10000 i got 9 yatzees

Bookie0

nice ;) @python88

EshaanAhuja

I got 3 in 1000

Bookie0

nice ;) @EshaanAhuja

EshaanAhuja

I ate rolled 100 times and on The 72 time i got a yatgese

Bookie0

ok nice @EshaanAhuja

EshaanAhuja

I got a Yahtzee on my 108 try

Bookie0

lol nice @EshaanAhuja

VivaanSa

have you joined the language jam? (https://repl.it/jam)

Bookie0
VivaanSa
TinaChen4

I rolled 600 times to get 1 yahtzee is that lucky or unlucky?

DARIENAFZALBINM

@TinaChen4 Lucky!

python88

i got 80 yahtzees!

python88

i used automatic for 9999999999999999 times and...

DigitCommander

rolling 100000 times...

DigitCommander

@DigitCommander 74 Yahtzees

Bookie0
JSDRAGONCODER

This pretty cool! And i noticed if automatic and press random very very high number, it sort of like animation

Bookie0

lol thanks! @JSDRAGONCODER

DSAEvan

Bookie0

wow lol thats a lot! ;) @DSAEvan

Name12

to be honest, this is quite a simple code. but in compartment to your other posts, it's better. good job!

Bookie0

ok thanks! @Name12

Name12
[deleted]

So good! I really like this game. Good Job!

codeitfast

I rolled it 10 million times and got 466 yahtzees!

codeitfast

Nice! fyi, When you ask how many times to roll the dice, you asked how much times you should do it. The correct grammar for counting is "many".

Bookie0

ah ok, thanks for telling me ;) @codeitfast

codeitfast

@Bookie0 You're welcome. It doesn't really matter, tho

k9chelsea2



hmms

Bookie0

on how many rolls? @k9chelsea2

k9chelsea2

that was on the automatic roll thing and the number i did was one thousand

Bookie0

oh ok lol nice @k9chelsea2

k9chelsea2

i also inputted a massive number like 382473047028438- but after about an hour the program (or browser prolly teh latter) crashed

Bookie0
LTI2


YAS-tzee

Bookie0

lol well done ;) @LTI2

ChezTacoz

This game is 100% rigged

Bookie0
ChezTacoz

@Bookie0 I ran it for like an hour

Bookie0
ChezTacoz

@Bookie0 I have no life lol

Bookie0
SixBeeps

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.

Bookie0

@SixBeeps

Lmao yea so close 7777

Thanks :)

firefish

Just casually holding down my enter key for five minutes on normal mode

Bookie0

lmao nice! @firefish

firefish

@Bookie0 They were scrolling by really fast, had to stop and scroll up when I saw something green. Which probably wasn't the first one I got

Bookie0

Ok lol @firefish