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