Robô de exemplo
O robô inicial do editor, completo, em cada linguagem.
Este é o código com que todo robô novo começa. Ele trava o radar no inimigo, mira virando o corpo, anda de lado para desviar, recarrega quando a energia baixa e foge da borda da arena. Use como ponto de partida e mude uma coisa de cada vez, testando a cada mudança.
// Trava o radar no inimigo, mira virando o corpo e anda de lado para desviar.
class Rastreador extends Robot {
// O corpo decide como o robô anda (veja Documentação → Corpos e peças):
// pernas andam de lado, rodas correm, esteiras aguentam, aranhas se seguram na borda.
// Peças: weapon, armor, head e torso. Orçamento: 12 pontos.
constructor() {
super({body: "forca", parts: {"weapon": "railgun", "head": "pesquisador.head"}});
this.lado = 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 alvo = state.scanned[0];
// Foge da lava antes de tudo.
if (me.distanceToEdge < 8) {
this.turn(me.centerBearing);
this.move(Math.abs(me.centerBearing) < 0.4 ? 5 : 0);
continue;
}
if (alvo) {
this.turnRadar(alvo.radarBearing * 2);
// O canhão fica no braço: mirar é virar o corpo.
this.turn(alvo.bearing);
if (Math.abs(alvo.bearing) < 0.05 && me.gunHeat === 0) {
this.fire(alvo.distance < 15 ? 3 : 1.5);
}
// Anda de lado sem perder a mira; troca de lado ao levar tiro.
if (state.events.some((e) => e.type === "hitByBullet")) this.lado = -this.lado;
this.strafe(this.lado * 4);
if (alvo.distance < 4.8) this.punch();
} else {
this.turnRadar(1);
this.turn(0.05);
this.move(3);
}
}
}
}// @language typescript
// Tipos ajudam o editor a explicar os sensores e comandos.
class Estrategista extends Robot {
constructor() { super({body: "forca"}); }
private lado: 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 alvo = state.scanned[0];
this.turnRadar(alvo ? alvo.radarBearing * 2 : 1);
if (alvo) {
this.turn(alvo.bearing);
if (Math.abs(alvo.bearing) < 0.08) this.fire(2);
if (state.events.some(event => event.type === "hitByBullet")) this.lado *= -1;
this.strafe(this.lado * 4);
if (alvo.distance < 4.8) this.punch();
} else { this.move(3); }
}
}
}# Rodas: mira, atira e, enquanto o canhão esfria, vira de lado e corre para desviar.
class Esquivador(Robot):
# O corpo decide como o robô anda (veja Documentação → Corpos e peças).
# Peças. Orçamento: 12 pontos.
def __init__(self):
super().__init__(body="explorador", parts={"weapon": "minigun", "torso": "aranha.torso"})
self.direcao = 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.direcao *= -1
para_centro = me.center_bearing
if me.distance_to_edge < 8:
self.turn(para_centro)
self.move(5 if abs(para_centro) < 0.4 else 0)
continue
alvo = state.scanned[0] if state.scanned else None
if not alvo:
self.turn_radar(1)
self.turn(0.05)
self.move(3)
continue
self.turn_radar(alvo.radar_bearing * 2)
if me.gun_heat > 0.4:
# Rodas não andam de lado: vira de lado para o alvo e corre.
self.turn(self.normalize_angle(alvo.bearing + self.direcao * math.pi / 2))
self.move(6)
else:
# O canhão fica no braço: mirar é virar o corpo.
self.turn(alvo.bearing)
if abs(alvo.bearing) < 0.05:
self.fire(1)# Esteiras: gira o radar, encara o inimigo, atira e soca quem chegar perto.
class Girador < Robot
# O corpo decide como o robô anda (veja Documentação → Corpos e peças).
# Peças. Orçamento: 12 pontos.
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
para_centro = me.center_bearing
if me.distance_to_edge < 8
turn para_centro
move(para_centro.abs < 0.4 ? 5 : 0)
next
end
alvo = state.scanned.first
if alvo
turn_radar alvo.radar_bearing * 2
# O canhão fica no braço: mirar é virar o corpo.
turn alvo.bearing
fire 2 if alvo.bearing.abs < 0.08
punch if alvo.distance < 4.8
move(alvo.distance > 12 ? 3 : 0)
else
turn_radar 1.0
turn 0.05
move 3
end
end
end
end-- Lua: índices das listas começam em 1; métodos usam dois-pontos.
Sentinela = Robot:extend()
function Sentinela: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 alvo = state.scanned[1]
if alvo then
self:turn_radar(alvo.radar_bearing * 2)
self:turn(alvo.bearing)
if math.abs(alvo.bearing) < 0.08 then self:fire(2) end
if alvo.distance < 4.8 then self:punch() end
self:move(alvo.distance > 12 and 3 or 0)
else
self:turn_radar(1)
self:turn(0.05)
self:move(3)
end
end
end
end