# CIS*1500: ASSIGNMENT 2 Rock-Paper-Scissors (Lizard-Spock) Solved

30.00 \$

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . ` zip` solution files instantly, after Payment

5/5 - (1 vote)

# 1.0 Rock-Paper-Scissors (Lizard-Spock) Context

(Dialogue below taken from Series 02 Episode 08 of Big Bang Theory)

Raj Koothrappali: I’ll tell you what. How about we go rock-paper-scissors?

Sheldon Cooper: Ooh, I don’t think so. Anecdotal evidence suggests that in the game of rock-paper-scissors, players familiar with each other will tie 75 to 80% of the time due to the limited number of outcomes. I suggest rock-paper-scissors-lizard-Spock.

Raj Koothrappali: What?

Sheldon Cooper: It’s very simple. 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. And as it always has, rock crushes scissors.

Rock-Paper-Scissors (RPS) is a hand game which involves making a motion three times with your fists, and then either show a flat hand (paper), clenched fist (rock), or two fingers extended and separated (scissors). Depending on the results, the game is a tie (both show the same), or one person wins. The objective is to select a gesture which defeats that of the opponent. Gestures are resolved as follows:

• Rock blunts or breaks scissors: rock defeats scissors.
• Scissors cut paper: scissors defeats paper.
• Paper covers, sands or captures rock: paper defeats rock.

If both players choose the same gesture, the game is tied.

You may refer to the Rock-paper-scissors Wikipedia page

Write a program to play a game of Rock, Paper, Scissors.

Make sure your program is readable, including appropriate comments, and incorporates aspects of usability in the text prompts to the user.

/!\ Note: Your program should use decision statements, loops and simple user-defined functions with return types and call-by-value parameters.

Your program should perform the following:

1. Prompt the player for the number of games they wish to play.
2. Use a loop to allow the program to run a number of games requested by the player.
3. Within each game, prompt the player for their choice of rock, paper or scissors. Use numeric values 1, 2, and 3 to allow the user to choose a gesture. Any other value is considered invalid. You must do this inside a function. Let the function return the gesture chosen by the player back to main.

Use the following name and prototype for this function:

int getPlayersResponse (void);

1. Use the code below (integrating it into your program) to generate the computers gesture: 1, 2, or 3.

/!\ Note: You must generate a new random value for x for each game.

 In the header section In the main part of the program #include #include int x; srand (time (NULL)); x = (rand () % 3) + 1;

How does this code work? Basically the function rand() generates a random number and then performs mod 3, i.e. it returns the remainder when the random number is divided by 3 – so the remainder will be 0, 1, or 2. A value of 1 is added to this number to give 1, 2, or 3.

1. Decide who wins, the player or the computer, and print out an appropriate message – indicate who the winner is, or if the game becomes tied.
2. At the end, your program should count the number of wins for the player, number of wins for the computer, and the number of ties, and display these statistics. You must do this inside a function.

Use the following name and prototype for this function:

void printResults (int gamesTied, int gamesWonByPlayer, int gamesWonByComputer);

# 3.0 Sample Program Output

An example of a program with the features mentioned above is shown below.

User inputs are Bolded and Underlined

This program allows you to play Rock, Paper, ScissorsÂ  How many games do you want? 2

Game Number: 1

Possible Choices: 3=Rock, 2=Scissors, 1=PaperÂ  What’s your choice (number)? 1

My choice is paper.

Tie game – no winner

Game Number: 2

Possible Choices: 3=Rock, 2=Scissors, 1=PaperÂ  What’s your choice (number)? 3

My choice is scissors.

You win!!

Here is the final score…

I have won 0 game(s), you have won 1 game(s) and 1 game ended in a tie.

Thanks for playing!

# 4.0 Additional Functionality

By completing the above task correctly, you have the potential to earn up to 90% of the grade for this assignment. By going beyond the material given and completing the task below, you have the potential of earning another 10% for a total of 100%.

• Extend the program to play rock-paper-scissors-lizard-Spock.

# 5.0 Program Submission and Administration Information

The following section outlines what is expected when submitting the assignment and various other administration information with respect to the assignment.

5.1 Program Submission

To submit your assignment, upload your program C file to the submission box for A2 on Moodle. The following is expected for the submission file that is to be submitted upon completing the assignment:

• You are to submit ONE file containing your program.
• The file you are to submit is a code C file. (ends with .c)
• The name of the file follows the following format: lastnameFirstnameA2.c o Example: Ritu is the first name and Chaturvedi is the last name then the file name is chaturvediRituA2.c

o Incorrect file name will result in penalty.

5.2 Program Expectations

Your program is expected to follow the outlined information exactly. Failure to do so will result in deductions to your assignment grade.

• The program file you submit MUST compile with NO warnings and errors using the -std=c99 and -Wall flags.
• Programs that fail to compile will be given a mark of 0.
• Programs that produce warnings upon compilation will receive a deduction of 1 mark for each type/category of warning.
• The program file must contain instructions for the TA on how to compile and run your program in a header comment. For more information on this please see section Compiling and Running Header Comment Format.

/!\ Note: A header comment is a type of comment that appears at the top of your program before the #include line.

• The program file must contain the header comment shown in section Program Header Comment Format with the underlined & bolded sections properly filled in.

5.3 Program Header Comment Format

/************************lastnameFirstnameA2.c**************

Student Name: Ritu ChaturvediÂ Â Â Â Â Â  Email Id: ritu

Due Date: Mar 1st, 2019Â  Â Â Â Â  Course Name: CIS 1500Â Â  I have exclusive control over this submission via my password.

By including this statement in this header comment, I certify that:

• I have read and understood the University policy on academic integrity;
• I have completed the Computing with Integrity Tutorial on Moodle; and
• I have achieved at least 80% in the Computing with Integrity

Self Test.

I assert that this work is my own. I have appropriately acknowledged any and all material that I have used, whether directly quoted or paraphrased. Furthermore, I certify that this assignment was prepared by me specifically for this course.

**********************************************************/

/!\ Note: The file name, student name and email ID must be changed per student.

Â

5.4 Compiling and Running Header Comment Format

/*********************************************************

Compiling the program

The program should be compiled using the following flags:

-std=c99 -Wall compiling:

gcc lastnameFirstnameA2.c -std=c99 -Wall

OR gcc lastnameFirstnameA2.c -std=c99 -Wall -o assn2

*********************************************************

Running the Program running: ./a.out

OR

Running: ./assn2

*********************************************************/

/!\ Note: The file name must be changed per student.

• A2.zip