Quick Reference (Formulas)
This page provides a quick lookup for essential formulas and constants used throughout bot development. For detailed explanations, see the linked pages.
Physics Constants
Bot Dimensions
Both games render the bot as a 36×36 unit square visually, centered at the bot's position.
Collision hitbox:
- Classic Robocode: Axis-aligned 36×36 square (does not rotate with bot heading)
- Diagonal: ~50.9 units
- Tank Royale: Circle with radius 18 units (diameter 36; always circular)
Movement Limits
Both Classic Robocode and Tank Royale use identical movement physics:
| Property | Value | Units |
|---|---|---|
| Max velocity () | 8 | units/turn |
| Max acceleration | 1 | units/turn² |
| Max deceleration | 2 | units/turn² |
| Max turn rate (at rest) | 10 | degrees/turn |
| Max turn rate (at max speed) | 4 | degrees/turn |
Linear velocity has acceleration/deceleration limits, but **rotation (body, gun, radar) has no
acceleration/deceleration**—turn rate changes instantly up to the maximum limit.
Notation:
- : current speed (units/turn)
- : maximum speed ( units/turn)
- : rest ( units/turn)
Turn rate formula:
Rotation Limits
| Component | Max Rate | Units |
|---|---|---|
| Body | 10° | degrees/turn |
| Gun (relative to body) | 20° | degrees/turn |
| Radar (relative to gun) | 45° | degrees/turn |
Maximum combined rates:
- Gun relative to battlefield: 30°/turn (body 10° + gun 20°)
- Radar relative to battlefield: 75°/turn (body 10° + gun 20° + radar 45°)
Bullet Physics
Bullet Speed
| Power | Speed | Units/turn |
|---|---|---|
| 0.1 | 19.7 | units/turn |
| 1.0 | 17.0 | units/turn |
| 2.0 | 14.0 | units/turn |
| 3.0 | 11.0 | units/turn |
Bullet Damage
| Power | Damage | Bonus | Total |
|---|---|---|---|
| 0.1 | 0.4 | 0 | 0.4 |
| 1.0 | 4.0 | 0 | 4.0 |
| 2.0 | 8.0 | 2.0 | 10.0 |
| 3.0 | 12.0 | 4.0 | 16.0 |
Gun Heat
| Power | Heat | Cool Time |
|---|---|---|
| 0.1 | 1.02 | 11 turns |
| 1.0 | 1.20 | 12 turns |
| 2.0 | 1.40 | 14 turns |
| 3.0 | 1.60 | 16 turns |
Angle & Distance Calculations
Coordinate Systems
Classic Robocode:
- Origin: bottom-left (0, 0)
- Heading 0°: North (up)
- Angles: clockwise from north
Tank Royale:
- Origin: bottom-left (0, 0)
- Heading 0°: East (right)
- Angles: counterclockwise from east
Absolute Bearing
Angle from your position to a target:
dx = target.x - my.x
dy = target.y - my.y
absoluteBearing = atan2(dx, dy) // Classic: atan2(x, y)
absoluteBearing = atan2(dy, dx) // Tank Royale: atan2(y, x)Relative Bearing
Angle from your heading to a target:
(wrap to )
Distance
Normalize Angle to [-180°, +180°]
Targeting Formulas
Head-On Targeting
Aim directly at the current enemy position:
Linear Targeting
Predict enemy position assuming constant velocity:
// Solve for bullet flight time (iterative)
bulletSpeed = 20 - 3 * bulletPower
time = distance / bulletSpeed // Initial guess
for iteration in 1..5:
futureX = enemy.x + enemy.velocityX * time
futureY = enemy.y + enemy.velocityY * time
distance = sqrt((futureX - my.x)² + (futureY - my.y)²)
time = distance / bulletSpeed
aimAngle = atan2(futureX - my.x, futureY - my.y)Circular Targeting
Predict enemy position assuming a constant turn rate:
// Estimate angular velocity
angleToEnemy = atan2(enemy.x - my.x, enemy.y - my.y)
lateralVelocity = enemy.velocity * sin(enemy.heading - angleToEnemy)
angularVelocity = lateralVelocity / distance
// Solve for time iteratively
bulletSpeed = 20 - 3 * bulletPower
time = distance / bulletSpeed
for iteration in 1..5:
futureHeading = enemy.heading + angularVelocity * time
futureX = enemy.x + enemy.velocity * sin(futureHeading) * time
futureY = enemy.y + enemy.velocity * cos(futureHeading) * time
distance = sqrt((futureX - my.x)² + (futureY - my.y)²)
time = distance / bulletSpeed
aimAngle = atan2(futureX - my.x, futureY - my.y)GuessFactor Formula
GuessFactor ranges from -1.0 (maximum clockwise dodge) to +1.0 (maximum counter-clockwise dodge).
Movement Calculations
Lateral Velocity
Velocity perpendicular to the enemy line of fire:
Sign:
- Positive: moving counter-clockwise (left) around an enemy
- Negative: moving clockwise (right) around an enemy
Advancing Velocity
Velocity toward/away from enemy:
Sign:
- Positive: moving toward an enemy
- Negative: moving away from an enemy
Orbital Movement
Maintain a constant distance while orbiting:
Wall Distance
Minimum distance to any wall:
Wall Smoothing (Basic)
Adjust heading to avoid hitting walls. For each wall, calculate push force proportional to proximity:
Similar calculations apply for the right wall, top wall, and bottom wall.
Energy & Scoring
Energy Bonuses
Bullet hit:
NOTE
Neither Classic Robocode nor Tank Royale awards energy bonuses for killing enemies. Energy is only gained from bullet hits (3× bullet power). Kills award scoring points (see Damage Scoring below), not energy.
Damage Scoring
Bullet hit damage:
Bullet kill bonus:
When a bot kills an enemy with a bullet, it scores an additional bonus:
Both Classic Robocode and Tank Royale:
Or equivalently:
Ram damage:
Ram kill bonus:
When a bot kills an enemy by ramming, it scores an additional bonus:
Both Classic Robocode and Tank Royale:
Or equivalently:
Survival score:
Last survivor bonus:
Wave Calculations
Max Escape Angle
Maximum angle the enemy can reach by moving perpendicular at full speed:
| Bullet Power | Speed | Max Escape Angle |
|---|---|---|
| 0.1 | 19.7 | ~24° |
| 1.0 | 17.0 | ~28° |
| 2.0 | 14.0 | ~35° |
| 3.0 | 11.0 | ~47° |
Wave Intersection
Time until a wave intersects bot position:
If , wave has already passed.
Turn Radius
Minimum turn radius at a given velocity:
| Velocity | Turn Rate | Radius |
|---|---|---|
| 0 | 10° | 0 |
| 4 | 7° | ~33 units |
| 8 | 4° | ~115 units |
Common Trigonometry
Radians ↔ Degrees:
Pythagorean theorem:
Sine law:
Small angle approximation ():
Platform-Specific API Equivalents
| Classic Robocode | Tank Royale | Purpose |
|---|---|---|
getX() | getX() | Bot X position |
getY() | getY() | Bot Y position |
getHeading() | getDirection() | Body heading (note: 0° differs!) |
getGunHeading() | getGunDirection() | Gun absolute heading |
getRadarHeading() | getRadarDirection() | Radar absolute heading |
getVelocity() | getSpeed() | Current velocity |
getEnergy() | getEnergy() | Current energy |
getBattleFieldWidth() | getArenaWidth() | Arena width |
getBattleFieldHeight() | getArenaHeight() | Arena height |
Further Reading
- Coordinate Systems & Angles — Detailed angle conventions
- Movement Constraints & Bot Physics — Physics deep dive
- Bullet Travel & Bullet Physics — Bullet mechanics
- GuessFactor Targeting — GuessFactor formula explained
- Wave Surfing Introduction — Wave math in action