
Title:
0115 Hand Rank Attempt

Description:

[Norvig] I think it's a good time to return to hand_rank,

the most complicated function we'll have to deal with.

We know hand_rank takes a hand as input, but what does it return?

We want it to return a value indicating the ranking of a hand,

but we're not quite sure what that value should be.

It has to be something that's comparable by max,

so, well, why not a number?

There are 9 different types of hands that we know about,

from straight flush at the top to high card at the bottom,

and we can number them from, say, 0 to 8,

with 8 being the highest for the straight flush.

So here's a sketch of a solution.

We know it's going to be important to look at ranks, so let's get them first.

We can extract the ranks with our card_ranks function,

and then we can say first we want to check and see if we have a straight flush.

So if the ranks form a straight and the cards form a flush,

then we can return 8, the highest value.

Otherwise what's next?

Four of a kind.

And the only thing we need in kind is the rank, so I'm going to just pass that in.

If the ranks form 4 of a kind, then return 7.

And we could go on from there.

I go through the cases 1 by 1.

We have straight flush, we have 4 of a kind,

we would next go to full house and then flush and so on.

The question is, would this work?

If we continued to flesh this out and we defined the 9 different cases

to return the numbers from 0 to 8, would that give us a definition of hand_rank

that's a working program?

And I want you to tell me yes, it would work fine in all cases;

no, it would signal an error condition and crash the program;

no, it would get some inputs wrong and some of them right;

or no, it would get all the inputs wrong.

Which do you think is correct?