0:14

This week you're going to implement a strategy player

for a simplified version of the game of Yahtzee.

Yahtzee is a dice game, so there's lots of probability and expected value here.

Okay, basically the idea is that you roll a set

of dice and then you have a choice to make.

Do you want to keep them or do you want to re-roll some or all of those dice?

So you're also going to have to

enumerate the possibilities, and there's some combinatorics here.

Okay?

All right.

So, let's take a look at how the

game works, and what you're going to need to do!

0:41

Okay.

So, as I said, Yahtzee is a dice game.

There are five dice, so you roll them.

You actually get three rolls.

Here's my first roll.

And we're going to play a simplified version, where the only way to score

is to take the sum of all the dice of a single number.

Okay?

So there are six boxes for scoring in, one thr, one through six.

And each turn, you have to pick one.

And you take the sum of the dice with that number on them, okay?

Now, I have three rolls.

So, this first roll, I got two fives.

So I want to save those and then I

can pick these other dice up and roll them again.

Okay, I got two more fives.

So now I have four fives and I'm going to put those aside

and roll my third time and this time I got a one.

All right, so I have four fives so the sum of four fives is 20.

I would be able to put 20 in the five box.

1:25

Okay.

For our version of a game.

This is the simplified scorecard.

There is a spot for ones, twos, threes, fours, fives and sixes.

Okay.

So, I just rolled four fives.

So, I have a score in the fives box and I would sum up all the fives.

So, I will get 20.

Now, if I only had one five, I would have to put a five there.

Okay.

If I had no fives, and I wanted a score

in that box I'd have to put a zero there, okay?

So it's the sum of the number of dice that match that number.

All right?

So if you're really playing this game in this way, you'd have six

turns, and each turn you'd have to fill in one of the boxes.

1:56

This is the mini-project page and you can see the

first part is an overview explaining the rules of the game.

Okay?

This is a summary of the details that I just gave you as well.

All right, once you've, sure that you understand how the

game works, okay, you can start looking at the template.

All right, here is what you're going to have to actually do.

All right, we're really asking you to write four functions here.

Score, expected_value, gen_all_holds, and strategy.

Okay?

So, what does score do?

Score takes a hand, and it computes a score for the hand, as a

maximum of the possible values for each choice of box in the upper section.

So, basically it's going to say, hey, with this

hand, here's the best score that you can get.

All right?

Expected_value, takes, you know, some number of dice that you're going to hold.

Okay, the number of sides on each dice,

and the number of dice that were originally rolled.

Okay.

And it's going to figure out what the

expected value is of rolling the remaining dice, okay?

So you have to figure out what are all the possibilities

that could happen if I rolled the remaining dice, what are

the scores that I would get for each possibility, and so

what do I expect by holding this particular set of dice?

Gen_all_holds basically takes a hand and tells you all

of the sequences of dice that you could hold.

All right.

And strategy, now, basically takes an original hand and

the number of sides on each die and tells you

which dice should you hold to maximize the expected

value of score fr, from rolling one more time, okay?

So what we're doing is simplifying the game.

Instead of getting three rolls we're basically starting from the hand that you

have after the second roll, and saying I have one more roll left.

All right?

And, so strategy will tell you what to do now.

It'll either tell you to keep all the dice you

have and tell you what your expected score is, or

it'll say hey hold this subset of the dice, roll

the rest and I expect your score to be as follows.

Okay?

And that's it.

All right.

So the idea here is simply to make the strategy function to allow

you to figure out what to do on the last roll of Yahtzee.

3:58

This is the template we are going to provide you for Yahtzee.

And you can see that we have given

you the function gen_all_sequences, which takes the possible

outcomes and the length, and this is what you would use then to roll some dice.

Okay?

[COUGH] It tells you what are all the possibilities, basically.

All right, then there are the four functions that you need to write.

Score, expected_value, gen_all_holds, and strategy.

Okay.

And then finally we have run_example, which is actually going to call

your strategy function and notice that the strategy function returns two things.

The first is an expected score.

And the second is a tuple, which the hand that you should actually hold.

Okay, all right, so, when you call your strategy function, we

have an initial hand here of one, one, one, five, six.

It's going to come back and tell you, hey, you should hold these

dice and that will expect your score to fall as you do.

When you've completed this mini-project, you'll have a strategy

planner for a simplified version of Yahtzee, where you

have a single roll and you can only score

in the upper section of the real score card, okay?

It should be easy for you to think about how

to add other scoring options and think about hey, what

are the other kinds of hands in Yahtzee I could

get, how do I score them, and maybe add those in.

All right?

We want you to start thinking though, about,

you know, probability, expected value, and enumeration, okay?

And that's really the key here, to think about how you combine

these things to actually do stuff like create such a strategy planner.