CIS200: Assignment 2
10 points. Due Saturday, February 9, 2008, 10:00pm

You will build a program that lets a human user play a dice game, called ``Doubles,'' against the computer.

How to play ``Doubles'': The object of the game is to achieve the highest score of all the players. In the computerized version, you compete against the computer. You go first.

  1. You start by throwing two dice, and your score is the sum of the two numbers. If the two dice show the same number, this is a ``Double'' and your score is doubled. At this point, you can stop and let the computer try to beat your score. Or, you can throw one last die.
  2. If you have a Double and you throw the third die, then, if the third die is the same number again, you have thrown a ``Triple'' and you win --- the game ends immediately. Otherwise, you subtract the score of the third die from your total score --- this is your penalty. For example, if you threw 5 and 5 and then chose to throw the third die and it was 4, then your score is ((5 + 5) * 2) - 4 == 20 - 4 == 16.
  3. If you did not throw a Double and you choose to throw the third die, then your total score is the sum of the first two dice plus half the score of the third die (drop any fraction). For example, if you threw 6 and 4 and then threw a 5, your score is (6 + 4) + (5/2) == 10 + 2 == 12.
  4. If you did not win by throwing a Triple, then the computer plays its turn and tries to equal or beat your score. The computer plays under the same rules you did.
  5. At the end of the game, if neither player threw a Triple, then the player with the higher score wins. If it is a tie, then the you win.

Sample behaviors of the program, Doubles.py:

>python Doubles.py
Welcome to Doubles!  You play first:
You rolled 6 and 3
Your score is 9
Do you want to throw the third die (y or n)?: y
Your third die is 5
Your total score is 11

The computer plays next:
The computer rolled 2 and 2
A Double!
Its score is 8
The computer will throw a third die.
It is a 3
The computer's score is reduced.
The computer's total score is 5

Congratulations --- you won!
Press Enter to finish


>python Doubles.py
Welcome to Doubles!  You play first:
You rolled 4 and 2
Your score is 6
Do you want to throw the third die (y or n)?: y
Your third die is 4
Your total score is 8

The computer plays next:
The computer rolled 5 and 5
A Double!
Its score is 20
The computer's total score is 20

Sorry --- the computer won.
Press Enter to finish


>python Doubles.py
Welcome to Doubles!  You play first:
You rolled 1 and 1
A Double!
Your score is 4
Do you want to throw the third die (y or n)?: y
Your third die is 1
You threw a Triple!

Congratulations --- you won!
Press Enter to finish

Designing and building the program: The Doubles game requires some planning before you start typing. Make sure that you

  1. understand the program's intended behavior by playing the game yourself with some real dice
  2. design the program's algorithm (draw a flowchart to see where if-commands are needed)
  3. write the program based on the algorithm and test it
  4. document your work (in the style required for Assignment 1)
The program will use if-commands that ask questions about the numbers of the dice, compare scores, and so on. To simulate the throw of a die, use the Python method, random.randrange(1,7), as demonstrated in lab. See also Dawson's text, Chapter 3.

Once you have completed your program and have tested it to your satisfaction, remember to attach comments to it that document the program's name, its purpose, the input it expects to receive, and the output it will produce.

Submit: By the submission deadline, use the web page at http://www.cis.ksu.edu/~schmidt/200s08/Assign to submit your file, Doubles.py.

Reminder: This is a single-person assignment. You are welcome to discuss the assignment with your instructors, tutors, and other students, but the algorithm you design and the program you write and submit must be your own work, just as if you are submitting an essay for an English Composition course.