init
This commit is contained in:
@ -47,16 +47,18 @@ class Trait
|
||||
end
|
||||
|
||||
def comb(n, r)
|
||||
return ((n-r+1)..n).product // (1..r).product
|
||||
return ((n.to_u64-r+1)..n).product // (1.to_u64..r).product
|
||||
end
|
||||
|
||||
def check_active(champions, trait_data, emblems = [] of String, uniques = false)
|
||||
def check_active(champions, trait_data, uniques = false)
|
||||
active = [] of Tuple(Trait, Int32, Int32)
|
||||
count = {} of String => Int32
|
||||
emblems = [] of String
|
||||
|
||||
champions.each do |champion|
|
||||
champion.traits.tally(count)
|
||||
end
|
||||
emblems.tally(count)
|
||||
count.each do |trait_name, count|
|
||||
trait = trait_data[trait_name]
|
||||
if trait.active_at?(count) && (uniques || !trait.unique?)
|
||||
@ -70,18 +72,21 @@ end
|
||||
def score_comp(champions, trait_data)
|
||||
traits = check_active(champions, trait_data)
|
||||
score = 0
|
||||
if champions.any?{|e| e.name == "Vander"}
|
||||
score += 100
|
||||
end
|
||||
if traits.any?{|e| e[0].name == "Family"}
|
||||
score += 100
|
||||
end
|
||||
# score += 100 if champions.any?{|e| e.name == "Vander"}
|
||||
# if traits.any?{|e| e[0].name == "Family"}
|
||||
# score += 100
|
||||
# end
|
||||
traits.each do |trait, count, tier|
|
||||
score += 2**tier
|
||||
score += 3**tier
|
||||
end
|
||||
return score
|
||||
end
|
||||
|
||||
def run_comp?(champions)
|
||||
return true #champions.any?{|e| e.name == "Vander"}
|
||||
end
|
||||
|
||||
|
||||
RES_FILE = "res/en_us.json"
|
||||
|
||||
file = File.open(RES_FILE)
|
||||
@ -95,45 +100,40 @@ champions.reject!{ |champ| champ.traits.empty? }
|
||||
cbn = champions.index_by(&.name)
|
||||
|
||||
unit_count = ARGV[0]?.try(&.to_i) || 7
|
||||
super_count = ARGV[1]?.try(&.to_i) || 4
|
||||
other_count = unit_count - super_count
|
||||
cost_limit = ARGV[2]?.try(&.to_i) || 10
|
||||
min_score = ARGV[3]?.try(&.to_i) || unit_count
|
||||
cost_limit = ARGV[1]?.try(&.to_i) || 10
|
||||
min_score = ARGV[2]?.try(&.to_i) || unit_count
|
||||
|
||||
champions.select!{ |champ| champ.cost <= cost_limit }
|
||||
champions.sort_by!{ |champ| champ.name }
|
||||
super_units = champions.select{ |champ| champ.traits.size == 3 }
|
||||
other_units = champions.select{ |champ| champ.traits.size == 2 }
|
||||
puts "#{super_count.to_s.rjust(2)}x #{super_units.size.to_s.rjust(2)} 3-trait champions"
|
||||
puts "#{other_count.to_s.rjust(2)}x #{other_units.size.to_s.rjust(2)} 2-trait champions"
|
||||
puts "#{unit_count.to_s.rjust(2)}x #{champions.size.to_s.rjust(3)} champions"
|
||||
|
||||
results = [] of Tuple(Array(Champion), Int32)
|
||||
|
||||
counter : UInt64 = 0
|
||||
total = comb(super_units.size, super_count)
|
||||
total *= comb(other_units.size, other_count)
|
||||
total = comb(champions.size, unit_count)
|
||||
|
||||
test_array1 = [] of Champion
|
||||
test_array2 = [] of Champion
|
||||
super_units.each_combination(super_count, reuse: test_array1) do |units|
|
||||
other_units.each_combination(other_count, reuse: test_array2) do |others|
|
||||
others.concat(units)
|
||||
score = score_comp(others, traits)
|
||||
if score >= min_score
|
||||
results << {others.dup, score}
|
||||
end
|
||||
if counter % 100000 == 0
|
||||
percent = (counter / total * 100).format(decimal_places: 2).rjust(6) + "%"
|
||||
puts "#{percent} | #{counter.to_s.rjust(10)} | #{score.to_s.rjust(3)} | #{others.map(&.name).join(", ")}"
|
||||
end
|
||||
counter += 1
|
||||
others.clear
|
||||
champions.each_combination(unit_count, reuse: test_array1) do |units|
|
||||
next unless run_comp?(units)
|
||||
score = score_comp(units, traits)
|
||||
if score >= min_score
|
||||
results << {units.dup, score}
|
||||
end
|
||||
if counter % 100000 == 0
|
||||
percent = (counter / total * 100).format(decimal_places: 2).rjust(6) + "%"
|
||||
puts "#{percent} | #{counter.to_s.rjust(10)} | #{score.to_s.rjust(3)} | #{units.map(&.name).join(", ")}"
|
||||
end
|
||||
counter += 1
|
||||
units.clear
|
||||
end
|
||||
|
||||
output = results.sort_by{|e| e[1]}.reverse.first(50).map do |list, count|
|
||||
"#{list.map(&.name).join(", ").ljust(30)} - #{count} score"
|
||||
<<-HERE
|
||||
#{list.map(&.name).join(", ")}
|
||||
Score: #{count}
|
||||
Traits: #{check_active(list, traits).size}
|
||||
Traits count: #{check_active(list, traits).map{|e| "#{e[0].name} #{e[1]}"}.join(", ")}
|
||||
HERE
|
||||
end
|
||||
|
||||
File.write("output.txt", output.join("\n"))
|
||||
|
Reference in New Issue
Block a user