Here's the code. The setAhead bit makes it so if I run into a wall, I have a 50% chance of turning back the other way ('bouncing' off the wall like CircleBot
did). The setTurnRight?
line would be easily twice as long if I targeted a range of distances instead of just trying to be 200 away like in this code, but I figured this was good enough. Ironically, this is basically equivalent to the original aiming/tracking code from CircleBot
(but not the original firing code).
* HaikuCircleBot - a poem by Kawigi based on CircleBot, my first robot. Like CircleBot, it beats all the sample bots :-)
public class HaikuCircleBot extends AdvancedRobot
public void run()
public void onScannedRobot(ScannedRobotEvent e)
setAhead((getDistanceRemaining() == 0) ? (int)(Math.random()*2)*400-200 : getDistanceRemaining()*100);
setTurnRight(e.getBearing()-90 + (((getDistanceRemaining() > 0) == (e.getDistance() > 200)) ? 30 : -30));