编辑代码

# coding:utf-8
#JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
import random

# 定义常量
BASE_RATE = 0.01  # 基础概率1%
PITY_START = 60   # 保底机制触发次数
RATE_INCREASE = 0.10  # 保底后每次增加10%概率
LIMITED_RATE = 0.75  # 75%概率为本期限定5星
CHARACTERS = ["沈星回·虚构妄想", "祁煜·狂热剂量", "夏以昼·附骨之痕"]  # 本期限定5星
TARGET_CHARACTER = "祁煜·狂热剂量"  # 定轨思念

def simulate_until_target(target_count):
    """
    模拟许愿,直到获得指定数量的定轨思念
    :param target_count: 需要获得的定轨思念数量
    :return: 总许愿次数, 详细抽取记录, 统计结果
    """
    current_rate = BASE_RATE  # 当前5星概率
    pity_counter = 0  # 连续未获得5星的次数
    is_guaranteed = False  # 是否触发定轨机制
    target_obtained = 0  # 已获得的定轨思念数量
    total_wishes = 0  # 总许愿次数
    wish_history = []  # 抽取记录

    # 统计变量
    total_5_star = 0  # 总获得5星次数
    character_counts = {char: 0 for char in CHARACTERS}  # 各5星思念获得次数
    character_counts["非限定5星思念"] = 0  # 非限定5星获得次数
    guaranteed_triggers = 0  # 定轨机制触发次数

    while target_obtained < target_count:
        total_wishes += 1
        # 判断是否触发保底机制
        if pity_counter >= PITY_START:
            current_rate = min(current_rate + RATE_INCREASE, 1.0)  # 概率增加,最高100%

        # 判断是否获得5星
        if random.random() < current_rate:
            # 获得5星
            total_5_star += 1
            if is_guaranteed:
                # 触发定轨机制,必定获得定轨思念
                result = TARGET_CHARACTER
                is_guaranteed = False
                guaranteed_triggers += 1
            else:
                # 判断是否为限定5星
                if random.random() < LIMITED_RATE:
                    # 从限定5星中随机选择一个
                    result = random.choice(CHARACTERS)
                    if result != TARGET_CHARACTER:
                        is_guaranteed = True  # 下一次必定为定轨思念
                else:
                    # 获得非限定5星
                    result = "非限定5星思念"
                    is_guaranteed = True  # 下一次必定为定轨思念

            # 判断是否为定轨思念
            if result == TARGET_CHARACTER:
                target_obtained += 1

            # 更新统计
            if result in character_counts:
                character_counts[result] += 1
            else:
                character_counts["非限定5星思念"] += 1

            # 记录抽取结果
            wish_history.append((total_wishes, result))

            # 重置概率和计数
            current_rate = BASE_RATE
            pity_counter = 0
        else:
            # 未获得5星
            pity_counter += 1

    # 统计结果
    stats = {
        "总抽数": total_wishes,
        "总获得5星次数": total_5_star,
        "各5星思念获得次数": character_counts,
        "定轨机制触发次数": guaranteed_triggers,
    }

    return total_wishes, wish_history, stats

# 输入需要获得的定轨思念数量
target_count = 3
# 模拟抽取过程
total_wishes, wish_history, stats = simulate_until_target(target_count)

# 输出结果
print(f"获得{target_count}张【{TARGET_CHARACTER}】总共需要{total_wishes}抽")
print("\n=== 详细抽取记录 ===")
for wish in wish_history:
    print(f"第{wish[0]}次许愿:获得【{wish[1]}】")

print("\n=== 统计结果 ===")
print(f"总抽数:{stats['总抽数']}")
print(f"总获得5星次数:{stats['总获得5星次数']}")
print("各5星思念获得次数:")
for char, count in stats["各5星思念获得次数"].items():
    print(f"{char}{count}次")
print(f"定轨机制触发次数:{stats['定轨机制触发次数']}次")