We use an extended version of Robocode open source project. Please make sure you use the zipped version we provide in the installation page. We implemented a robot that has two parts:
- The JC3 robot proxy is running into Robocode, it receives events from the Robocode framework, and forwards them to the jc3bot application running into a smart card. In response it receives the movements and actions it applies on the robot.
- The jc3bot is a web application running into the Java Card 3.0 capable smart card. It receives events from the JC3 robot proxy, and decides what actions the controlled robot should take according to the jc3bot strategy. There is one JC3 robot proxy per Java Card 3.0 capable server. You should use the JC3_RI server when deploying your jc3bot on Sun's Reference Implemenation server, and the JC3_Card1 when using the Gemalto smart card.
Your tasks consists in implementing the jc3bot strategy. You cannot change the robot proxy code, neither the protocol between the proxy and the jc3bot. You can only modify the strategy implemented in the jc3bot. For this, you can start from a basic jc3bot, and modify it according to what you think is the winning strategy.
In NetBeans, create a new project using the provided template. In the next window make sure you have at least two Java Card Servers: one based on Sun's Reference Implementation and another based on Gemalto Card. The context URI of your application has to be "/jc3bot".
Once you have created the application, you will be able to edit MyRobot class to implement your strategy. This consists of sending commands to your robot proxy in response to the events it sends to you. MyRobot class has a set of "on..." methods called when events are received from the proxy. Commands are sent by invoking the various command methods implemented by inherited Robot class.
Both MyRobot's event methods and Robot's commands methods are explained below. In addition, MyRobot has a getName method that you can edit to set the name you want to your robot. This name will be displayed beside your robot in Robocode.
Note that MyRobot only provides a subset of the events and commands available in Robocode. This is intentional, and enforced by the JC3 proxy that you cannot change. Once you have implemented your strategy, it is time to load it onto a Java Card 3.0 capable server. In NetBeans, first choose in your project properties the Java Card Server you want to deploy to. Then run your project. This will start the server if needed, package your application,
load it into the server, and start the web application. Note that the sources of your project will automatically be included within your application (as a src.zip resources in the war file), and loaded into the Java Card Server. This means that once you have deployed your application into a smart card, you can retrieve the sources of your application by a simple HTTP request: 192.168.253.1/jc3bot/src.zip
You now have your application ready. It is time to test it in a battle. Launch Robocode, and create a new battle including your robot proxy (JC3_RI or JC3_Card1, depending on the server you use) as well as any sample robot you want. Once the battle started, you will see you robot (with either the default "JC3Bot" name or the one you set) move according to the strategy you implemented. You must first unload your application from the server before loading a new version.
You should first develop your robot on the Sun's Reference Implementation Server, as there is no deployment limit on it. Once you have validated your strategy, deploy your jc3bot on the Gemalto card, to make sure it works similarly. However, note that you will not be allowed to perform more than 50 deployments on your smart card. When this limit is reached, no application loading will be possible on the card. If this occurs to you, you may go to Gemalto booth (#1127) to get another card.
Once you have validated your strategy on card, go to the contest booth and compete!
Initializing the robot
Your robot is named "JC3Bot" by default in the robot template and a method is available to modify it. setName sets the name of the robot.
Command your robot
The robot has a rotating gun, and on top of the gun is a rotating radar. The robot vehicle, the gun, and the radar can all rotate independently.
At any moment in time the robot's vehicle, the gun and radar can be turned in different directions. By default these items are aligned facing the direction of the vehicle movement.
The set of commands for a robot are all documented in the Javadoc API. You will find them as public methods of the jc3bot.Robot class. You can find the rest of the Robocode API in the Javadoc, which can be accessed from the battlefield's help menu.
Your robot is implemented as a web application, made of two servlets: EventServlet and ConfigServlet. EventServlet will receive events from the robot engine during the game, while config servlet will expose some information on your robot, like its name. Implement your own strategy into MyRobot that extends directly Robot. In the following sections we'll cover each of the available commands by category.
Moving the robot, gun, and radar
Let's begin with the basic commands to move the robot and its accoutrement. Look into jc3bot.MyRobot class::
- ahead and back move the robot by the specified pixel distance; these two methods are completed if the robot hits a wall or another robot.
- turnGunRight and turnGunLeft turn the gun, independent of the vehicle's direction.
- turnRadarRight and turnRadarLeft turn the radar on top of the gun,independent of the gun's direction (and the vehicle's direction).
- turnRight and turnLeft turn the robot by a specified degree.
Any of these commands must return control to the web server. Furthermore, when the vehicle is turned, the direction of the gun (and radar) will also move, unless indicate differently by calling the following methods:
- setAdjustGunForRobotTurn: If it is set to true, the gun will remain in the same direction while the vehicle turns.
- setAdjustRadarForRobotTurn: If it is set to true, the radar will remain in the same direction while the vehicle (and the gun) turns.
- setAdjustRadarForGunTurn: If it is set to true, the radar will remain in the same direction while the gun turns. It will also act as if setAdjustRadarForRobotTurn has been called.
Obtaining information about the robot
Many methods exist for getting information about the robot. Here is a short list of frequently used method calls:
- getX and getY get the current coordinates of the robot
- getHeading, getGunHeading, and getRadarHeading get the current heading of the vehicle, gun, or radar in degrees
- getBattleFieldWidth and getBattleFieldHeight get the dimensions of the battlefield for the current round
- getEnergy get the current energy of the robot
- getOthers get how many opponents are left in the current round
Firing commands
Once you have mastered how to move the robot and its associated weaponry, it's a good time to consider the tasks of firing and controlling damage. Each robot starts out with a default "energy level" and is considered destroyed when its energy level falls to zero. When firing, the robot can use up to three units of energy. The more energy supplied to the bullet, the more damage it will inflict on the target robot. fire is used to fire a bullet with the specified energy (fire power).
Events
Whenever the robot moves or turns, the radar is always active, and if it detects any robots within its range, an event is triggered. As the robot creator, you can choose to handle various events that can occur during the battle. The basic Robot class has default handlers for all of these events. However, you can override any of these "do nothing" default handlers and implement your own custom actions. The start event (EVENT_START) is received at each start of battle. Here are some of the more frequently used events:
- ScannedRobotEvent: Handles the ScannedRobotEvent by overriding the onScannedRobot() method; this method is called when the radar detects a robot.
- HitByBulletEvent: Handles the HitByBulletEvent by overriding the onHitByBullet() method; this method is called when the robot is hit by a bullet.
- HitRobotEvent: Handles the HitRobotEvent by overriding the onHitRobot() method; this method is called when your robot hits another robot.
- HitWallEvent: Handles the HitWallEvent by overriding the onHitWall() method; this method is called when your robot hits a wall.
- BulletMissedEvent: Handles the BulletMissedEvent by overriding the bulletMissed() method; this method is called when your bullet does not hit a robot.
- RobotDeathEvent: Handles the RobotDeathEvent by overriding the robotDeath() method. this method is called when your robot does not have any energy left
- OnIdleEvent: Handles the OnIdleEvent by overriding the onIdle() method. this method is called when your robot is idle.
That's all we need to know to create some pretty complex robots. If you encounter some troubles, first look into the FAQ, then visit the support forum jc3bot.
Configure your robot
There is a servlet to handle jc3bot configuration and you can modify it according to your need. This servlet is accessible at the following address : 192.168.253.1/jc3bot/config
The template version simply exposes information on your robot and is updated at each won battle.

