Please read through the entire lab before starting!
Also, as always, run update21 to create your cs21/labs/07 directory.
Write your programs for lab 7 in this directory.
Two-Dice Pig
Our lab this week and next is to write a dice game called
two-dice pig.
This is a "user vs computer" game, where each player takes turns rolling
two dice, trying to reach 100 points (see rules below).
For this lab you will use top-down design. We are giving you two weeks
to complete this program. However, we require your
initial top-down design this Saturday (March 19) and the full implementation
the following week (March 26).
Remember, for the design of a program, you should have:
- main() completely written
- functions called from main() all stubbed out with parameters,
comment, and a sample return statement
- clear use of data structures and variables in main() and the stubbed-out functions
- a design that runs without errors (although it doesn't play the game yet)
Here is a simple
example of a top-down design.
Examples, Requirements, and Tips
Here are some examples of the two-dice pig game, to help you see how it works:
Special proceedures for this two-week lab:
- create your design in design-twodicepig.py. This program should have main()
done, all function stubs written, and should run (no syntax errors!) but not really play the
game. Here is an example of one possible working design: design example
- after you have a working design, run handin21 to turn it in! Then, send your
professor a short email, letting them know your design is done. We will take a look at
each design and send you comments (usually within a day or two).
- after you have the design done, and have heard back from your professor,
copy the file to twodicepig.py and implement the full game
(cp design-twodicepig.py twodicepig.py)
You have some freedom in how you want your game to look. Here
are our requirements for the game:
- you may assume the user always goes first, and the computer always gets
a final turn to try to win
- only allowed user input is: roll, hold, quit (and r, h, q)
- user can quit early if they want
- player must get to 100 to win (if both get there, higher score wins)
- computer keeps rolling as long as turn score < 20, or has enough
to win (or rolls a 1 or double 1's)
- you may use the two functions (roll(), score()) we wrote for a
previous lab, if you want
Optional Challenges
Here are a few optional challenges for this game. If you do these (just
for fun, no extra points!), please copy your working game to a new file:
cp twodicepig.py twodicepig-extra.py
- the rules listed on wikipedia say you have to roll again
if you roll doubles (except for 1 1). That is, you can't "hold". Add that rule to the game.
- add in random messages, instead of the same two or three the computer
uses every time (in my game: "I'll stick with that!", "Bleh...", "Barnacles!")
- write a better computer algorithm (not just roll until over 20)
- ask the user for the end score (Play to 100? 200?)
- ask if user wants to play again, or best two out of three?
Submit
Once you are satisfied with your program, hand it in by typing
handin21 in a terminal window.