Talon/source

From Robowiki
< Talon
Revision as of 18:11, 30 January 2011 by Chase-san (talk | contribs) (size reduced further)
Jump to navigation Jump to search
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();
		}
	}
}