Advertisement
t_a_w

EU4 Gold Mine Development Calculations

Jun 28th, 2017
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.90 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require "rational"
  3.  
  4. # Game shows in tooltip:
  5. # Base | Change per year
  6. # 1      0.00%
  7. # 2      0.01%
  8. # 5      0.12%
  9. # 10     0.49%
  10. # 15     1.12%
  11. # 20     1.99%
  12. # Best fit says there's extra digit 0.5 missing,
  13. # so it's really
  14. def fail_chance(base)
  15.   return 0 if base <= 1
  16.   Rational(base**2-1, 20000)
  17. end
  18.  
  19. def lerp(ratio, a, b)
  20.   ratio = 0 if ratio <= 0
  21.   ratio = 1 if ratio >= 1
  22.   ratio * a + (1-ratio) * b
  23. end
  24.  
  25. # Depletion keeps fractional development, so 61 depletes to 30.5
  26. # For simplicity/performance round to two decimal places
  27. $base_after_depletion = {}
  28. def base_after_depletion(base)
  29.   Rational((base*50).floor, 100)
  30. end
  31.  
  32. $expected_gold = {}
  33. def expected_gold_income(base, years)
  34.   $expected_gold[[base, years]] ||= begin
  35.     if years == 0
  36.       0
  37.     else
  38.       # Assume depletion only happens on annual tick, since we don't know any better
  39.       current_year_income = 8 * base
  40.       chance = fail_chance(base)
  41.       depleted = base_after_depletion(base)
  42.       current_year_income + lerp(chance, expected_gold_income(depleted, years-1), expected_gold_income(base, years-1))
  43.     end
  44.   end
  45. end
  46.  
  47. def value_of_button_press(base, year)
  48.   expected_gold_income(base+1, year) - expected_gold_income(base, year)
  49. end
  50.  
  51.  
  52. puts "Expected Total Income By Dev [100/200/300/400 years]"
  53. (1..50).each do |base|
  54.   puts ["*",
  55.     base,
  56.     "-",
  57.     expected_gold_income(base, 100).round,
  58.     expected_gold_income(base, 200).round,
  59.     expected_gold_income(base, 300).round,
  60.     expected_gold_income(base, 400).round,
  61.   ].join(" ")
  62. end
  63.  
  64. puts "Expected Total Gold Value Of Pressing Dev Button [100/200/300/400 years]"
  65. (1..50).each do |base|
  66.   puts ["*",
  67.     base,
  68.     "-",
  69.     value_of_button_press(base, 100).round,
  70.     value_of_button_press(base, 200).round,
  71.     value_of_button_press(base, 300).round,
  72.     value_of_button_press(base, 400).round,
  73.   ].join(" ")
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement