RBN-CODE
SPINBOT
-
robot uses
context.memory
to count frames
-
moves closer to center of arena with
context.state.angleToCenter
-
why stop moving at 23 frames?
number was determined from trial and error testing
on robot control panel
-
spins and fires at consistent pace
// create a persistent frame counter in memory
// runs once per frame of simulation
if (!('counter' in context.memory)) context.memory.counter = 0;
context.memory.counter++;
// move forward towards center of arena for first 23 frames ...
if (context.memory.counter < 23) {
context.action.desiredAngle = context.state.angleToCenter;
context.action.desiredForce = 0.001;
} else {
// ...then start spinning and shooting!
context.action.desiredAngle = context.state.angle + 0.05;
context.action.desiredLaunch = true;
}
FASTBOT / SLOWBOT
-
turns away from walls using
context.state.proximity
and context.state.angleToCenter
-
move forwards with consistent speed
-
fires when anything enters scanner
(including walls and enemy projectiles!)
var closest = context.state.proximity[0] || {};
// when detecting a wall very nearby, turn towards center of arena
if (closest.entityType == "wall") {
// face robot towards center of arena if too close to wall
context.action.desiredAngle = context.state.angleToCenter;
}
// always move forward - the divisor (/2) determines max speed/force
context.action.desiredForce = context.state.maxForce/2;
// fire at anything within scanner range
if (context.state.scanner.ALL.length > 0)
context.action.desiredLaunch = true;
DEFAULT
-
the default robot in trainer demos
-
moves forward randomly
-
turns away from walls using
context.state.proximity
and context.state.angleToCenter
-
distinguishes between enemy and friendly robots
-
tracks and fires at active enemy robots
(not on same team)
-
avoids friendly (on same team), inactive robots
-
turns randomly
// randomly move forward
if (Math.random() < 0.5) {
context.action.desiredForce = context.state.maxForce;
}
// detect closest entity via (short range) proximity alerts
var closest = context.state.proximity[0] || {};
// detect robot entity in front of robot via (short-medium range) scanner
var front = context.state.scanner.robot[0] || false;
if (closest.entityType == "wall") {
// face robot towards center of arena if too close to wall
context.action.desiredAngle = context.state.angleToCenter;
} else if (front) {
if (front.active && front.team != context.state.team) {
// follow active enemy robots
context.action.desiredAngle = (
context.state.angle - (context.state.angle - front.angleFromRobot));
context.action.desiredLaunch = true;
} else {
// avoid inactive/friendly robots
dir = (front.angleFromRobot - context.state.angle) < 0 ? -1:1;
context.action.desiredAngle = context.state.angle - (dir * 0.174533);
context.action.desiredForce = context.state.maxForce / 2;
}
} else if (Math.random() < 0.005) {
// face random direction
var maxvar = Math.PI / 4, // 45 degrees
random = (Math.random() * maxvar) - maxvar/2; // left or right
context.action.desiredAngle = context.state.angle + random;
context.action.desiredForce = 0; // tight turn
}