Write a robot
Your robot is the teal one, and it starts with the hunter's program. Each time your edits compile, a new match starts.
The arena runs your robot's main function once every tick, and global variables keep their values between ticks. Paste this robot into the editor to try it. It circles and fires at the first robot its radar finds.
var radar: float;
fn main() -> void {
drive(6.0);
steer(4.0);
if scan(radar) < 0.0 {
radar = radar + 20.0;
return;
}
fire(radar, 2.0);
}
The language
| Types | int, float, bool and arrays such as [int; 8] |
|---|---|
| Variables | var count: int = 3; or const POWER: float = 2.0; A variable without a value starts at zero. |
| Functions | fn half(x: float) -> float { ... } |
| Control flow | if, else, while, break, continue and return. Write else if as else { if ... }. |
| Built-ins | int() and float() convert between whole and decimal numbers, and sqrt() and abs() take a float. |
Arena functions
Angles are in degrees, counterclockwise from the x axis.
my_x(), my_y() | The robot's position |
my_heading(), my_speed(), my_energy() | Its heading, speed and energy |
scan(direction) | The distance to the nearest robot within 10° of the direction, or -1 |
scan_x(), scan_y() | The position of the robot that this tick's last scan found, or 0 |
drive(speed) | Sets a speed from -4 to 8, which lasts until it changes or the robot hits something |
steer(degrees) | Turns up to 10° this tick |
fire(direction, power) | Fires a bullet with a power from 0.1 to 3. The gun then needs 10 ticks to cool. |
sin, cos, atan2(y, x) | Trigonometry |
Rules
| Field | 800 by 600, with its origin at the lower left |
|---|---|
| Steps | Each statement and each function call costs a step, and a while loop costs a step every time it checks its condition. When a robot runs out, its calls to drive, steer and fire before then still count. |
| Energy | Each robot starts with 100. Firing costs the bullet's power, and a hit takes 4 times the power from the robot hit and gives the shooter 3 times the power. A robot with no energy left is destroyed. |
| Winner | The last robot left, or after 3000 ticks the one with the most energy. Otherwise the match is a draw. |