MatLab Code, requires more arguments to run

2 次查看(过去 30 天)
why wont this code run?
function [winner,playerscore] = goFish2(h1,h2,deck)
playerscore(1)=0;
playerscore(2)=0;
for i = 1:(length(h1)-1)
if(h1(i)==h1(i+1))
playerscore(1) = playerscore(1)+1;
h1(i)=[];
h1(i)=[];
if(i+2>length(h1))
break;
end
end
end
for i = 1:length(h2)-1
if(h2(i)==h2(i+1))
playerscore(2) = playerscore(2)+1;
h2(i)=[];
h2(i)=[];
if(i+2>length(h2))
break;
end
end
while(isempty(h1) && ~isempty(h2))
if(h1(1)==h2(1))
h1 = h1(2:end);
h2 = h2(2:end);
score(1) = score(1) + 1;
else
if(~isempty(deck) && h1(1)==deck(1))
h1 = h1(2:end);
deck = deck(2:end);
score(1) = score(1) + 1;
else
if(~isempty(deck))
temp = h1(1);
h1.append(deck(1));
h1 = h1(2:end);
h1.append(temp);
deck = deck(2:end);
end
end
end
end
if(isempty(h1) || isempty(h2))
break;
end
if(h1(1)==h2(1))
h1 = h1(2:end);
h2 = h2(2:end);
playerscore(2) = playerscore(2) + 1;
else
if(~isempty(deck) && h2(1)==deck(1))
h2 = h2(2:end);
deck = deck(2:end);
playerscore(2) = playerscore(2) + 1;
else
if(~isempty(deck))
temp = h2(1);
h2.append(deck(1));
h2 = h2(2:end);
h2.append(temp);
deck = deck(2:end);
end
end
end
if(playerscore(1)>playerscore(2))
winner = 'PLAYER 1 WON!';
elseif(playerscore(2)>playerscore(1))
winner = 'PLAYER 2 WON!';
else
winner = 'TIE GAME!';
end
end
end
  3 个评论
Nick Olibrice
Nick Olibrice 2020-12-19
I wasnt using the correct input for the command window so it was not working, I think I got it now. I have been trying to make a functional game of goFish in MatLab.
Nick Olibrice
Nick Olibrice 2020-12-19
Nevermind, I am unaware how to run this script, it does not work. I am trying to do what I said in my previous comment.
Thank you.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Conway's Game of Life 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by