English subtitles

← 01-15 Hand Rank Attempt

Get Embed Code
2 Languages

Showing Revision 1 created 04/23/2012 by Amara Bot.

  1. [Norvig] I think it's a good time to return to hand_rank,
  2. the most complicated function we'll have to deal with.
  3. We know hand_rank takes a hand as input, but what does it return?
  4. We want it to return a value indicating the ranking of a hand,
  5. but we're not quite sure what that value should be.
  6. It has to be something that's comparable by max,
  7. so, well, why not a number?
  8. There are 9 different types of hands that we know about,
  9. from straight flush at the top to high card at the bottom,
  10. and we can number them from, say, 0 to 8,
  11. with 8 being the highest for the straight flush.
  12. So here's a sketch of a solution.
  13. We know it's going to be important to look at ranks, so let's get them first.
  14. We can extract the ranks with our card_ranks function,
  15. and then we can say first we want to check and see if we have a straight flush.
  16. So if the ranks form a straight and the cards form a flush,
  17. then we can return 8, the highest value.
  18. Otherwise what's next?
  19. Four of a kind.
  20. And the only thing we need in kind is the rank, so I'm going to just pass that in.
  21. If the ranks form 4 of a kind, then return 7.
  22. And we could go on from there.
  23. I go through the cases 1 by 1.
  24. We have straight flush, we have 4 of a kind,
  25. we would next go to full house and then flush and so on.
  26. The question is, would this work?
  27. If we continued to flesh this out and we defined the 9 different cases
  28. to return the numbers from 0 to 8, would that give us a definition of hand_rank
  29. that's a working program?
  30. And I want you to tell me yes, it would work fine in all cases;
  31. no, it would signal an error condition and crash the program;
  32. no, it would get some inputs wrong and some of them right;
  33. or no, it would get all the inputs wrong.
  34. Which do you think is correct?