1290 字
6 分钟
抽卡模拟
本文许可:转载时转载请注明出处
基于明日方舟的抽卡概率做的抽卡模拟
术语表:| 名词 | 对应机制 || --- | ------------------ || 硬保底 | 概率固定,第 N 抽必出 || 软保底 | 50 抽后每抽 +2% || 天井 | 300 抽可直接兑换当期 UP 六星 |while True: try: guess = int(input('请输入 1-100 的整数:')) break except ValueError: print('格式错误,请重新输入!')将会分步骤一步步变难
标准池(6⭐概率2%) 无保底写法
import randomchou = int(input('你想要抽多少发?:')) #自定义想抽多少发def gacha(): #用def函数方便自定义抽数 r = random.randint(1, 100) # random.randint(1,100) 生成的是 1~100 闭区间,共 100 个整数 if r <= 2: # 6⭐ 2/100 = 2% return '⭐⭐⭐⭐⭐⭐' elif r <= 8: return '⭐⭐⭐⭐⭐' elif r <= 50: return '⭐⭐⭐⭐' else: return '⭐⭐⭐'for i in range(chou): #循环输入的次数 print(gacha()) #执行def函数并输出(假)保底写法
因为明日方舟保底概率是随着抽数的增长而增长,为了方便理解,这里先介绍硬保底(也就是抽到多少抽必出,不随着抽数增加概率)
import random
chou = int(input('你想要抽多少发?:'))
def gacha(pity): """返回 (结果, 新pity)""" # 硬保底:第99抽必出6⭐ if pity == 99: return '⭐⭐⭐⭐⭐⭐', 0
# 正常概率 r = random.randint(1, 100) if r <= 2: # 出6⭐ return '⭐⭐⭐⭐⭐⭐', 0 elif r <= 8: return '⭐⭐⭐⭐⭐', pity + 1 elif r <= 50: return '⭐⭐⭐⭐', pity + 1 else: return '⭐⭐⭐', pity + 1
pity = 0for i in range(chou): result, pity = gacha(pity) print(result)(真)保底写法
import randomchou = int(input('你想要抽多少发?:'))def gacha(pity): """返回 (抽卡结果, 新的pity计数)""" # 计算当前 6⭐概率 six_rate = min(2 + max(0, pity - 49) * 2, 100) # 第51抽开始+2% 官方:50 抽之后(即第 51 抽)每抽 +2% r = random.randint(1, 100)
if r <= six_rate: # 出 6⭐ return '⭐⭐⭐⭐⭐⭐', 0 elif r <= 8: # 5⭐ return '⭐⭐⭐⭐⭐', pity + 1 elif r <= 50: # 4⭐ return '⭐⭐⭐⭐', pity + 1 else: # 3⭐ return '⭐⭐⭐', pity + 1
pity = 0 # 开局垫 0 抽for i in range(chou): result, pity = gacha(pity) # 抽一次,拿到新 pity print(result)集大成者完整版(拥有随抽数增加保底概率增加,会歪,有统计功能)
#!/usr/bin/env python3# -*- coding: utf-8 -*-"""明日方舟限定 UP 池模拟器(真实概率链 + 300 抽天井补发)"""import osimport jsonimport randomfrom collections import Counter
# ========== 用户可改参数 ==========UP_NAME = "影焰·苇草" # 当期 UP 六星SAVE_FILE = "arknights_pity.json"# ==================================
# ---------- 工具:读档 ----------def load_data(): if os.path.exists(SAVE_FILE): with open(SAVE_FILE, "r", encoding="utf-8") as f: return json.load(f) return {"total": 0, "pity": 0}
# ---------- 工具:写档 ----------def save_data(total, pity): with open(SAVE_FILE, "w", encoding="utf-8") as f: json.dump({"total": total, "pity": pity}, f, ensure_ascii=False)
# ---------- 核心抽卡(真实概率链) ----------def pull_once(pity): """返回 (结果字符串, 新pity, 是否六星)""" six_prob = min(2 + max(0, pity - 49) * 2, 100) # 软保底 r = random.randint(1, 100) # 只掷一次
if r <= six_prob: # 1. 六星 up_or_ng = random.choices(["UP", "歪"], weights=[70, 30])[0] return (f"六星·{UP_NAME}" if up_or_ng == "UP" else "六星·常驻"), 0, True
elif r <= six_prob + 2: # 2. 五星 2% return "五星", pity + 1, False
elif r <= six_prob + 2 + 50: # 3. 四星 50% return "四星", pity + 1, False
else: # 4. 三星 46% return "三星", pity + 1, False
# ---------- 主流程 ----------def main(): data = load_data() total_hist = data["total"] pity = data["pity"]
n = int(input("本次抽多少发?:"))
print("\n===== 抽卡开始 =====") record = [] first_6 = None six_count = 0
for i in range(1, n + 1): result, pity, is6 = pull_once(pity) # ← 仅此处修复:pull_one → pull_once record.append(result) if is6: six_count += 1 if first_6 is None: first_6 = i
total_hist += n
# ---------- 统计 ---------- c = Counter(record) print("\n===== 统计 =====") for k, v in c.items(): print(f"{k}: {v} 张")
# ---------- 天井检查(自动补发) ---------- if total_hist >= 300: print(f"\n>>> 累计已 {total_hist} 抽,可兑换当期 UP 六星「{UP_NAME}」!<<<") if c.get(f"六星·{UP_NAME}", 0) == 0: c[f"六星·{UP_NAME}"] += 1 six_count += 1 print(f">>> 已自动为你兑换「六星·{UP_NAME}」,更新统计结果!<<<") total_hist = 0 # 兑换后清零
print(f"\n总计六星: {six_count} 张") print(f"UP 六星: {c.get(f'六星·{UP_NAME}', 0)} 张") print(f"歪六星: {c.get('六星·常驻', 0)} 张") if first_6: print(f"最早六星: 第 {first_6} 抽") print(f"当前垫抽: {pity}") print(f"历史累计: {total_hist} 抽")
# ---------- 存盘 ---------- save_data(total_hist, pity) print("\n数据已保存,下次继续累计。")
if __name__ == "__main__": main()运行结果差不多如下
===== 统计 =====三星: 25 张四星: 3 张五星: 1 张六星·苇草: 1 张(300井兑换)六星·常驻: 1 张总计六星: 2 张最早六星: 第 29 抽最晚六星: 第 300 抽(井兑换)当前垫抽数: 1说实话,这玩意看的我都头痛(拿AI搞得)😗,没事,只要搞熟了你也行
分享文章
生成精美分享图或复制链接,与更多人分享本文。
继续阅读
换条路线
从其他文章中稳定抽取
最后更新于 ,距今已过 345 天
部分内容可能已过时