[Home]HaikuCircleBot

Robo Home | Changes | Preferences | AllPages

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).
package kawigi.haiku;
import robocode.*;

/**
 * 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()
	{
		turnGunRight(Double.POSITIVE_INFINITY);
	}

	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));
		setFire(e.getEnergy()/4);
	}	
}

Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited August 6, 2003 23:11 EST by Kawigi (diff)
Search: