Robocode Installation & Debugging
posted in design on • by Wouter Van Schandevijlrobo-code/robocode : Build the best - destroy the rest!
Robocode is a programming game, where the goal is to develop a robot battle tank to battle against other tanks in Java or .NET. The robot battles are running in real-time and on-screen.
Install Robocode
Prerequisites:
Or follow the official step by step instructions.
If you get a “‘java’ is not recognized as an internal or external command”, then add your JDK to PATH.
Building a Robot
In the Robocode UI
Robot > Source Editor (Control + E) > New Robot (Control + N)
This will generate something like:
public class MyRobot extends Robot
{
public void run() {
setColors(Color.red, Color.blue, Color.green); // body, gun, radar
while(true) {
ahead(100); // pixels
turnGunRight(360); // degrees
back(100);
turnGunRight(360);
}
}
public void onScannedRobot(ScannedRobotEvent e) {
fire(1); // Strength between 0.1 and 3.0
}
public void onHitByBullet(HitByBulletEvent e) {
back(10);
}
public void onHitWall(HitWallEvent e) {
back(20);
}
}
Extend either Robot
or AdvancedRobot
. An AdvancedRobot:
- Loses energy when bumping into walls.
- Can have non-blocking calls (
setXXX() methods
), custom events and FileSystem access.
When you are ready for battle, use: Compiler > Compile (Control + B) in the Source Editor.
In Eclipse
New Project:
- Libraries > Add External JARs…: Add
libs/robocode.jar
.- External annotations > Edit: Javadoc is bundled with Robocode.
- Do not create a
module-info.java
. - Add a new Java Class with Superclass:
robocode.Robot
.
Be sure your final robot is packaged!
A *
appears ingame next to a robot’s name if it is a development version.
Robocode UI
Add the project’s bin
folder in the Robocode UI:
Options > Preferences > Development Options > Add
Debugging
Run as > Run configurations > Java Application
- Main class:
robocode.Robocode
- Arguments > VM arguments:
-Xmx512M -Dsun.io.useCanonCaches=false -Ddebug=true
- Arguments > Working directory > Other > Robocode install path (ex: c:\robocode)
Do not point to a Robocode directory where the .NET plug-in is also installed!
In Visual Studio
Download the .NET plug-in for Robocode and install in the same directory as Robocode itself!
Create a .NET Framework project and reference libs\robocode.dll
.
See dotnet-bots
for a minimal example.
Robocode UI
Add the bin\Debug
folder in the Robocode UI:
Options > Preferences > Development Options > Add
Debugging
Project > Properties > Debug:
- Start external program:
C:\Program Files\Java\jdk1.8.0_211\bin\java.exe
- Command line arguments:
-Ddebug=true -Xmx512M -cp libs/robocode.jar;libs/jni4net.j-0.8.7.0.jar -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/sun.awt=ALL-UNNAMED" robocode.Robocode
- Working directory: Where installed (ex: c:\robocode)
Be sure your final robot is a Release
build!
More Debugging
Start Robocode UI in debug mode:
java -Ddebug=true -Xmx512M ...
Find the CLI arguments in robocode.bat
.
Robot Console
See out.println()
(or Console.WriteLine()
) in your robot log by clicking on your robot name in the right top battle
view pane in the UI. SYSTEM events and crash stack traces will also be printed in the robot console.