COMP 141-03 Fall 2013

Program 2: Rock, Paper, Scissors

50 Points

Assigned: Friday, September 13
Due: Monday, September 23, 2013 by 11:55pm

You will write a program that allows the user to play the game Rock, Paper, Scissors against the computer. This will be done using a random number generator, simple while loop, and branching statements. You must write all of your code inside of a main function, and call that main function. You are not required to use additional functions, but you may if you like.

Background

Rock, Paper, Scissors (also known by several other names, see http://en.wikipedia.org/wiki/Rock_paper_scissors) is an extremely popular hand game most often played by children. 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.

Rules of the Game

The objective of Rock, Paper, Scissors is to defeat your opponent by selecting a weapon that defeats their choice under the following rules:

  • Rock smashes (or blunts) Scissors, so Rock wins.
  • Scissors cut Paper, so Scissors win.
  • Paper covers Rock, so Paper wins.
  • If players choose the same weapon, neither win and the game is played again.
  • Program Specifications

    This program requires you to use:

  • The input function to prompt the user.
  • The print function to output the results.
  • At least one branching statement
  • At least one loop (while loop)
  • Boolean logic
  • Description

    Your program will allow a human user to play Rock, Paper, Scissors with the computer. Each round of the game will have the following structure:

  • The program will choose a weapon (Rock, Paper, Scissors), but its choice will not be displayed until later so the user doesn't see it. (Hint: Generate a random number between 1 and 3.)
  • The program will announce the beginning of the round and ask the user for his/her weapon choice.
  • The two weapons will be compared to determine the winner (or a tie) and the results will be displayed by the program.
  • The next round will begin, and the game will continue until the user chooses to quit.

  • At the beginning of the game, the user should be prompted for his/her input. The valid choices for input are:
  • R or r (Rock)
  • P or p (Paper)
  • S or s (Scissors)
  • Q or q (Quit)

  • At the beginning of each round, your program should ask the user for an input. You may either assume that the user will not input something other than r, R, p, P, s, S, q or Q, or you may assume that the user is trying to quit the game if they enter anything other than an R, r, P, p, S, or s.

    An example of possible dialog with the user might be (user input is in italics):

    Let's play Rock, Paper, Scissors!
    Please select your weapon: (R) for rock, (P) for paper, (S) for scissors, or (Q) to quit: P
    You have chosen Paper and the computer chose Scissors. The computer has won this round.
    Please select your weapon: (R) for rock, (P) for paper, (S) for scissors, or (Q) to quit: S
    You have chosen Scissors and the computer chose Scissors. It's a tie!
    Please select your weapon: (R) for rock, (P) for paper, (S) for scissors, or (Q) to quit: R
    You have chosen Rock and the computer chose Rock. It's a tie!
    Please select your weapon: (R) for rock, (P) for paper, (S) for scissors, or (Q) to quit: R
    You have chosen Rock and the computer chose Rock. It's a tie!
    Please select your weapon: (R) for rock, (P) for paper, (S) for scissors, or (Q) to quit: R
    You have chosen Rock and the computer chose Paper. The computer has won this round.
    Please select your weapon: (R) for rock, (P) for paper, (S) for scissors, or (Q) to quit: P
    You have chosen Paper and the computer chose Rock. You win!
    Please select your weapon: (R) for rock, (P) for paper, (S) for scissors, or (Q) to quit: Q
    I'm sorry to see you go! You've proven to be a worthy adversary.
    
    Your code does not need to follow this exact script, but all the mentioned functionality should work as shown.

    HINT: You should get your code to work for a single round of Rock, Paper, Scissors first. Then add the loop statement to allow the user to keep playing multiple rounds.

    What to Do

  • Create a Python program named yourlastname_prg2.py
  • Include the standard program header at the top of your Python file.
  • Submit your Python file on Moodle under Program 2
  • Requirements

    When I examine your program, it must satisfy the following requirements. The maximum point value for each requirement is shown in brackets.

  • [3] Your program file is named correctly and it includes the standard program header.
  • [5] You must randomly choose a weapon for the computer to use in each round.
  • [5] You must prompt the user to enter their weapon of choice.
  • [20] You must properly determine if the user has won, tied, or lost the round and output it.
  • [15] You must write a while loop to play multiple rounds of the game.
  • [2] You must comment your code appropriately and your code must be neatly and clearly formatted and include proper use of 'white space'.

  • Note: If your program doesn't run (i.e, has a syntax error), you may receive partial credit for the items listed above in bold.

    Extra Credit (5 points)

    You may only attempt the extra credit after your program is working correctly as described above.
    To earn extra credit on this assignment, your program should remember the game history (whether the user wins, the computer wins, or the round is tied). At the end of the game (when the user chooses to Quit), your program should display the following:

  • The number of rounds the computer has won.
  • The number of rounds the user has won.
  • The number of rounds that ended in a tie.
  • The number of times the user selected each weapon (Rock, Paper, Scissors).