Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require "rational"
- # Game shows in tooltip:
- # Base | Change per year
- # 1 0.00%
- # 2 0.01%
- # 5 0.12%
- # 10 0.49%
- # 15 1.12%
- # 20 1.99%
- # Best fit says there's extra digit 0.5 missing,
- # so it's really
- def fail_chance(base)
- return 0 if base <= 1
- Rational(base**2-1, 20000)
- end
- def lerp(ratio, a, b)
- ratio = 0 if ratio <= 0
- ratio = 1 if ratio >= 1
- ratio * a + (1-ratio) * b
- end
- # Depletion keeps fractional development, so 61 depletes to 30.5
- # For simplicity/performance round to two decimal places
- $base_after_depletion = {}
- def base_after_depletion(base)
- Rational((base*50).floor, 100)
- end
- $expected_gold = {}
- def expected_gold_income(base, years)
- $expected_gold[[base, years]] ||= begin
- if years == 0
- 0
- else
- # Assume depletion only happens on annual tick, since we don't know any better
- current_year_income = 8 * base
- chance = fail_chance(base)
- depleted = base_after_depletion(base)
- current_year_income + lerp(chance, expected_gold_income(depleted, years-1), expected_gold_income(base, years-1))
- end
- end
- end
- def value_of_button_press(base, year)
- expected_gold_income(base+1, year) - expected_gold_income(base, year)
- end
- puts "Expected Total Income By Dev [100/200/300/400 years]"
- (1..50).each do |base|
- puts ["*",
- base,
- "-",
- expected_gold_income(base, 100).round,
- expected_gold_income(base, 200).round,
- expected_gold_income(base, 300).round,
- expected_gold_income(base, 400).round,
- ].join(" ")
- end
- puts "Expected Total Gold Value Of Pressing Dev Button [100/200/300/400 years]"
- (1..50).each do |base|
- puts ["*",
- base,
- "-",
- value_of_button_press(base, 100).round,
- value_of_button_press(base, 200).round,
- value_of_button_press(base, 300).round,
- value_of_button_press(base, 400).round,
- ].join(" ")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement