function Opdrachtc
clear;
clc;
fontSize = 15;
for kk = 1 : 10
h(kk) = MDealer(kk)
H=categorical(h,[1,2,3,4,5,6,7,8,9,10]);
end
histogram(H,'FaceColor','k','Edgecolor','r','LineWidth',2);
title('BlackJack', 'FontSize', fontSize);
fontSize=12;
xlabel('Mogelijkheden', 'FontSize', fontSize);
ylabel('Kans op 1000', 'FontSize', fontSize);
function k= MDealer(~)
for l=1:10
k=l ;
a = 0;
if k == 1
k=11;
a=a+1;
end
while k < 17
r = min(10, randi([1, 13]));
if r == 1
a = a+1;
r=11;
k=k+r;
else
k=k+r;
end
if k > 21 && a > 0
k = k - 10;
a = a-1;
end
end
if k>21 && l==1
k=1;
elseif k>21 &&l==2
k=2;
elseif k>21 && l==3
k=3;
elseif k>21 && l==4
k=4;
elseif k>21 &&l==5
k=5;
elseif k>21 && l==6
k=6;
elseif k>21 && l==7
k=7;
elseif k>21 &&l==8
k=8;
elseif k>21 && l==9
k=9;
elseif k>21 && l==10
k=10;
else k=0;
end
x(l)=k;
end
k=x;
k
1 Comment
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/315343-i-have-a-mistake-in-my-loop#comment_411371
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/315343-i-have-a-mistake-in-my-loop#comment_411371
Sign in to comment.