diff --git a/contest.rb b/contest.rb index 7125d6c..87c4e26 100644 --- a/contest.rb +++ b/contest.rb @@ -8,15 +8,15 @@ class Contest include Judge - def initialize - load_bots + def initialize(*names) + load_bots(*names) @results = [] @win_counts = Hash.new(0) end def start @bots.each_with_index do |bot, index| - @bots.slice(index..(-1)).each do |opponent| + @bots.slice((index + 1)..(-1)).each do |opponent| fight! bot, opponent end end @@ -25,11 +25,15 @@ def start private - def load_bots + def load_bots(*names) @bots = Dir['./bots/*.rb'].map do |path| require path File.basename(path).sub('.rb', '').classify.constantize end + + if names.any? + @bots.select! { |bot| names.include?(bot.name) } + end end def fight!(botclass1, botclass2) @@ -65,6 +69,4 @@ def print_avg_result(a, b, sums) end -contest = Contest.new -contest.start diff --git a/script/fight b/script/fight new file mode 100755 index 0000000..d47912e --- /dev/null +++ b/script/fight @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby + +require File.expand_path('../../contest.rb', __FILE__) + +Contest.new(*ARGV).start