This project rocks!

... except when it papers or scissors, that is.

In this project, you'll apply your Python and object-oriented programming skills to build a program that plays the game of Rock Paper Scissors. You'll build classes that represent the game and its players. You'll write computer players that follow various different strategies, as well as a human player class that lets a human play the game against the computer.

About the game

The game of Rock Paper Scissors is played throughout the world. It dates back to the Han Dynasty of ancient China, contemporary with the Roman Empire. Today it is called jian dao, shi tou, bu in China, pierre-papier-ciseaux or chifoumi in France; roshambo in parts of the U.S., ta kat makas in Turkey, and jan-ken-pon in Japan. It is the distant ancestor of the type system in the immensely popular Pokmon games. The game is played competitively; there have been international RPS tournaments however, it's more commonly used as a playful way of settling disputes, whether in the schoolyard or the barroom.

The game has two players. In a single round of the game, each player secretly chooses one of three moves, or "throws" rock, paper, or scissors. Then, players reveal their moves at the same time. If both players picked the same move, there is no winner. Otherwise, rock beats scissors; paper beats rock; and scissors beat paper. Players can play a single round, or "best of three", or any number of other options.

Demonstration

In the terminal workspace below, you can play a demo of the Rock Paper Scissors game. Try entering different moves: type in rock, paper, or scissors to play a round against a computer player. see image.

How you will build it

You'll start this project with a piece of starter code that doesn't quite know how to play Rock Paper Scissors yet. In fact, it contains a computer player class that only knows how to play rock.

"Good ol' rock, nothing beats that!" Bart Simpson

From that humble beginning, you will add classes and modify methods, expanding it into a full game. You'll use the input function to read the human player's moves from the keyboard, and print the results of each round. You'll use subclasses to build more intelligent computer players. And you'll test your code at every step by running your program, or by importing it to test specific functions and methods.

Getting started

Here are some steps to get you started in the Rock Paper Scissors project! As you work through the project, make sure to test your program by running it.

1. Download the starter code

Click here to download the starter code. (Link below) https://s3.amazonaws.com/video.udacity-data.com/topher/2018/November/5c002226_rps-starter-code/rps-starter-code.py

The starter code gives you a place to begin, with Player and Game classes that are mostly empty. Over the course of the project, you will be greatly expanding the classes and methods in this program.

Read the starter code, and run it on your computer to see what it does.

Try importing it into the Python interpreter and experimenting with the Player and Game objects.

2. Create a player subclass that plays randomly

The starter Player class always plays 'rock'. That's not a very good strategy! Create a subclass called RandomPlayer that chooses its move at random. When you call the move method on a RandomPlayer object, it should return one of 'rock', 'paper', or 'scissors' at random. Change the code so it plays a game between two RandomPlayer objects.

3. Keep score

The starter Game class does not keep score. It doesn't even notice which player won each round. Update the Game class so that it displays the outcome of each round, and keeps score for both players. You can use the provided beats function, which tells whether one move beats another one. Make sure to handle ties when both players make the same move!

4. Create a subclass for a human player.

The game is a lot more interesting if you can actually play it, instead of just watching the computer play against itself. Create a HumanPlayer subclass, whose move method asks the human user what move to make. (Take another look back at the project demo to see what this can look like!) Set the program to play a game between HumanPlayer and RandomPlayer.

5. Create player classes that remember

At the end of each game round, the Game class calls the learn method on each player object, to tell that player what the other player's move was. This means you can have computer players that change their moves depending on what has happened earlier in the game. To do this, you will need to implement learn methods that save information into instance variables.

Create a ReflectPlayer class that remembers what move the opponent played last round, and plays that move this round. (In other words, if you play 'paper' on the first round, a ReflectPlayer will play 'paper' on the second round.)

Create a CyclePlayer class that remembers what move it played last round, and cycles through the different moves. (If it played 'rock' this round, it should play 'paper' in the next round.) (Something to think about: What should these classes do on the first move?)

Test each of these player classes versus HumanPlayer.

6. Validate user input

The human player might sometimes make typos. If they enter roxk instead of rock, the HumanPlayer code should let them try again. (See how this works in the demo if you type something in that isn't a valid move.)

7. Announce the winner

It's up to you how long the game should run. The starter code always plays three rounds, but that's not the only way it could work. You could choose to continue until the player types quit, or you could have the game run until one player is ahead by three points, or any other rule that makes sense to you.

At the end of the game, have it print out which player won, and what the final scores are.

8. Check your code formatting

Use the pycodestyle tool to check the formatting of your code. Make the edits that it recommends, then re-run it to see fewer and fewer warnings. By the time you're done, it should display no warnings or errors at all.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.