참고 : AI(MS Copilot)가 작성한 코드임. 저작권 없이 Public Domain으로 배포함.


Python 코드 

from itertools import product


# 게임 보드 설정

items = ['티켓', '장비*53', '강화석*13', '경험치*17', '3칸앞으로', '크레딧*2000000', '장비*41', '경험치*11', '엘리그마*5', '크레딧*1600000', '1칸앞으로', '크레딧*1800000', '엘리그마*4', '강화석*11', '장비*37', '크레딧*1900000', '2칸앞으로', '경험치*19']

jumps = {4: 3, 10: 1, 16: 2}


# 사용자 입력 받기

dice_counts = list(map(int, input("가지고 있는 확정 주사위 갯수(1~6까지 순서대로 공백으로 구분): ").split()))

position = int(input("현재 말의 위치(0번부터 17번 자리): "))

preferences = list(map(int, input("선호도(0번부터 17번 자리): ").split()))


# 동적 프로그래밍을 위한 초기 설정

dp_table = {}

def calculate_optimal_path_dp(position, remaining_dice, preferences):

    if remaining_dice == (0,) * 6:

        return preferences[position], []


    if (position, remaining_dice) in dp_table:

        return dp_table[(position, remaining_dice)]


    best_preference = 0

    best_path = []

    for i, count in enumerate(remaining_dice):

        if count > 0:

            next_dice = list(remaining_dice)

            next_dice[i] -= 1

            next_position = (position + i + 1) % 18

            if next_position in jumps:

                next_position = (next_position + jumps[next_position]) % 18


            preference, path = calculate_optimal_path_dp(next_position, tuple(next_dice), preferences)

            preference += preferences[position]


            if preference > best_preference:

                best_preference = preference

                best_path = [i + 1] + path


    dp_table[(position, remaining_dice)] = (best_preference, best_path)

    return best_preference, best_path


# 최적의 경로 찾기

best_preference, best_path = calculate_optimal_path_dp(position, tuple(dice_counts), preferences)


# 결과 출력

print("사용할 주사위 순서:", ' '.join(map(str, best_path)))


# 아이템 수집 계산

items_collected = {'장비': 0, '강화석': 0, '경험치': 0, '엘리그마': 0, '크레딧': 0, '티켓': 0}

for pos in best_path:

    position = (position + pos) % 18

    if position in jumps:

        position = (position + jumps[position]) % 18

    item = items[position]

    if '칸앞으로' not in item:

        item_type, item_count = item.split('*')

        if item_type == '크레딧':

            items_collected[item_type] += int(item_count)

        else:

            items_collected[item_type] += int(item_count.split('개')[0])


# 얻게 되는 아이템의 갯수 출력

print("얻게 되는 아이템의 갯수:", ', '.join([f"{key}*{value}개" for key, value in items_collected.items() if value > 0]))



구 코드(느림, 모든 경우의 수 대입)

from itertools import permutations


# 게임 보드 설정

items = ['티켓', '장비*53', '강화석*13', '경험치*17', '3칸앞으로', '크레딧*2000000', '장비*41', '경험치*11', '엘리그마*5', '크레딧*1600000', '1칸앞으로', '크레딧*1800000', '엘리그마*4', '강화석*11', '장비*37', '크레딧*1900000', '2칸앞으로', '경험치*19']

jumps = {4: 3, 10: 1, 16: 2}


# 사용자 입력 받기

dice_counts = list(map(int, input("가지고 있는 확정 주사위 갯수(1~6까지 순서대로 공백으로 구분): ").split()))

position = int(input("현재 말의 위치(0번부터 17번 자리): "))

preferences = list(map(int, input("선호도(0번부터 17번 자리): ").split()))


# 가능한 모든 주사위 사용 순서 생성

dice_permutations = list(permutations([i for i in range(1, 7) for _ in range(dice_counts[i-1])]))


# 최적의 결과를 찾기 위한 함수

def calculate_optimal_path(dice_perm, position, preferences):

    total_preference = 0

    items_collected = {'장비': 0, '강화석': 0, '경험치': 0, '엘리그마': 0, '크레딧': 0, '티켓': 0}

    path = []


    for die in dice_perm:

        position = (position + die) % 18

        path.append(position)

        if position in jumps:

            position = (position + jumps[position]) % 18

        item = items[position]

        if '칸앞으로' not in item:

            item_type, item_count = item.split('*')

            if item_type == '크레딧':

                items_collected[item_type] += int(item_count)

            else:

                items_collected[item_type] += int(item_count.split('개')[0])

        total_preference += preferences[position]


    return total_preference, items_collected, path


# 최적의 경로 찾기

best_preference = 0

best_paths = []


for perm in dice_permutations:

    preference, collected_items, path = calculate_optimal_path(perm, position, preferences)

    if preference > best_preference:

        best_preference = preference

        best_paths = [(perm, collected_items)]

    elif preference == best_preference:

        best_paths.append((perm, collected_items))


# 결과 출력

for perm, collected_items in best_paths:

    print("사용할 주사위 순서:", ' '.join(map(str, perm)))

    print("얻게 되는 아이템의 갯수:", ', '.join([f"{key}*{value}개" for key, value in collected_items.items() if value > 0]))



1. Python 코드 실행방법(Python 개발환경이 갖춰져 있지 않다면)

colab.google 접속

New Notebook 클릭후 위 코드 복붙

왼쪽 실행버튼 누르면 아랫쪽에 입력창 뜸

입력하면 결과 뜸

참고 :  아래 예시처럼 가지고 있는 확정 주사위 갯수가 1*2개, 3*1개, 4*1개 일 경우, 아래처럼 공백으로 구분해서 입력(후 엔터)하고,

현재 유우카의 위치(입력후 엔터)

(확정권 주는 시작자리가 0번으로 시작하여 반시계방향으로 17번자리까지 있음)

0~17번에 해당하는 각 자리별 선호도(1~3, 1이 비선호, 3이 가장 선호)를 입력후 엔터


(예시)



코드 만든거는 MS Copilot 한테 이런식으로 시킴


수정할거나 문제있으면 알려주셈


-------------------------------------------------------

03-29 20:37 Dynamic Programming으로 코드 최적화(이것도 MS Copilot AI가 한거)