Intro to Computer Science

PA05

A Game!


Code due Feb 27 at 11:59pm

You can turn in the code up to 2 days late for a 10% deduction per day


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:

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:

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". Note: only put this code inside your main program loop. Don't put it at the top of your program. 

 

Getting Started

  1. Do all the standard startup things. Create a new file called rps.py. Put your comments in at the top, save it.
  2. 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.
  3. Now address one subtask, getting user input. Do this in stages as well. Can you:
    1. Prompt for and get a choice (a string) from the user?
    2. Once you can do that, can you repeatedly prompt for a character until you see a ‘q’ or ‘Q’ for quit?
    3. 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?
    4. 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.

  1. 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.