% RPS.m
clear; clc;

% Assign constant values to make program easier to read
ROCK = 1;
PAPER = 2;
SCISSORS = 3; 

% Display intro message to user
disp( 'Let''s play ROCK-PAPER-SCISSORS ');
disp( 'Each of us picks ROCK, PAPER, or SCISSORS and I''ll determine who wins.');

% Randomly choose for the computer
r = randperm(3); % randomly generate values from 1-3
c = r(1);        % pick the first one for the computer
disp( 'I have picked my object, now it''s your turn ');

% Get the user's choice
u = input('Choose 1-ROCK, 2-PAPER, or 3-SCISSORS: ');

% Check for valid choice
if u < 1 | u > 3

    disp('ERROR: Your choice was not 1,2 or 3.  Please try again.');

else   % If it was valid choice, determine the output message

    if c == u
        disp( 'It''s a tie!' );
    elseif c == ROCK & u == PAPER
        disp( 'You win. PAPER lays on top of ROCK.' );
    elseif c == ROCK & u == SCISSORS
        disp( 'I win. ROCK breaks SCISSORS.' );
    elseif c == PAPER & u == ROCK
        disp( 'I win. PAPER lays on top of ROCK.' );
    elseif c == PAPER & u == SCISSORS
        disp( 'You win. SCISSORS cuts PAPER.' );
    elseif c == SCISSORS & u == ROCK
        disp( 'You win. ROCK breaks SCISSORS.' );
    elseif c == SCISSORS & u == PAPER
        disp( 'I win. SCISSORS cuts PAPER.' );
    else
        disp( 'I''m confused.  I didn''t think this could happen.  CHECK CODE' );
    end

end