Difference between revisions of "Talon/source"
< Talon
Jump to navigation
Jump to search
m (removing enemy.clear()) |
(Thanks Rednaxela for the suggestion) |
||
Line 13: | Line 13: | ||
* nearer ones are more dangerous to drive towards | * nearer ones are more dangerous to drive towards | ||
*/ | */ | ||
− | public class Talon extends AdvancedRobot { | + | public final class Talon extends AdvancedRobot { |
− | private static | + | private static double[][] map = new double[10][2]; |
− | private static | + | private static int n = 0; |
public void run() { | public void run() { | ||
Line 26: | Line 26: | ||
while(true) { | while(true) { | ||
− | |||
− | |||
angle = 6.3; | angle = 6.3; | ||
gn = bd = 2000; | gn = bd = 2000; | ||
while(angle > 0) { | while(angle > 0) { | ||
angle -= 0.1; | angle -= 0.1; | ||
− | int t = | + | int t = getOthers(); |
try { | try { | ||
while(true) { | while(true) { | ||
− | double[] v = | + | double[] v = map[--t]; |
if(v[0] < gn) { | if(v[0] < gn) { | ||
gn = v[0]; | gn = v[0]; | ||
Line 46: | Line 44: | ||
bd = md; | bd = md; | ||
setTurnRightRadians(Utils.normalRelativeAngle(angle - getHeadingRadians())); | setTurnRightRadians(Utils.normalRelativeAngle(angle - getHeadingRadians())); | ||
− | setAhead( | + | setAhead(20); |
} | } | ||
} | } | ||
Line 59: | Line 57: | ||
public void onScannedRobot(ScannedRobotEvent e) { | public void onScannedRobot(ScannedRobotEvent e) { | ||
− | + | try { | |
− | + | map[--n] = new double[]{e.getDistance(),getHeadingRadians() + e.getBearingRadians()}; | |
− | + | } catch(Exception ex) { | |
− | + | n = getOthers(); | |
− | + | } | |
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 17: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 final class Talon extends AdvancedRobot {
private static double[][] map = new double[10][2];
private static int n = 0;
public void run() {
double angle, gn, bd, md;
setAllColors(Color.red);
setAdjustGunForRobotTurn(true);
setAdjustRadarForGunTurn(true);
while(true) {
angle = 6.3;
gn = bd = 2000;
while(angle > 0) {
angle -= 0.1;
int t = getOthers();
try {
while(true) {
double[] v = 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(20);
}
}
} catch(Exception e) {}
}
setFire(gn);
turnRadarRightRadians(1);
}
}
public void onScannedRobot(ScannedRobotEvent e) {
try {
map[--n] = new double[]{e.getDistance(),getHeadingRadians() + e.getBearingRadians()};
} catch(Exception ex) {
n = getOthers();
}
}
}