Paste: matlab
Author: | rex |
Mode: | ml |
Date: | Thu, 14 May 2009 18:48:51 |
Plain Text |
%tchukaruma.m
bins = input('Please enter the number of bins, excluding the ruma.');
%stones = input('Please enter the number of stones in each bin.');
state=[stones*ones(1,bins) 0 ];
for i=1:bins
i
state(i)=input('how many in this hole?');
end
gamestate=1;
while(gamestate && ~min(state(1:bins)==zeros(1,bins)))
state
move = input('Please enter bin you would like to move (1 is leftmost bin).');
while(move>bins || state(move)==0)
move=input('You cannot move stones in the ruma or from an emtpy bin, please select another bin.');
end
while(move~=(bins+1) && state(move)~=0 && gamestate==1)
moving = state(move);
state(move)=0;
for i=1:moving
if(move==bins+1)
move=1;
else
move=move+1;
end
if((i==moving && state(move)==0) && move~=bins+1) %% && i=bins+1 ??
gamestate=0;
end
state(move)=state(move)+1;
%state
end
end
end
if(gamestate==1)
fprintf('!!YOU WIN!!\n')
else
fprintf('YOU LOSE :(\n')
end
Author: | rex |
Mode: | ml |
Date: | Thu, 14 May 2009 19:11:30 |
Plain Text |
%tchukaruma.m
bins = input('Please enter the number of bins, excluding the ruma.');
stones = input('Please enter the number of stones in each bin.');
state=[stones*ones(1,bins) 0 ];
%for i=1:bins
% i
% state(i)=input('how many in this hole?');
%end
gamestate=1;
while(gamestate && ~min(state(1:bins)==zeros(1,bins)))
state
move = input('Please enter bin you would like to move (1 is leftmost bin).');
while(move>bins || state(move)==0)
move=input('You cannot move stones in the ruma or from an emtpy bin, please select another bin.');
end
while(move~=(bins+1) && state(move)~=0 && gamestate==1)
moving = state(move);
state(move)=0;
for i=1:moving
if(move==bins+1)
move=1;
else
move=move+1;
end
if((i==moving && state(move)==0) && move~=bins+1) %% && i=bins+1 ??
gamestate=0;
end
state(move)=state(move)+1;
end
state
end
end
if(gamestate==1)
fprintf('!!YOU WIN!!\n')
else
fprintf('YOU LOSE :(\n')
end
New Annotation