Discussion:
How to Use BattleRunner
Jonathan Addison
2017-03-22 14:22:22 UTC
Permalink
Hello, I'm trying to write a genetic program for robocode. I want the
battles to be automated, so that I can run the program at night. However, I
can't seem to work out how to do it. I've Ctrl-C the source code from
http://robocode.sourceforge.net/docs/robocode/robocode/control/package-summary.html (I
believe this is for robocode 1.9.2.0) and I'm definitely using 1.9.2.4 . It
compiles, but I get a runtime error.

I enter java BattleRunner on the command line (I use Windows 10)
I've tried java -jar robocode.jar BattleRunner and that doesn't change
anything.
and get this Error: A JNI error has occurred, please check your
installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError:
robocode/control/events/IBattleListener
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException:
robocode.control.events.IBattleListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more

My robocode is installed @ C:\robocode. BattleRunner is stored @
C:\robocode\libs.

I can robocode from the command line, but once that's open I can't use the
command prompt.

I'm very sorry, if this has already been answered, many thanks for your
time.
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Patrick Cupka
2017-03-23 00:41:18 UTC
Permalink
Hey! A few thoughts / suggestions:

- Passing "-jar robocode.jar" basically means robocode.jar is the program
you want to execute. In this case, you want to execute BattleRunner and
link in robocode.jar (your code references Robocode's). So you want
robocode.jar on your "classpath", with a param like: "-cp
path/to/robocode.jar". And probably execute it from the dir with
BattleRunner in it.

- One issue you'll face is that you can't simply run multiple Robocode
engines in different threads. You need a separate process and install
directory for each Robocode that's running. I wrote a battle running tool
called RoboRunner which handles that pretty well:
http://robowiki.net/?RoboRunner .. If you're running battles overnight,
you'll definitely want multi-threading. It's possible you have some need to
interface with the Robocode Control API directly, but I'd consider instead
trying to interface with RoboRunner to run your battles. But if nothing
else, it's good reference code for how to use the Control API.

- A tip from someone else who's played with GA and Robocode: one hurdle
with genetic algorithms in Robocode is that each piece of code you want to
test has to be packaged into a .jar for Robocode to run battles with it.
Alternatively, you could evolve the contents of a data file that your bot
reads in and have that dictate the behavior. This will be an issue whether
you use RoboRunner or the Control API. It's one reason all my Robocode GA
experiments ended up being run fully outside of Robocode, against data sets
collected with Robocode. And I actually wrote a game called BerryBots with
a different style of automation API and made sure it's a bit friendlier to
things like GA.

Hope that helps! Let us know how it goes. Good luck,


On Wed, Mar 22, 2017 at 10:22 AM, Jonathan Addison <
Post by Jonathan Addison
Hello, I'm trying to write a genetic program for robocode. I want the
battles to be automated, so that I can run the program at night. However, I
can't seem to work out how to do it. I've Ctrl-C the source code from
http://robocode.sourceforge.net/docs/robocode/robocode/control/package-
summary.html (I believe this is for robocode 1.9.2.0) and I'm definitely
using 1.9.2.4 . It compiles, but I get a runtime error.
I enter java BattleRunner on the command line (I use Windows 10)
I've tried java -jar robocode.jar BattleRunner and that doesn't change
anything.
and get this Error: A JNI error has occurred, please check your
installation and try again
robocode/control/events/IBattleListener
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: robocode.control.events.
IBattleListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
C:\robocode\libs.
I can robocode from the command line, but once that's open I can't use the
command prompt.
I'm very sorry, if this has already been answered, many thanks for your
time.
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Patrick Cupka, ***@gmail.com
--
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jonathan Addison
2017-03-24 08:39:48 UTC
Permalink
Many Thanks Patrick, but I'm still struggling. So I tried putting on the
command line java -cp path/to/robocode.jar BattleRunner and I get Error:
Could not find or load main class BattleRunner. But BattleRunner is
definitely there, as I can do java BattleRunner and get that wonderful
printout seen earlier. I tried moving BattleRunner to C:\robocode but then
it won't compile with javac -cp robocode.jar BattleRunner.java saying
packing robocode.libs.control doesn't exist (even though it happily
compiles in C:\robocode\libs).

I looked at your RoboRunner, I run Windows, is it going to be suitable?
Post by Patrick Cupka
- Passing "-jar robocode.jar" basically means robocode.jar is the program
you want to execute. In this case, you want to execute BattleRunner and
link in robocode.jar (your code references Robocode's). So you want
robocode.jar on your "classpath", with a param like: "-cp
path/to/robocode.jar". And probably execute it from the dir with
BattleRunner in it.
- One issue you'll face is that you can't simply run multiple Robocode
engines in different threads. You need a separate process and install
directory for each Robocode that's running. I wrote a battle running tool
http://robowiki.net/?RoboRunner .. If you're running battles overnight,
you'll definitely want multi-threading. It's possible you have some need to
interface with the Robocode Control API directly, but I'd consider instead
trying to interface with RoboRunner to run your battles. But if nothing
else, it's good reference code for how to use the Control API.
- A tip from someone else who's played with GA and Robocode: one hurdle
with genetic algorithms in Robocode is that each piece of code you want to
test has to be packaged into a .jar for Robocode to run battles with it.
Alternatively, you could evolve the contents of a data file that your bot
reads in and have that dictate the behavior. This will be an issue whether
you use RoboRunner or the Control API. It's one reason all my Robocode GA
experiments ended up being run fully outside of Robocode, against data sets
collected with Robocode. And I actually wrote a game called BerryBots with
a different style of automation API and made sure it's a bit friendlier to
things like GA.
Hope that helps! Let us know how it goes. Good luck,
On Wed, Mar 22, 2017 at 10:22 AM, Jonathan Addison <
Post by Jonathan Addison
Hello, I'm trying to write a genetic program for robocode. I want the
battles to be automated, so that I can run the program at night. However, I
can't seem to work out how to do it. I've Ctrl-C the source code from
http://robocode.sourceforge.net/docs/robocode/robocode/control/package-summary.html (I
believe this is for robocode 1.9.2.0) and I'm definitely using 1.9.2.4 . It
compiles, but I get a runtime error.
I enter java BattleRunner on the command line (I use Windows 10)
I've tried java -jar robocode.jar BattleRunner and that doesn't change
anything.
and get this Error: A JNI error has occurred, please check your
installation and try again
robocode/control/events/IBattleListener
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
robocode.control.events.IBattleListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
C:\robocode\libs.
I can robocode from the command line, but once that's open I can't use
the command prompt.
I'm very sorry, if this has already been answered, many thanks for your
time.
--
You received this message because you are subscribed to the Google Groups
"robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
--
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jonathan Addison
2017-03-24 17:29:20 UTC
Permalink
Worked it out now.

I need to put java -cp robocode.jar*;* BattleRunner
Post by Jonathan Addison
Hello, I'm trying to write a genetic program for robocode. I want the
battles to be automated, so that I can run the program at night. However, I
can't seem to work out how to do it. I've Ctrl-C the source code from
http://robocode.sourceforge.net/docs/robocode/robocode/control/package-summary.html (I
believe this is for robocode 1.9.2.0) and I'm definitely using 1.9.2.4 . It
compiles, but I get a runtime error.
I enter java BattleRunner on the command line (I use Windows 10)
I've tried java -jar robocode.jar BattleRunner and that doesn't change
anything.
and get this Error: A JNI error has occurred, please check your
installation and try again
robocode/control/events/IBattleListener
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
robocode.control.events.IBattleListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
C:\robocode\libs.
I can robocode from the command line, but once that's open I can't use the
command prompt.
I'm very sorry, if this has already been answered, many thanks for your
time.
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jonathan Addison
2017-03-24 10:59:49 UTC
Permalink
Do this need approval?
Post by Jonathan Addison
Hello, I'm trying to write a genetic program for robocode. I want the
battles to be automated, so that I can run the program at night. However, I
can't seem to work out how to do it. I've Ctrl-C the source code from
http://robocode.sourceforge.net/docs/robocode/robocode/control/package-summary.html (I
believe this is for robocode 1.9.2.0) and I'm definitely using 1.9.2.4 . It
compiles, but I get a runtime error.
I enter java BattleRunner on the command line (I use Windows 10)
I've tried java -jar robocode.jar BattleRunner and that doesn't change
anything.
and get this Error: A JNI error has occurred, please check your
installation and try again
robocode/control/events/IBattleListener
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
robocode.control.events.IBattleListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
C:\robocode\libs.
I can robocode from the command line, but once that's open I can't use the
command prompt.
I'm very sorry, if this has already been answered, many thanks for your
time.
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...