Time and distance measurements in Robocode

Time (t):

Robocode time is measured in "ticks". Each robot gets one turn per tick. 1 tick = 1 turn.

Distance Measurement:

Robocode's units are basically measured in pixels, with two exceptions. First, all distances are measured with double precision, so you can actually move a fraction of a pixel. Second, Robocode automatically scales down battles to fit on the screen. In this case, the unit of distance is actually smaller than a pixel.

Robot Movement Physics

Acceleration (a):

Robots accelerate at the rate of 1 pixel/turn/turn. Robots decelerate at the rate of 2 pixels/turn/turn. Robocode determines acceleration for you, based on the distance you are trying to move.

Velocity Equation(v):

v = at. Velocity can never exceed 8 pixels/turn. Note that technically, velocity is a vector, but in Robocode we simply assume the direction of the vector to be the robot's heading.

But this kind of nesting could lead to a stack overflow. Or—more commonly—cases where the first handler finishes up its actions long after the response-provoking situation has passed. Thus, Robocode takes special steps for events generated within event handlers; these measures are implemented in EventManager.processEvents(). In particular, the call stack will get as far as

It is possible, though not usually useful, to catch and respond to EventInterruptedExceptions in the first handler instead.

Firing Pitfall

Because bullets are fired before the gun is moved, calling setFire() will cause the bullet to leave at the current gun heading. This may seem counter-intuitive if you are used to thinking in terms of pointing a gun, then shooting. It is also inconvenient because you can't call setTurnGun(...) and setFire(...) right after each other (not if you need perfect accuracy, anyway). Most of the time, the error will be so small you won't notice it, but if you're testing a pattern matcher against sample.Walls, you will occasionally spot the bug.

To get the bullet to leave after turning the gun, you will need to use code like this: