Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.gradle
.idea/*
libs/robocode.jar
build/
84 changes: 84 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import java.util.stream.Collectors

plugins {
id 'java'
}

group 'roborunner'
version '2.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
implementation files('libs/robocode.jar')
implementation group: 'com.google.guava', name: 'guava', version: '30.0-jre'
}

sourceSets {
main {
java {
srcDir 'src'
}
}
}

def distDir = "$buildDir/dist"

task cleanDist(type: Delete) {
delete += "$distDir"
}

task copyDependencies(dependsOn: cleanDist, type: Copy) {
from(configurations.runtimeClasspath) {
include 'guava*'
}
into "$distDir/lib"
}

task runnerJar(type: Jar, dependsOn: [compileJava]) {
from(compileJava.outputs)

archiveName jar.archiveName
}

task copyLibs(dependsOn: [runnerJar, copyDependencies], type: Copy) {
from(runnerJar.outputs)
into "$distDir/lib"
}

task generateScripts(dependsOn: [copyLibs]) {
String genOutputDir = file("$buildDir/generated-scripts")

File outputFile = file("$genOutputDir/rr.sh")
outputs.file(outputFile)

doLast {
def libs = copyLibs.outputs.getFiles().singleFile
def path = fileTree(dir: libs).files.stream().map({ x -> 'lib' + x.toString().substring(libs.toString().length()) }).collect(Collectors.joining(File.pathSeparator))

def robocodeJar = ['robocodes','r1','libs','robocode.jar'].join(File.separator)

outputFile.text = "#!/bin/sh\n" +
"java -cp '${path}${File.pathSeparator}${robocodeJar}' robowiki.runner.RoboRunner \$*"
}
}

task makeDist(dependsOn: copyLibs, type: Copy, group: 'deploy') {
from('scripts') {
include '*.sh'
fileMode = 0755
}
from('scripts') {
exclude '*.sh'
}
from(generateScripts.getOutputs()) {
fileMode = 0755
}
into "$distDir"
}

classes.dependsOn(makeDist)
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion scripts/rmall.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
echo "Clearing Robocode JARs, robot caches and databases... "
cd robocodes
rm -rf r*/robots/.data
rm r*/robots/robot.database
rm r*/robots/*.jar
#rm r*/robots/*.jar
find r*/robots -name '*.jar' -delete
echo " Done!"

1 change: 1 addition & 0 deletions scripts/rmdata.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/usr/bin/env bash
rm -rf robocodes/r*/robots/.data

2 changes: 0 additions & 2 deletions scripts/rr.sh

This file was deleted.

3 changes: 1 addition & 2 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ else
echo " Done!"
fi
echo "robocodePaths=$paths" > roborunner.properties
echo "jvmArgs=-Xmx512M" >> roborunner.properties
echo "jvmArgs=-Xmx1024M -Dapple.awt.UIElement\=true -Djava.security.manager=allow -XX:+IgnoreUnrecognizedVMOptions --add-opens\=java.base/sun.net.www.protocol.jar\=ALL-UNNAMED --add-opens\=java.base/java.lang.reflect\=ALL-UNNAMED --add-opens\=java.desktop/javax.swing.text\=ALL-UNNAMED --add-opens\=java.desktop/sun.awt\=ALL-UNNAMED --add-opens\=java.desktop/java.awt\=ALL-UNNAMED --add-opens\=java.base/java.lang\=ALL-UNNAMED --add-opens\=java.desktop/sun.java2d.opengl\=ALL-UNNAMED" >> roborunner.properties
echo "botsDirs=./bots" >> roborunner.properties
fi

1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'roborunner'
5 changes: 4 additions & 1 deletion src/robowiki/runner/BattleRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ private void initEngine(String enginePath, String jvmArgs) {
String processOutput;
do {
processOutput = reader.readLine();
} while (!processOutput.equals(BattleProcess.READY_SIGNAL));
} while (processOutput != null && !processOutput.equals(BattleProcess.READY_SIGNAL));
if (processOutput == null) {
throw new IOException("processOutput == null");
}
System.out.println("done!");
_processQueue.add(battleProcess);
} catch (IOException e) {
Expand Down
41 changes: 28 additions & 13 deletions src/robowiki/runner/RoboRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ private List<BotList> getBattleList(ScoreLog scoreLog,
for (BotList botList : challenge.allReferenceBots) {
List<String> battleBots = Lists.newArrayList(challenger);
List<String> botNames = botList.getBotNames();

if (botNames.contains(challenger)) {
continue;
}

if (!skip(skipMap, scoreLog.getSortedBotList(botNames))) {
battleBots.addAll(botNames);
battleList.add(new BotList(battleBots));
Expand Down Expand Up @@ -424,7 +429,9 @@ private ScoreError getScoreError(ScoreLog scoreLog,
List<Double> scores = Lists.newArrayList();
for (BattleScore battleScore : battleScores) {
RobotScore totalScore = battleScore.getRelativeTotalScore(challenger);
scores.add(scoringStyle.getScore(totalScore));
if (totalScore != null) {
scores.add(scoringStyle.getScore(totalScore));
}
}
return new ScoreError(scores,
scoreLog.getAverageBattleScore(botList).getElapsedTime());
Expand Down Expand Up @@ -619,9 +626,14 @@ private ScoreSummary getScoreSummary(ScoreLog scoreLog,
RobotScore totalRobotScore = scoreLog
.getAverageBattleScore(botListString)
.getRelativeTotalScore(scoreLog.challenger);
sumScores += scoringStyle.getScore(totalRobotScore);
scoredBotLists++;
numBattles += totalRobotScore.numBattles;
double score = scoringStyle.getScore(totalRobotScore);
if (!Double.isNaN(score)) {
sumScores += score;
scoredBotLists++;
numBattles += totalRobotScore.numBattles;
} else {
System.err.println("NaN: " + scoreLog.challenger + " " + botListString);
}
}
}
return new ScoreSummary(sumScores, numBattles, scoredBotLists);
Expand Down Expand Up @@ -650,11 +662,12 @@ private void printAllScores(ScoreLog scoreLog, ChallengeConfig challenge,
.getAverageBattleScore(botListString)
.getRelativeTotalScore(scoreLog.challenger);
ScoreError scoreError = errorMap.get(botListString);
double score = challenge.scoringStyle.getScore(totalRobotScore);
System.out.println(" " + botListString + ": "
+ round(challenge.scoringStyle.getScore(totalRobotScore), 2)
+ (scoreError.numBattles > 1
? " +- " + round(1.96 * scoreError.getStandardError(), 2) : "")
+ " (" + scoreError.numBattles + " battles)");
+ (Double.isNaN(score) ? Double.NaN : round(score, 2))
+ (scoreError.numBattles > 1
? " +- " + round(1.96 * scoreError.getStandardError(), 2) : "")
+ " (" + scoreError.numBattles + " battles)");
}
}
}
Expand Down Expand Up @@ -739,10 +752,12 @@ public void processResults(
errorMap.put(botList,
getScoreError(scoreLog, scoringStyle, challenger, botList));

printBattleScore(challenger, botList, lastScore, avgScore,
scoringStyle, elapsedTime, errorMap);
if (robotScores.size() > 2) {
printMeleeScores(lastScore, avgScore, challenger, scoringStyle);
if (lastScore != null) {
printBattleScore(challenger, botList, lastScore, avgScore,
scoringStyle, elapsedTime, errorMap);
if (robotScores.size() > 2 && avgScore != null) {
printMeleeScores(lastScore, avgScore, challenger, scoringStyle);
}
}
printOverallScores(
scoreLog, errorMap, challenger, challenge, printWikiFormat, false);
Expand Down Expand Up @@ -841,7 +856,7 @@ public ScoreSummary(
}

public double getTotalScore() {
return round(sumScores / scoredBotLists, 2);
return Double.isNaN(sumScores) ? Double.NaN : round(sumScores / scoredBotLists, 2);
}
}
}
30 changes: 27 additions & 3 deletions src/robowiki/runner/RobotScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public RobotScore getScoreRelativeTo(
/**
* Calculates this score relative to the given enemy scores.
*
* @param enemyScore score data for the other robots in the battle
* @param enemyScores score data for the other robots in the battle
* @param numRounds number of rounds in the battle
* @return the {@code RobotScore} relative to the given enemy robot scores
*/
Expand All @@ -110,14 +110,38 @@ public RobotScore getScoreRelativeTo(
numBattles);
}

RobotScore getAverageScoreRelativeTo1(List<RobotScore> enemyScores) {
return new RobotScore(botName,
getAverageScore(NORMAL_SCORER, enemyScores),
survivalRounds,
survivalScore,
bulletDamage,
energyConserved,
numBattles);
}

RobotScore getAverageScoreRelativeTo2(List<RobotScore> enemyScores, int numRounds) {
return new RobotScore(botName,
score,
getAverageScore(SURVIVAL_FIRSTS_SCORER, enemyScores),
getAverageScore(SURVIVAL_SCORER, enemyScores),
bulletDamage / numRounds,
getAverageEnergyConserved(enemyScores, numRounds),
numBattles);
}

private double getAverageScore(
Function<RobotScore, Double> scorer, Collection<RobotScore> enemyScores) {
double totalScore = 0;
double challengerScore = scorer.apply(this);
int numScores = 0;
for (RobotScore robotScore : enemyScores) {
totalScore += 100 * (challengerScore
/ (challengerScore + scorer.apply(robotScore)));
double sum = challengerScore + scorer.apply(robotScore);
if (sum == 0.) {
totalScore += 50;
} else {
totalScore += 100 * (challengerScore / sum);
}
numScores++;
}
return totalScore / numScores;
Expand Down
Loading