有关游戏抽卡的保底问题

        每个人对于游戏抽卡中的保底都有不同的理解,我这边从程序员的视角去描述这个问题。

        首先我们要确认一件事情——那就是抽卡保底机制诞生的原因。这其中分为两个方面。第一方面是国家政策方面:所有抽卡奖池必须要公开公布中奖概率,并且设计保底机制,相关文件中说这样是为了防止未成年人不理性消费现象。而第二个方面也可以说是对一个方面中的解释:在现实中,概率小的事情也有发生的可能。在这里就不放出数据了,假设一个up池子角色概率1%,在抽卡100次之后,仍有大约30%的概率无法将其收入囊中,就算抽1000次,也有大约0.08%的概率无法抽到。

        而抽卡保底可以很好解决小概率发生时给玩家带来不好体验的问题。最近原神出的大、小保底规则更是减少了这种尴尬情况的发生。

        网络游戏需要用数据库记录从账号注册以来所有的抽卡信息,在这里,我用单机文件读写的方式实现《明日方舟》的6星保底机制,即6星角色综合爆率2%,如果连续50次没有抽出6星角色,之后的每次抽卡,6星角色概率+2%,直到抽出之后重置此概率。

#include<iostream>
#include<fstream>
#include<ctime>
#include<string.h>

using namespace std;

int DrawOne(){
    ifstream  fin;
    fin.open("E:\\codeblocks\\test.txt");
    string str,tempstr;
    if (fin){
        //条件成立,则说明文件打开成功
        cout<<"endless.txt open scessful"<<endl;
        getline(fin,str);//按行显示
        cout<<str<<endl;
        fin.close();
    }

    int finalstar=0,tempstar=0;
    int N=999;float reward=0;
    float a=rand() % (N + 1) / (float)(N + 1);

    int position=str.find("6");
    if(position==str.npos){
        position=0;
    }
    if(position+50>=str.length()){
        //常规抽卡
        if(a<0.020f){
            tempstar=6;
        }else if(a<0.100f){
            tempstar=5;
        }else if(a<0.400f){
            tempstar=4;
        }else{
            tempstar=3;
        }
    }else{
        reward=(str.length()-50-position)*0.02f;
        if(a<0.020f+reward){
            tempstar=6;
            reward=0;//此规则抽出即重置
        }else if(a<0.100f){
            tempstar=5;
        }else if(a<0.400f){
            tempstar=4;
        }else{
            tempstar=3;
        }

    }

    std::string strstar = std::to_string(tempstar);
    //cout<<strstar<<endl;
    //将结果写入
    ofstream  fout;
    fout.open("E:\\codeblocks\\test.txt");
    fout<<str+strstar;
    if(fout){
        cout<<"endless.txt write scessful"<<endl;
    }
    fout.close();

    finalstar=tempstar;cout<<finalstar<<"  ";
    return finalstar;

}

int main(){

    srand(time(0));
    for(int i=0;i<10;i++){
        //十连
        DrawOne();
    }
}

        记得在相应路径建立响应文件(为空或由3456组成的字符串,数字即代表角色星级)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值