Skip to content

Instantly share code, notes, and snippets.

@pitluga
Created September 17, 2010 02:16
Show Gist options
  • Save pitluga/583545 to your computer and use it in GitHub Desktop.
Save pitluga/583545 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<project name="MyProject" default="dist" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init" description="compile the source ">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>
<target name="dist" depends="compile" description="generate the distribution">
<!-- Create the distribution directory -->
<mkdir dir="${dist}"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/mybot.jar" basedir="${build}"/>
</target>
<target name="zip" description="generate the zip file for submission">
<zip destfile="${dist}/submission.zip" basedir="${src}" />
</target>
<target name="clean" description="clean up">
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
BOTS = %w(Bully Dual Prospector Rage Random)
MAPS = 1..100
def parse_results(output)
output = output.split("\n")
loss = (output[-1] =~ /Player 1 Wins/).nil?
turns = output[-2].split[1]
[!loss, turns.to_i]
end
def print_results(victory, turns)
print victory ? "W" : "L"
print "(#{turns}) "
STDOUT.flush
end
def play_game(map, challenger)
my_cmd = 'java -cp dist/mybot.jar MyBot'
opp_cmd = "java -jar example_bots/#{challenger}Bot.jar"
cmd = %Q{java -jar tools/PlayGame-1.2.jar maps/map#{map}.txt 1000 1000 log.txt "#{my_cmd}" "#{opp_cmd}"}
`#{cmd} 2> commentary.txt > video.txt`
parse_results(File.read('commentary.txt'))
end
task :build do
`ant`
end
task :play => :build do
map = ENV['MAP'] || 7
bot = ENV['BOT'] || 'Dual'
print_results *play_game(map, bot)
puts
end
task :watch do
`cat video.txt | java -jar tools/ShowGame.jar`
end
task :tournament => :build do
BOTS.each do |bot|
wins = losses = turns_sum = 0
print "Challenging #{bot}Bot: "
MAPS.each do |map|
victory, turns = play_game map, bot
victory ? wins += 1 : losses +=1
turns_sum += turns
print (victory ? 'W' : 'L')
STDOUT.flush
end
puts " #{wins}-#{losses} (avg #{turns_sum/(wins+losses)} turns)"
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