4个人,每个人尝试一次,不考虑加值,完成技能挑战的概率
clear all;
close all;
S = 20; % S faces
R = 1; % each dice is rolled R times
N = 4; % roll N dice at once
T = 1; % repeat all T times
C = 1:1:4; %Number of passes required
DC = 1:1:S
success = zeros(N,S);
Num = 100000
for (tab = 1:1:Num)
Out = randi([1 S],[R N T]);
for (k = 1:1:S)
pass = 0;
for (tab2 = 1:1:N)
roll = Out(tab2);
if (roll>=DC(k))
pass = pass+1;
end
end
for (tab3 = 1:1:N)
if (pass>=C(tab3))
success(tab3,k) = success(tab3,k) +1;
end
end
end
end
plot(DC,success'/Num*100);
xlim([1,S]);
ylim([0,100]);
hold all;
title('Num of attempts = 4');
legend('pass>=1','pass>=2','pass>=3','pass>=4');
xlabel('DC');
ylabel('Chance of Success(%)');