diff --git a/README.md b/README.md index b210790..efd69e7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![Summary graphic for the latest battle](https://darbycomputerclub.github.io/robocode-results/results/melee/darbygraphic.png)](https://darbycomputerclub.github.io/robocode-results/results/melee/darby-col.txt)
[view leaderboard](https://darbycomputerclub.github.io/robocode-results/results/melee/darby-col.txt) | [download battle record](https://darbycomputerclub.github.io/robocode-results/results/melee/darby.br) - [![Circle CI](https://circleci.com/gh/DarbyComputerClub/darbyrobocode/tree/master.svg?style=svg)](https://circleci.com/gh/DarbyComputerClub/darbyrobocode/tree/master) This version of robocode is for the Darby Computer Club. diff --git a/battles/tournament/t2.tournament b/battles/tournament/t2.tournament new file mode 100644 index 0000000..30427e9 --- /dev/null +++ b/battles/tournament/t2.tournament @@ -0,0 +1,10 @@ +#Battle Properties +robocode.battleField.width=800 +robocode.battleField.height=600 +robocode.battle.numRounds=5 +robocode.battle.gunCoolingRate=0.1 +robocode.battle.rules.inactivityTime=450 +robocode.battle.hideEnemyNames=true +# ADD YOUR ROBOT HERE IN THE FORM lastname.firstname.RobotName* +# star is important ^ +darby.tournament.selectedRobots=sample.Corners,sample.MyFirstBot,io.github.jacobsims.AimingBot* diff --git a/battles/tournament/t3.tournament b/battles/tournament/t3.tournament new file mode 100644 index 0000000..82fbfbd --- /dev/null +++ b/battles/tournament/t3.tournament @@ -0,0 +1,10 @@ +#Battle Properties +robocode.battleField.width=800 +robocode.battleField.height=600 +robocode.battle.numRounds=7 +robocode.battle.gunCoolingRate=0.1 +robocode.battle.rules.inactivityTime=450 +robocode.battle.hideEnemyNames=true +# ADD YOUR ROBOT HERE IN THE FORM lastname.firstname.RobotName* +# star is important ^ +darby.tournament.selectedRobots=sample.Corners,sample.Crazy,sample.Fire,sample.MyFirstJuniorRobot,sample.MyFirstRobot,sample.PaintingRobot,sample.RamFire,sample.SittingDuck,sample.SpinBot,sample.Target,sample.Tracker,sample.TrackFire,sample.VelociRobot,sample.Walls,io.github.jacobsims.AimingBot*,io.github.enzanki_ars.AlexSimpleBot* diff --git a/battles/tournament/withsample.tournament b/battles/tournament/withsample.tournament new file mode 100644 index 0000000..fb03547 --- /dev/null +++ b/battles/tournament/withsample.tournament @@ -0,0 +1,10 @@ +#Battle Properties +robocode.battleField.width=800 +robocode.battleField.height=600 +robocode.battle.numRounds=5 +robocode.battle.gunCoolingRate=0.1 +robocode.battle.rules.inactivityTime=450 +robocode.battle.hideEnemyNames=true +# ADD YOUR ROBOT HERE IN THE FORM lastname.firstname.RobotName* +# star is important ^ +darby.tournament.selectedRobots=sample.Corners,sample.Fire,sample.MyFirstRobot,sample.RamFire,sample.Target,sample.TrackFire,sample.Walls,sample.Crazy,io.github.enzanki_ars.AlexSimpleBot*,io.github.jacobsims.AimingBot* diff --git a/circle.yml b/circle.yml index 8432467..d37b28f 100644 --- a/circle.yml +++ b/circle.yml @@ -7,12 +7,12 @@ general: dependencies: pre: - - cp -R run ~/run - - pip install --user cairosvg - - ~/run/pull_results.sh + - pip install --user cairosvg pyjavaproperties override: - - unzip -n ~/run/robocode-1.9.2.5-setup.jar -d . + - cp -R run ~/run + - unzip ~/run/robocode-1.9.2.5-setup.jar -d . - mkdir ~/battles + - ~/run/pull_results.sh cache_directories: - ~/gh-results diff --git a/run/robocoderun.py b/run/robocoderun.py new file mode 100644 index 0000000..ba35f2b --- /dev/null +++ b/run/robocoderun.py @@ -0,0 +1,11 @@ +import subprocess + +def robocoderun(battlefile, resultsfile, recordfile): + code = subprocess.call(['java', '-Xmx512M', '-Dsun.io.useCanonCaches=false', '-cp', 'libs/robocode.jar', + 'robocode.Robocode', + '-battle', battlefile, + '-nodisplay', + '-results', resultsfile, + '-nosound', + '-record', recordfile]) + return code diff --git a/run/runner.py b/run/runner.py index 58ee25f..83abee8 100755 --- a/run/runner.py +++ b/run/runner.py @@ -5,8 +5,10 @@ import pip import subprocess import robosvgmake +import tournament +from robocoderun import robocoderun -battles = ["melee/darby", "melee/officers", "melee/all", "melee/withsample","1v1/enz_v_jac","1v1/jac_v_wall","1v1/enz_v_wall"] +battles = ["tournament/withsample","tournament/t2","tournament/t3","melee/darby","melee/withsample","1v1/enz_v_jac","1v1/jac_v_wall","1v1/enz_v_wall"] run = [battles[i::int(os.environ['CIRCLE_NODE_TOTAL'])] for i in range(int(os.environ['CIRCLE_NODE_TOTAL']))] @@ -21,16 +23,15 @@ print(battleList) for battle in battleList: - os.makedirs(os.path.expanduser('~/battles/results/' + battle)) - exitcode = subprocess.call(['java', '-Xmx512M', '-Dsun.io.useCanonCaches=false', '-cp', 'libs/robocode.jar', - 'robocode.Robocode', - '-battle', 'battles/' + battle + '.battle', - '-nodisplay', - '-results', os.path.expanduser('~/battles/results/' + battle + '.txt'), - '-nosound', - '-record', os.path.expanduser('~/battles/results/' + battle + ".br")]) - if exitcode != 0: - exit(exitcode) + os.makedirs(os.path.expanduser('~/battles/results/' + os.path.dirname(battle))) + if os.path.isfile('battles/' + battle + '.battle'): + code = robocoderun('battles/' + battle + '.battle', + os.path.expanduser('~/battles/results/' + battle + '.txt'), + os.path.expanduser('~/battles/results/' + battle + '.br')) + if code != 0: + exit(code) + elif os.path.isfile('battles/' + battle + '.tournament'): + print tournament.runTournamentCalled(battle) with open(os.path.expanduser('~/battles/results/' + battle + '-col.txt'), 'w') as w: w.write('Darby Robocode Battle\n') diff --git a/run/tournament.py b/run/tournament.py new file mode 100644 index 0000000..97a3263 --- /dev/null +++ b/run/tournament.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python +import pyjavaproperties +from robocoderun import robocoderun +import tempfile +import shutil +import random +import copy +import csv +import os + +def loadFile(fpath): + p = pyjavaproperties.Properties() + with open(fpath, 'r') as f: + p.load(f) + return p + +def saveFile(p, fpath): + with open(fpath, 'w') as f: + p.store(f) + +def makeTempBattle(p): + tempdir = tempfile.mkdtemp('', 'darbyrobocode_') + saveFile(p, tempdir + '/a.battle') + return tempdir + +def separateProps(p): + d = p.getPropertyDict() + newp = pyjavaproperties.Properties() + darbyopts = {} + for key in d: + if key.startswith('darby.'): + darbykey = key.split('.', 1)[1] + darbyopts[darbykey] = d[key] + else: + # Allow other options to go through to the battle file + newp[key] = d[key] + + return newp, darbyopts + +def getWinnerOfBattle(bot1, bot2, battletemplate): + print battletemplate + battle = battletemplate + battle['robocode.battle.selectedRobots'] = ','.join([bot1, bot2]) + tempdir = makeTempBattle(battle) + robocoderun(tempdir + '/a.battle', tempdir + '/results.txt', tempdir + '/results.br') + with open(tempdir + '/results.txt', 'r') as r: + lines = csv.reader(r, delimiter='\t') + for line in lines: + if len(line) > 0 and line[0].startswith('1st:'): + return line[0][5:], tempdir + +def getWinnerAndDiscard(bot1, bot2, battletemplate): + winner, tempdir = getWinnerOfBattle(bot1, bot2, battletemplate) + shutil.rmtree(tempdir) + return winner + + +def splitList(l): + split = [] + for i in range(int(len(l)/2)): + split.append([l[2*i], l[2*i + 1]]) + if len(l) % 2 != 0: + split.append(l[-1]) + return split + +def retrieveWinners(botList, battletemplate): + winnerList = [] + for pair in splitList(botList): + if type(pair) == type([]): + winnerList.append(getWinnerAndDiscard(pair[0], pair[1], battletemplate)) + else: + winnerList.append(pair) + return winnerList + +def runTournament(botList, battletemplate): + if len(botList) == 2: + winner, tempdir = getWinnerOfBattle(botList[0], botList[1], battletemplate) + loser = [l for l in botList if l != winner][0] + return (winner, loser, tempdir,) + else: + winners = retrieveWinners(botList, battletemplate) + return runTournament(winners, battletemplate) + +def runTournamentCalled(name): + p = loadFile('battles/' + name + '.tournament') + battletemplate, darbyopts = separateProps(p) + + botsincluded = ['sample.Fire', 'sample.Crazy'] + for k in darbyopts: + if k == 'tournament.selectedRobots': + botsincluded = darbyopts[k].split(',') + + winner, loser, tempdir = runTournament(botsincluded, battletemplate) + shutil.copyfile(tempdir + '/results.txt', os.path.expanduser('~/battles/results/' + name + '.txt')) + shutil.copyfile(tempdir + '/results.br', os.path.expanduser('~/battles/results/' + name + '.br'))