Difference between revisions of "SuperTrackFire"

From Robowiki
Jump to navigation Jump to search
(→‎Code: changed the code and removed redundant imports)
m (Using <syntaxhighlight>.)
Line 13: Line 13:
 
== Code ==
 
== Code ==
  
<pre>package wiki.SuperSampleBot;
+
<syntaxhighlight>package wiki.SuperSampleBot;
  
 
import robocode.util.*;
 
import robocode.util.*;
Line 63: Line 63:
 
dir=-dir;//change direction when we hit the wall
 
dir=-dir;//change direction when we hit the wall
 
}
 
}
} </pre>
+
} </syntaxhighlight>

Revision as of 10:31, 1 July 2010

SuperTrackFire is a part of the Super Sample Bots set by CrazyBassoonist. It is intended to provide new robocoders with a new challenge after beating all of the sample robots.


Movement

SuperTrackFire uses a random oscillating movement. It's movement is quite bad, it will run into walls alot. This should be one of the easiest Super Sample Bots to beat.


Targeting

SuperTrackFire locks its gun on and then jiggles it just a little bit so that it does not always fire exactly head-on.


Code

package wiki.SuperSampleBot;

import robocode.util.*;
import robocode.*;
import java.awt.*;


/**
 * TrackFire - a Super Sample Bot by CrazyBassoonist, based on TrackFire Mathew Nelson and maintained by Flemming N. Larsen
 * <p/>
 *Random oscillating movement with slightly random Head-On Targeting
 */
public class SuperTrackFire extends AdvancedRobot {
	int dir=1;//Which way we want to move
	/**
	 * TrackFire's run method
	 */
	public void run() {
		// Set colors
		setAdjustRadarForGunTurn(true);
		setAdjustGunForRobotTurn(true);
		setBodyColor(Color.pink);
		setGunColor(Color.pink);
		setRadarColor(Color.pink);
		setScanColor(Color.pink);
		setBulletColor(Color.pink);
		turnRadarRightRadians(Double.POSITIVE_INFINITY);//turnRadarRight
	}

	/**
	 * onScannedRobot:  We have a target.  Go get it.
	 */
	public void onScannedRobot(ScannedRobotEvent e) {
		double absoluteBearing = getHeadingRadians() + e.getBearingRadians();//robot's absolute bearing
		double randomGuessFactor = (Math.random() - .5) * 2;
		double maxEscapeAngle = Math.asin(8.0/(20 - (3 *Math.min(3,getEnergy()/10))));//farthest the enemy can move in the amount of time it would take for a bullet to reach them
		double randomAngle = randomGuessFactor * maxEscapeAngle;//random firing angle
		double firingAngle = Utils.normalRelativeAngle(absoluteBearing - getGunHeadingRadians()+randomAngle/3);//amount to turn our gun
		setTurnLeftRadians(-90-e.getBearingRadians()*dir);//Turn perpendicular to them
		setTurnGunRightRadians(firingAngle);//Aim!
		setAhead(100*Math.random()*dir);
		setFire(getEnergy()/10);//Fire, using less energy if we have low energy
		setTurnRadarRightRadians(Utils.normalRelativeAngle(absoluteBearing-getRadarHeadingRadians()));//lock on the radar
		if(Math.random()>.9){
			dir=-dir;//randomly changing move and turn direction
		}
	}
	public void onHitWall(HitWallEvent e){
		dir=-dir;//change direction when we hit the wall
	}
}