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
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Conway's Game of Life 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!