clc;clear;
YES = input('请问要进行抽卡吗?1.是的 2.不要 :');
if YES == 1
%%————————————————————————————————————————————————————————————————————————————————
%初始化数据。count分别表示抽取到的1、2、3星卡的数量。
count1 = 0;
count2 = 0;
count3 = 0;
no2count = 0;%计数器,计数没有抽到2星卡的次数。每次执行抽卡,都应该对其进行判断,如果为9,本次抽卡应为二星保底。
no3count = 0;
%%————————————————————————————————————————————————————————————————————————————————-
while(YES == 1)
cnt = input('请问是单抽还是十连? 1.单抽 2.十连 :');
%%——————————————————————————————————————————单抽——————————————————————
if cnt == 1
if no3count == 90
disp('牛逼,单抽获得了三星卡。可惜是保底的捏.');
count3 = count3 + 1;
no2count = no2count + 1;
no3count = 0;
elseif no2count == 9
disp('单抽获得了保底的二星卡。');
count2 = count2 + 1;
no3count = no3count + 1;
no2count = 0;
else
card = randi([1 100],1,1);
disp('您选择了单抽,本次抽卡结果是:')
mark = select_card(card);
if mark == 1
count1 = count1 + 1;
no2count = no2count + 1;
elseif mark == 2
count2 = count2 + 1;
else
count3 = count3 + 1;
no2count = no2count + 1;
end
end
%%——————————————————————————————————单抽判断结束————————————————————————————
else
star_1 = 0;
star_2 = 0;
star_3 = 0;
for i = 1:10
if no3count == 90
star_3 = star_3 + 1;
no3count = 0;
no2count = no2count + 1;
continue;
elseif no2count == 9
star_2 = star_2 + 1;
disp('通过保底获得了一次二星卡。');
no2count = 0;
continue
else
card = randi([1 100],1,1);
disp(['第' num2str(i) '次抽卡结果是:'])
mark = select_card(card);
if mark == 1
star_1 = star_1 + 1;
no2count = no2count + 1;
no3count = no3count + 1;
elseif mark == 2
star_2 = star_2 + 1;
no2count = 0;
no3count = no3count + 1;
else
no2count = no2count + 1;
no3count = 0;
star_3 = star_3 + 1;
end
end
count1 = count1 + star_1;
count2 = count2 + star_2;
count3 = count3 + star_3;
disp(['本次抽卡共得到' num2str(star_3) '个三星;' num2str(star_2) '个二星;' num2str(star_1) '个一星!'])
end
end
YES = input(['请问还要继续抽卡吗?1.继续 2.退出'])
end
disp('抽卡结束捏')
disp(['本次抽卡合计获得' num2str(count3) '次三星卡,' num2str(count2) '次二星卡' num2str(count1) '次一星卡']);
else
disp('好的,欢迎下次光临。')
end
function output = select (card)
if card >= 98
disp('牛逼!抽到了三星卡!')
output = 3;
elseif card >= 82
disp('不错,抽到了二星卡!')
output = 2;
else
disp('抽到了一星卡');
output = 1;
end
end
3%概率抽到三星卡,15%概率抽到2星卡,3星卡保底90发出,2星卡保底十发出。