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
답변 (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!