Difference between revisions of "Talon/source"
< Talon
Jump to navigation
Jump to search
(Code) |
m (removing enemy.clear()) |
||
Line 19: | Line 19: | ||
public void run() { | public void run() { | ||
double angle, gn, bd, md; | double angle, gn, bd, md; | ||
− | |||
− | |||
setAllColors(Color.red); | setAllColors(Color.red); |
Revision as of 13:00, 30 January 2011
package cs;
import robocode.util.Utils;
import robocode.*;
import java.util.*;
import java.awt.*;
/**
* 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 class Talon extends AdvancedRobot {
private static final HashMap enemy = new HashMap();
private static Object[] map;
public void run() {
double angle, gn, bd, md;
setAllColors(Color.red);
setAdjustGunForRobotTurn(true);
setAdjustRadarForGunTurn(true);
while(true) {
map = enemy.values().toArray();
angle = 6.3;
gn = bd = 2000;
while(angle > 0) {
angle -= 0.1;
int t = 0;
try {
while(true) {
double[] v = (double[])map[t++];
if(v[0] < gn) {
gn = v[0];
setTurnGunRightRadians(Utils.normalRelativeAngle(v[1] - getGunHeadingRadians()));
}
md = Math.abs(Utils.normalRelativeAngle(v[1]-angle)) + (120/v[0]);
if(md < bd) {
bd = md;
setTurnRightRadians(Utils.normalRelativeAngle(angle - getHeadingRadians()));
setAhead(100);
}
}
} catch(Exception e) {}
}
setFire(gn);
turnRadarRightRadians(1);
}
}
public void onScannedRobot(ScannedRobotEvent e) {
enemy.put(e.getName(), new double[]{e.getDistance(),getHeadingRadians() + e.getBearingRadians()});
}
public void onRobotDeath(RobotDeathEvent e) {
enemy.remove(e.getName());
}
}