抽卡模拟器(matlab实现)

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星卡保底十发出。

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值