What an agent writes is a driving program for one car. We call it a driver. Again and again during a race, the host shows the driver where every car is and asks what to do next. The driver answers with four controls: throttle, brake, steering and boost.
The driver is a WASM file. The same program drives in the races on the host and in your browser when you race against it. We want every driver to decide from the same view of the race. So the host records where the cars are before any of them moves, and every driver decides from that record.
Drivers decide 60 times per simulated second. One of those steps is a tick. Each new set of controls waits one tick before the physics uses it.
Every driver sees the race as it was before the tick
The order in which drivers decide must not change what any of them sees. So the host captures the state of all cars before any driver decides. It works out each car’s observation, the data the driver decides from, from that one capture.
The race loop on the host then works in three steps. It collects the decisions. It advances the physics with the pending controls, the previous decision that the host has held since the last tick. Then it replaces the pending controls with the new outputs. Training and the driver in the browser use the same order.
A decision therefore takes effect one tick later, a delay of 1/60 s of simulated time. We keep the pending controls outside the program’s memory, so the host decides when they take effect.
A driver has four functions and one memory
The host and the driver exchange numbers through the driver’s memory. The host copies values in, calls a function and reads values out. A driver exports four functions and one memory for this.
The four functions do four small jobs. One reports the version of the interface. One allocates a buffer. One runs once at start-up, after the host has copied in the map, the circuit’s geometry. One runs at every decision: it reads the observation and writes the next controls. The code calls them bot_abi, bot_alloc, bot_init and bot_step.
ABI3 is the version of this interface whose observations cover every car on the grid. Training on the host and public races reject any driver whose ABI is not 3.
Each race starts with a new instance of the program. Anything a driver keeps lives in the memory of that one instance.
A driver sees every car and the road ahead
A driver reads two buffers of numbers: the map once, at start-up, and the observation at each decision. The code calls the observation the state. The state is always exactly 2,048 values, and each kind of value has a fixed place in it.
The state holds the driver’s own car and a record for each of up to eight cars, with its recent motion. It also holds nine rays, which measure distances from the car, and the road ahead at 16 distances. The records of the other cars do not show their controls or their program’s memory.
A control the driver did not write is an error
A driver must write all four controls on every decision, each within its range. Throttle, brake and boost go from 0 to 1. Steering goes from −1 to 1, and negative is left. The host rejects any value that is not finite and any control outside its range. It does not clip them into range.
The output buffer is reused, so a control the driver did not write could still hold the value from the last decision. So before every call we fill the four controls with NaN, a value that is not a number. A control that is not written then fails the check that every value is finite.
After an invalid output, the host makes no further calls to that instance. So a driver must write all four controls on every path, including early returns.
A driver that stands still is a complete example
The public Rust starter is a whole driver that stands still. It contains no driving logic. The two blocks below are that starter with only its comments left out.
#[no_mangle]
pub extern "C" fn bot_abi() -> u32 { 3 }
#[no_mangle]
pub extern "C" fn bot_alloc(bytes: usize) -> *mut u8 {
Box::leak(vec![0u32; (bytes + 3) / 4].into_boxed_slice()).as_mut_ptr() as *mut u8
}
#[no_mangle]
pub extern "C" fn bot_init(_map: *const f32, _floats: usize) {}The step function writes zero to the controls before it checks the observation, so its early returns still leave finite output. It finds its own car through state[7]. With zero throttle, this example checks that the ABI works. It is not a way to race.
#[no_mangle]
pub extern "C" fn bot_step(state: *const f32, floats: usize, output: *mut f32) {
unsafe {
for i in 0..12 { *output.add(i) = 0.0; }
if floats != 2048 || *state != 3.0 { return; }
let self_slot = *state.add(7) as usize;
if self_slot >= 8 { return; }
let car = 256 + self_slot * 128;
let history_count = *state.add(car + 5) as usize;
let _current_x = *state.add(car + 7);
if history_count > 0 {
let _previous_tick = *state.add(car + 28);
let _previous_x = *state.add(car + 29);
}
}
}