CPSC 120 B




Lecture
MWF 10:50am - 11:50am
Lab
MWF 12:00pm - 1:00pm

Scotty Smith

Office
Trexler 365-B
Office Hours
Monday / Thursday
3:00pm - 5:00pm
Email
chssmithATroanoke.edu

< Back
Printable Copy

Pig - The Dice Game

One of the more popular forms of entertainment in the computer industry is video games. The video game industry is a multi-billion dollar industry, which has greatly grown over the past decade. Popular games typically allow the user to control the game through some input device, and display visually the results of the user input.

For this assignment, you will design and code a program based on the simple dice game, "Pig." Your input device will be the users keyboard, and the output device will be the terminal screen.


Setup

Create a directory assignment5 under assignments in your cs120 directory. All code for the assignment should be stored in this directory.

cd ~/cs120/assignments
mkdir assignment5
cd assignment5

Details

The game of Pig has 2 simple, easy to follow rules. A round of Pig consists of two turns. Player 1 takes a turn, then player 2 takes a turn. Each turn starts off with the player rolling a dice.

The players overall score is the total sum of all of their turns. The game is won by the first player to score 100 or more points.

Your program should implement a two player game of pig. For each round, you must process an entire turn for player one, and an entire turn for player two. You can use the random.randint function to simulate dice rolls in this program.

For each turn, you should roll a dice for the player, and then ask if they want to Roll a new dice, or Hold their current score. You should use the "R" and "H" characters to determine what the user input. You should print each roll the player makes to the screen, and their turn score before every roll. When a players turn is over, you should print their overall score to the terminal.

For this program, you are required to write /at least/ two functions. The first function is get_user_input, which continually asks the user to command your program until they correctly enter an "R" or "H". Your second function is process_round, which will process one entire round of the pig game.


Submission

You are required to submit a tar file to http://cseval.roanoke.edu/. On cseval, there is a link for Assignment 5. You can create a tar file by issuing the following commands:

cd ~/cs120/assignments
tar czvf assignment5.tgz assignment5/
Both partners must submit through cseval!

"Hacker" Prompt

  1. ASCII Art: This program is (somewhat) boring looking. ASCII (pronounced ass-KEY) art are images that are generated using traditional (and some non-traditional) characters. Spice the game up by printing some ASCII art to the screen for each roll the player makes.

  2. Multiple Dice: There are variants of the game of pig that use more than a single die. In these variants, if any of the dice rolled are a 1, you lose all of your current turns points. If all the dice rolled are a 1, you lose all points earned *in the entire game*.

    Modify your program to allow the players to specify how many dice they want to play with. You should make sure your code still works when playing with a single dice.

  3. Play Suggestions: With such a simple game, it should come to no surprise that an optimal method of playing the game is known. Unfortunately, the computations necessary are