“Rock, Paper, Scissors” Game
Develop a Python application which allows a human user to play a game of Rock Paper Scissors against a computer opponent. The game’s functionality should adhere to the “Requirements” section below.
Requirements
For this assignment, all game code should exist in a single code cell!
Welcome Message
The application should instruct the player via text cell to set their name using a notebook secret specifically called PLAYER_NAME
(using all capital letters).
The application should read the player name from the notebook secrets, and store the value in a Python variable specifically called PLAYER_NAME
(using all capital letters).
The application should display a friendly message welcoming the user, for example: “Welcome Jon, to our Rock Paper Scissors Game!” (if “Jon” was set as the player’s name).
Processing User Inputs
The application should prompt the user to input, or otherwise select, an option (i.e. “rock”, “paper”, or “scissors”). It should store the user’s selection in a variable for later reference.
Use the input
function, or form inputs, or widgets, to capture user inputs. If you use form inputs or widgets, that should also satisfy the validation steps below. 😸
Validating User Inputs
The application should compare the user’s selection against the list of valid options (i.e. “rock”, “paper”, “scissors”) to determine whether the user has selected a valid option. See additional validation requirements below.
Graceful Failure
If the selection is invalid, the program should fail gracefully by displaying a friendly message to the user, and preventing further program execution. The program should not try to further process an invalid input, as it may lead to runtime errors. In other words, the program should not move on to generating a computer choice (see “Simulating Computer Selection” section below) unless the user input is valid.
Check the selection option using conditional logic.
Case Normalization
The program should be able to handle various capitalizations of the valid options (e.g. “ROCK”, “Rock”, “rock”, “RoCk”, etc.) Any combination of lowercase and uppercase letters for a given option should be considered valid.
Modify the user input value string case manipulation before checking the selected option.
Validation Loop
If the selection is invalid, the program should continue to prompt the user to input a value until the user inputs a valid input.
Ask for an input within the scope of a while
loop, and break out of the loop if the selection is valid.
Simulating Computer Selection
The application should select one of the options (i.e. “rock”, “paper”, or “scissors”) at random, and assign that as the computer player’s choice.
Use the choice
function provided by the random
module.
Ensure the valid choices are stored in a list datatype, and then pass that list to the random choice function.
Determining the Winner
The application should compare the user’s selection to the computer player’s selection, and determine which is the winner. The following logic should govern that determination:
- Rock beats Scissors
- Paper beats Rock
- Scissors beats Paper
- Rock vs Rock, Paper vs Paper, and Scissors vs Scissors each results in a “tie”
Beginners, feel free to use conditional logic.
Displaying Results
After determining the winner, the application should display the results to the user. Desired information outputs (from start to finish) should include at least the following:
- A friendly welcome message, including the player’s name (e.g. “Player One”).
- The user’s selected option
- The computer’s selected option
- What the game outcome was (user wins, computer wins, or tie)
- A friendly farewell message
Example desired output after one round of game-play:
Welcome 'Player One' to my Rock-Paper-Scissors Game!
---------
Please choose an option ('rock', 'paper', or 'scissors'): rock
---------
User choice: 'rock'
---------
Computer choice: 'scissors'
---------
You won! Thanks for playing.
Evaluation
Submissions will be evaluated according to the detailed “Requirements” above, as represented by the following rubric:
Category | Requirement | Weight |
---|---|---|
Info Inputs | Reads the player name from notebook secrets. | 10% |
Info Inputs | Prompts the user to input or select an option. | 15% |
Validations | Handles user inputs of various capitalization. | 15% |
Validations | Fails gracefully if encountering an invalid user input. | 15% |
Simulation | Generates a random computer choice. | 15% |
Calculations | Displays the winner accurately. | 15% |
Info Outputs | Displays all desired information. | 15% |
This rubric is tentative, and may be subject to slight adjustments during the grading process.
If experiencing execution error(s) while evaluating the application’s required functionality, evaluators are advised to reduce the project’s grade by between 4% and 25%, depending on the circumstances and severity of the error(s).
Further Exploration
Game Loop Challenges
Play Again: The application should ask the user whether they’d like to play again. If they say “yes”, it should play the game again, otherwise it should stop. The user should be able to continue playing as many games as they want.
Use an infinite while
loop!
Game Stats: The application should keep track of how many games have been played, and how many games have been won, and once the user elects to stop playing, it should display their win percentage.
You can count ties as losses, or remove them from the denominator. In other words, either of the following win percentage formulae would be fine:
\[\text{win percentage} = \frac{\text{wins}}{\text{total games}}\]
\[\text{win percentage} = \frac{\text{wins}}{\text{total games} - \text{ties}}\]
Use a counter approach in conjunction with your while
loop.