COMP 142 Project 1: Rock-Paper-Scissors-Lizard-Spock
You will write a program that simulates the two-player game
Rock-paper-scissors-lizard-Spock.
This game is an extension of the traditional rock-paper-scissors
(RPS) game with two additional choices: a lizard and
Spock.
The game was popularized on
The Big Bang Theory,
though it was invented earlier as a way to reduce the
probability of a tie in a regular rock-paper-scissors game.
Here's a brief introduction to the "regular" rock-paper-scissors game.
RPS is two-player game that is played only with the hands. Each player mentally chooses
one of "rock," "paper," or "scissors," and simultaneously the two players show (or, "throw")
a hand symbol illustrating their choice. Rock uses a closed fist, paper uses an open hand with
the fingers together, and scissors uses a fist with the pointer and middle finger extended.
Each one of the three hand gestures defeats one other gesture, and is defeated by
one other gesture: rock crushes (beats) scissors, scissors cuts (beats) paper, and paper
covers (beats) rock.
If both players choose the same gesture,
then the game is repeated. The game can be played until the first winner is determined or in repeated rounds.
Rock-paper-scissors-lizard-Spock (RPSLS) introduces two new gestures:
lizard (all fingers touching the thumb) and
Spock (fingers extended with a v-shape between the middle and ring figure). The new rules are as follows (in each rule,
the first gesture beats the second)
- Scissors cuts paper
- Paper covers rock
- Rock crushes lizard
- Lizard poisons Spock
- Spock smashes scissors
- Scissors decapitates lizard
- Lizard eats paper
- Paper disproves Spock
- Spock vaporizes rock
- Rock crushes scissors
Note that this rule set is an extension of the classic RPS rules. The rule set still permits a fair game:
every gesture defeats two other gestures and loses to two other gestures (see the diagram).
And while the possibility of tying still exists, the probability of ties is lower.
The goal of your project is to create a two player game of RPSLS.
At the beginning of the game, you should ask the players how many
points it will take to declare the winner of RPSLS.
Your program will allow the players to play multiple rounds of RPSLS
until one of them reaches the critical number of points.
The winner of each round receives one point.
Although ties are not as common, your program must be able to
handle ties by allowing the users to go again until you can announce a proper winner of that round.
You must adhere to good programming techniques and style while making sure your code is efficient.
You should spend a significant amount of time thinking about what
chunks of code will be reused and how you can take advantage of this when you write your program.
Here is a checklist of things that your program should include:
- Allow both players to enter their names and use those names in the program.
- Validate the user input (For example, make sure that a user doesn't enter -1
for the number of points that it takes to win the game).
- Give appropriate feedback so it's clear to the users how the
game is played and how the game is progressing.
- Provide a short introduction to your game and a conclusion.
- Your program must break ties by allowing the players to re-select gestures in each round until there is no more tie.
- Your main function should not do all the work; it should call other functions to run the "guts" of the game.
- You should use at least two other functions.
Language
If you took CS141, you should write this program in Python. If you took APCS and skipped
CS141, you may use Java, since presumably you are familiar with that language.
If you do not know Python or Java, talk to the instructor.
Coding style
Program- and function-level comments
These guidelines apply to this program and all future programs.
- You should place a comment section at the top of your program that contains:
- Your name, the date, and the class.
- The honor pledge saying you have neither given nor received any help you weren't
supposed to.
- A description of the program (a few sentences).
- A description of the input to the program (what the user types), if any.
- A description of the output of the program (what the user sees).
Here's an example:
# Name: Phil Kirlin
# Date: 9/18/2013
# Class: CS142
# Pledge: I have neither given nor received unauthorized aid on this program.
# Description: Skynet is a artificial intelligence system which guides
# the global digital defense network. It will not start a nuclear war.
# Input: The user types commands to Skynet such as "launch probe" or "send Terminator back in time."
# Output: The state of the Skynet system after each command, including statistics
# about number of Terminators created, dollars spent, and nuclear wars started (should always be zero).
- For every function you write (except main), you must include a comment immediately before the
function definition line that contains:
- A description of what the function does.
- Any parameters the function takes (if any), along with their meanings.
- The return value of the function, if there is one, and what it means.
Here's an example you'd use for a function that computes the circumference of a circle:
# This function computes the circumference of a circle.
# Parameters: r, the radius of the circle.
# Returns: the circumference of the circle.
def circumference_of_circle(r):
return 2 * 3.14 * r
About the pledge
Because we are writing complex programs, it is not uncommon to get stuck.
However, as the syllabus states, all homework assignments you complete outside of class must be
entirely your own work, with the exception of help from the instructor, tutors, or other
people while respecting the "Rules for Completing Assignments Independently" (see the
syllabus).
I'm asking everyone to please include the honor pledge in the comments at the top
of your programs indicating you have conformed to the request to work individually.
(See the example above for the text to include.)
Testing your program
You should test your program thoroughly to make sure it works. Your program should
gracefully handle situations where numbers are typed incorrectly for the number of points
to win, or the gesture to throw.
Sample interaction
Welcome to Rock, Paper, Scissors, Lizard, Spock!
How many points does it take to win? 2
Please enter Player 1's name: Alice
Please enter Player 2's name: Bob
ROUND 1
Enter (0) Rock, (1) Paper, (2) Scissors, (3) Lizard, (4) Spock
Alice, enter your throw: 4
Bob, enter your throw: 0
Spock defeats Rock
Alice defeats Bob
Here's the score: Alice (1), Bob (0)
ROUND 2
Enter (0) Rock, (1) Paper, (2) Scissors, (3) Lizard, (4) Spock
Alice, enter your throw: 3
Bob, Enter your throw: 2
Scissors defeats Lizard
Bob defeats Alice
Here's the score: Alice (1), Bob (1)
ROUND 3
Enter (0) Rock, (1) Paper, (2) Scissors, (3) Lizard, (4) Spock
Alice, enter your throw: 5
Incorrect choice
Alice, enter your throw: 3
Bob, Enter your throw: 3
It's a tie, both players will throw again.
Alice, enter your throw: 4
Bob, Enter your throw: 2
Spock defeats Scissors
Alice defeats Bob
Here's the score: Alice (2), Bob (1)
FINAL RESULTS
Alice wins by a score of 2 to 1!
What to turn in
Through Moodle, turn in your code as a file called rpsls_yourLastName_yourFirstName.py.
Challenge Problems
From time to time, I will offer "challenge problems" on assignments. These problems
are designed to have little (but some) impact on your grade whether you do them or not.
You should think of these problems as opportunities to work on something interesting and optional,
rather than a way to raise your grade through "extra credit."
Policy on challenge problems:
-
Challenge problems will typically allow you to get 2-5% of additional credit on an assignment, yet they
will typically be much more difficult than this credit amount suggests.
-
You should not attempt a challenge problem until you have finished the rest of an assignment.
- The tutors will not provide help on challenge problems. The instructor
will provide minimal assistance only, as these problems are optional and are designed
to encourage independent thought.
- Challenge problems may be less carefully specified and less
carefully calibrated for how difficult or time-consuming they are.
- If you solve a challenge problem, include a comment at the top of your program detailing what you did.
Challenge problem for this assignment:
- Add a computer player that plays randomly and let the user choose whether or not they want to play the
computer or another player. Note: Your game must work for two real players as well.
- Make the computer player use some sort of intelligent strategy (but not cheat).
For example, they could keep track of their opponents' common moves
and always pick a choice that defeats that common choice.
- Let more than 2 players play the game.
- Report some statistics about the game.
- Expand the game some more (you still must support the regular RPSLS).