Coordinate Systems & Angles
Understanding how coordinates and angles work is essential for programming bots in both classic Robocode and Robocode Tank Royale. This page explains the battlefield coordinate system, how angles are measured, and highlights key differences between the two platforms.
Battlefield Coordinate System
Both classic Robocode and Tank Royale use a Cartesian coordinate system for the battlefield. On both platforms:
- The origin (0, 0) is in the bottom left corner of the battlefield—not the top left as in most computer graphics.
- All positions and movements are measured in units (not pixels).
- Example: A bot's size is 36×36 units, and the scan length is 1200 units.
Angle Conventions
Classic Robocode
- Angles are measured clockwise from North (upwards):
- 0° = North
- 90° = East
- 180° = South
- 270° = West
- Headings and turns can be specified in degrees (deg) or radians (rad).
- This system is similar to a compass.
Mathew A. Nelson, Robocode's original Robocode creator, chose this navigation-style convention to make angles easier to understand—North is "up" at 0°, and angles follow the familiar clockwise direction of a compass. However, this can be confusing when using standard trigonometric functions, which expect mathematical angles.
Robocode Tank Royale
- Angles are measured counterclockwise from East (right):
- 0° = East
- 90° = North
- 180° = West
- 270° = South
- Only degrees (deg) are used for headings and turns (0–360).
- This matches the standard mathematical convention for angles.
Tank Royale adopted the standard mathematical coordinate system to make trigonometry intuitive. With 0° pointing East and angles increasing counterclockwise, standard functions like sin(), cos(), and atan2() work directly without conversion—the same convention used in mathematics, physics, and most programming libraries.
Platform Differences
- Classic Robocode: Headings increase clockwise from the North; supports both degrees and radians.
- Tank Royale: Headings increase counterclockwise from East; uses only degrees.
- Both use the same coordinate system, but angle conventions differ.
Why This Matters
Getting coordinates and angles right is crucial for:
- Moving your bot to specific locations
- Aiming guns and radar
- Calculating enemy positions
Mistakes in understanding the system can lead to bots moving or firing in unexpected directions.
Further Reading & References
- Robocode Game Physics (RoboWiki)
- Robocode Robot API
- Robocode AdvancedRobot API
- IBM DeveloperWorks: Robocode
- Tank Royale: Coordinates and Angles
Linking Forward
This page is foundational for understanding movement, targeting, and bullet physics. For more on how angles and coordinates are used in bot movement and targeting, see the upcoming pages on Bullet Physics and Targeting Systems, as well as Movement Constraints & Bot Physics for the exact movement and turning formulas.