SHOW:
|
|
- or go back to the newest paste.
1 | - | TOTAL_CARDS = { :common => 100, :rare => 70, :epic => 50, :legendary => 30 } |
1 | + | TARGET_TOTAL = { :common => 200, :rare => 140, :epic => 100, :legendary => 30 } |
2 | CARDS_BY_RARITY = { :common => 100, :rare => 70, :epic => 50, :legendary => 30 } | |
3 | RARITY_CHANCE = { :legendary => 0.005, :epic => 0.025, :rare => 0.1, :common => 1 } | |
4 | RARITY_PRIORITY_CHECK = [ :legendary, :epic, :rare, :common ] | |
5 | DISENCHANTED_ARCANE_DUST = { :common => 2, :rare => 10, :epic => 100, :legendary => 400 } | |
6 | CRAFT_ARCANE_DUST = { :legendary => 1600, :epic => 400, :rare => 100, :common => 10 } | |
7 | CRAFT_RARITY_PRIORITY = [ :legendary, :epic, :rare, :common ] | |
8 | CARDS_PER_PACK = 5 | |
9 | ||
10 | class Card | |
11 | attr_accessor :rarity, :number | |
12 | def initialize(rarity, number) | |
13 | @rarity = rarity | |
14 | @number = number | |
15 | end | |
16 | end | |
17 | ||
18 | class PackGenerator | |
19 | ||
20 | def initialize | |
21 | @collection = { :common => [], :rare => [], :epic => [], :legendary => [] } | |
22 | @arcane_dust = 0 | |
23 | @packs_open = 0 | |
24 | @disenchanted = 0 | |
25 | end | |
26 | ||
27 | def check_packs_needed | |
28 | while !is_collection_complete? | |
29 | add_collection(random_pack) | |
30 | @packs_open += 1 | |
31 | #puts info | |
32 | end | |
33 | ||
34 | return @packs_open | |
35 | end | |
36 | - | unless @collection[card.rarity].any? { |c| c.number == card.number } |
36 | + | |
37 | def add_collection(pack) | |
38 | pack.each do |card| | |
39 | unless is_card_number_already_in_collection?(card.rarity, card.number) | |
40 | @collection[card.rarity] << card | |
41 | else | |
42 | disenchant_card(card) | |
43 | end | |
44 | end | |
45 | end | |
46 | ||
47 | def disenchant_card(card) | |
48 | - | CRAFT_ARCANE_DUST.each do |rarity, craft_cost| |
48 | + | |
49 | - | if @collection[rarity].size != TOTAL_CARDS[rarity] |
49 | + | |
50 | - | craft_card(rarity) if craft_cost <= @arcane_dust |
50 | + | |
51 | CRAFT_RARITY_PRIORITY.each do |rarity| | |
52 | if @collection[rarity].size != TARGET_TOTAL[rarity] | |
53 | craft_card(rarity) if CRAFT_ARCANE_DUST[rarity] <= @arcane_dust | |
54 | break | |
55 | end | |
56 | end | |
57 | - | (1..TOTAL_CARDS[rarity]).each do |i| |
57 | + | |
58 | - | unless @collection[rarity].any? { |card| card.number == i } |
58 | + | |
59 | def craft_card(rarity) | |
60 | (1..CARDS_BY_RARITY[rarity]).each do |i| | |
61 | unless is_card_number_already_in_collection?(rarity, i) | |
62 | @arcane_dust -= CRAFT_ARCANE_DUST[rarity] | |
63 | @collection[rarity] << Card.new(rarity, i) | |
64 | return | |
65 | end | |
66 | end | |
67 | - | pack = [] |
67 | + | |
68 | ||
69 | - | pack << random_rarity_card(i == 5 && !pack.any? { |card| card.rarity != :common }) |
69 | + | def is_card_number_already_in_collection?(rarity, i) |
70 | target_total = rarity == :legendary ? 1 : 2 | |
71 | - | return pack |
71 | + | return @collection[rarity].select { |card| card.number == i }.size == target_total |
72 | end | |
73 | ||
74 | - | def random_rarity_card(force_atleast_rare) |
74 | + | |
75 | @last_pack = [] | |
76 | - | while r < RARITY_CHANCE[:rare] |
76 | + | |
77 | - | r = rand |
77 | + | @last_pack << random_rarity_card((i == 5 && !@last_pack.any? { |card| card.rarity != :common })) |
78 | - | end if force_atleast_rare |
78 | + | #@last_pack << random_rarity_card(i == 1) |
79 | end | |
80 | return @last_pack | |
81 | - | RARITY_CHANCE.each do |rarity, chance| |
81 | + | |
82 | ||
83 | - | card = Card.new(rarity, random_card_from_rarity(TOTAL_CARDS[rarity])) |
83 | + | def random_rarity_card(force_rare) |
84 | r = rand # get rarity | |
85 | ||
86 | card = nil | |
87 | RARITY_PRIORITY_CHECK.each do |rarity| | |
88 | chance = force_rare && rarity == :rare ? 1 : RARITY_CHANCE[rarity] | |
89 | if r < chance | |
90 | card = Card.new(rarity, random_card_from_rarity(CARDS_BY_RARITY[rarity])) | |
91 | break | |
92 | end | |
93 | end | |
94 | ||
95 | return card | |
96 | end | |
97 | - | return false if list.size != TOTAL_CARDS[rarity] |
97 | + | |
98 | def random_card_from_rarity(max) | |
99 | return (rand * (max - 1) + 1).round | |
100 | end | |
101 | ||
102 | def is_collection_complete? | |
103 | @collection.each do |rarity, list| | |
104 | - | msg << "packs: #{@packs_open}, " |
104 | + | return false if list.size != TARGET_TOTAL[rarity] |
105 | - | msg << "common: #{@collection[:common].size}, " |
105 | + | |
106 | - | msg << "rare: #{@collection[:rare].size}, " |
106 | + | |
107 | - | msg << "epic: #{@collection[:epic].size}, " |
107 | + | |
108 | - | msg << "leg: #{@collection[:legendary].size}, " |
108 | + | |
109 | - | msg << "dis: #{@disenchanted}, " |
109 | + | |
110 | - | msg << "dust: #{@arcane_dust}" |
110 | + | |
111 | - | msg << "." |
111 | + | msg << "#{@packs_open}\t" |
112 | msg << "#{@last_pack.collect { |c| c.rarity }.inspect}\t" | |
113 | msg << "#{@collection[:common].size}\t" | |
114 | msg << "#{@collection[:rare].size}\t" | |
115 | msg << "#{@collection[:epic].size}\t" | |
116 | msg << "#{@collection[:legendary].size}\t" | |
117 | - | (0..49).each do |i| |
117 | + | msg << "#{@disenchanted}\t" |
118 | msg << "#{@arcane_dust}" | |
119 | return msg | |
120 | - | puts "Packs needed: #{results[i]}." |
120 | + | |
121 | end | |
122 | ||
123 | #STDOUT.reopen(File.open('generator.log', 'w+')) | |
124 | - | puts "Min: #{results.min}" |
124 | + | |
125 | results = [] | |
126 | - | #Packs needed: 1167. |
126 | + | (1..500).each do |i| |
127 | - | #Packs needed: 1310. |
127 | + | |
128 | - | #Packs needed: 1598. |
128 | + | |
129 | - | #Packs needed: 1471. |
129 | + | puts "[#{i}] Packs needed: #{results[i-1]}." |
130 | - | #Packs needed: 1178. |
130 | + | |
131 | - | #Packs needed: 1288. |
131 | + | |
132 | - | #Packs needed: 1434. |
132 | + | |
133 | - | #Packs needed: 1254. |
133 | + | puts "Min: #{results.min}" |