编辑代码

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

def simulate_until_target(target_featured):
    five_star_prob = 0.01  # 基础概率
    pity_counter = 0  # 连续未获得5星思念的次数
    guaranteed_featured = False  # 是否必定获得限定5星思念
    featured_count = 0  # 已获得【祁煜·沉入无尽海】的数量
    total_wishes = 0  # 总许愿次数

    while featured_count < target_featured:
        total_wishes += 1
        # 检查是否触发保底机制
        if pity_counter >= 60:
            five_star_prob = min(five_star_prob + 0.10, 1.0)  # 概率增加10%,最高100%
        
        # 判断是否获得5星思念
        if random.random() < five_star_prob:
            if guaranteed_featured or random.random() < 0.5:
                result = f"第{total_wishes}次许愿结果: 5星思念【祁煜·沉入无尽海】"
                featured_count += 1
                guaranteed_featured = False  # 重置必定获得限定
            else:
                result = f"第{total_wishes}次许愿结果: 5星思念(非本期活动限定)"
                guaranteed_featured = True  # 下一次必定获得限定
            print(result)  # 输出获得5星思念的结果
            five_star_prob = 0.01  # 重置概率
            pity_counter = 0  # 重置保底计数器
        else:
            pity_counter += 1  # 未获得5星思念,保底计数器+1

    return total_wishes

# 目标:获得4张【祁煜·沉入无尽海】
target_featured = 4
total_wishes = simulate_until_target(target_featured)
print(f"\n获得 {target_featured} 张【祁煜·沉入无尽海】所需的许愿次数: {total_wishes} 次")