Sample Output From Pig Game

By Terry Hawthorne

I coded a Pig game in Python. In the game represented by the following output, I used the classic Pig strategy of rolling until I accumulated at least 20 points per turn*, then passing play to my software opponent, named Porky. The strategy didn't work in this game. Porky beat me 104-64. The only optimization I coded into Porky's strategy was to ensure that he rolled at least once per turn. Then I used a random number between 0 and 2 to determine whether Porky would continue to roll. If the random number was 0, Porky passed; otherwise, he continued to roll.

Time required to code and test in CodeSkulptor: 85 minutes.

*For an explanation of the "hold at 20" strategy, see page 3 of this document on using Pig for instructional purposes.

Sample Output

You rolled 4.
You rolled 6.
You rolled 2.
You rolled 2.
You rolled 6.
Your score for this turn: 20
Your current score is: 20.
Porky rolled 5.
Porky's score for this turn: 5
Porky's current score is: 5.
You rolled 4.
You rolled 4.
You rolled 5.
You rolled 3.
You rolled 6.
Your score for this turn: 22
Your current score is: 42.
Porky rolled 5.
Porky rolled 2.
Porky's score for this turn: 7
Porky's current score is: 12.
You rolled 4.
You rolled 2.
You rolled 1.
You lose all your points from this turn.
Let Porky show you how it's done.
Your current score is: 42.
Porky rolled 4.
Porky's score for this turn: 4
Porky's current score is: 16.
You rolled 4.
You rolled 4.
You rolled 2.
You rolled 1.
You lose all your points from this turn.
Let Porky show you how it's done.
Your current score is: 42.
Porky rolled 2.
Porky rolled 6.
Porky rolled 4.
Porky rolled 5.
Porky's score for this turn: 17
Porky's current score is: 33.
You rolled 1.
You lose all your points from this turn.
Let Porky show you how it's done.
Your current score is: 42.
Porky rolled 6.
Porky rolled 3.
Porky's score for this turn: 9
Porky's current score is: 42.
You rolled 5.
You rolled 2.
You rolled 4.
You rolled 6.
You rolled 1.
You lose all your points from this turn.
Let Porky show you how it's done.
Your current score is: 42.
Porky rolled 4.
Porky's score for this turn: 4
Porky's current score is: 46.
You rolled 6.
You rolled 4.
You rolled 5.
You rolled 3.
You rolled 4.
Your score for this turn: 22
Your current score is: 64.
Porky rolled 6.
Porky rolled 2.
Porky rolled 3.
Porky rolled 4.
Porky rolled 3.
Porky rolled 3.
Porky rolled 4.
Porky's score for this turn: 25
Porky's current score is: 71.
You rolled 5.
You rolled 4.
You rolled 1.
You lose all your points from this turn.
Let Porky show you how it's done.
Your current score is: 64.
Porky rolled 5.
Porky rolled 5.
Porky rolled 3.
Porky's score for this turn: 13
Porky's current score is: 84.
You rolled 4.
You rolled 5.
You rolled 1.
You lose all your points from this turn.
Let Porky show you how it's done.
Your current score is: 64.
Porky rolled 4.
Porky's score for this turn: 4
Porky's current score is: 88.
You rolled 5.
You rolled 1.
You lose all your points from this turn.
Let Porky show you how it's done.
Your current score is: 64.
Porky rolled 2.
Porky rolled 1.
Porky lost his bacon on this turn.
Porky's current score is: 88.
You rolled 1.
You lose all your points from this turn.
Let Porky show you how it's done.
Your current score is: 64.
Porky rolled 5.
Porky rolled 5.
Porky rolled 6.
Porky's score for this turn: 16
Porky's current score is: 104.
Oink! Oink! Porky won.