English subtitles

← 05-07 Hold And Roll Solution

dummy description

Get Embed Code
1 Language

Showing Revision 1 created 05/13/2012 by Amara Bot.

  1. Here's my solution:
  2. So, I have my state--I just broke it up into pieces so that I know what I'm talking about.
  3. Then if I hold it becomes the other player's turn.
  4. The other player's score is the same as it was before.
  5. So now remember the second place is the score of the player whose turn it is.
  6. So, that was you previously, and then the score that I got--I just add in the pending.
  7. I reap all of those, and the pending gets reset to zero.
  8. When I roll, again let's figure out what's in the state,
  9. if the roll is one that's a pig out,
  10. it becomes the other player's turn, and I only got one lousy point.
  11. Pending gets reset to zero.
  12. If the role is not a one then it's still my turn.
  13. I don't change my score so far, but I add d onto the pending.
  14. Here's just a way to map from one player to the other.
  15. If the other player, if it was one it becomes zero.
  16. If it was zero it becomes one.
  17. It's always a great idea to write some test cases.
  18. Now, one comment on style.
  19. Right here I'm taking this state, which is a tuple that has four components,
  20. and I'm breaking it up like this into it's four components.
  21. When you have four components that's probably okay,
  22. but it's getting to worry me a little bit that maybe I won't be able to remember
  23. which part of the state is which.
  24. If I had more than four, if I had five or six components,
  25. I really start to worry about that.
  26. So there are other possibilities where we can be more explicit about what the state is
  27. rather than just have it be a set of undifferentiated elements of a tuple
  28. that we then define like this.
  29. We can define it ahead of time.