Write a program in the Codio programming environment that allows you to play the game of Rock / Paper / Scissors against the computer. Within the Codio starting project you will find starter code as well as tests to run at each stage. There are three stages to the program, as illustrated below. You must pass the tests at each stage before continuing in to the next stage. We may rerun all tests within Codio before grading your program. Please see the executable version of the program within the Codio project for the definitive version of what it should look like, as sometimes conversion to html to display on this page can affect how the output lines up.
The first stage sets the computer guess to always be 'R' for Rock each move. Running the program with the first stage should look like the following:
CS 141 Program #1: Rock/Paper/Scissors
Welcome to the game of Rock/Paper/Scissors where you play against
the computer. On each move the computer will choose R, P, or S, then
the user will be prompted for their choice, and then the score will
be updated. P beats R, R beats S, and S beats P. The score starts
at 0. Add one if the person wins, subtract one if the computer wins.
The game ends if the score reaches -5 or + 5.
User input of 'x' or 'X' causes the game to exit.
Here we go!
Select how the computer chooses its move:
1. Always choose Rock
2. Random guess
3. Random guess with graphical score
Enter your choice: 1
1. Your move: r
Computer chose R
Tie. Score: 0
2. Your move: R
Computer chose R
Tie. Score: 0
3. Your move: p
Computer chose R
User's point. Score: 1
4. Your move: S
Computer chose R
Computer's point. Score: 0
5. Your move: x
Exiting program...
Tie game!
Ending program...
The second stage uses a random number generator to set the
computer's guess to be 'R' for Rock, 'P' for Paper, or 'S' for
Scissors. In order for your output to match what is
expected, you must do the following:
1. Get a random number using rand() % 3 to give you a result
of 0, 1, or 2
2. Use the result of the previous step to decide which letter to
assign to the computer's guess. If it is 0, assign 'R'. If it is 1,
assign 'P'. If it is 2, assign 'S'.
Running the second stage should look like the following:
CS 141 Program #1: Rock/Paper/Scissors
Welcome to the game of Rock/Paper/Scissors where you play against
the computer. On each move the computer will choose R, P, or S, then
the user will be prompted for their choice, and then the score will
be updated. P beats R, R beats S, and S beats P. The score starts
at 0. Add one if the person wins, subtract one if the computer wins.
The game ends if the score reaches -5 or + 5.
User input of 'x' or 'X' causes the game to exit.
Here we go!
Select how the computer chooses its move:
1. Always choose Rock
2. Random guess
3. Random guess with graphical score
Enter your choice: 2
1. Your move: r
Computer chose P
Computer's point. Score: -1
2. Your move: P
Computer chose P
Tie. Score: -1
3. Your move: r
Computer chose R
Tie. Score: -1
4. Your move: p
Computer chose P
Tie. Score: -1
5. Your move: x
Exiting program...
Computer wins!
Ending program...
The third stage is the same as the second except it displays the score graphically rather than as a number. Running the third stage should look like the following:
CS 141 Program #1: Rock/Paper/Scissors
Welcome to the game of Rock/Paper/Scissors where you play against
the computer. On each move the computer will choose R, P, or S, then
the user will be prompted for their choice, and then the score will
be updated. P beats R, R beats S, and S beats P. The score starts
at 0. Add one if the person wins, subtract one if the computer wins.
The game ends if the score reaches -5 or + 5.
User input of 'x' or 'X' causes the game to exit.
Here we go!
Select how the computer chooses its move:
1. Always choose Rock
2. Random guess
3. Random guess with graphical score
Enter your choice: 3
1. Your move: r
Computer chose P
Computer's point.
-5 -4 -3 -2 -1 0 1 2 3 4 5
----------------------------------
..............^
2. Your move: s
Computer chose P
User's point.
-5 -4 -3 -2 -1 0 1 2 3 4 5
----------------------------------
.................^
3. Your move: p
Computer chose R
User's point.
-5 -4 -3 -2 -1 0 1 2 3 4 5
----------------------------------
....................^
4. Your move: s
Computer chose P
User's point.
-5 -4 -3 -2 -1 0 1 2 3 4 5
----------------------------------
.......................^
5. Your move: x
Exiting program...
User wins!
Ending program...
What You Need to Know
Grading Rubric
The grading rubric is included in your starter code within your Codio project, and is included here as well.
55 Execution points
Option 1: (Computer always chooses R) and:
2 User input of X immediately exits program
3 User input of x (lower-case) immediately exits program
10 Program handles both lower and upper case user input (e.g. 'r' and 'R'); Move number increments each move
15 Score updates correctly for all user inputs: r, p, s
Option 2: Computer's move is random and:
7 Predetermined input sequence correctly leads to a win for computer, with assessment results hidden
8 Predetermined input sequence correctly leads to a win for computer, with assessment results hidden
Option 3:
2 Correctly displays and updates the graphical score
8 Correctly displays and updates the graphical score, with assessment results hidden
45 Programming Style (Given only if program runs substantially correctly)
10 Meaningful identifier names
10 Comments: Has header. Comments on each block of code.
15 Appropriate data and control structures. Code duplication is avoided.
10 Code Layout: Appropriate indentation and blank lines.
#include<iostream>
#include <string>
#include <stdlib.h>
#include <time.h>
int getComputerChoice();
int getPlayerChoice();
bool isTie(int playerChoice,int computerChoice);
bool isPlayerWinner(int playerChoice,int computerChoice);
int main()
{
char option;
int computerChoice;
int playerChoice;
//srand funtion outside the loop
//if we put inside the for loop same random number is
generated
//Srand will seed the random number generator to
prevent random numbers from being the same every time
srand(time(NULL));
string computerSelection;
string playerSelection;
do
{
cout<<"ROCK PAPER SCISSORS
MENU\n";
cout<<"-------------------------\n";
cout<<"p)Play Game\n";
cout<<"q)Quit\n";
cout<<"Enter your
option\n";
cin>>option;
switch(option)
{
case
'p':
playerChoice =
getPlayerChoice();
if(playerChoice==1)
cout<<"You chose: Rock\n";
else
if(playerChoice==2)
cout<<"You chose: Paper\n";
else
if(playerChoice==3)
cout<<"You chose: Scissors\n";
computerChoice =
getComputerChoice();
if(computerChoice==1)
cout<<"The computer chose: Rock\n";
else
if(computerChoice==2)
cout<<"The computer chose: Paper\n";
else
if(computerChoice==3)
cout<<"The computer chose: Scissors\n";
if(isTie(playerChoice,computerChoice))
{
cout<<"It's a TIE!\n";
}
else
if(isPlayerWinner(playerChoice,computerChoice))
{
cout<<"You WIN!\n";
}
else
{
cout<<"Sorry you LOSE.\n";
}
break;
case 'q':
break;
default:
cout<<"Invalid
Choice\n";
}
}while(option!='q');
return 0;
}
int getComputerChoice()
{
int randnum;
//Generate number between 1 and 3
randnum = 1 + (rand() % 3);
return randnum;
}
int getPlayerChoice()
{
int playerChoice;
while(true)
{
cout<<"Rock, Paper or
Scissors?\n";
cout<<"1) Rock\n";
cout<<"2) Paper\n";
cout<<"3) Scissors\n";
cout<<"Please enter your
choice:\n";
cin>>playerChoice;
switch(playerChoice)
{
case 1:
return 1;
break;
case 2:
return 2;
break;
case 3:
return 3;
break;
default:
cout<<"Please enter 1 or 2 or 3
only\n";
}
}
return playerChoice;
}
bool isTie(int playerChoice,int computerChoice)
{
if(playerChoice==computerChoice)
return true;
else
return false;
}
bool isPlayerWinner(int playerChoice,int
computerChoice)
{
if(playerChoice==1 && computerChoice==3)
return true;
else if(playerChoice==3 &&
computerChoice==2)
return true;
else if(playerChoice==2 &&
computerChoice==1)
return true;
else
return false;
}
Write a program in the Codio programming environment that allows you to play the game of...
C++ Write a program that plays the rock, paper, scissors game. Rock beats scissors; scissors beats paper; paper beats rock. You must use these specific functions in your program. These are the prototypes: char generateP2toss(); int checkThrow(char, char); void printStatistics(int, int, int, int); void finalStatistics(int, int, int, int); void welcome(); Notes on these functions: generateP2toss() will generate the computer's toss (the computer is player2). It returns either an "r", "p", or "s/" checkThrow(char char) will check the throw by passing...
Write a C# program that allows one user to play Rock-Paper-Scissors with computer. The user will pick a move (Rock Paper Scissors) from 3 radio buttons and click the play button to play the game. The application will use random number generator to pick a move for the computer. Then, the application display the computer's move and also display whether you won or lost the game, or the game is tie if both moves are the same. The application must...
In python language
Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: 1. When the program begins, a random number in the range of 1 and 3 is generated. 1 = Computer has chosen Rock 2 = Computer has chosen Paper 3 = Computer has chosen Scissors (Dont display the computer's choice yet) 2. The user enters his or her choice of “Rock”, “Paper", “Scissors" at...
Write a program in python that lets the user play the game Rock, Paper, Scissors against the computer. The program should work as follows: When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. 2 corresponds to paper, and 3 corresponds to scissors. To set up the random number library, write the following at the top of your code: import random random.seed(300) Use...
JAVA Beginnings of a paper-rock-scissors game. Paper-rock-scissors is a game often used to make decisions. There are two players. Each player secretly chooses either, paper, rock or scissors. At the count of three, each player reveals what they have chosen. The winner of the game is determined this way: paper beats rock (because paper covers rock) rock beats scissors (because rock crushes scissors) scissors beat paper (because scissors cut paper) If the two players choose the same item, it is...
C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this game against the computer. The program should work as follows: When the program begins, a random number between 1 and 3 is generated. If the number is 1, the computer has chosen rock. If the number is 2, the computer has chosen paper. If the number is 3, the computer has chosen scissors. Don't display the computer's choice yet. Use a menu to display...
I'm trying to write this program in C++ and I'm having trouble initializing the overload function I have to use. Here's the assignment and what I got so far, thanks for the help! /*2. Implement the game of Rock-Paper-Scissors in C++, where you can play against the computer. a. Scissors beat paper, paper beats rock, and rock beats scissors. If both you and computer choose the same tool, it is a tie. b. Your program should have a class game...
This program should be in c++. Rock Paper Scissors: This game is played by children and adults and is popular all over the world. Apart from being a game played to pass time, the game is usually played in situations where something has to be chosen. It is similar in that way to other games like flipping the coin, throwing dice or drawing straws. There is no room for cheating or for knowing what the other person is going to...
Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember the rules: 1. Rock beats scissors 2. Scissors beats paper 3. Paper beats rock The program should ask the users for their names, then ask them for their picks (rock, paper or scissors). After that, the program should print the winner's name. Note, the players may pick the same thing, in this case the program should say it's tie. when the user input an...
It's writing a simple rock paper scissors game strictly following the instructions. INSTRUCTIONS: If the user selects 'p': 1. First the program should call a function named getComputerChoice to get the computer's choice in the game. The getComputerChoice function should generate a random number between 1 and 3. If the random number is 1 the computer has chosen Rock, if the random number is 2 the user has chosen Paper, and if the random number is 3 the computer has...