import random

# 시뮬레이션 설정
num_repeats = 3000  # 평균값 계산을 위해 시뮬레이션을 반복할 횟수

# 픽업 캐릭터 목록
pickup_characters = ["노노윌", "모모"]

# 캐릭터 목록
legendary_characters = [
    "베이라", "구즈만", "사만다", "미구엘", "자비에르", "파칼", "마이타", "콜", "디탈리오", "라비에", "릴리윌",
    "글로리아", "타이던", "노노윌", "레오니드", "이치", "네르갈", "눈갈", "이난나", "가르시아", "매그너스",
    "에다", "모모", "알렉세이", "시모나"
]

hero_characters = [
    "촛불", "불꽃 마녀", "나비", "브레이커", "나이팅게일", "서프레서", "크러셔", "래쉬", "돌풍", "천사", "어비스",
    "스팅어", "마이트", "글레어", "매의 눈", "집행자", "팔콘", "레이븐", "그레이스", "블레이드", "플래시"
]

rare_characters = [
    "베르더 정팔병", "왕실군 궁수", "다크 화염 마법사", "왕실군 불 주술사", "교황령 투창병", "교황령 얼음 사제",
    "기사 동맹 장창병", "왕실군 보병", "왕실군 장창병", "기사 동맹 보병", "다크 얼음 주술사", "왕실군 빛 마법사",
    "교황령 보병"
]

common_characters = [
    "무법자 도끼병", "용병 보병", "용병 궁수", "용병 장창병", "용병 암살자", "무법자 도끼 보병", "무법자 장창병",
    "무법자 암살자", "무법자 궁병", "무법자 석궁병"
]

# 확률 설정
legendary_rate = 0.02  # 전설 캐릭터의 출현 확률 (2%)
pickup_rate = 0.75  # 전설 캐릭터 중 픽업 캐릭터의 출현 확률 (75%)
hero_rate = 0.20  # 영웅 캐릭터의 출현 확률 (20%)
rare_rate = 0.40  # 희귀 캐릭터의 출현 확률 (40%)
common_rate = 0.38  # 일반 캐릭터의 출현 확률 (38%)

# 확정 획득 조건 설정
pickup_guarantee = 180  # 픽업 캐릭터 확정 획득까지의 횟수
legendary_guarantee = 100  # 전설 캐릭터 확정 획득까지의 횟수

def pull(legendary_counter, pickup_counter, obtained_pickups, obtained_legendaries, obtained_heroes ,obtained_rares, obtained_commons):
    """
    하나의 가챠를 시뮬레이션합니다.
    """
    total_pulls = 1
    legendary_counter -= 1  # 전설 캐릭터 확정 횟수 감소
    pickup_counter -= 1  # 픽업 캐릭터 확정 횟수 감소

    
    # 픽업 캐릭터 확정 획득 조건 확인
    if pickup_counter == 0:
        missing_pickups = set(pickup_characters) - {k for k, v in obtained_pickups.items() if v > 0}  # 아직 획득하지 못한 픽업 캐릭터 찾기
        if missing_pickups:
            obtained_pickup = random.choice(list(missing_pickups))  # 획득하지 못한 픽업 캐릭터 중 랜덤 선택
            obtained_pickups[obtained_pickup] += 1  # 선택된 픽업 캐릭터 획득 수 증가
        else:
            obtained_pickup = random.choice(pickup_characters)  # 모든 픽업 캐릭터를 획득한 경우, 랜덤으로 픽업 캐릭터 선택
        obtained_pickups[obtained_pickup] += 1  # 픽업 캐릭터 획득 횟수 증가
        pickup_counter = pickup_guarantee  # 픽업 확정 횟수 초기화
        return total_pulls, legendary_counter, pickup_counter, obtained_pickups, obtained_legendaries, obtained_heroes ,obtained_rares, obtained_commons

    # 전설 캐릭터 확정 획득 조건 확인
    if legendary_counter == 0:
        obtained_legendary = random.choice(legendary_characters)  # 랜덤으로 전설 캐릭터 선택
        # 픽업 캐릭터 획득 여부 결정
        if obtained_legendary in pickup_characters:  # 픽업 캐릭터일 경우
            obtained_pickups[obtained_legendary] += 1  # 픽업 캐릭터 획득 횟수 증가
            pickup_counter = pickup_guarantee  # 픽업 확정 횟수 초기화
            legendary_counter = legendary_guarantee  # 전설 확정 횟수 초기화
        obtained_legendaries[obtained_legendary] += 1  # 전설 캐릭터 획득 횟수 증가
        legendary_counter = legendary_guarantee  # 전설 확정 횟수 초기화
        return total_pulls, legendary_counter, pickup_counter, obtained_pickups, obtained_legendaries, obtained_heroes ,obtained_rares, obtained_commons

    # 가챠 결과 결정
    roll = random.random()  # 0과 1 사이의 랜덤 값 생성

    # 전설 캐릭터 획득 여부 결정
    if roll < legendary_rate:
        obtained_legendary = random.choice(legendary_characters)  # 랜덤으로 전설 캐릭터 선택
        # 픽업 캐릭터 획득 여부 결정
        if obtained_legendary in pickup_characters:  # 픽업 캐릭터일 경우
            obtained_pickups[obtained_legendary] += 1  # 픽업 캐릭터 획득 횟수 증가
            pickup_counter = pickup_guarantee  # 픽업 확정 횟수 초기화
            legendary_counter = legendary_guarantee  # 전설 확정 횟수 초기화
        obtained_legendaries[obtained_legendary] += 1  # 전설 캐릭터 획득 횟수 증가
        legendary_counter = legendary_guarantee  # 전설 확정 횟수 초기화
        return total_pulls, legendary_counter, pickup_counter, obtained_pickups, obtained_legendaries, obtained_heroes ,obtained_rares, obtained_commons

    elif roll < legendary_rate + hero_rate:
        obtained_hero = random.choice(hero_characters)  # 랜덤으로 영웅 캐릭터 선택
        obtained_heroes[obtained_hero] += 1  # 영웅 캐릭터 획득 횟수 증가
    elif roll < legendary_rate + hero_rate + rare_rate:
        obtained_rare = random.choice(rare_characters)  # 랜덤으로 희귀 캐릭터 선택
        obtained_rares[obtained_rare] += 1  # 희귀 캐릭터 획득 횟수 증가
    else:
        obtained_common = random.choice(common_characters)  # 랜덤으로 일반 캐릭터 선택
        obtained_commons[obtained_common] += 1  # 일반 캐릭터 획득 횟수 증가

    return total_pulls, legendary_counter, pickup_counter, obtained_pickups, obtained_legendaries, obtained_heroes ,obtained_rares, obtained_commons

def simulate():
    """
    시뮬레이션을 실행하여 두 픽업 캐릭터를 모두 획득할 때까지의 총 뽑기 횟수를 반환합니다.
    """
    # 획득 카운트 초기화
    legendary_counter = legendary_guarantee
    pickup_counter = pickup_guarantee

    total_pulls = 0  # 총 뽑기 횟수
    obtained_pickups = {character: 0 for character in pickup_characters}  # 픽업 캐릭터별 획득 횟수 초기화
    obtained_legendaries = {character: 0 for character in legendary_characters}  # 전설 캐릭터별 획득 횟수 초기화
    obtained_heroes = {character: 0 for character in hero_characters}  # 영웅 캐릭터별 획득 횟수 초기화
    obtained_rares = {character: 0 for character in rare_characters}  # 희귀 캐릭터별 획득 횟수 초기화
    obtained_commons = {character: 0 for character in common_characters}  # 일반 캐릭터별 획득 횟수 초기화

    while not all(character in obtained_pickups and obtained_pickups[character] > 0 for character in pickup_characters):
        pulls, legendary_counter, pickup_counter, obtained_pickups, obtained_legendaries, obtained_heroes ,obtained_rares, obtained_commons = pull(
            legendary_counter, pickup_counter, obtained_pickups, obtained_legendaries, obtained_heroes ,obtained_rares, obtained_commons
        )
        total_pulls += pulls  # 현재까지의 총 뽑기 횟수 누적

    # 캐릭터 카운트 통합
    total_legendary_count = sum(count for char, count in obtained_legendaries.items() if char not in pickup_characters)
    total_hero_count = sum(count for char, count in obtained_heroes.items())
    total_rare_count = sum(count for char, count in obtained_rares.items())
    total_common_count = sum(count for char, count in obtained_commons.items())

    return total_pulls, obtained_pickups, total_legendary_count, total_hero_count, total_rare_count, total_common_count
    

# 반복 시뮬레이션 및 결과 집계
all_pulls_for_both_pickups = []
all_obtained_pickups = []
all_legendary_counts = []
all_hero_counts = []
all_rare_counts = []
all_common_counts = []

for _ in range(num_repeats):
    pulls_for_both_pickups, obtained_pickups, legendary_count, hero_count, rare_count, common_count = simulate()  # 시뮬레이션 실행
    all_pulls_for_both_pickups.append(pulls_for_both_pickups)
    all_obtained_pickups.append(obtained_pickups)
    all_legendary_counts.append(legendary_count)
    all_hero_counts.append(hero_count)
    all_rare_counts.append(rare_count)
    all_common_counts.append(common_count)
    

# 평균값 계산
average_pulls_for_both_pickups = sum(all_pulls_for_both_pickups) / num_repeats
average_legendary_counts = sum(all_legendary_counts) / num_repeats
average_hero_counts = sum(all_hero_counts) / num_repeats
average_rare_counts = sum(all_rare_counts) / num_repeats
average_common_counts = sum(all_common_counts) / num_repeats


# 결과 출력
print(f"총 {num_repeats}회 반복 시뮬레이션 결과:")
print(f"두 픽업 캐릭터를 모두 획득하는 데 필요한 평균 뽑기 횟수): {average_pulls_for_both_pickups:.2f}")
print()
for pickup_character in pickup_characters:
    total_pickup_count = sum(obtained_pickups[pickup_character] for obtained_pickups in all_obtained_pickups)
    average_pickup_count = total_pickup_count / num_repeats
    print(f"{pickup_character}의 평균 획득 횟수: {average_pickup_count:.2f}")
print()
print(f"픽업 캐릭터 제외 얻은 전설 갯수: {average_legendary_counts:.2f}")
print(f"얻은 영웅 갯수: {average_hero_counts:.2f}")
print(f"얻은 희귀 갯수: {average_rare_counts:.2f}")
print(f"얻은 일반 갯수: {average_common_counts:.2f}")


Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: