CSC207 - Project 2
Rolling Hogs
Assigned Oct 18th 12 p.m.
Due October 27th 5 p.m.
Overview
For this project, we will explore more complex interactions with the user by implementing
control statements and loops. We will create a program for one user to play the game HOG
versus the computer.
In particular, this project will cover the following concepts we have discussed in class:
- Booleans
- Functions
- Control Statements
- Sentinel Loops
- Definite Loops
- Lists
- Randomness
Description
The game of Hog is played as follows. On your turn, you choose to roll as many six-sided dice as
you want, then roll them. If you roll a 1 on any of the die, you score zero points, otherwise,
you score the total of the dice you rolled. The first player to score 100 points wins the game.
For example, the first few turns of the game might be as follows:
You: 0
Computer: 0
How many dice would you like to roll? 3
You rolled 3, 4, 6
You: 13
Computer: 0
Computer rolled 5, 6, 2, 3
You: 13
Computer: 16
How many dice would you like to roll? 5
You rolled 4, 2, 1, 4, 5
You: 13
Computer: 16
Computer rolled 2, 3
You: 13
Computer: 21
.
.
Coding
For this assignment we will be writing a Python program to let a user Hog versus
the computer
You must create a python program
called hog.py
. It will:
- Tell the user about the game.
- Tell the user their score and the computer's score.
- Ask the user how many die they would like to roll. For our game, this will be a number between
1 and 30.
- Simulate rolling that many die, and show the rolls to the user.
- If any rolls are a 1, the score is 0, otherwise sum up the score and add it to the user's total.
- If the game has not been won by the user by earning 100 points, the computer gets to roll.
- The computer chooses a random number of dice between 1 and 10 inclusive, and scores accordingly.
- If the game has not been won by the computer, repeat from step 2.
- When the game is over, tell the user who was the winner.
- Finally, ask the player if they would like to play again. If so, play the game again.
Your code should make good use of functions, as there are clear pieces of the game which
are repeated. Using functions will reduce the amount of code you need
to write as well as make your program easier to debug. However, do not write spaghetti code,
where functions call each other back and forth to continue execution of the program;
let your functions naturally return values and use loops to repeat the game turns.
Your code must check all user input for validity and reprompt them for correct input if
any mistakes are made.
What to Hand In
Log in to cs.centenary.edu
through either Secure FTP or WinSCP using your
cs login and password. Copy your hog.py
project into the project2 directory, along with any other files
you need to run your code. Make sure
you have followed the Python Style Guide, and
have run your project through the Automated Style Checker.
You must hand in:
and any other files necessary to run your code.
© Mark Goadrich 2010, Centenary College of Louisiana