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;