Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
170 lines (115 sloc) 5.01 KB
layout author title date desc bigimg img categories tags series extras interesting toc package-versions redirect_from
post
Wouter Van Schandevijl
Robocode Installation & Debugging
2019-06-17 17:00:00 -0700
Robocode tutorials for the itenium roborumble™
url
robocode-big.png
url desc origin
robocode.png
Photo by Ray Rui
design
fun
robocode
githubproject githubtext
Example Eclipse and Visual Studio Robocode projects
url desc
Official Robocode site
url desc
Robocode Wiki
title
💣 Installation
robocode
1.9.3.3
/blog/productivity/robocode-installation/

{% include github-stars.html url="robo-code/robocode" desc="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

Wiki

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!

Wiki

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.

You can’t perform that action at this time.