3. Tutorial One - The Game of Pig#

3.1. Objectives#

  • Implement some simple strategies for playing a basic “jeopardy” dice game.

  • Implement a competetion to compare the effectiveness of different strategies

3.2. Outcomes#

  • Improved python programming

  • A collection of pig strategies

  • Experience of API design

3.3. What is the Game of “Pig” ?#

Pig is a jeopardy dice game. The rules are very simple but the best strategies for play are not obvious.

The book

provides a nice explanation of Pig and other related games.

3.4. Online Resources#

  • As usual, you can find useful information on Google

3.5. Thinking about Strategies#

Think of a strategy for standard Pig i.e.

  • 6 sided die

  • target score 100

  • loose round score with roll of 1

How would you describe this strategy ?

How would you represent your stragey using python ?

3.6. Programming Task#

  • Implement a strategy for pig using Python.

  • Implement a competition between two (different) strategies using Python

  • You may find the following code useful

import random
random.seed(0)
print(random.randint(1,6))
4
  • Use your code to determine which is the better of the two strategies

3.7. Extension Tasks#

  • Add someone elses strategy code to your competition.

  • Modify your code to allow for different types of Pig competition. For example

    • Change the target score

    • add a loose round score when a 2 is rolled

    • Use two dice and loose your round score if double 1 is rolled

    • a version of Pig of your own making

    • Re-implement your code in R