Intro to Computer Science
PA05
A Game!
Code due October 3rd at 11:59pm
Points
Introduction
The game Rock, Paper, Scissors is a game is a simple game that two people can play to determine a winner
(see this post.)
Two players each, independently, select one of the three
hand gestures (Rock, Paper, or Scissors) and simultaneously reveal their selection as follows:
- Rock beats (bashes) scissors
- Scissors beats (cuts) paper
- Paper beats (covers) rock
If they select the same attack it is a tie. If they select different
attacks, than one of the two is a winner, based on the rules above.
Often, it is used as a method of selection similar to flipping a coin or
throwing dice to randomly select a person for some purpose. Of course, this game
is not truly random since a skilled player can often recognize and exploit the
non-random behavior of an opponent; for instance, if you notice that your
opponent chooses Rock most frequently, you may choose Paper (which beats
Rock) most often in an effort to win.
Original Program Specifications
Your program (saved in a file called rps.py) will allow a human user to play several rounds
of Rock, Paper, Scissors with the computer. Each round of the game will have
the following structure:
- The program will choose an attack (Rock, Paper, Scissors), but its choice will not be displayed until later so the user
doesn’t see it.
- The program will announce the beginning of the round and
ask the user for his/her attack of choice
- The user can enter either of the three attacks or the signal to quit
- If the user inputs something other than r, R, p, P, s, S, q or Q, the
program should detect the invalid entry and ask the user to make another
choice.
- If the user entered a attack :
- The two attacks will be compared to determine the winner (or a tie) and
the results will be displayed by the program
- The computer will keep score which will be displayed later.
- The next round will begin, and the game will continue until the user
chooses to quit
- If the user enters quit than the computer:
- Prints a goodbye message which should include a score of all of the
games played
For example, one sample game might look like this:
For the initial version of this game you can program the computer to play
randomly. To do this you should put the following line of code at the top of your
program:
import random
This is the code necessary to set up a random number
generator.
Each time you need to pick a random number you use:
picked=random.choice(["r","p","s"])
This will produce a string that is randomly either "r", "p", or "s".
Getting Started
- Do all the standard startup things. Create a new file
called rps.py. Put your comments in at the top, save it.
- Now you need to break the problem down into parts. Read
the description and identify the subtasks that need to be solved. For example,
one subtask would be to get proper user input. Create a design document and mark in the empty program,
using comments, all the subtasks you need to solve.
- Now address one subtask, getting user input. Do this in
stages as well. Can you:
- Prompt for and get a choice (a string) from the user?
- Once you can do that, can you repeatedly prompt for a
character until you see a ‘q’ or ‘Q’ for quit?
- Once you can do that, can you check for “legal”
character responses from the user, and print an error message when an
illegal response is given?
- Next, can you check for legal responses that are in
both upper and lower case?
Once you can do all that,
move on to the next subtask.
- Remember, save the file and run it all the time! It will
make debugging the program easier.
Final Submission
Use the Program Submission System to submit your code.