import numpy as np
from scipy.optimize import linprog

# 능력치 순서: 힘, 생명, 정신, 지능, 행운, 속도
# 여기에 현재 능력 한계치 입력
current_stats = [
        328, 290, 278, 306, 281, 325
    ]

def optimize_levelups_improved(current_stats):
    # 각 직업별 능력치 증가량 (행: 직업, 열: 스탯)
    stat_gains = np.array([
        [2, 1, 0, 0, 1, 0],  # 검술
        [1, 0, 1, 0, 0, 2],  # 인술
        [0, 1, 2, 1, 0, 0],  # 신술
        [0, 0, 1, 2, 1, 0],  # 마술
        [0, 0, 1, 0, 2, 1],  # 궁술
        [1, 2, 0, 0, 0, 1]   # 체술
    ])
    
    max_stat = 401  # 목표 능력 한계치
    required_stats = np.array([max_stat] * 6) - np.array(current_stats)
    
    # 선형 계획법 설정 - 부등호 제약조건으로 변경 (A_ub, b_ub 사용)
    c = np.ones(6)  # 최소화할 목표 (레벨업 횟수)
    A_ub = -stat_gains.T  # 음수를 취해 ≥ 제약조건으로 변환
    b_ub = -required_stats  # 음수를 취해 ≥ 제약조건으로 변환
    bounds = [(0, None)] * 6  # 각 직업의 레벨업 횟수는 0 이상
    
    # 선형 계획법 실행
    res = linprog(c, A_ub=A_ub, b_ub=b_ub, bounds=bounds, method='highs')
    
    if res.success:
        # 소수점 처리를 위해 반올림
        job_levelups = [round(x) for x in res.x]
        
        # 결과 출력
        result = {"검술": job_levelups[0], "인술": job_levelups[1], "신술": job_levelups[2], 
                  "마술": job_levelups[3], "궁술": job_levelups[4], "체술": job_levelups[5]}
        
        # 최종 결과 능력치 계산
        final_stats = np.array(current_stats) + np.dot(job_levelups, stat_gains)
        
        print("== 직업별 능력치업 횟수 ==")
        for job, levelups in result.items():
            print(f"{job} : {levelups} 번")
        
        print("\n== 총 능력치업 횟수 ==")
        print(f"총 {sum(job_levelups)} 번")
        
        print("\n== 최종 능력치 ==")
        stat_names = ["힘", "생명", "정신", "지능", "행운", "속도"]
        for i, (name, value) in enumerate(zip(stat_names, final_stats)):
            print(f"{name}: {value} (목표: {max_stat}, 차이: {value - max_stat})")
            
    else:
        print("해결 불가능한 상태입니다.")
        print("오류:", res.message)


optimize_levelups_improved(current_stats)
# 제작자 : 태양
# 문의는 인게임 쪽지로 해주세요.

Embed on website

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