Example robot
The editor's starting robot, complete, in every language.
This is the code every new robot starts with. It locks the radar on the enemy, aims by turning the body, strafes to dodge, recharges when energy runs low and runs from the arena’s edge. Use it as a starting point and change one thing at a time, testing after each change.
// Locks the radar on the enemy, aims by turning the body and strafes to dodge.
class Tracker extends Robot {
// The body decides how the robot moves (see Documentation → Bodies and parts):
// legs strafe, wheels race, treads endure, spiders grip the edge.
// Parts: weapon, armor, head and torso. Budget: 12 points.
constructor() {
super({body: "forca", parts: {"weapon": "railgun", "head": "pesquisador.head"}});
this.side = 1;
}
/** @param {State} state */
run() {
while (true) {
const state = this.scan();
const me = state.me;
if (me.charging || me.energy < 20) { this.recharge(); continue; }
const target = state.scanned[0];
// Get away from the lava before anything else.
if (me.distanceToEdge < 8) {
this.turn(me.centerBearing);
this.move(Math.abs(me.centerBearing) < 0.4 ? 5 : 0);
continue;
}
if (target) {
this.turnRadar(target.radarBearing * 2);
// The gun is on the arm: aiming means turning the body.
this.turn(target.bearing);
if (Math.abs(target.bearing) < 0.05 && me.gunHeat === 0) {
this.fire(target.distance < 15 ? 3 : 1.5);
}
// Strafes without losing the aim; switches sides when hit.
if (state.events.some((e) => e.type === "hitByBullet")) this.side = -this.side;
this.strafe(this.side * 4);
if (target.distance < 4.8) this.punch();
} else {
this.turnRadar(1);
this.turn(0.05);
this.move(3);
}
}
}
}// @language typescript
// Types help the editor explain the sensors and commands.
class Strategist extends Robot {
constructor() { super({body: "forca"}); }
private side: number = 1;
run(): void {
while (true) {
const state: State = this.scan();
const me = state.me;
if (me.charging || me.energy < 20) { this.recharge(); continue; }
if (me.distanceToEdge < 8) {
this.turn(me.centerBearing);
this.move(Math.abs(me.centerBearing) < 0.4 ? 5 : 0);
continue;
}
const target = state.scanned[0];
this.turnRadar(target ? target.radarBearing * 2 : 1);
if (target) {
this.turn(target.bearing);
if (Math.abs(target.bearing) < 0.08) this.fire(2);
if (state.events.some(event => event.type === "hitByBullet")) this.side *= -1;
this.strafe(this.side * 4);
if (target.distance < 4.8) this.punch();
} else { this.move(3); }
}
}
}# Wheels: aims, shoots and, while the gun cools down, turns sideways and runs to dodge.
class Dodger(Robot):
# The body decides how the robot moves (see Documentation → Bodies and parts).
# Parts. Budget: 12 points.
def __init__(self):
super().__init__(body="explorador", parts={"weapon": "minigun", "torso": "aranha.torso"})
self.direction = 1
def run(self):
while True:
state = self.scan()
me = state.me
if me.charging or me.energy < 20:
self.recharge()
continue
for e in state.events:
if e.type == "hit_by_bullet":
self.direction *= -1
to_center = me.center_bearing
if me.distance_to_edge < 8:
self.turn(to_center)
self.move(5 if abs(to_center) < 0.4 else 0)
continue
target = state.scanned[0] if state.scanned else None
if not target:
self.turn_radar(1)
self.turn(0.05)
self.move(3)
continue
self.turn_radar(target.radar_bearing * 2)
if me.gun_heat > 0.4:
# Wheels don't strafe: turn sideways to the target and run.
self.turn(self.normalize_angle(target.bearing + self.direction * math.pi / 2))
self.move(6)
else:
# The gun is on the arm: aiming means turning the body.
self.turn(target.bearing)
if abs(target.bearing) < 0.05:
self.fire(1)# Treads: spins the radar, faces the enemy, shoots and punches whoever gets close.
class Spinner < Robot
# The body decides how the robot moves (see Documentation → Bodies and parts).
# Parts. Budget: 12 points.
def initialize
super(parts: {armor: :shield})
end
def run
loop do
state = scan
me = state.me
if me.charging || me.energy < 20
recharge
next
end
to_center = me.center_bearing
if me.distance_to_edge < 8
turn to_center
move(to_center.abs < 0.4 ? 5 : 0)
next
end
target = state.scanned.first
if target
turn_radar target.radar_bearing * 2
# The gun is on the arm: aiming means turning the body.
turn target.bearing
fire 2 if target.bearing.abs < 0.08
punch if target.distance < 4.8
move(target.distance > 12 ? 3 : 0)
else
turn_radar 1.0
turn 0.05
move 3
end
end
end
end-- Lua: list indices start at 1; methods use a colon.
Sentinel = Robot:extend()
function Sentinel:run()
while true do
local state = self:scan()
local me = state.me
if me.charging or me.energy < 20 then
self:recharge()
elseif me.distance_to_edge < 8 then
self:turn(me.center_bearing)
self:move(math.abs(me.center_bearing) < 0.4 and 5 or 0)
else
local target = state.scanned[1]
if target then
self:turn_radar(target.radar_bearing * 2)
self:turn(target.bearing)
if math.abs(target.bearing) < 0.08 then self:fire(2) end
if target.distance < 4.8 then self:punch() end
self:move(target.distance > 12 and 3 or 0)
else
self:turn_radar(1)
self:turn(0.05)
self:move(3)
end
end
end
end