编辑代码

# 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_wish(wish_count):
    current_rate = BASE_RATE  # 当前5星概率
    pity_counter = 0  # 连续未获得5星的次数
    is_guaranteed = False  # 是否触发定轨机制

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

    for i in range(1, wish_count + 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 in character_counts:
                character_counts[result] += 1
            else:
                character_counts["非限定5星思念"] += 1

            # 重置概率和计数
            current_rate = BASE_RATE
            pity_counter = 0
            print(f"第{i}次许愿:获得【{result}】")
        else:
            # 未获得5星
            pity_counter += 1

    # 输出统计结果
    print("\n=== 许愿统计 ===")
    print(f"总获得5星次数:{total_5_star}")
    print("各5星思念获得次数:")
    for char, count in character_counts.items():
        print(f"{char}{count}次")
    print(f"定轨机制触发次数:{guaranteed_triggers}次")

# 输入许愿次数
wish_count = int(input("请输入许愿次数:"))
simulate_wish(wish_count)