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 (최근 30일)
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

채택된 답변

ragesh r menon
ragesh r menon 2014년 4월 2일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by