Skip to content

Instantly share code, notes, and snippets.

@KhoraLee
Created July 6, 2023 15:59
Show Gist options
  • Save KhoraLee/ed1556a19a7e88aa75acdfeccd5dd497 to your computer and use it in GitHub Desktop.
Save KhoraLee/ed1556a19a7e88aa75acdfeccd5dd497 to your computer and use it in GitHub Desktop.
메이플 헥사 스텟 시뮬레이션
//
// main.swift
// HexaSimulator
//
// Created by _ on 2023/07/06.
//
import Foundation
let hexaProbs = [0.35, 0.35, 0.35, 0.2, 0.2, 0.2, 0.2, 0.15, 0.1, 0.05] // 메인 스텟 확률표
let maxTry = 20
let maxLevel = 10
var runCount = 0
var mainLevel = Array(repeating: 0.0, count: 11)
while true {
var table = [0, 0, 0]
var count = 0
// 강화 시뮬
while count < maxTry {
let prob: Double // 메인 스텟 확률
if table[0] < 10 {
prob = hexaProbs[table[0]]
} else {
prob = 0 // 메인 스텟이 10이면 서브 스텟만 남음
}
let subProb = (1 - prob) / 2 // 서브 스텟 확률
let arc4random64 = UInt64(arc4random()) << 32 &+ UInt64(arc4random())
let random = Double(arc4random64) / Double(UInt64.max) // [0, 1] 범위 랜덤 / 64 bits precision
if random < prob { // 메인 스텟
table[0] += 1 // 메인 스텟 강화
} else if random < prob + subProb { // 서브 스텟 1번
if table[1] == 10 { // 1번 서브 스텟이 10이면
table[2] += 1 // 무조건 2번 강화
} else {
table[1] += 1 // 1번 서브 스텟 강화
}
} else {
if table[2] == 10 { // 2번 서브 스텟이 10이면
table[1] += 1 // 무조건 1번 강화
} else {
table[2] += 1 // 2번 서브 스텟 강화
}
}
count += 1 // 강화 횟수 증가
}
// 한 사이클 끝
mainLevel[table[0]] += 1 // 메인 스텟 레벨 기록
runCount += 1 // 전체 시뮬 횟수 증가
// 로그 출력
if runCount % 10000 == 0 {
print("""
10: \(String(format: "%.6f", mainLevel[10] / Double(runCount))),\
9: \(String(format: "%.6f", mainLevel[9] / Double(runCount))),\
8: \(String(format: "%.6f", mainLevel[8] / Double(runCount))), ... /\
run #\(runCount), \(table)
""")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment