设为首页 收藏本站
开启辅助访问 快捷导航
菜单
猿人部落 主页 资讯 查看内容

模拟明日方舟抽卡v2.0

2019-7-25 16:24 发布者: admin 评论 0 查看 1223
初版在此 https://fishc.com.cn/thread-142205-1-1.html# v2.1 告急修复了6星出率过高的bug(由10连保底机制产生)# v2.0 模块化 到场了标准池子STANDARD_POOL(无up, 包罗限定干员) 自界说up池 池子查抄等功能登录/注


初版在此 https://fishc.com.cn/thread-142205-1-1.html

# v2.1 告急修复了6星出率过高的bug(由10连保底机制产生)
# v2.0 模块化 到场了标准池子STANDARD_POOL(无up, 包罗限定干员) 自界说up池 池子查抄等功能
QQ图片20190725161820.png
登录/注册后可看大图
将kokodayo 杜宾seisei 以及(还没到我宿舍逛过的)白面的up率修改为1 =。=


代码有点长 稍后放出github地点
[url]
  1. # author:ietar
  2. # email: 410473517@qq.com
  3. # 嫡方舟模拟抽卡器 调用draw()抽1次 draw10()则为10次 10次触发保底
  4. # 也可以draw()其他次数 但只有10次时触发保底
  5. # 很显着 尚有其他功能正在写
  6. # v2.0 模块化 到场了标准池子STANDARD_POOL(无up, 包罗限定干员) 自界说up池 池子查抄等功能

  7. import random

  8. Official6 = ['推进之王', '能天使', '星熊', '闪灵', '伊芙利特', '银灰', '塞雷娅', '夜莺', '艾雅法拉', '陈', '安洁莉娜', '斯卡蒂']
  9. Official5 = ['白面鸮', '幽灵鲨', '芙兰卡', '德克萨斯', '凛冬', '普罗旺斯', '蓝毒', '雷蛇', '临光', '红', '赫默', '夜魔', '天火', '初雪', '拉普兰德', '华法琳', '守林人', '狮蝎', '真理', '白金', '陨星', '梅尔', '可颂', '崖心', '空', '食铁兽', '诗怀雅']
  10. Official4 = ['杜宾', '深海色', '白雪', '远山', '夜烟', '流星', '蛇屠箱', '末药', '猎蜂', '慕斯', '砾', '暗索', '地灵', '调香师', '霜叶', '清道夫', '角峰', '古米', '缠丸', '阿消', '红豆', '杰西卡']
  11. Official3 = ['芬', '克洛丝', '炎熔', '米格鲁', '芙蓉', '卡缇', '史都华德', '香草', '玫兰莎', '安赛尔', '梓兰', '翎羽', '空爆', '月见夜']

  12. # 干员数据来自http://wiki.joyme.com/arknights/干员寻访模拟器
  13. # 5星也太多了 我没搞错吧


  14. def makepool():

  15.     pool = []
  16.     typedict = {0:'前锋', 1:'近卫', 2:'偷袭', 3:'医疗', 4:'术士',5:'特种', 6:'重装', 7:'辅助'}


  17.     def addo(**kw):
  18.         '''add Official'''
  19.         pool.append(Official(**kw))

  20.         
  21.     for i in Official6:
  22.         addo(name=i, stars=6)
  23.     for i in Official5:
  24.         addo(name=i, stars=5)
  25.     for i in Official4:
  26.         addo(name=i, stars=4)
  27.     for i in Official3:
  28.         addo(name=i, stars=3)

  29.     return pool


  30. def checkpool(pool):
  31.     '''查抄池子内各星级up率是否溢出'''
  32.     current = {3:0, 4:0, 5:0, 6:0}
  33.     stars = 0
  34.     for i in pool:
  35.         if i.stars == 6:
  36.             current[6] += i.uprate
  37.         if i.stars == 5:
  38.             current[5] += i.uprate
  39.         if i.stars == 4:
  40.             current[4] += i.uprate
  41.         if i.stars == 3:
  42.             current[3] += i.uprate
  43.             
  44.     for i in current:
  45.         if current[i] > 1:
  46.             return 0
  47.         
  48.     return 1
  49.    

  50. def set_uprate(pool, name, uprate):
  51.     '''自界说池子 修改干员up率 重复调用可修改多个 留意每个星级up率之和不能高出1'''

  52.     if uprate > 1 or uprate < 0:
  53.         raise ValueError('up率必须在0-1之间!')
  54.     current = {3:0, 4:0, 5:0, 6:0}
  55.     stars = 0
  56.     flag = 0
  57.     for i in pool:
  58.         if i.name == name:
  59.             stars = i.stars
  60.             temp = i
  61.             flag = 1
  62.             break;

  63.     if not flag:
  64.         raise ValueError('池子中找不到该干员,无法修改up率!')
  65.         
  66.     assert stars != 0
  67.    
  68.     for i in pool:
  69.         if i.stars == 6:
  70.             current[6] += i.uprate
  71.         if i.stars == 5:
  72.             current[5] += i.uprate
  73.         if i.stars == 4:
  74.             current[4] += i.uprate
  75.         if i.stars == 3:
  76.             current[3] += i.uprate
  77.             
  78.     after_update = uprate - temp.uprate + current[stars]
  79.     if  after_update > 1:
  80.         raise ValueError('up率设置过高, 当前{}星up率之和为{}'.format(stars, current[stars]))

  81.     temp.uprate = uprate
  82.             


  83. class Official(object):
  84.     '''嫡方舟干员
  85. Official((str)name, (int)stars, uprate=0[, (int)otype])'''
  86.    
  87.     def __init__(self, name, stars, uprate=0, otype=''):
  88.         self._name = name
  89.         self._stars = stars
  90.         self._uprate = uprate
  91.         self._otype = otype

  92.     @property
  93.     def name(self):
  94.         return self._name

  95.     @name.setter
  96.     def name(self, value):
  97.         if not isinstance(value, str):
  98.             raise TypeError("name must be string!")
  99.         elif len(value)>12:
  100.             raise ValueError("The max length of name is 12.")
  101.         self._name = value

  102.     @property
  103.     def stars(self):
  104.         return self._stars

  105.     @stars.setter
  106.     def stars(self, value):
  107.         if not isinstance(value, int):
  108.             raise TypeError("stars should be integer!")
  109.         elif value not in range(1, 7):
  110.             raise ValueError("value should be in range(1,7).")
  111.         self._stars = value
  112.         self._rate = RATE[self._stars]

  113.     @property
  114.     def otype(self):
  115.         return self._otype

  116.     @otype.setter
  117.     def otype(self, value):
  118.         if not isinstance(value, str):
  119.             raise TypeError("otype should be str!")
  120.         elif value not in typedict.values():
  121.             raise ValueError("unvalid otype!not in typedict.values().")
  122.         self._otype = value

  123.     @property
  124.     def uprate(self):
  125.         return self._uprate

  126.     @uprate.setter
  127.     def uprate(self, value):
  128.         if not isinstance(value, float) and not isinstance(value, int):
  129.             raise TypeError("uprate should be 0 or float!")
  130.         elif value > 1 or value < 0:
  131.             raise ValueError("uprate should be in (0, 1).")
  132.         self._uprate = value

  133.     def info(self):
  134.         return '{} {}星干员 {} uprate:{}'.format(\
  135.             self._name, self._stars, self._otype, self._uprate)

  136.     def __str__(self):
  137.         return self._name

  138.     __repr__ = __str__



  139. STADNARD_POOL = makepool()


  140. def draw10(pool=STADNARD_POOL):
  141.     return draw(10, pool)


  142. def draw(times=1, pool=STADNARD_POOL):
  143.     pool6 = {}
  144.     pool5 = {}
  145.     pool4 = {}
  146.     pool3 = {}
  147.     RATE = {6:0.02, 5:0.08, 4:0.4, 3:0.5, 2:0, 1:0}
  148.     count6, count5, count4, count3 = 0, 0, 0, 0
  149.     # 分别对应6, 5, 4, 3星 干员出货数目
  150.     ratemax6, ratemax5, ratemax4, ratemax3 = 1, 1, 1, 1
  151.     nonup6, nonup5, nonup4, nonup3 = 0, 0, 0, 0
  152.     # 分别对应6, 5, 4, 3星 非up干员数目
  153.     res = []
  154.     # pool6,5,4,3 = {干员名:同星级内抽取率}
  155.     #初始化完成

  156.     # if干员的uprate不为0 将其直接设为权重
  157.     # else 使此中分剩下的rate 分的人数+1
  158.     for i in pool:
  159.         if i.stars == 6:
  160.             pool6[i] = i.uprate
  161.             if i.uprate:
  162.                 ratemax6 -= i.uprate
  163.             else:
  164.                 nonup6 += 1
  165.         elif i.stars == 5:
  166.             pool5[i] = i.uprate
  167.             if i.uprate:
  168.                 ratemax5 -= i.uprate
  169.             else:
  170.                 nonup5 += 1
  171.         elif i.stars == 4:
  172.             pool4[i] = i.uprate
  173.             if i.uprate:
  174.                 ratemax4 -= i.uprate
  175.             else:
  176.                 nonup4 += 1
  177.         elif i.stars == 3:
  178.             pool3[i] = i.uprate
  179.             if i.uprate:
  180.                 ratemax3 -= i.uprate
  181.             else:
  182.                 nonup3 += 1
  183.    
  184.     # nweight == normal weight
  185.     nweight6 = ratemax6/nonup6
  186.     nweight5 = ratemax5/nonup5
  187.     nweight4 = ratemax4/nonup4
  188.     nweight3 = ratemax3/nonup3

  189.     for i in pool6:
  190.         if not i.uprate:
  191.             pool6[i] = nweight6
  192.     for i in pool5:
  193.         if not i.uprate:
  194.             pool5[i] = nweight5
  195.     for i in pool4:
  196.         if not i.uprate:
  197.             pool4[i] = nweight4
  198.     for i in pool3:
  199.         if not i.uprate:
  200.             pool3[i] = nweight3
  201.    
  202.     for _ in range(times):
  203.         a = random.random()
  204.         if a <= RATE[6]:
  205.             out = random.choices(list(pool6.keys()),list(pool6.values()))[0]
  206.             res.append(out)
  207.             count6+=1
  208.         elif a <= RATE[5]:
  209.             out = random.choices(list(pool5.keys()),list(pool5.values()))[0]
  210.             res.append(out)
  211.             count5+=1
  212.         elif a <= RATE[4]:
  213.             out = random.choices(list(pool4.keys()),list(pool4.values()))[0]
  214.             res.append(out)
  215.             count4+=1
  216.         else:
  217.             out = random.choices(list(pool3.keys()),list(pool3.values()))[0]
  218.             res.append(out)
  219.             count3+=1
  220.     # 正式抽卡 完成

  221.    
  222.     # 保底思量直接重抽10次 只在10连抽时触发
  223.     if times==10 and not (count6 + count5 + count4):
  224.         # print("保底机制使您免收紫气东来困扰 1次")
  225.         return draw(10, pool)
  226.     return res


  227. if __name__ == '__main__':
  228.     while 1:
  229.         user_input = input("输入抽卡数目(或q退出),发起直接回车开启带保底的10连:") or '10'
  230.         if user_input.lower() == 'q':
  231.             break
  232.         try:
  233.             numbers = int(user_input)
  234.         except ValueError:
  235.             print("输入的不是整型,不太好抽啊")
  236.             continue
  237.         if numbers not in range(0,1001):
  238.             print("亲亲发起您输入0-1000的数目呢(呕)")
  239.             continue
  240.         print('\n')
  241.         print(draw(numbers,STADNARD_POOL),'\n')
  242.     pass

[/hide]

路过

雷人

握手

鲜花

鸡蛋
收藏 邀请
上一篇:爬虫:一只爬取yande.re的妹子图爬虫(15禁)下一篇:我测试递归的最大深度996

相关阅读

一周热门

头条攻略!

日排行榜

相关分类