throws to get yahtzee!?

I have a schoolproject where I'm about to create a function that shows how many throws u need to get a yatzy with five dices.
I think my code works to get yatzy one time, but when I try to do it 50000 times and take out the average value (suppost to be 11~) I get 18 every time.
Can anyone see whats wrong? The problem might be that my function counts every dice as a throw, when its suppost to count for example 3 dices as one throw if I "want" the function to throw all 3 at ones, just like u do in yatzy if u know the game. If u have any questions about names etc, just let me know!
Anyway, here is my code so far:
function yatzy=yatz(n)
MC = 0;
for z=1:50000;
i=0;
count=1;
for i = 1:n;
kast(i)=floor(rand*6);
end
sort(kast);
[Y,I]= mode(kast);
A = ones(1,I);
B = Y*A;
dices = 5-I;
while dices ~= 0;
O = floor(rand*6);
if O==Y;
dices = dices-1;
end
count=count+1;
end
korv=ones(1,n)*Y;
MC = MC+count;
end
medel = MC/50000;
medel
end

Answers (1)

Jan
Jan on 6 May 2012

0 votes

At first I'd remove the unnecessary code to reduce the confusion. E.g. "i = 0" has no effect, "sort(kast)" neither, "A = ones(1,I); B = Y*A;" is not required and "korv=ones(1,n)*Y;" wastes time only also.
Then the game, that I know and which is called "Yatzee", allowed throwing the dice 3 times only, while you throw them until you have 5 equal values. So I guess, that the game you have programmed, and the game, which leads to 11, have different rules.

Categories

Find more on Word games in Help Center and File Exchange

Tags

Asked:

Max
on 6 May 2012

Edited:

on 29 Jun 2016

Community Treasure Hunt

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

Start Hunting!