It's a little early in the morning and I can't think straight yet. We are out of coffee and I'm waiting for my wife to return home from her shoping. So instead of helping you directly, I'll give you a few tips on how to solve this and other similar problems in the future.
How to deal with stuff - Crash Course
First you are going to grab that text and make certain keywords strike out.
A player must use both numbers of a roll
if this is legally possible (
or all four numbers of a double).
When only one number can be played, the player must play that number.
Or if either number can be played
but not both, the player must play the larger one.
When neither number can be used, the player loses his turn.
In the case of doubles,
when all four numbers cannot be played, the player must play as many numbers as he can.
Look at how all the when's, if's, or's, and's, but's have been emphasized. These are words that generally orient your code. They have direct relation to constructs that exist in the programming language. If Statements, AND, OR, etc...
What other keywords should I emphasize, you may ask. Too many, I say. But here's a few more other than those above: "until", "while", "for every", etc...
Next we grab that text and separate it into it's smaller parts (aka phrases).
Code:
A player must use both numbers of a roll if this is legally possible (or all four numbers of a double).
When only one number can be played, the player must play that number.
Or if either number can be played but not both, the player must play the larger one.
When neither number can be used, the player loses his turn.
In the case of doubles, when all four numbers cannot be played, the player must play as many numbers as he can.
You are getting there. Suddenly all starts to become easier to understand, doesn't it? Notice how I formated the text so that those lines that are dependent of the previous line (i.e. lines that exist in the context of the previous line) are indented to the right. This is another visual clue to help you better understand the text.
On many situations we stop here. You can already construct your code from here. But for the fun of it lets dig deeper imagining this was a more complex problem.
Next we enter to the realm of text analysis. We are going to spot one or more trends and insert them in the text as visual clues. So... first lets get something straight. What is the text referring to? It is talking about movement rules. What is that the text assumes you know already? That you throw two dice and if it's doubles it is as if you had thrown 4 dice.
So... With that in our baggage let's analyse the text and simply indicate shortly what each line is talking about.
Code:
[When to use rolls]
A player must use both numbers of a roll if this is legally possible (or all four numbers of a double).
[If can't play all rolls]
When only one number can be played, the player must play that number.
Or if either number can be played but not both, the player must play the larger one.
In the case of doubles, when all four numbers cannot be played, the player must play as many numbers as he can.
[If can't play any rolls]
When neither number can be used, the player loses his turn.
Wow! Many changes. First... I simply added small text to the top of each line that describes what the line is talking about. If more than one line talks about the same thing they all are left bellow this indicator text.
But what is important here is that I moved the last line further up. When doing this I suddenly realize that the last line has nothing to do after all with not being able to play any rolls. If you read it carefully it is obviously describing a situation where you rolled a double, you can can use some of the movements allowed, but not all.
This is the importance of this step. It helps you restructure the code so that you spot possible errors or imperfections in the language used by the writer. And in doing so, it helps you better structure your thoughts and... you got it right, eventually the code.
Next... we are going to change the actual text. It is about time we get into pseudo code. We are going to reformat the whole text so that it resembles (but is not!) C++.
Code:
[When to use rolls]
if (all_rolls_possible)
do them;
[If can't play all rolls]
if (only_one_move_possible)
do it;
if(either_roll_can_be_played_but_not_all)
if(it_was_a_double_roll)
do play_as_many_as_you_can;
else
do play_the_larger_one;
[If can't play any rolls]
if(no_roll_can_be_played)
do lose_turn;
I can already smell C++ code. Can you?
From here on it's programming already. The next step is to refine the pseudo code. You should create some variables in pseudo code and use them instead of the descriptive names. http://en.wikipedia.org/wiki/Pseudocode
There's no fixed rules for Pseudo code. It's up to you to devise your own if you intend to use it only for yourself. If you intend to share it then just read the above link for a few guidelines. But remember there's is no set syntax for pseudo code as there is for C++. It's purpose is to describe the programming logic in order to help coding.
And that's it. And my coffee hasn't come home yet