SPINBOT
-
robot uses memory to count frames
-
moves closer to center of arena
-
spins and fires wildly
// 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
-
always move forwards
-
avoids walls using
context.state.proximity
-
fires when it sees anything in its scanner
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;