Last active
June 24, 2017 00:48
-
-
Save SimianLogic/6d95d55c8e63c2684abb898ad0fae197 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array; def sum; inject( nil ) { |sum,x| sum ? sum+x : x }; end; end | |
class Array; def mean; sum / size; end; end | |
class Ungoro | |
attr_accessor :packs, :completion | |
attr_accessor :nice_packs | |
attr_accessor :pity_timer | |
#est. average of 75 gold per day | |
PACKS_PER_DAY = 0.75 | |
PITY_TIMER = 40 | |
#COMPLETION PERCENT IS A FLOAT (1.0, NOT 100) | |
def self.simulate(nice_packs, completion_percent) | |
data = [] | |
1000.times{ packs = Ungoro.new(nice_packs).get_em_all(completion_percent).packs.to_f; data << packs; p packs } | |
result = data.mean | |
puts "*"*50 | |
puts result | |
puts "NO $$$: #{result/PACKS_PER_DAY} days" | |
puts "PREORDER: #{(result-50)/PACKS_PER_DAY} days" | |
puts "PREORDER+$50: #{(result-90)/PACKS_PER_DAY} days" | |
end | |
def initialize(nice_packs) | |
if nice_packs | |
@pity_timer = 10 | |
else | |
@pity_timer = PITY_TIMER | |
end | |
@packs = 0 | |
@completion = { | |
:common => [], | |
:rare => [], | |
:epic => [], | |
:legend => [], | |
:dust => 0 | |
} | |
@set = { | |
:common => 49, | |
:rare => 36, | |
:epic => 27, | |
:legend => 23 | |
} | |
end | |
def get_em_all(completion_percent) | |
total_dust = 69520 - dust_remaining + @completion[:dust] | |
while total_dust < 69520*completion_percent | |
open_pack | |
total_dust = 69520 - dust_remaining + @completion[:dust] | |
end | |
self #chaining | |
end | |
def get_rarity(is_pitiful) | |
if is_pitiful | |
p "PITY TIMER" | |
@pity_timer = PITY_TIMER | |
return :legend, false, 400 | |
end | |
#rarity source: http://www.pcgamer.com/blizzards-chinese-hearthstone-website-confirms-card-rarity-drop-rates/ | |
roll = rand | |
#legendary : 1 in 20 (/5) | |
# epic : 1 in 5 (/5) | |
# rare : 1 in 5 | |
# common : all the rest | |
#golden chance source: http://hearthstone.gamepedia.com/Card_pack_statistics#Golden_cards | |
#chance to be golden | |
# common: 2.06% | |
# rare: 5.54% | |
# epic: 4.52% | |
# legendary: 7.31% | |
roll = rand | |
golden_roll = rand | |
legendary_chance = 1.0 / 20.0 / 5.0 | |
golden_legendary_chance = 0.0731 #chance for a legendary to be golden, not chance to pull golden legendary | |
epic_chance = 1.0 / 5.0 / 5.0 | |
golden_epic_chance = 0.0452 | |
rare_chance = 1.0 / 5.0 | |
golden_rare_chance = 0.0554 | |
golden_common_chance = 0.0206 | |
if roll < legendary_chance | |
if golden_roll < golden_legendary_chance | |
return :legend, true, 1600 | |
else | |
return :legend, false, 400 | |
end | |
elsif roll < legendary_chance + epic_chance | |
if golden_roll < golden_epic_chance | |
return :epic, true, 400 | |
else | |
return :epic, false, 100 | |
end | |
elsif roll < legendary_chance + epic_chance + rare_chance | |
if golden_roll < golden_rare_chance | |
return :rare, true, 100 | |
else | |
return :rare, false, 20 | |
end | |
else | |
if golden_roll < golden_common_chance | |
return :common, true, 50 | |
else | |
return :common, false, 5 | |
end | |
end | |
end | |
def get_card(excludes, is_pitiful) | |
rarity, golden, dust = get_rarity(is_pitiful) | |
#guaranteed at least one rare | |
if excludes[:common].length == 4 && rarity == :common | |
rarity = :rare | |
end | |
#pool of eligible cards | |
pool = (1..@set[rarity]).to_a | |
if rarity == :legend | |
#no duplicate legends until we get them all | |
if @completion[:legend].length < pool.length | |
pool = pool - @completion[:legend] | |
end | |
pool = pool - excludes[rarity] | |
else | |
excludes[rarity].each do |card_id| | |
if excludes[rarity].count(card_id) >= 2 | |
pool = pool - [card_id] | |
end | |
end | |
end | |
#if we broke it start over | |
if pool.length == 0 | |
pool = (1..@set[rarity]).to_a | |
end | |
card_id = pool.sample | |
#always dust golden cards to fill in missing cards | |
if golden | |
@completion[:dust] += dust | |
else | |
count = (rarity == :legend) ? 1 : 2 | |
if(@completion[rarity].count(card_id) < count) | |
@completion[rarity] << card_id | |
else | |
@completion[:dust] += dust | |
end | |
end | |
return rarity, card_id, golden | |
end | |
def open_pack | |
pack = { | |
:common => [], | |
:rare => [], | |
:epic => [], | |
:legend => [] | |
} | |
5.times do | |
rarity, card_id = get_card(pack, (@pity_timer <= 0)) | |
pack[rarity] << card_id | |
#always dust golden cards to fill in missing cards | |
end | |
if pack[:legend].length == 0 | |
@pity_timer -= 1 | |
end | |
@packs += 1 | |
# p pack | |
end | |
def dust_remaining | |
common_dust = (98 - @completion[:common].count) * 40 | |
rare_dust = (72 - @completion[:rare].count) * 100 | |
epic_dust = (54 - @completion[:epic].count) * 400 | |
legend_dust = (23 - @completion[:legend].count) * 1600 | |
common_dust + rare_dust + epic_dust + legend_dust | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment