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

Please help me: Using Matlab program implement the rock-paper-scissors-lizard-sp

ID: 3766925 • Letter: P

Question

Please help me: Using Matlab program implement the rock-paper-scissors-lizard-spock game. Only use "switch constructs" in your program (Do not use "if construct").

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.

Please use MATLAB:

1.- Computer makes a random choice

2.- Accept user's choice

3.- Determine who wins the game

4.- Create an array (rules)

5.- Print out results

0---draw, 1---you win, -1---computer win

Explanation / Answer


% Array of rules:
% Scissors ( = S = 1) wins over paper, lizard
% paper ( = P =2 ) wins over rock, Spock
% rock ( = R = 3 ) wins over scissors, lizard,
% lizard ( = L = 4) wins over paper, Spock
% Spock ( = K =5 ) wins over Scissors, rock

%draw conditions:
% only when both players have the same tool like
% Lizard Versus ( = V ) Lizard, Spock Versus Spock
% R V R , P V P etc

iPersonTurn=input(' Enter Choice: 1 = Scissors , 2 = paper , 3 = rock, 4 = lizard , 5 = Spock ');

iCompTurn=randi(1,5)

switch iCompTurn
   case 1 % Computer chose Scissors
       switch iPersonTurn
           case 1 % You chose Scissors
               disp('Draw = 0') $ Scissors Versus Scissors is a draw
           case 2 % You chose Paper
               disp ('Computer wins = -1 ')   % Scissor cuts paper
           case 3 % You chose Rock
               disp('You Win = 1 ')    % Rock crushes Scissors
           case 4 % You chose Lizard
               disp ('Computer wins = -1 ') % Scissor decapitates Lizard
           case 5 % You chose Spoke
               disp('You Win = 1 ') % Spoke Crushes Scissors
           otherwise
               disp('Wrong Choice')

   case 2 % computer chose Paper
       switch iPersonTurn
           case 1 % You chose Scissors
               disp('You Win = 1 ') % Scissor cuts paper
           case 2 % You chose Paper
               disp('Draw ')
           case 3 % You chose Rock
               disp ('Computer wins = -1 ') % Paper Covers Rock
           case 4 % You chose Lizard
               disp('You Win = 1 ') % Lizard eats Paper
           case 5 % You chose Spoke
               disp ('Computer wins = -1 ') % Paper disproves Spoke
           otherwise
               disp('Wrong Choice')


   case 3 % computer chose Rock
       switch iPersonTurn
           case 1 % You chose Scissors
               disp ('Computer wins = -1 ') % Rock crushes Scissors
           case 2 % You chose Paper
               disp('You Win = 1 ')
           case 3 % You chose Rock
               disp(' draw')
           case 4 % You chose Lizard
               disp ('computer wins ') % Rock crushes L
           case 5 % You chose Spoke
               disp(' You win') % K Vaporises R
           otherwise
               disp('Wrong Choice')

   case 4 % computer chose Lizard
       switch iPersonTurn
           case 1 % You chose Scissors
               disp('you win ')
           case 2 % You chose Paper
               disp('computer wins ') % L eats P
           case 3 % You chose Rock
               disp('you win ')
           case 4 % You chose Lizard
               disp (' draw')
           case 5 % You chose Spoke
               disp('you win ') % P Disproves K
           otherwise
               disp('Wrong Choice')

   case 5 % computer chose Spoke
       switch iPersonTurn
           case 1 % You chose Scissors
               disp('Computer wins ') % K smashes S
           case 2 % You chose Paper
               disp('You win ')
           case 3 % You chose Rock
               disp(' computer wins')
           case 4 % You chose Lizard
               disp ('you win ')
           case 5 % You chose Spoke
               disp(' draw')
           otherwise
               disp('Wrong Choice')

   otherwise
       disp('Wrong Choice')
end % end of switch

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote