Difference between revisions of "Talon/source"

From Robowiki
Jump to navigation Jump to search
(Thanks Rednaxela for the suggestion)
(size reduced further)
Line 3: Line 3:
 
import robocode.util.Utils;
 
import robocode.util.Utils;
 
import robocode.*;
 
import robocode.*;
import java.util.*;
 
import java.awt.*;
 
  
 
/**
 
/**
Line 14: Line 12:
 
  */
 
  */
 
public final class Talon extends AdvancedRobot {
 
public final class Talon extends AdvancedRobot {
private static double[][] map = new double[10][2];
+
private static double[][] map = new double[10][3];
 
private static int n = 0;
 
private static int n = 0;
  
Line 20: Line 18:
 
double angle, gn, bd, md;
 
double angle, gn, bd, md;
 
 
setAllColors(Color.red);
+
setAllColors(java.awt.Color.red);
 
 
 
setAdjustGunForRobotTurn(true);
 
setAdjustGunForRobotTurn(true);
setAdjustRadarForGunTurn(true);
 
 
 
 
while(true) {
 
while(true) {
angle = 6.3;
+
angle = 360;
 
gn = bd = 2000;
 
gn = bd = 2000;
while(angle > 0) {
+
while(--angle > 0) {
angle -= 0.1;
 
 
int t = getOthers();
 
int t = getOthers();
 
try {
 
try {
 
while(true) {
 
while(true) {
 
double[] v = map[--t];
 
double[] v = map[--t];
if(v[0] < gn) {
+
if((md = v[0]) < gn) {
gn = v[0];
+
gn = md;
setTurnGunRightRadians(Utils.normalRelativeAngle(v[1] - getGunHeadingRadians()));
+
setTurnGunRight(Utils.normalRelativeAngleDegrees(v[1] - getGunHeading()));
 
}
 
}
 
 
md = Math.abs(Utils.normalRelativeAngle(v[1]-angle)) + (120/v[0]);
+
md = Math.abs(Utils.normalRelativeAngleDegrees(angle-v[1])) * (800.0/md);
 
 
 
if(md < bd) {
 
if(md < bd) {
 
bd = md;
 
bd = md;
setTurnRightRadians(Utils.normalRelativeAngle(angle - getHeadingRadians()));
+
setTurnRight(Utils.normalRelativeAngleDegrees(angle - getHeading()));
setAhead(20);
+
setAhead(gn);
 
}
 
}
 
}
 
}
Line 58: Line 54:
 
public void onScannedRobot(ScannedRobotEvent e) {
 
public void onScannedRobot(ScannedRobotEvent e) {
 
try {
 
try {
map[--n] = new double[]{e.getDistance(),getHeadingRadians() + e.getBearingRadians()};
+
map[--n] = new double[]{e.getDistance(),getHeading() + e.getBearing()};
 
} catch(Exception ex) {
 
} catch(Exception ex) {
 
n = getOthers();
 
n = getOthers();

Revision as of 18:11, 30 January 2011

package cs;
import robocode.util.Utils;
import robocode.*;

/**
 * Talon - a robot by Chase
 * Nano Melee bot
 *
 * The idea is to avoid driving toward enemy robots,
 * nearer ones are more dangerous to drive towards
 */
public final class Talon extends AdvancedRobot {
	private static double[][] map = new double[10][3];
	private static int n = 0;

	public void run() {
		double angle, gn, bd, md;
		
		setAllColors(java.awt.Color.red);
		
		setAdjustGunForRobotTurn(true);
		
		while(true) {
			angle = 360;
			gn = bd = 2000;
			while(--angle > 0) {
				int t = getOthers();
				try {
					while(true) {
						double[] v = map[--t];
						if((md = v[0]) < gn) {
							gn = md;
							setTurnGunRight(Utils.normalRelativeAngleDegrees(v[1] - getGunHeading()));
						}
						
						md = Math.abs(Utils.normalRelativeAngleDegrees(angle-v[1]))  * (800.0/md);
						
						if(md < bd) {
							bd = md;
							setTurnRight(Utils.normalRelativeAngleDegrees(angle - getHeading()));
							setAhead(gn);
						}
					}
				} catch(Exception e) {}
			}

			setFire(gn);
			
			turnRadarRightRadians(1);
		}
	}

	public void onScannedRobot(ScannedRobotEvent e) {
		try {
			map[--n] = new double[]{e.getDistance(),getHeading() + e.getBearing()};
		} catch(Exception ex) {
			n = getOthers();
		}
	}
}