I'm trying to make a paper-scissors-rock game that you verse the computer in. I need some help with the final part ... I have posted what my start of my program looks like

11 views (last 30 days)
clc; clear;
%Make your move
player_move = input('Make your move [R/P/S]; ', 's');
if player_move == 'R'
player_move = 'Rocks';
disp('Human chose rocks ');
elseif player_move == 'P'
player_move = 'Paper';
disp('Human chose paper ');
elseif player_move == 'S'
player_move = 'Scissors';
disp('Human chose scissors ');
end
%Computer makes move
computer_move = randi([0,2],1);
if computer_move == 0
disp('Computer chose rocks')
elseif computer_move == 1
disp('Computer chose paper')
elseif computer_move == 2
disp('Computer chose scissors')
end
%Determine the winner

Accepted Answer

ragesh r menon
ragesh r menon on 2 Apr 2014
Madeleine, now that you have done this far, its very easy. You just need to check if the human wins or computer wins or the game gets tie based on the choice. There will be total of 9 combinations For the game to be tie, both the players needs to choose the same, you can put this in "if " condition. for example :-
if((player_move==R&&computer_move==0)||(player_move==P&&computer_move==1)||(player_move==S&&computer_move==2))
disp('game is tie')
end
same way you can do for the case of human winning/computer winning in if loop
if (conditions for human to win eg;human choose rock and comp choose scissors.....)
disp('human won')
else
disp('comp won')
end

More Answers (0)

Categories

Find more on Just for fun in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!