Skip to content

Commit

Permalink
fight script
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Cathor committed May 30, 2012
1 parent 91283f7 commit c5c913b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 8 additions & 6 deletions contest.rb
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -65,6 +69,4 @@ def print_avg_result(a, b, sums)

end

contest = Contest.new
contest.start

5 changes: 5 additions & 0 deletions script/fight
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require File.expand_path('../../contest.rb', __FILE__)

Contest.new(*ARGV).start

0 comments on commit c5c913b

Please sign in to comment.