init
This commit is contained in:
commit
b5a96b621d
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@ -0,0 +1,9 @@
|
||||
root = true
|
||||
|
||||
[*.cr]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = true
|
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/docs/
|
||||
/lib/
|
||||
/bin/
|
||||
/.shards/
|
||||
*.dwarf
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Edith Boles <tirededith@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
27
README.md
Normal file
27
README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# tft_crunch
|
||||
|
||||
TODO: Write a description here
|
||||
|
||||
## Installation
|
||||
|
||||
TODO: Write installation instructions here
|
||||
|
||||
## Usage
|
||||
|
||||
TODO: Write usage instructions here
|
||||
|
||||
## Development
|
||||
|
||||
TODO: Write development instructions here
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork it (<https://github.com/your-github-user/tft_crunch/fork>)
|
||||
2. Create your feature branch (`git checkout -b my-new-feature`)
|
||||
3. Commit your changes (`git commit -am 'Add some feature'`)
|
||||
4. Push to the branch (`git push origin my-new-feature`)
|
||||
5. Create a new Pull Request
|
||||
|
||||
## Contributors
|
||||
|
||||
- [Edith Boles](https://github.com/your-github-user) - creator and maintainer
|
50
output.txt
Normal file
50
output.txt
Normal file
@ -0,0 +1,50 @@
|
||||
Garen, Vander, Violet, Gangplank, Powder - 205 score
|
||||
Scar, Vander, Violet, Ekko, Powder - 205 score
|
||||
Garen, Vander, Violet, Ekko, Powder - 205 score
|
||||
Nami, Vander, Violet, Powder, Vladimir - 204 score
|
||||
Tristana, Vander, Violet, Powder, Urgot - 204 score
|
||||
Garen, Vander, Violet, Powder, Urgot - 204 score
|
||||
Corki, Vander, Violet, Powder, Urgot - 204 score
|
||||
Garen, Vander, Violet, Powder, Sevika - 204 score
|
||||
Garen, Vander, Violet, Powder, Rumble - 204 score
|
||||
Tristana, Vander, Violet, Gangplank, Powder - 204 score
|
||||
Smeech, Vander, Violet, Gangplank, Powder - 204 score
|
||||
Scar, Vander, Violet, Gangplank, Powder - 204 score
|
||||
Nami, Vander, Violet, Gangplank, Powder - 204 score
|
||||
Jinx, Vander, Violet, Gangplank, Powder - 204 score
|
||||
Jayce, Vander, Violet, Gangplank, Powder - 204 score
|
||||
Darius, Vander, Violet, Gangplank, Powder - 204 score
|
||||
Camille, Vander, Violet, Gangplank, Powder - 204 score
|
||||
Amumu, Vander, Violet, Gangplank, Powder - 204 score
|
||||
Vander, Violet, Zeri, Ekko, Powder - 204 score
|
||||
Vander, Vi, Violet, Ekko, Powder - 204 score
|
||||
Tristana, Vander, Violet, Ekko, Powder - 204 score
|
||||
Smeech, Vander, Violet, Ekko, Powder - 204 score
|
||||
Nami, Vander, Violet, Ekko, Powder - 204 score
|
||||
Jinx, Vander, Violet, Ekko, Powder - 204 score
|
||||
Draven, Vander, Violet, Ekko, Powder - 204 score
|
||||
Darius, Vander, Violet, Ekko, Powder - 204 score
|
||||
Camille, Vander, Violet, Ekko, Powder - 204 score
|
||||
Amumu, Vander, Violet, Ekko, Powder - 204 score
|
||||
Draven, Vander, Violet, Ambessa, Powder - 204 score
|
||||
Darius, Vander, Violet, Ambessa, Powder - 204 score
|
||||
Vander, Violet, Zyra, Powder, Vladimir - 203 score
|
||||
Vander, Violet, Zoe, Powder, Vladimir - 203 score
|
||||
Vander, Violet, Ziggs, Powder, Vladimir - 203 score
|
||||
Vander, Vi, Violet, Powder, Vladimir - 203 score
|
||||
Trundle, Vander, Violet, Powder, Vladimir - 203 score
|
||||
Tristana, Vander, Violet, Powder, Vladimir - 203 score
|
||||
Smeech, Vander, Violet, Powder, Vladimir - 203 score
|
||||
Lux, Vander, Violet, Powder, Vladimir - 203 score
|
||||
LeBlanc, Vander, Violet, Powder, Vladimir - 203 score
|
||||
Jinx, Vander, Violet, Powder, Vladimir - 203 score
|
||||
Garen, Vander, Violet, Powder, Vladimir - 203 score
|
||||
Draven, Vander, Violet, Powder, Vladimir - 203 score
|
||||
Corki, Vander, Violet, Powder, Vladimir - 203 score
|
||||
Camille, Vander, Violet, Powder, Vladimir - 203 score
|
||||
Vander, Violet, Ziggs, Powder, Urgot - 203 score
|
||||
Trundle, Vander, Violet, Powder, Urgot - 203 score
|
||||
Smeech, Vander, Violet, Powder, Urgot - 203 score
|
||||
Scar, Vander, Violet, Powder, Urgot - 203 score
|
||||
Nami, Vander, Violet, Powder, Urgot - 203 score
|
||||
Jinx, Vander, Violet, Powder, Urgot - 203 score
|
216641
res/en_us.json
Normal file
216641
res/en_us.json
Normal file
File diff suppressed because it is too large
Load Diff
2992175
saves/9-5.txt
Normal file
2992175
saves/9-5.txt
Normal file
File diff suppressed because it is too large
Load Diff
13
shard.yml
Normal file
13
shard.yml
Normal file
@ -0,0 +1,13 @@
|
||||
name: tft_crunch
|
||||
version: 0.1.0
|
||||
|
||||
authors:
|
||||
- Edith Boles <tirededith@gmail.com>
|
||||
|
||||
targets:
|
||||
tft_crunch:
|
||||
main: src/tft_crunch.cr
|
||||
|
||||
crystal: '>= 1.13.3'
|
||||
|
||||
license: MIT
|
2
spec/spec_helper.cr
Normal file
2
spec/spec_helper.cr
Normal file
@ -0,0 +1,2 @@
|
||||
require "spec"
|
||||
require "../src/tft_crunch"
|
9
spec/tft_crunch_spec.cr
Normal file
9
spec/tft_crunch_spec.cr
Normal file
@ -0,0 +1,9 @@
|
||||
require "./spec_helper"
|
||||
|
||||
describe TftCrunch do
|
||||
# TODO: Write tests
|
||||
|
||||
it "works" do
|
||||
false.should eq(true)
|
||||
end
|
||||
end
|
143
src/tft_crunch.cr
Normal file
143
src/tft_crunch.cr
Normal file
@ -0,0 +1,143 @@
|
||||
require "json"
|
||||
require "math"
|
||||
|
||||
class Champion
|
||||
include JSON::Serializable
|
||||
|
||||
property cost : Int32
|
||||
property name : String
|
||||
property traits : Array(String)
|
||||
end
|
||||
|
||||
class Trait
|
||||
include JSON::Serializable
|
||||
|
||||
class Effect
|
||||
include JSON::Serializable
|
||||
|
||||
@[JSON::Field(key: "minUnits")]
|
||||
property min_units : Int32
|
||||
|
||||
@[JSON::Field(key: "maxUnits")]
|
||||
property max_units : Int32
|
||||
|
||||
property style : Int32
|
||||
end
|
||||
|
||||
property effects : Array(Effect)
|
||||
property name : String
|
||||
|
||||
def active_at?(unit_count)
|
||||
return effects.any? do |effect|
|
||||
effect.max_units >= unit_count && effect.min_units <= unit_count
|
||||
end
|
||||
end
|
||||
|
||||
def tier_at(unit_count)
|
||||
return effects.index do |effect|
|
||||
effect.max_units >= unit_count && effect.min_units <= unit_count
|
||||
end
|
||||
end
|
||||
|
||||
def unique?
|
||||
return effects.any? do |effect|
|
||||
effect.style == 4
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def comb(n, r)
|
||||
return ((n-r+1)..n).product // (1..r).product
|
||||
end
|
||||
|
||||
def check_active(champions, trait_data, emblems = [] of String, uniques = false)
|
||||
active = [] of Tuple(Trait, Int32, Int32)
|
||||
count = {} of String => Int32
|
||||
|
||||
champions.each do |champion|
|
||||
champion.traits.tally(count)
|
||||
end
|
||||
count.each do |trait_name, count|
|
||||
trait = trait_data[trait_name]
|
||||
if trait.active_at?(count) && (uniques || !trait.unique?)
|
||||
active << {trait, count, trait.tier_at(count).not_nil!}
|
||||
end
|
||||
end
|
||||
|
||||
return active
|
||||
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
|
||||
traits.each do |trait, count, tier|
|
||||
score += 2**tier
|
||||
end
|
||||
return score
|
||||
end
|
||||
|
||||
RES_FILE = "res/en_us.json"
|
||||
|
||||
file = File.open(RES_FILE)
|
||||
data = JSON.parse(file)
|
||||
trait_data = data["sets"]["13"]["traits"].as_a.to_json
|
||||
champion_data = data["sets"]["13"]["champions"].as_a.to_json
|
||||
|
||||
traits = Array(Trait).from_json(trait_data).index_by(&.name)
|
||||
champions = Array(Champion).from_json(champion_data)
|
||||
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
|
||||
|
||||
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"
|
||||
|
||||
results = [] of Tuple(Array(Champion), Int32)
|
||||
|
||||
counter : UInt64 = 0
|
||||
total = comb(super_units.size, super_count)
|
||||
total *= comb(other_units.size, other_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
|
||||
end
|
||||
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"
|
||||
end
|
||||
|
||||
File.write("output.txt", output.join("\n"))
|
||||
|
||||
puts "\nTop Ten:"
|
||||
puts "-" * 80
|
||||
puts output.first(10).reverse.join("\n")
|
Loading…
x
Reference in New Issue
Block a user