Difference between revisions of "SuperTrackFire"

From Robowiki
Jump to navigation Jump to search
(SuperTrackFire)
 
(→‎Code: changed the code and removed redundant imports)
Line 15: Line 15:
 
<pre>package wiki.SuperSampleBot;
 
<pre>package wiki.SuperSampleBot;
  
 
+
import robocode.util.*;
import robocode.Robot;
 
import robocode.ScannedRobotEvent;
 
import robocode.WinEvent;
 
import robocode.util.Utils.normalRelativeAngleDegrees;
 
 
import robocode.*;
 
import robocode.*;
 
import java.awt.*;
 
import java.awt.*;
Line 54: Line 50:
 
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 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 randomAngle = randomGuessFactor * maxEscapeAngle;//random firing angle
double firingAngle = robocode.util.Utils.normalRelativeAngle(absoluteBearing - getGunHeadingRadians()+randomAngle/3);//amount to turn our gun
+
double firingAngle = Utils.normalRelativeAngle(absoluteBearing - getGunHeadingRadians()+randomAngle/3);//amount to turn our gun
 
setTurnLeftRadians(-90-e.getBearingRadians()*dir);//Turn perpendicular to them
 
setTurnLeftRadians(-90-e.getBearingRadians()*dir);//Turn perpendicular to them
 
setTurnGunRightRadians(firingAngle);//Aim!
 
setTurnGunRightRadians(firingAngle);//Aim!
 
setAhead(100*Math.random()*dir);
 
setAhead(100*Math.random()*dir);
 
setFire(getEnergy()/10);//Fire, using less energy if we have low energy
 
setFire(getEnergy()/10);//Fire, using less energy if we have low energy
setTurnRadarRightRadians(robocode.util.Utils.normalRelativeAngle(absoluteBearing-getRadarHeadingRadians()));//lock on the radar
+
setTurnRadarRightRadians(Utils.normalRelativeAngle(absoluteBearing-getRadarHeadingRadians()));//lock on the radar
 
if(Math.random()>.9){
 
if(Math.random()>.9){
 
dir=-dir;//randomly changing move and turn direction
 
dir=-dir;//randomly changing move and turn direction

Revision as of 04:09, 19 May 2009

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
	}
}