抽奖模型设计代码

需求:
1:奖池奖品为 5、20、50、10000,每次投入10,抽奖10次,系统随机反馈奖品或不反馈奖品,要求最终的产出投入比在0.85左右。
2:不得让游戏玩家通过历史抽奖数据观察出中奖规律
3:新玩家的中奖概率大于老玩家的中奖概率
4:解决玩家万一抽中奖品10000,放弃游戏,对平台造成损失的情况
5:不得让玩家过早抽中10000的奖品

from math import *
import random
from collections import Counter

def game(nums,P,bits,game_gift):
    game_gift2=game_gift.copy()
    if 0 in game_gift2 and len(game_gift2)> 0:
        for i in game_gift2:
            if i == 0:
                game_gift2.remove(0)
    bis = -1 / 1000 * nums[1] + 0.2
    if bis < 0: bis = 0
    rand = random.random()
    datas = list(map(lambda x ,y: x*y-rand+bis, nums[0],P))
    bit = datas.index(max(datas))
    if max(datas)< 0 or \
            (bits[1]>0.85 and bits[0]<1000) or \
            nums[1]<6000 and gifts[bit] ==10000 or \
            bits[2]>0.8 and (gifts[bit] ==10000 or random.random()<0.6 or (len(game_gift2)>0 and random.random()<0.9)or len(game_gift2)>3):
        gitf = 0
    else:
        gitf = gifts[bit]
    return gitf

'''
    gifts = [5, 20, 50, 10000]
    bits = [20, 0.84, 0]
    nums = [[1, 1, 1, 1], 1]
 '''
def choujiang(nums,gifts,bits):
    P = list(map(lambda x: 1 / (10 * x), gifts))
    game_gift = []
    for k in range(10):
        c =game(nums,P,bits,game_gift)
        game_gift.append(c)
        for i in range(len(gifts)):
            if gifts[i] not in game_gift:nums[0][i] = nums[0][i]+ 1
            else:nums[0][i] = floor(round(random.random(), 1) * nums[0][i])
    nums[1] = nums[1]+ 1
    # print(game_gift)
    return nums ,game_gift

if __name__ == "__main__":
    gifts = [5, 20, 50, 10000]
    bit = [20, 0.84, 0]
    point = []
    for j in range(10):
        data = []
        nums = [[1, 1, 1, 1], 1]
        for i in range(8000):
            nums, c = choujiang(nums, gifts, bit)
            data.extend(c)
            bit[2] = sum(data) / len(data)
            print("第",i,"次抽奖的产出投入比为", sum(data) / len(data))
        print("用户", j, "中奖数据为", data)
        print("用户", j, "中奖数据统计", Counter(data))
    print("均值", sum(point) / len(point))

变量名写的很随意,请见谅。

猜你喜欢

转载自blog.csdn.net/weixin_41690892/article/details/84340001