Advertisement
Guest User

Untitled

a guest
Jun 5th, 2025
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const stages = 10
  2. const iterations = 1000000
  3. const goldCost = 3000
  4.  
  5. type State = {
  6.   orbs: number
  7.   free?: boolean
  8.   enhanced?: boolean
  9.   progress: number
  10.   paid: number
  11.   juice: number
  12. }
  13.  
  14. type Dwarf = {
  15.   chance: number
  16.   func: (state: State, value: number) => void
  17. }
  18.  
  19. const dwarvesNormal: Dwarf[] = [
  20.   {
  21.     // Galatur's Hammer
  22.     // Advanced Honing XP increased by 5 times
  23.     chance: 1250,
  24.     func: (state, value) => (state.progress += value * 4)
  25.   },
  26.   {
  27.     // Ghelar's Sword
  28.     // Advanced Honing XP increased by 3 times
  29.     chance: 2500,
  30.     func: (state, value) => (state.progress += value * 2)
  31.   },
  32.   {
  33.     // Kuhumbar's Anvil
  34.     // Advanced Honing XP increased by 30 and Ancestor's Grace has been recharged.
  35.     chance: 1250,
  36.     func: (state) => {
  37.       state.progress += 30
  38.       state.orbs = 6
  39.     }
  40.   },
  41.   {
  42.     // Temer's Chisel
  43.     // Advanced Honing XP increased by 10 and next honing cost is free
  44.     chance: 2500,
  45.     func: (state) => {
  46.       state.progress += 10
  47.       state.free = true
  48.     }
  49.   },
  50.   {
  51.     // Naber's Awl
  52.     // Next Advanced Honing is enhanced and recharges Ancestor's Grace
  53.     chance: 1250,
  54.     func: (state) => {
  55.       state.orbs = 6
  56.       state.enhanced = true
  57.     }
  58.   },
  59.   {
  60.     // Everre's Burin
  61.     // Advanced Honing Level +1
  62.     chance: 1250,
  63.     func: (state) => {
  64.       state.progress = Math.floor(state.progress / 100) * 100 + 100
  65.     }
  66.   }
  67. ]
  68.  
  69. const dwarvesEnhanced: Dwarf[] = [
  70.   {
  71.     // Galatur's Hammer
  72.     // Advanced Honing XP increased by 7 times
  73.     chance: 2000,
  74.     func: (state, value) => (state.progress += value * 6)
  75.   },
  76.   {
  77.     // Ghelar's Sword
  78.     // Advanced Honing XP increased by 5 times
  79.     chance: 2000,
  80.     func: (state, value) => (state.progress += value * 4)
  81.   },
  82.   {
  83.     // Kuhumbar's Anvil
  84.     // Advanced Honing XP increased by 80 and Ancestor's Grace has been recharged.
  85.     chance: 2000,
  86.     func: (state) => {
  87.       state.progress += 80
  88.       state.orbs = 6
  89.     }
  90.   },
  91.   {
  92.     // Temer's Chisel
  93.     // Advanced Honing XP increased by 30 and next honing cost is free
  94.     chance: 2000,
  95.     func: (state) => {
  96.       state.progress += 30
  97.       state.free = true
  98.     }
  99.   },
  100.   {
  101.     // Everre's Burin
  102.     // Advanced Honing Level +2
  103.     chance: 2000,
  104.     func: (state) => {
  105.       state.progress = Math.floor(state.progress / 100) * 100 + 200
  106.     }
  107.   }
  108. ]
  109.  
  110. function step(state: State) {
  111.   const juice = state.orbs >= 6 ? 1 : 0
  112.   const chance2 = 0.15 + 0.15 * juice
  113.   const chance4 = 0.05 + 0.15 * juice
  114.   const roll = Math.random()
  115.   const step = roll < chance4 ? 40 : roll < chance4 + chance2 ? 20 : 10
  116.   const dwarves =
  117.     state.orbs >= 6
  118.       ? state.enhanced
  119.         ? dwarvesEnhanced
  120.         : dwarvesNormal
  121.       : undefined
  122.   state.orbs = state.orbs >= 6 ? 0 : state.orbs + 1
  123.   state.progress += step
  124.   if (!state.free) state.paid += 1
  125.   if (juice) state.juice += 1
  126.   state.free = false
  127.   state.enhanced = false
  128.   if (dwarves) {
  129.     let droll = Math.random() * 10000
  130.     for (const d of dwarves) {
  131.       if (droll < d.chance) {
  132.         d.func(state, step)
  133.         break
  134.       }
  135.       droll -= d.chance
  136.     }
  137.   }
  138. }
  139.  
  140. let totalPaid = 0
  141. let worstPaid = 0
  142. let bestPaid = 1000000
  143. let totalJuice = 0
  144.  
  145. for (let i = 0; i < iterations; ++i) {
  146.   const state: State = {
  147.     orbs: 0,
  148.     progress: 0,
  149.     paid: 0,
  150.     juice: 0,
  151.     free: false,
  152.     enhanced: false
  153.   }
  154.   while (state.progress < stages * 100) {
  155.     step(state)
  156.     //    console.log(`${state.progress} ${state.orbs}`)
  157.   }
  158.   totalPaid += state.paid
  159.   totalJuice += state.juice
  160.   worstPaid = Math.max(worstPaid, state.paid)
  161.   bestPaid = Math.min(bestPaid, state.paid)
  162. }
  163.  
  164. console.log(`gold: ${(totalPaid / iterations) * goldCost}`)
  165. console.log(`best gold: ${bestPaid * goldCost}`)
  166. console.log(`worst gold: ${worstPaid * goldCost}`)
  167. console.log(`juice: ${totalJuice / iterations}`)
  168.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement