Добавил генерацию колоды и улучшил бд
This commit is contained in:
31
script/test_deck.rb
Normal file
31
script/test_deck.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "../config/app"
|
||||
|
||||
Hanami.app.prepare
|
||||
|
||||
repo = ClashDeckGenerator2::Repos::CardsRepo.new
|
||||
cards = repo.all.select { |card| card.rarity == "common" }
|
||||
|
||||
raise "No common cards found in DB." if cards.empty?
|
||||
raise "Not enough common cards to build a deck. Need at least 8, got #{cards.size}." if cards.size < 8
|
||||
|
||||
deck = cards.sample(8)
|
||||
|
||||
puts "========================================"
|
||||
puts "DECK GENERATED SUCCESSFULLY"
|
||||
puts "========================================"
|
||||
|
||||
deck.each_with_index do |card, index|
|
||||
puts "#{index + 1}. #{card.name} | #{card.type} | #{card.rarity} | #{card.elixir_cost}"
|
||||
end
|
||||
|
||||
puts "----------------------------------------"
|
||||
puts "Cards count: #{deck.size}"
|
||||
|
||||
names = deck.map(&:name)
|
||||
puts "Unique cards count: #{names.uniq.size}"
|
||||
|
||||
avg_elixir = deck.sum(&:elixir_cost).to_f / deck.size
|
||||
puts "Average elixir: #{avg_elixir.round(2)}"
|
||||
puts "========================================"
|
||||
Reference in New Issue
Block a user