Naval Robocode

From Robowiki
Jump to navigation Jump to search


These are some of the things that make Naval Robocode different from Robocode.

The Rules are all subject to change, so be sure to tell me about any changes you’d like to see.

For the discussion on Google Groups:!topic/robocode-developers/X0Z9rSQCMMI

If you wanna look into the (still slightly messy) code, go to:

And if you wanna dive straight into Naval Robocode, go to:

The above setup hasn't been forked with the official Robocode repository, yet.

Also, I didn't get the in-game editor to work for myself, so I recommend downloading the setup and then following this guide: Robocode/Eclipse/Create_a_Project

Don't forget to replace robocode.Robocode to robocode.NavalRobocode in Robocode/Running_from_Eclipse ~

Creating Your First Ship

Yarrr, matey! Welcome to creating your first fleet.

If ye be makin’ those automated tanks for the past years, ye might want to check out the Modified Rules.

Remember that ye can always steal one of the sample ships and use them as yer own.

I assume ye have yer men ready at the bay to build yer ship during this intro.

(I assume you got Naval Robocode all set up in Eclipse. If not, check out this guide: )

My First Ship

Away with the pirate act! Your Ship is much more like a marine ship than a pirate ship.

(Though, if anybody wants to re-skin the current ships to look like a pirate ship, be my guest!)

As stated before, I assume you’re creating your Ship in Eclipse.

(I couldn’t get the in-game editor to work, myself) On top of this, I assume you are at least a beginner at Java.

I will create a full guide for total beginners at programming later, but for now this guide will have to do.

package thoma;

import robocode.*;

public class MyFirstShip extends Ship{
    public void run(){  
    public void onScannedShip(ScannedShipEvent e){

Take a look at this example. This is your first Ship! When your Ship is first created, the run function will be called.(public void run())

Anything in between the squiggly brackets {} is what your Ship will do while it’s still alive and kickin’.

Within this run-function, two methods are called. setAhead() and setTurnRightDegrees().

setAhead(200) tells your ship to move ahead 200 pixels.

setTurnRightDegrees(90) tells your ship it should turn until it’s 90 degrees to the right of your Ship’s original direction.

Remember! Ships can’t turn if there’s no velocity, much like a real ship.


A Ship has two cannons, called FrontCannon and BackCannon.

Firing them is done by fireFrontCannon(your_gun_power) and fireBackCannon(your_gun_power) respectively.

What’s your_gun_power, you ask? Cannons can fire a bullet that’s stronger or weaker depending on the gun power. This power can be between 0.1 and 3.

Placing this method inside the onScannedShip(ScannedShipEvent e) method makes it so that the gun will only fire when the radar has seen another Ship.


Acceleration is still 1 pixel/turn^2

Deceleration is 0.8 pixels/turn^2 now (Gives a nice floaty effect)

At the moment the turn rate is 0.8 degrees/turn. Do you find your Ship is moving around in circles which are way too big?

Try decreasing your max velocity. The less you move per turn, the sharper your turns are.

Ships only start turning if there’s some velocity, unlike a Robot.


Bullet damage has been decreased to

damage = 4 * bulletPower;
if(bulletPower > 1){damage += 1.2 * (bulletPower - 1);}

Though. This might be a bit too low.-Thomas

Energy restored from the bullets has been reduced to bulletPower * 2

I tried to make the bullets a bit weaker, since Ships are easier to hit.

This, on top of the fact Ships already got 2 cannons, made me think Ships died too quickly.

Bullets can be fired from two cannons. (FrontCannon and BackCannon)

At the moment you can fire them with the fireFrontCannon(double) and fireBackCannon(double) commands.


Mine damage is calculated as followed damage = 3 * minePower; if(minePower == 15){damage+=5;}

Energy restored from a mine is MinePower * 3

Mines can be placed with a power between 5 and 15.



Length of a ship is 207. Width is 40.

The pivot of a Ship is NOT in the middle.

If you look at the picture on the right, the red dot will indicate the pivot of the Ship, which should be 50 pixels from the center of the Ship.

Furthermore, a Ship has two cannons, FrontCannon and BackCannon. (See the blue weapons on the Ship)

A Ship has a Radar which is exactly the same as a Robocode Radar.

And a Ship has a MineComponent, which is the darkgreenish thing at the back of the Ship. This is used to drop mines.

Each of these components can be colored.

The coordinates of each of these components can be retrieved with getXFrontCannon()/getYRadar() etc.

Ships work like AdvancedRobots for as far as I know. setTurnLeftDegrees() doesn’t have a turnLeftDegrees() equivalent. This means you’ll have to work with the execute()-function most of the time.


Ships don’t take hit damage from walls.

If anybody is interested, I accidentally implemented something that creates the possibility to take more or less damage depending on where your Ship has been hit.

(If they run head-first into eachother, they could take massive damage, where hitting from the side would result in less damage)

Right now the ramming damage is the same as in Robocode.

Things to look out for

At the moment there are still a few things I’m not too sure about. Here’s a list about them~

1. Acceleration and Deceleration

2. Size of BlindSpot. (Options->Preferences->View Options->Visible Naval Blind Spot)

3. Function names (Too large? Too unclear? Not enough documentation?)

4. Bugs

Known "Bugs"

1. In game editor doesn’t work (for me) since it can’t find a compiler.

2. The game is still mixed with the original Robocode, thus there can still be played with Tanks. I made a slightly “dirty” fix to make sure Ships and Tanks can’t play together on the same map. This fix is basically “If there’s Ships on the map, IS_NAVAL = true, else IS_NAVAL = false”. If you record a game in Naval Robocode, boot up a fresh game and try to watch the recording, you’ll get a cool bug. Since the game hasn’t tested yet whether there are Ships on the Map, IS_NAVAL = false. So when you watch the recording, it’ll interpret the Ships in the recording as quirky moving Robots. (Watching a recording while IS_NAVAL=true works as intended) Fixed with TO-DO #1 #2

3. Making your weapons move independently from your ship, makes them move a bit quirky, because of their blind spots. Independent radars, however, move just fine.


We held a competition within the company and so far we haven’t found any bugs.(They couldn’t even find the bugs I already knew of)

They did, however, have some comments regarding the game itself.

1. IShip::getBodyHeadingRadians does nor return values between 0..2*Pi;nor is specified in which range the values are to be expected. Specify, document and enforce that each return angle (radians) is between –pi .. pi or 0 and 2*pi (similar for the methods using degrees). Done.

2. IShip::setCourse has no radians variant Done.

3. Create an interface for controlling the Front- and BackCannon. Calling something like getFrontCannon().setTurnRightDegrees(), might be nicer than setTurnFrontCannonRightDegrees(double).

4. Implement some kind of blast-radius for the mines. (The winner of the competition basically just rammed people backwards to throw mines on their ships.) Created a new bug. Ships killing themselves with mines get bonus points :D

Thoma’s TO-DO List

1. Finding a way to separate the database into two. I mean, I’d love to get rid of the regular Robots in the list of bots to choose from. Though, this doesn’t isn’t top priority. Didn't split it up, just filtered the original database.

2. Creating a custom run configuration for Naval Robocode would be really nice. If you look back at “Known Bugs #3”, creating a new way to run Naval Robocode that would automatically set IS_NAVAL = true, would simultaneously get rid of bug #3. Moved the variable which states whether we're playing Naval Robocode or not to HiddenAccess.

3. Creating some clearer documentation.

4. Refactoring. Ooooh. I REALLY want to refactor this program. Background story: The assignment to create Naval Robocode has been given to an intern last year, as well. Feeling “lucky”, I worked from where he left of, since he didn’t get to finish it. I used to look at his code as if it couldn’t contain any mistakes, but as of right now, I want to get rid of most of the stuff he did. Which include:

• Trying to reverse all Y-values. If we take an 800x600 screen, according to him the top of the screen would be y=0, while the bottom of the screen would be y=-600. I understand that some game do this, but I never understood why he wanted to implement this so badly. Luckily, I got rid of most of this, though there might still be something left behind.

• The IProjectile-interface. It’s simply not needed. Worst part is that I used this interface for the mines. Done.

• The ShipStatus class. I made this one myself, but I don’t really like the fact I’m giving ShipProxy access to all every component on the Ship.