Difference between revisions of "Talon/source"
< Talon
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.*; | ||
− | |||
− | |||
/** | /** | ||
Line 14: | Line 12: | ||
*/ | */ | ||
public final class Talon extends AdvancedRobot { | public final class Talon extends AdvancedRobot { | ||
− | private static double[][] map = new double[10][ | + | 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); | ||
− | |||
while(true) { | while(true) { | ||
− | angle = | + | angle = 360; |
gn = bd = 2000; | gn = bd = 2000; | ||
− | while(angle > 0) { | + | while(--angle > 0) { |
− | |||
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 = | + | gn = md; |
− | + | setTurnGunRight(Utils.normalRelativeAngleDegrees(v[1] - getGunHeading())); | |
} | } | ||
− | md = Math.abs(Utils. | + | md = Math.abs(Utils.normalRelativeAngleDegrees(angle-v[1])) * (800.0/md); |
if(md < bd) { | if(md < bd) { | ||
bd = md; | bd = md; | ||
− | + | setTurnRight(Utils.normalRelativeAngleDegrees(angle - getHeading())); | |
− | setAhead( | + | setAhead(gn); |
} | } | ||
} | } | ||
Line 58: | Line 54: | ||
public void onScannedRobot(ScannedRobotEvent e) { | public void onScannedRobot(ScannedRobotEvent e) { | ||
try { | try { | ||
− | map[--n] = new double[]{e.getDistance(), | + | 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();
}
}
}