function yahtzee(varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab version of dice game %
% Completed 07-30-03 by KDC for programming practice %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
again = 'Y';
disp(' ');
disp(' ');
disp(' ');
disp(' \ / /\ | | ----------- ------- ------- ------- |');
disp(' \ / / \ | | | / | | |');
disp(' \ / / \ | | | / | | |');
disp(' \/ / \ | | | / | | |');
disp(' || /--------\ |--------| | / |----- |----- |');
disp(' || / \ | | | / | | |');
disp(' || / \ | | | / | | ');
disp(' || / \ | | | /______ |______ |______ O');
disp(' ');
roll{1} = {' _____ ','| |','| o |','|_____|'}';
roll{2} = {' _____ ','|o |','| |','|____o|'}';
roll{3} = {' _____ ','|o |','| o |','|____o|'}';
roll{4} = {' _____ ','|o o|','| |','|o___o|'}';
roll{5} = {' _____ ','|o o|','| o |','|o___o|'}';
roll{6} = {' _____ ','|o o|','|o o|','|o___o|'}';
disp([roll{1},roll{2},roll{3},roll{4},roll{5},roll{6}]);
disp(' ');
disp(' ');
disp('Welcome to Matlab Yahtzee 1.0');
disp(' ');
disp('The object of Yahtzee is to score as many points as possible with the rolls of five dice.');
disp(' ');
disp('As a player, you must try to fill each of the following dice combinations once: ');
disp(' ');
disp(' Ones (Ex. 2 x 1 = 2 points)');
disp(' Twos (Ex. 3 x 2 = 6 points)');
disp(' Threes (Ex. 2 x 3 = 6 points)');
disp(' Fours (Ex. 4 x 4 = 16 points)');
disp(' Fives (Ex. 1 x 5 = 5 points)');
disp(' Sixes (Ex. 3 x 6 = 18 points)');
disp(' Three of a Kind - total of all 5 dice, (Ex. 4 4 4 2 6 = 20 points)');
disp(' Four of a Kind - total of all 5 dice, (Ex. 5 5 5 5 1 = 21 points)');
disp(' Full House - 3 of a kind & a pair (Ex. 5 5 5 3 3; 25 points)');
disp(' Small Straight - 4 numbers in a row (Ex. 2 3 4 5 5; 30 points)');
disp(' Large Straight - 5 numbers in a row (Ex. 2 3 4 5 6; 40 points)');
disp(' Yahtzee - 5 of a kind (Ex. 1 1 1 1 1; 50 points)');
disp(' Chance - Any hand (Ex. 5 4 1 3 3 = 16 points)');
disp(' ');
disp(' For a maximum of 13 rounds...');
disp(' ');
disp(' Numbers from a particular roll can be discarded twice, i.e.:');
disp(' First Roll: 4 4 2 1 6 <-- keep the fours, discard the others');
disp(' Second Roll: 4 4 4 3 5 <-- 3 dice rolled; keep the fours again');
disp(' Third Roll: 4 4 4 4 2 <-- 2 dice rolled, final roll');
disp(' ');
disp(' After each roll, select the dice (if any) you want to roll again.');
disp(' If you can fill all 12 slots, you win.');
disp(' ');
play = input('Want to play? (Y)/N ','s');
if play == 'N' | play == 'n'
return
else
disp(' ');
name = input('What is your name? ','s');
if name == ''
name = 'Mister No-Name';
end
disp(' ');
while again == 'Y' | again == 'y'
disp(['Ok, ',name, ', Get ready to play!']);
disp(' ');
total_score = 0;
round_score = 0;
for x = 1:100000
% pause
end
disp('Press any key to begin');
pause
choice = [0,0,0,0,0,0,0,0,0,0,0,0,0];
already = 0;
s1 = 0;
s2 = 0;
s3 = 0;
s4 = 0;
s5 = 0;
s6 = 0;
for turn = 1:13
disp(' ');
disp(' ');
disp(' ');
disp(' ');
disp(' ');
disp(' ');
disp(' ');
disp(' ');
disp(' ');
disp(' ');
disp(' ');
disp(' ');
disp(' ');
disp(' ');
ok = 0;
disp('Dice roll: ');
for x = 1:5
num(x) = rand(1);
if num(x) > .8333
num(x) = 6;
elseif num(x) > .6667
num(x) = 5;
elseif num(x) > .5
num(x) = 4;
elseif num(x) > .3333
num(x) = 3;
elseif num(x) > .1666
num(x) = 2;
else
num(x) = 1;
end
% disp(roll{num(x)});
end
disp(' ');
disp(' ');
disp(' ________________________________________________________________');
disp(' ');
disp(' ');
disp([roll{num(1)},roll{num(2)},roll{num(3)},roll{num(4)},roll{num(5)}]);
disp(' ');
disp(' ________________________________________________________________');
disp(' ');
disp(' ');
disp('Possible hands:');
disp(' ');
if num(1) == num(2) & num(3) == num(4) & num(5) == num(1) & num(1) == num(3) & choice(12) == 0
disp('Yahtzee!');
end
if num(1) == num(2) & num(1) == num(3) & num(1) == num(4) & choice(11) == 0
disp('Four of a kind');
elseif num(1) == num(3) & num(1) == num(4) & num(1) == num(5) & choice(11) == 0
disp('Four of a kind');
elseif num(1) == num(2) & num(1) == num(4) & num(1) == num(5) & choice(11) == 0
disp('Four of a kind');
elseif num(1) == num(2) & num(1) == num(3) & num(1) == num(5) & choice(11) == 0
disp('Four of a kind');
elseif num(2) == num(3) & num(2) == num(4) & num(2) == num(5) & choice(11) == 0
disp('Four of a kind');
else
end
if num(1) == num(2) & num(2) == num(3)
if choice(9) == 0
disp('Three of a kind');
end
if num(4) == num(5) & choice(10) == 0
disp('Full House');
end
elseif num(1) == num(2) & num(2) == num(4)
if choice(9) == 0
disp('Three of a kind');
end
if num(3) == num(5) & choice(10) == 0
disp('Full House');
end
elseif num(1) == num(2) & num(2) == num(5)
if choice(9) == 0
disp('Three of a kind');
end
if num(3) == num(4) & choice(10) == 0
disp('Full House');
end
elseif num(1) == num(3) & num(3) == num(4)
if choice(9) == 0
disp('Three of a kind');
end
if num(2) == num(5) & choice(10) == 0
disp('Full House');
end
elseif num(1) == num(3) & num(3) == num(5)
if choice(9) == 0
disp('Three of a kind');
end
if num(2) == num(4) & choice(10) == 0
disp('Full House');
end
elseif num(1) == num(4) & num(4) == num(5)
if choice(9) == 0
disp('Three of a kind');
end
if num(2) == num(3) & choice(10) == 0
disp('Full House');
end
elseif num(2) == num(3) & num(3) == num(4)
if choice(9) == 0
disp('Three of a kind');
end
if num(1) == num(5) & choice(10) == 0
disp('Full House');
end
elseif num(2) == num(3) & num(3) == num(5)
if choice(9) == 0
disp('Three of a kind');
end
if num(1) == num(4) & choice(10) == 0
disp('Full House');
end
elseif num(2) == num(4) & num(4) == num(5)
if choice(9) == 0
disp('Three of a kind');
end
if num(1) == num(3) & choice(10) == 0
disp('Full House');
end
elseif num(3) == num(4) & num(4) == num(5)
if choice(9) == 0
disp('Three of a kind');
end
if num(1) == num(2) & choice(10) == 0
disp('Full House');
end
else
end
small = 0;
if num(1)==1 | num(2)==1 | num(3)==1 | num(4)==1 | num(5) == 1
if num(1)==2 | num(2)==2 | num(3)==2 | num(4)==2 | num(5) == 2
if num(1)==3 | num(2)==3 | num(3)==3 | num(4)==3 | num(5) == 3
if num(1)==4 | num(2)==4 | num(3)==4 | num(4)==4 | num(5) == 4
if choice(7) == 0
disp('Small Straight');
small=1;
end
if num(1)==5 | num(2)==5 | num(3)==5 | num(4)==5 | num(5) == 5
if choice(8) == 0
disp('Large Straight');
end
end
end
end
end
end
if num(1)==2 | num(2)==2 | num(3)==2 | num(4)==2 | num(5) == 2
if num(1)==3 | num(2)==3 | num(3)==3 | num(4)==3 | num(5) == 3
if num(1)==4 | num(2)==4 | num(3)==4 | num(4)==4 | num(5) == 4
if num(1)==5 | num(2)==5 | num(3)==5 | num(4)==5 | num(5) == 5
if small==0
if choice(7) == 0
disp('Small Straight');
small = 1;
end
end
if num(1)==6 | num(2)==6 | num(3)==6 | num(4)==6 | num(5) == 6
if choice(8) == 0
disp('Large Straight');
end
end
end
end
end
end
if num(1)==3 | num(2)==3 | num(3)==3 | num(4)==3 | num(5) == 3
if num(1)==4 | num(2)==4 | num(3)==4 | num(4)==4 | num(5) == 4
if num(1)==5 | num(2)==5 | num(3)==5 | num(4)==5 | num(5) == 5
if num(1)==6 | num(2)==6 | num(3)==6 | num(4)==6 | num(5) == 6
if small == 0
if choice(7) == 0
disp('Small Straight');
small = 1;
end
end
end
end
end
end
if choice(13) == 0
disp('Chance');
end
if num(1) == 1 | num(2) == 1 | num(3) == 1 | num(4) == 1 | num(5) == 1
if choice(1) == 0
disp('Ones');
end
end
if num(1) == 2 | num(2) == 2 | num(3) == 2 | num(4) == 2 | num(5) == 2
if choice(2) == 0
disp('Twos');
end
end
if num(1) == 3 | num(2) == 3 | num(3) == 3 | num(4) == 3 | num(5) == 3
if choice(3) == 0
disp('Threes');
end
end
if num(1) == 4 | num(2) == 4 | num(3) == 4 | num(4) == 4 | num(5) == 4
if choice(4) == 0
disp('Fours');
end
end
if num(1) == 5 | num(2) == 5 | num(3) == 5 | num(4) == 5 | num(5) == 5
if choice(5) == 0
disp('Fives');
end
end
if num(1) == 6 | num(2) == 6 | num(3) == 6 | num(4) == 6 | num(5) == 6
if choice(6) == 0
disp('Sixes');
end
end
discard_y = 'x';
while discard_y == 'x'
discard_y = input(' Discard any dice? (Y)/N)','s');
if isempty(discard_y)
discard_y = 'Y';
end
if strcmp(discard_y,'Y') == 0 & strcmp(discard_y,'y') == 0 & strcmp(discard_y,'N') == 0 & strcmp(discard_y,'n') == 0
discard_y = 'x';
elseif strcmp(discard_y,'N') == 1 | strcmp(discard_y,'n') == 1
final_hand = {roll{num(1)},roll{num(2)},roll{num(3)},roll{num(4)},roll{num(5)}};
else
for die = 1:5
discard = 'x';
while discard == 'x'
discard = input(['Discard die #',num2str(die),'? (Y/(N)): '],'s');
if isempty(discard)
discard = 'N';
end
if strcmp(discard,'Y') == 0 & strcmp(discard,'y') == 0 & strcmp(discard,'n') == 0 & strcmp(discard,'N') == 0
discard = 'x';
elseif strcmp(discard,'n') == 1 | strcmp(discard,'N') == 1
% go on to next die #
else
num(die) = rand(1);
if num(die) > .8333
num(die) = 6;
elseif num(die) > .6667
num(die) = 5;
elseif num(die) > .5
num(die) = 4;
elseif num(die) > .3333
num(die) = 3;
elseif num(die) > .1666
num(die) = 2;
else
num(die) = 1;
end
end
end
end
end
end
for x = 1:100000
end
disp('Results of second roll: ');
disp(' ');
disp(' ________________________________________________________________');
disp(' ');
disp(' ');
disp([roll{num(1)},roll{num(2)},roll{num(3)},roll{num(4)},roll{num(5)}]);
disp(' ');
disp(' ________________________________________________________________');
disp(' ');
disp(' ');
disp('Possible hands:');
disp(' ');
if num(1) == num(2) & num(3) == num(4) & num(5) == num(1) & num(1) == num(3) & choice(12) == 0
disp('Yahtzee!');
end
if num(1) == num(2) & num(1) == num(3) & num(1) == num(4) & choice(11) == 0
disp('Four of a kind');
elseif num(1) == num(3) & num(1) == num(4) & num(1) == num(5) & choice(11) == 0
disp('Four of a kind');
elseif num(1) == num(2) & num(1) == num(4) & num(1) == num(5) & choice(11) == 0
disp('Four of a kind');
elseif num(1) == num(2) & num(1) == num(3) & num(1) == num(5) & choice(11) == 0
disp('Four of a kind');
elseif num(2) == num(3) & num(2) == num(4) & num(2) == num(5) & choice(11) == 0
disp('Four of a kind');
else
end
if num(1) == num(2) & num(2) == num(3)
if choice(9) == 0
disp('Three of a kind');
end
if num(4) == num(5) & choice(10) == 0
disp('Full House');
end
elseif num(1) == num(2) & num(2) == num(4)
if choice(9) == 0
disp('Three of a kind');
end
if num(3) == num(5) & choice(10) == 0
disp('Full House');
end
elseif num(1) == num(2) & num(2) == num(5)
if choice(9) == 0
disp('Three of a kind');
end
if num(3) == num(4) & choice(10) == 0
disp('Full House');
end
elseif num(1) == num(3) & num(3) == num(4)
if choice(9) == 0
disp('Three of a kind');
end
if num(2) == num(5) & choice(10) == 0
disp('Full House');
end
elseif num(1) == num(3) & num(3) == num(5)
if choice(9) == 0
disp('Three of a kind');
end
if num(2) == num(4) & choice(10) == 0
disp('Full House');
end
elseif num(1) == num(4) & num(4) == num(5)
if choice(9) == 0
disp('Three of a kind');
end
if num(2) == num(3) & choice(10) == 0
disp('Full House');
end
elseif num(2) == num(3) & num(3) == num(4)
if choice(9) == 0
disp('Three of a kind');
end
if num(1) == num(5) & choice(10) == 0
disp('Full House');
end
elseif num(2) == num(3) & num(3) == num(5)
if choice(9) == 0
disp('Three of a kind');
end
if num(1) == num(4) & choice(10) == 0
disp('Full House');
end
elseif num(2) == num(4) & num(4) == num(5)
if choice(9) == 0
disp('Three of a kind');
end
if num(1) == num(3) & choice(10) == 0
disp('Full House');
end
elseif num(3) == num(4) & num(4) == num(5)
if choice(9) == 0
disp('Three of a kind');
end
if num(1) == num(2) & choice(10) == 0
disp('Full House');
end
else
end
small = 0;
if num(1)==1 | num(2)==1 | num(3)==1 | num(4)==1 | num(5) == 1
if num(1)==2 | num(2)==2 | num(3)==2 | num(4)==2 | num(5) == 2
if num(1)==3 | num(2)==3 | num(3)==3 | num(4)==3 | num(5) == 3
if num(1)==4 | num(2)==4 | num(3)==4 | num(4)==4 | num(5) == 4
if choice(7) == 0
disp('Small Straight');
small = 1;
end
if num(1)==5 | num(2)==5 | num(3)==5 | num(4)==5 | num(5) == 5
if choice(8) == 0
disp('Large Straight');
end
end
end
end
end
end
if num(1)==2 | num(2)==2 | num(3)==2 | num(4)==2 | num(5) == 2
if num(1)==3 | num(2)==3 | num(3)==3 | num(4)==3 | num(5) == 3
if num(1)==4 | num(2)==4 | num(3)==4 | num(4)==4 | num(5) == 4
if num(1)==5 | num(2)==5 | num(3)==5 | num(4)==5 | num(5) == 5
if small==0
if choice(7) == 0
disp('Small Straight');
small = 1;
end
end
if num(1)==6 | num(2)==6 | num(3)==6 | num(4)==6 | num(5) == 6
if choice(8) == 0
disp('Large Straight');
end
end
end
end
end
end
if num(1)==3 | num(2)==3 | num(3)==3 | num(4)==3 | num(5) == 3
if num(1)==4 | num(2)==4 | num(3)==4 | num(4)==4 | num(5) == 4
if num(1)==5 | num(2)==5 | num(3)==5 | num(4)==5 | num(5) == 5
if num(1)==6 | num(2)==6 | num(3)==6 | num(4)==6 | num(5) == 6
if small == 0
if choice(7) == 0
disp('Small Straight');
small = 1;
end
end
end
end
end
end
if choice(13) == 0
disp('Chance');
end
if num(1) == 1 | num(2) == 1 | num(3) == 1 | num(4) == 1 | num(5) == 1
if choice(1) == 0
disp('Ones');
end
end
if num(1) == 2 | num(2) == 2 | num(3) == 2 | num(4) == 2 | num(5) == 2
if choice(2) == 0
disp('Twos');
end
end
if num(1) == 3 | num(2) == 3 | num(3) == 3 | num(4) == 3 | num(5) == 3
if choice(3) == 0
disp('Threes');
end
end
if num(1) == 4 | num(2) == 4 | num(3) == 4 | num(4) == 4 | num(5) == 4
if choice(4) == 0
disp('Fours');
end
end
if num(1) == 5 | num(2) == 5 | num(3) == 5 | num(4) == 5 | num(5) == 5
if choice(5) == 0
disp('Fives');
end
end
if num(1) == 6 | num(2) == 6 | num(3) == 6 | num(4) == 6 | num(5) == 6
if choice(6) == 0
disp('Sixes');
end
end
discard_2 = input(' Discard any dice? (Y)/N ','s');
if isempty(discard_2)
discard_2 = 'Y';
end
if discard_2 == 'n' | discard_2 == 'N'
final_hand = {roll{num(1)},roll{num(2)},roll{num(3)},roll{num(4)},roll{num(5)}};
else
for die = 1:5
discard = 'x';
while discard == 'x'
discard = input(['Discard die #',num2str(die),'? (Y/(N)): '],'s');
if isempty(discard)
discard = 'N';
end
if strcmp(discard,'Y') == 0 & strcmp(discard,'y') == 0 & strcmp(discard,'n') == 0 & strcmp(discard,'N') == 0
discard = 'x';
elseif strcmp(discard,'n') == 1 | strcmp(discard,'N') == 1
% go on to next die #
else
num(die) = rand(1);
if num(die) > .8333
num(die) = 6;
elseif num(die) > .6667
num(die) = 5;
elseif num(die) > .5
num(die) = 4;
elseif num(die) > .3333
num(die) = 3;
elseif num(die) > .1666
num(die) = 2;
else
num(die) = 1;
end
end
end
end
end
for x = 1:100000
end
disp('Results of third roll: ');
disp(' ');
disp(' ________________________________________________________________');
disp(' ');
disp(' ');
disp([roll{num(1)},roll{num(2)},roll{num(3)},roll{num(4)},roll{num(5)}]);
disp(' ');
disp(' ________________________________________________________________');
disp(' ');
disp(' ');
disp('Possible Final Hands:');
disp(' ');
num_ones = 0;
num_twos = 0;
num_threes = 0;
num_fours = 0;
num_fives = 0;
num_sixes = 0;
available = [0,0,0,0,0,0,0,0,0,0,0,0,0];
if num(1) == 1 | num(2) == 1 | num(3) == 1 | num(4) == 1 | num(5) == 1
if choice(1) == 0
disp('1 - Ones');
ok = 1;
available(1) = 1;
for q = 1:5
if num(q) == 1
num_ones = num_ones + 1;
end
end
end
end
if num(1) == 2 | num(2) == 2 | num(3) == 2 | num(4) == 2 | num(5) == 2
if choice(2) == 0
disp('2 - Twos');
ok = 1;
available(2) = 1;
for q = 1:5
if num(q) == 2
num_twos = num_twos + 1;
end
end
end
end
if num(1) == 3 | num(2) == 3 | num(3) == 3 | num(4) == 3 | num(5) == 3
if choice(3) == 0
disp('3 - Threes');
available(3) = 1;
ok = 1;
for q = 1:5
if num(q) == 3
num_threes = num_threes + 1;
end
end
end
end
if num(1) == 4 | num(2) == 4 | num(3) == 4 | num(4) == 4 | num(5) == 4
if choice(4) == 0
disp('4 - Fours');
ok = 1;
available(4) = 1;
for q = 1:5
if num(q) == 4
num_fours = num_fours + 1;
end
end
end
end
if num(1) == 5 | num(2) == 5 | num(3) == 5 | num(4) == 5 | num(5) == 5
if choice(5) == 0
disp('5 - Fives');
available(5) = 1;
ok = 1;
for q = 1:5
if num(q) == 5
num_fives = num_fives + 1;
end
end
end
end
if num(1) == 6 | num(2) == 6 | num(3) == 6 | num(4) == 6 | num(5) == 6
if choice(6) == 0
disp('6 - Sixes');
available(6) = 1;
ok = 1;
for q = 1:5
if num(q) == 6
num_sixes = num_sixes + 1;
end
end
end
end
small = 0;
if num(1)==1 | num(2)==1 | num(3)==1 | num(4)==1 | num(5) == 1
if num(1)==2 | num(2)==2 | num(3)==2 | num(4)==2 | num(5) == 2
if num(1)==3 | num(2)==3 | num(3)==3 | num(4)==3 | num(5) == 3
if num(1)==4 | num(2)==4 | num(3)==4 | num(4)==4 | num(5) == 4
if choice(7) == 0
disp('7 - Small Straight');
available(7) = 1;
ok = 1;
small=1;
end
if num(1)==5 | num(2)==5 | num(3)==5 | num(4)==5 | num(5) == 5
if choice(8) == 0
disp('8 - Large Straight');
available(8) = 1;
ok = 1;
end
end
end
end
end
end
if num(1)==2 | num(2)==2 | num(3)==2 | num(4)==2 | num(5) == 2
if num(1)==3 | num(2)==3 | num(3)==3 | num(4)==3 | num(5) == 3
if num(1)==4 | num(2)==4 | num(3)==4 | num(4)==4 | num(5) == 4
if num(1)==5 | num(2)==5 | num(3)==5 | num(4)==5 | num(5) == 5
if small==0
if choice(7) == 0
disp('7 - Small Straight');
available(7) = 1;
ok = 1;
small = 1;
end
end
if num(1)==6 | num(2)==6 | num(3)==6 | num(4)==6 | num(5) == 6
if choice(8) == 0
disp('8 - Large Straight');
available(8) = 1;
ok = 1;
end
end
end
end
end
end
if num(1)==3 | num(2)==3 | num(3)==3 | num(4)==3 | num(5) == 3
if num(1)==4 | num(2)==4 | num(3)==4 | num(4)==4 | num(5) == 4
if num(1)==5 | num(2)==5 | num(3)==5 | num(4)==5 | num(5) == 5
if num(1)==6 | num(2)==6 | num(3)==6 | num(4)==6 | num(5) == 6
if small == 0
if choice(7) == 0
disp('7 - Small Straight');
available(7) = 1;
ok = 1;
small = 1;
end
end
end
end
end
end
if num(1) == num(2) & num(2) == num(3)
if choice(9) == 0
disp('9 - Three of a kind');
available(9) = 1;
ok = 1;
end
if num(4) == num(5) & choice(10) == 0
disp('10 - Full House');
available(10) = 1;
ok = 1;
end
elseif num(1) == num(2) & num(2) == num(4)
if choice(9) == 0
disp('9 - Three of a kind');
available(9) = 1;
ok = 1;
end
if num(3) == num(5) & choice(10) == 0
disp('10 - Full House');
available(10) = 1;
ok = 1;
end
elseif num(1) == num(2) & num(2) == num(5)
if choice(9) == 0
disp('9 - Three of a kind');
available(9) = 1;
ok = 1;
end
if num(3) == num(4) & choice(10) == 0
disp('10 - Full House');
available(10) = 1;
ok = 1;
end
elseif num(1) == num(3) & num(3) == num(4)
if choice(9) == 0
disp('9 - Three of a kind');
available(9) = 1;
ok = 1;
end
if num(2) == num(5) & choice(10) == 0
disp('10 - Full House');
available(10) = 1;
ok = 1;
end
elseif num(1) == num(3) & num(3) == num(5)
if choice(9) == 0
disp('9 - Three of a kind');
available(9) = 1;
ok = 1;
end
if num(2) == num(4) & choice(10) == 0
disp('10 - Full House');
available(10) = 1;
ok = 1;
end
elseif num(1) == num(4) & num(4) == num(5)
if choice(9) == 0
disp('9 - Three of a kind');
available(9) = 1;
ok = 1;
end
if num(2) == num(3) & choice(10) == 0
disp('10 - Full House');
available(10) = 1;
ok = 1;
end
elseif num(2) == num(3) & num(3) == num(4)
if choice(9) == 0
disp('9 - Three of a kind');
available(9) = 1;
ok = 1;
end
if num(1) == num(5) & choice(10) == 0
disp('10 - Full House');
available(10) = 1;
ok = 1;
end
elseif num(2) == num(3) & num(3) == num(5)
if choice(9) == 0
disp('9 - Three of a kind');
available(9) = 1;
ok = 1;
end
if num(1) == num(4) & choice(10) == 0
disp('10 - Full House');
available(10) = 1;
ok = 1;
end
elseif num(2) == num(4) & num(4) == num(5)
if choice(9) == 0
disp('9 - Three of a kind');
available(9) = 1;
ok = 1;
end
if num(1) == num(3) & choice(10) == 0
disp('10 - Full House');
available(10) = 1;
ok = 1;
end
elseif num(3) == num(4) & num(4) == num(5)
if choice(9) == 0
disp('9 - Three of a kind');
available(9) = 1;
ok = 1;
end
if num(1) == num(2) & choice(10) == 0
disp('10 - Full House');
available(10) = 1;
ok = 1;
end
else
end
if num(1) == num(2) & num(1) == num(3) & num(1) == num(4) & choice(11) == 0
disp('11 - Four of a kind');
available(11) = 1;
ok = 1;
elseif num(1) == num(3) & num(1) == num(4) & num(1) == num(5) & choice(11) == 0
disp('11 - Four of a kind');
available(11) = 1;
ok = 1;
elseif num(1) == num(2) & num(1) == num(4) & num(1) == num(5) & choice(11) == 0
disp('11 - Four of a kind');
available(11) = 1;
ok = 1;
elseif num(1) == num(2) & num(1) == num(3) & num(1) == num(5) & choice(11) == 0
disp('11 - Four of a kind');
available(11) = 1;
ok = 1;
elseif num(2) == num(3) & num(2) == num(4) & num(2) == num(5) & choice(11) == 0
disp('11 - Four of a kind');
available(11) = 1;
ok = 1;
else
end
if num(1) == num(2) & num(3) == num(4) & num(5) == num(1) & num(1) == num(3) & choice(12) == 0
disp('12 - Yahtzee!');
available(12) = 1;
ok = 1;
end
if choice(13) == 0
disp('13 - Chance');
available(13) = 1;
ok = 1;
end
disp(' ');
if ok == 0
disp('Game Over - No More Slots Available for your current roll');
disp(['Final Score: ',num2str(total_score)]);
break
else
fill_num = '0';
if turn > 1
disp(' ');
disp('Used already: ');
for p = 1:13
used = {'Ones','Twos','Threes','Fours','Fives','Sixes','Small Straight','Large Straight','Three of a Kind','Full House','Four of a Kind','Yahtzee','Chance'};
if choice(p) == 1
disp(used{p});
end
end
disp(' ')
end
while str2num(fill_num) < 1 | str2num(fill_num) > 13
fill_num = input('Which do you want to fill? ','s');
disp(' ');
if isempty(fill_num)
fill_num = '14';
end
for p = 1:13
if choice(p) == 1 & str2num(fill_num) == p
disp('Sorry, that option has already been used. Pick another!');
fill_num = '14';
end
if available(p) == 0 & str2num(fill_num) == p
disp('Sorry, that option is not available for this roll. Pick another!');
fill_num = '14';
end
end
if str2num(fill_num) == 12
total_score = total_score + 50;
round_score = 50;
choice(12) = 1;
end
if str2num(fill_num) == 13 | str2num(fill_num) == 9 | str2num(fill_num) == 11
total_score = total_score + num(1) + num(2) + num(3) + num(4) + num(5);
round_score = num(1) + num(2) + num(3) + num(4) + num(5);
if str2num(fill_num) == 13
choice(13) = 1;
elseif str2num(fill_num) == 9
choice(9) = 1;
else
choice(11) = 1;
end
end
if str2num(fill_num) == 10
total_score = total_score + 25;
round_score = 25;
choice(10) = 1;
end
if str2num(fill_num) == 7
total_score = total_score + 30;
round_score = 30;
choice(7) = 1;
end
if str2num(fill_num) == 8
total_score = total_score + 40;
round_score = 40;
choice(8) = 1;
end
if str2num(fill_num) == 1
total_score = total_score + (1*num_ones);
round_score = num_ones;
s1 = round_score;
choice(1) = 1;
if s1 + s2 + s3 + s4 + s5 + s6 >= 63 & already == 0
disp('35 point bonus for scoring 63 or better for 1-6');
total_score = total_score + 35;
already = 1;
end
end
if str2num(fill_num) == 2
total_score = total_score + (2*num_twos);
round_score = 2*num_twos;
s2 = round_score;
choice(2) = 1;
if s1 + s2 + s3 + s4 + s5 + s6 >= 63 & already == 0
disp('35 point bonus for scoring 63 or better for 1-6');
total_score = total_score + 35;
already = 1;
end
end
if str2num(fill_num) == 3
total_score = total_score + (3*num_threes);
round_score = 3*num_threes;
s3 = round_score;
choice(3) = 1;
if s1 + s2 + s3 + s4 + s5 + s6 >= 63 & already == 0
disp('35 point bonus for scoring 63 or better for 1-6');
total_score = total_score + 35;
already = 1;
end
end
if str2num(fill_num) == 4
total_score = total_score + (4*num_fours);
round_score = 4*num_fours;
s4 = round_score;
choice(4) = 1;
if s1 + s2 + s3 + s4 + s5 + s6 >= 63 & already == 0
disp('35 point bonus for scoring 63 or better for 1-6');
total_score = total_score + 35;
already = 1;
end
end
if str2num(fill_num) == 5
total_score = total_score + (5*num_fives);
round_score = 5*num_fives;
s5 = round_score;
choice(5) = 1;
if s1 + s2 + s3 + s4 + s5 + s6 >= 63 & already == 0
disp('35 point bonus for scoring 63 or better for 1-6');
total_score = total_score + 35;
already = 1;
end
end
if str2num(fill_num) == 6
total_score = total_score + (6*num_sixes);
round_score = 6*num_sixes;
s6 = round_score;
choice(6) = 1;
if s1 + s2 + s3 + s4 + s5 + s6 >= 63 & already == 0
disp('35 point bonus for scoring 63 or better for 1-6');
total_score = total_score + 35;
already = 1;
end
end
end
disp(['Round Score: ',num2str(round_score)]);
disp(['Total Score: ',num2str(total_score)]);
disp(' ');
available = [0,0,0,0,0,0,0,0,0,0,0,0,0];
disp('Press any key to continue');
pause
end
end
if choice == [1,1,1,1,1,1,1,1,1,1,1,1,1]
disp(' ');
disp('Perfect - you used all the available slots!');
disp(['Final Score: ',num2str(total_score)]);
disp(' ');
end
again = input('Play again? (Y)/N','s');
if again == 'N' | again == 'N'
disp(' ');
disp(' ');
return
end
end
end