- Review the game of pig
- Is this an algorithm?
PIG
- Each turn, a player repeatedly rolls a die until either a 1 is rolled or the player decides to "hold":
- If the player rolls a 1, they score nothing and it becomes the next player's turn.
- If the player rolls any other number, it is added to their turn total and the player's turn continues.
- If a player chooses to "hold", their turn total is added to their score, and it becomes the next player's turn.
- The first player to score 100 or more points wins.
- Why or why not?
- Can we give an algorithm to play pig?
-
Pig
- Set each players score to 0
- Give the die to the first player
- While no player has a score of 100 or more
- The player with the die takes a turn
- Pass the die to the player to the left
- Is This a good player turn algorithm?
Player Turn I
- Take a turn.
- How about this one?
Player Turn II
- Set tempScore = 0
- While tmpScore + score < 100 and you have not rolled a 1
- roll the die
- if the result is not a 1, add it to tempScore
- If tmpScore + score ≥ 100 You win.
- How about this one?
Player Turn III
- Set tempScore to 0
- Roll the die.
- If the die is 1,
- stop, turn over, no points
- Add the value to the tempScore
- Is your score plus tempScore 100 or more?
- stop, add tempScore to your score, you win
- Do you think your next roll will be a 1?
- Hold, add tmpScore to your score, stop
- Go back to step 2
- How about this one?
Player Turn IV
- tmpScore=0
- pick up the die
- shake it around in your hand
- drop it on the table
- count the number of dots that are face up.
- If there is only one dot the turn is over, stop
- if there are two dots add two to tmpScore
- if there are three dots add three to tmpScore
- if there are four dots add four to tmpScore
- if there are five dots add five to tmpScore
- if there are six dots add six to tmpScore
- store the results back into tmpScore
- Add tmpScore to totalScore
- If tmpScore plus totalScore is 100 or more stop, you win
- If you think your next roll will be a 1
- Add tmpScore to totalScore
- store the results in totalScore
- stop
- Go back to step 2.