Skip to content

Instantly share code, notes, and snippets.

@pitluga
Created September 10, 2010 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pitluga/572991 to your computer and use it in GitHub Desktop.
Save pitluga/572991 to your computer and use it in GitHub Desktop.
BOTS = %w(Bully Dual Prospector Rage Random)
MAPS = 1..100
def play_game(map, challenger)
cmd = %Q{java -jar tools/PlayGame.jar maps/map#{map}.txt 1000 1000 log.txt "ruby mybot.rb" "java -jar example_bots/#{challenger}Bot.jar"}
`#{cmd} 2> commentary.txt`
output = File.read('commentary.txt').split("\n")
victory = output[-1] =~ /Player 1 Wins/
turn = output[-2].split[1]
print victory.nil? ? "L" : "W"
print "(#{turn}) "
end
task :play do
map = ENV['MAP'] || 7
bot = ENV['BOT'] || 'Dual'
play_game(map, bot)
puts
end
task :tournament do
BOTS.each do |bot|
print "Challenging #{bot}Bot: "
MAPS.each do |map|
play_game map, bot
STDOUT.flush
end
puts
end
end
task :help do
puts "Available bots: #{BOTS.join(',')}"
puts "Available maps: #{MAPS.inspect}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment