public class WartHog
extends AdvancedRobot
This is a tank for Robocode.
The latest version should be available at https://oroup.com/pub/warthog/
The source code is available at https://oroup.com/pub/warthog/WartHog.java
The javadoc is available at https://oroup.com/pub/warthog/javadoc/com/oroup/robocode/WartHog.html
This tank takes the basic strategy of always moving, trying to maintain a fixed range from the best target and firing on it when it thinks it can hit. In case you're wondering, the WartHog is what people call the American A-10 Tank Killer airplane.
TODO:Constructor and Description |
---|
WartHog() |
Modifier and Type | Method and Description |
---|---|
double |
bearing(com.oroup.robocode.WartHog.Point p)
Calculates the bearing from the tank to the point.
|
double |
bulletFlightTime(double distance,
double force)
Calculate how long a bullet will take to fly a certain distance.
|
double |
bulletVelocity(double force) |
double |
computeForce(com.oroup.robocode.WartHog.Enemy enemy)
Compute how hard to fire at an enemy.
|
double |
distance(com.oroup.robocode.WartHog.Point p)
Calculates the distance from the tank to the point.
|
com.oroup.robocode.WartHog.Enemy |
getBestEnemy()
Find the juiciest target to shoot at.
|
com.oroup.robocode.WartHog.Point |
getPoint()
Returns the current position of the tank as a point.
|
com.oroup.robocode.WartHog.Point |
getRadDelt(double dist,
double heading)
Given a distance and a direction, compute the point we will arrive at.
|
double |
gunBearingTolerance(com.oroup.robocode.WartHog.Point target,
double gunBearing)
Given a target point, and a gun bearing, figure out how close the bullet will come to the target.
|
static void |
main(java.lang.String[] args) |
double |
normalizeAngle(double angle)
Converts any angle to be between -180 and 180.
|
void |
onHitRobot(HitRobotEvent e)
If we hit a robot, change directions if that will get us away
from what we hit.
|
void |
onHitWall(HitWallEvent e)
If we hit a wall change directions.
|
void |
onRobotDeath(RobotDeathEvent e)
If a robot dies, remove it from our list so we don't go after
dead enemies.
|
void |
onScannedRobot(ScannedRobotEvent e)
If we see an enemy, figure out where it is and store it's data
away.
|
void |
run()
The tank execution loop:
Spin the radar.
|
void |
setGunHeading(double heading)
Turn the gun to the heading supplied using whichever direction is faster.
|
void |
setHeading(double heading)
Turns the tank to the supplied heading,
using whichever direction
is fastest.
|
double |
triangulate(double distToTarget,
double rangeToKeep,
double distanceToCover)
There is a point we want to target, but we want to
keep a certain distance from it, and there's a certain
amount of distance we can cover this turn.
|
void |
updateEnemyData(java.lang.String name,
com.oroup.robocode.WartHog.Point point,
double heading,
double velocity,
long time)
Save away all the data about enemies that we see.
|
public void run()
public void onScannedRobot(ScannedRobotEvent e)
e
- ScannedRobotEventpublic void onHitRobot(HitRobotEvent e)
e
- HitRobotEventpublic void onHitWall(HitWallEvent e)
e
- HitWallEventpublic void onRobotDeath(RobotDeathEvent e)
e
- RobotDeathEventpublic com.oroup.robocode.WartHog.Enemy getBestEnemy()
public double computeForce(com.oroup.robocode.WartHog.Enemy enemy)
enemy
- The enemy to calculate force forpublic double bulletFlightTime(double distance, double force)
distance
- The distance for the bullet to travelforce
- The force of the bullet.public double bulletVelocity(double force)
public double gunBearingTolerance(com.oroup.robocode.WartHog.Point target, double gunBearing)
target
- The point we are shooting at.gunBearing
- The actual bearing of our gun.public void updateEnemyData(java.lang.String name, com.oroup.robocode.WartHog.Point point, double heading, double velocity, long time)
name
- The name of the enemy.point
- The position of the enemy.heading
- The enemy headingvelocity
- The enemy velocitytime
- The time we saw this enemy.public void setHeading(double heading)
heading
- The heading for the tank to assumepublic void setGunHeading(double heading)
heading
- The heading for the gun to assume.public double distance(com.oroup.robocode.WartHog.Point p)
p
- The pointpublic double bearing(com.oroup.robocode.WartHog.Point p)
p
- The pointpublic double normalizeAngle(double angle)
angle
- The supplied angle.public com.oroup.robocode.WartHog.Point getPoint()
public com.oroup.robocode.WartHog.Point getRadDelt(double dist, double heading)
dist
- The distanceheading
- The headingpublic double triangulate(double distToTarget, double rangeToKeep, double distanceToCover)
distToTarget
- Distance to targetrangeToKeep
- Range to keepdistanceToCover
- Distance to coverpublic static void main(java.lang.String[] args) throws java.lang.Throwable
java.lang.Throwable