Advertisement
Guest User

TESL Pack opening simulator

a guest
Mar 20th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.38 KB | None | 0 0
  1. COST = [50, 100, 400, 1200, 1200]
  2. DUST = [5, 20, 100, 400, 400]
  3. ODDS = [688, 923, 985, 990, 1000] # cumulative odds out of 1000
  4. MAX = [3, 3, 3, 3, 1] # number you want of each card
  5. CARDS_PER_TYPE = [57, 45, 22, 10, 20]
  6.  
  7. got = [{}, {}, {}, {}, {}] # card ID => number of them
  8.  
  9. rng = Random.new
  10.  
  11. total_dust_reqd = 0
  12. total_dust_earnt = 0
  13.  
  14. (0..4).each do |i|
  15.   total_dust_reqd += (CARDS_PER_TYPE[i] * MAX[i] * COST[i])
  16. end
  17.  
  18. got_counts = [0, 0, 0, 0, 0]
  19. packs = 0
  20.  
  21. while total_dust_earnt < total_dust_reqd
  22.   packs += 1
  23.  
  24.   6.times do # 6 cards in a pack
  25.     card_type_number = rng.rand(1000)
  26.     card_type = 0
  27.     while ODDS[card_type] < card_type_number
  28.       card_type += 1
  29.     end
  30.    
  31.     raise "wtf?" if card_type >= 5
  32.    
  33.     card = rng.rand(CARDS_PER_TYPE[card_type])
  34.  
  35.     if !got[card_type].has_key?(card)
  36.       got[card_type][card] = 1
  37.       total_dust_reqd -= COST[card_type]    
  38.       got_counts[card_type] += 1
  39.     elsif got[card_type][card] < MAX[card_type]    
  40.       got[card_type][card] += 1
  41.       total_dust_reqd -= COST[card_type]
  42.       got_counts[card_type] += 1
  43.     else
  44.       total_dust_earnt += DUST[card_type]
  45.     end
  46.   end
  47.    
  48.   puts "After #{packs} packs, got #{got_counts[0]} C, #{got_counts[1]} R, #{got_counts[2]} E, #{got_counts[3]} L, #{got_counts[4]} UL, #{total_dust_earnt} dust, need #{total_dust_reqd} dust"
  49. end
  50.  
  51. puts "Done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement