Look at the
WhiteWhales page. Several people say that they can't hit
MyFirstRobot from
long range with any gun simpler than a pattern matcher. It follows that an upgrade of
MyFirstRobot might perform very well. So I created
SuperMyFirstRobot.
Bot Name
SuperMyFirstRobot
Author
AaronR
Extends
AdvancedRobot
What's special about it?
It is
MyFirstRobot, except that it has things like
PerpendicularMovement,
Radar locks,
WallSmoothing...
How competitive is it?
It is very effective at dodging simpler targeting methods. It also is fairly good in melee.
How does it move?
It oscillates back and forth, using
WallSmoothing to avoid hitting the walls. Sometimes it
takes off on a mad dash to the opposite side of the battlefield.
How does it fire?
It uses
CircularTargeting.
How does the melee strategy differ from one-on-one strategy?
No difference, except it uses a radar lock in 1v1.
What does it save between rounds and matches?
Nothing.
Where did you get the name?
Well, it was originally based on
MyFirstRobot, and I think it is a pun on Super Mario.
On the
OceansOfSpareTime page, I put a comment about how if you attached a
GuessFactorTargeting gun to
MyFirstRobot, it could probably beat
Dookious...
Can I use your code?
Sure, here it is:
package ar.tests;
import static java.lang.Math.*;
import static ar.tests.Util.*;
import java.awt.Color;
import java.awt.geom.*;
import robocode.*;
public class SuperMyFirstRobot extends AdvancedRobot {
private static final double WALL_STICK = 250.0;
private Rectangle2D.Double fieldRectangle;
private double angle;
private int direction = 1;
private double lastEnemyHeading;
public void run() {
setColors(null, null, Color.RED, Color.YELLOW, Color.RED);
setAdjustGunForRobotTurn(true);
setAdjustRadarForRobotTurn(true);
setAdjustRadarForGunTurn(true);
setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
fieldRectangle = new Rectangle2D.Double(ROBOT_CENTER, ROBOT_CENTER / 2,
getBattleFieldWidth() - ROBOT_CENTER, getBattleFieldHeight()
- ROBOT_CENTER);
do {
direction = 1;
scan();
setBackAsFront(angle);
for (int i = 0; i < 18; i++) {
doNothing();
}
direction = -1;
scan();
setBackAsFront(angle);
for (int i = 0; i < 18; i++) {
doNothing();
}
} while (true);
}
public void onScannedRobot(ScannedRobotEvent e) {
double absoluteBearing = getHeadingRadians() + e.getBearingRadians();
// Radar lock.
if (getOthers() == 1) {
setTurnRadarLeftRadians(getRadarTurnRemainingRadians());
}
// Perpendicular movement.
angle = normalRelativeAngle(wallSmoothing(new Point2D.Double(getX(), getY()),
absoluteBearing + PI / 2, direction));
// Circular targeting.
double relativeX = e.getDistance() * Math.sin(absoluteBearing);
double relativeY = e.getDistance() * Math.cos(absoluteBearing);
double db = 0;
double ww = lastEnemyHeading; // enemy's starting heading
do {
db += getBulletSpeed(3);
double dx = e.getVelocity() * Math.sin(ww);
double dy = e.getVelocity() * Math.cos(ww);
ww += e.getHeadingRadians() - lastEnemyHeading;
relativeX += dx;
relativeY += dy;
} while (db < Util.distance(0, 0, relativeX, relativeY));
lastEnemyHeading = e.getHeadingRadians();
setTurnGunRightRadians(Math.asin(Math.sin(Math.atan2(relativeX,
relativeY)
- getGunHeadingRadians())));
setFire(3);
}
private double wallSmoothing(Point2D.Double botLocation, double angle,
int orientation) {
while (!fieldRectangle.contains(project(botLocation, angle, WALL_STICK))) {
angle += orientation * 0.1;
}
return angle;
}
private void setBackAsFront(double goAngle) {
double angle = normalRelativeAngle(goAngle - getHeadingRadians());
if (abs(angle) > (PI / 2)) {
if (angle < 0) {
setTurnRightRadians(PI + angle);
} else {
setTurnLeftRadians(PI - angle);
}
setBack(100);
} else {
if (angle < 0) {
setTurnLeftRadians(-angle);
} else {
setTurnRightRadians(angle);
}
setAhead(100);
}
}
}
Comments, questions, feedback: