Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming Assignment 3- Rock, Paper Scissors CSCI 251-Spring 2018 Rock, Paper,

ID: 3732420 • Letter: P

Question

Programming Assignment 3- Rock, Paper Scissors CSCI 251-Spring 2018 Rock, Paper, Scissors, Lizard, Spock the BiG BANG THEORY Its Simple spock smashes scissors scissors cuts paper lizara paper disproves spock spock rock rock crushes SciSsorS paper covers rock lizard poisons spock eats paper rock crushes lizard Introduction For program 3, you will simulate the game of rock, paper, scissors, lizard, Spock (RPSLV). Prompt for1 entry and generate a random integer, 1-5, for the second entry. Then, play rock, paper, scissors, lizard or Spock. Determine who wins, ties or loses the round: See diagram above for what to output Note: if both choose the same, then it is a tie. Input Data: One player's choice, int Output Data: Player 1's move, character string Player 2's move, character string Winner of game, or tie game . . To Start: a Matlab file RPSLV.m. Include header comments (i.e, at the beginning of your file) formatted as n below. Your electronic submission of the program file will represent your endorsement of the Honor Code Statement. Use your name and ID number.

Explanation / Answer

ScreenShot

-------------------------------------------------------------------------------------------------------------------------

Program

%display welcome message
disp "Let's play Rock Paper Scissors Lizard Spoke!!! It's only logical!"
%Prompt user for input
player1=input("Enter your choice :");
      disp   "1 for Rock"
      disp "2 for Paper"
      disp "3 for Scissors"
      disp "4 for Lizar"
      disp "5 for Spoke"
      disp (player1)
%According to the input shows the player1 choice
if (player1==1)
    fprintf('You Chose Rock');
elseif (player1==2)
    fprintf('You Chose Paper');
elseif (player1==3)
     fprintf('You Chose Scissors');
elseif (player1==4)
    fprintf('You Chose Lizard');
elseif (player1==5)
    fprintf('You Chose Spoke');
else
    fprintf('wrong choice!! try again');
end

%randomly generate player2 choice
player2=randi(5);
%According to the random number shows the player2 choice
if (player2==1)
    fprintf(' The computer Chose Rock');
elseif (player2==2)
    fprintf(' The computer Chose Paper');
elseif (player2==3)
     fprintf(' The computer Chose Scissors');
elseif (player2==4)
    fprintf(' computer Chose Lizard');

elseif (player2==5)
    fprintf(' The computer Chose Spoke');
else
    fprintf(' wrong choice!! try again');
end
%Nested switch to decide the winner
switch(player1)
     %outer switch for Rock
     case 1
     %Inner switch for comparison
     switch(player2)
        case 1
           fprintf(' Two players chose same!!Game is tie');
        case 2
           fprintf(' You lose.Paper covers Rock');
        case 3
           fprintf(' You Win!!Rock crushes Scissors');
        case 4
           fprintf(' You Win!!Rock crushes Lizard');
        case 5
           fprintf(' You lose.Spoke vaporizes Rock');
     end
     %outer switch case for Paper
     case 2
     %Inner switch for comparison
     switch(player2)
        case 1
           fprintf(' You Win!!Paper covers Rock');
        case 2
           fprintf(' Two players chose same!!Game is tie');
        case 3
           fprintf(' You lose.Scissors cut Paper');
        case 4
           fprintf(' You lose.Lizard eats Paper');
        case 5
           fprintf(' You Win!!Paper disproves Spoke');
     end
     %Outer switch case for Scissors
     case 3
     %Inner switch for comparison
     switch(player2)
        case 1
           fprintf(' You lose.Rock crushes Scissors');
        case 2
           fprintf(' You Win!!Scissors cut Paper');
        case 3
           fprintf(' Two players chose same!!Game is tie');
        case 4
           fprintf(' You Win!!Scissors decapitate Lizard');
        case 5
           fprintf(' You lose.Spoke smashes Scissors');
     end
     %outer switch case for Lizard
     case 4
     %inner switch for comparison
     switch(player2)
        case 1
           fprintf(' You lose.Rock crushes Lizard');
        case 2
           fprintf(' You Win!!Lizard eat Paper');
        case 3
           fprintf(' You lose.Scissors decapitate Lizard');
        case 4
           fprintf(' Two players chose same!!Game is tie');
        case 5
           fprintf(' You Win!!Lizard poisons Spoke');
     end
     %outer switch for spoke

case 5
     %inner switch for comparison
     switch(player2)
        case 1
           fprintf(' You Win!!Spoke vaporizes Rock');
        case 2
           fprintf(' You lose.Paper disproves spoke');
        case 3
           fprintf(' You Win!!Spoke smashes Scissors');
        case 4
           fprintf(' You lose.Lizars poisons spoke');
        case 5
           fprintf(' Two players chose same!!Game is tie');
     end
end
%end message
disp " Come back any time!"