package bayen.nano;
import robocode.AdvancedRobot;
import robocode.ScannedRobotEvent;
import robocode.HitByBulletEvent;
import robocode.BulletHitEvent;
import robocode.BulletMissedEvent;
import robocode.HitWallEvent;
import robocode.util.Utils;
//import java.awt.Color;
/**
* Squirrel - a robot by (your name here)
* codesize: 237
*/
public class Squirrel extends AdvancedRobot
{
//private static final double INFINITY = Double.POSITIVE_INFINITY;
private static final double RADAR_EXTRA = 2.2;
private static final double RIGHT_ANGLE = 1.57;
private static final double POSITIVE_ONE = 1.0;
private static final double NEGATIVE_ONE = -1.0;
private static final double ZERO = 0.0;
private static final double BULLET_POWER = 3.0;
private static final double EIGHT = 8.0;
private static final double SIXTEEN = 16.0;
//private static final double THREE = 3.0;
private static final double ONE_TENTH = 0.1;
private static final double HUNDRED = 100.0;
private static final double THIRTEEN = 13.0;
private static double _gunCheck;
private static double _moveCheck = POSITIVE_ONE;
private static double _energy = HUNDRED;
private static double _direction = POSITIVE_ONE;
/**
* run: Squirrel's default behavior
*/
public void run() {
// After trying out your robot, try uncommenting the import at the top,
// and the next line:
//setColors(Color.red,Color.blue,Color.green);
do {
turnRadarRightRadians(HUNDRED);
} while(true);
}
/**
* onScannedRobot: What to do when you see another robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
double bearing;
setTurnRadarRightRadians(Utils.normalRelativeAngle(((bearing = e.getBearingRadians()) + getHeadingRadians() - getRadarHeadingRadians()) * RADAR_EXTRA));
setTurnRightRadians(bearing + RIGHT_ANGLE);
if(_energy > (_energy = e.getEnergy()))
_direction *= _moveCheck;
setAhead(HUNDRED * _direction);
double absoluteBearing = getHeadingRadians() + bearing;
setTurnGunRightRadians(Utils.normalRelativeAngle(absoluteBearing - getGunHeadingRadians() + ((_gunCheck<ZERO?((Math.random() * SIXTEEN) - EIGHT):e.getVelocity()) * Math.sin(e.getHeadingRadians() - absoluteBearing) / THIRTEEN)));
setFire(BULLET_POWER);
}
/**
* onHitByBullet: What to do when you're hit by a bullet
*/
public void onHitByBullet(HitByBulletEvent e) {
_moveCheck *= NEGATIVE_ONE;
}
/**
* onBulletHit: What to do when a bullet hits
*/
public void onBulletHit(BulletHitEvent e) {
_gunCheck -= (_gunCheck<ZERO?POSITIVE_ONE:NEGATIVE_ONE);
}
/**
* onBulletMissed: What to do when a bullet misses
*/
public void onBulletMissed(BulletMissedEvent e) {
_gunCheck += (_gunCheck<ZERO?POSITIVE_ONE:NEGATIVE_ONE);
}
/**
* onHitWall: What to do when you hit a wall
*/
public void onHitWall(HitWallEvent e) {
_direction *= NEGATIVE_ONE;
}
}
Here it is at 249 bytes. You could gain 2 more by doing "energy diff > 0" instead of "energy diff > 0.1".
package bayen.nano;
import robocode.AdvancedRobot;
import robocode.ScannedRobotEvent;
import robocode.HitByBulletEvent;
import robocode.BulletHitEvent;
import robocode.BulletMissedEvent;
import robocode.HitWallEvent;
import robocode.util.Utils;
//import java.awt.Color;
/**
* Squirrel - a robot by (your name here)
*/
public class Squirrel extends AdvancedRobot
{
//private static final double INFINITY = Double.POSITIVE_INFINITY;
private static final double RADAR_EXTRA = 2.2;
private static final double RIGHT_ANGLE = 1.57;
private static final double POSITIVE_ONE = 1.0;
private static final double NEGATIVE_ONE = -1.0;
private static final double ZERO = 0.0;
private static final double BULLET_POWER = 3.0;
private static final double EIGHT = 8.0;
private static final double SIXTEEN = 16.0;
//private static final double THREE = 3.0;
private static final double ONE_TENTH = 0.1;
private static final double HUNDRED = 100.0;
private static final double THIRTEEN = 13.0;
private static double _gunCheck;
private static double _moveCheck = POSITIVE_ONE;
private static double _energy = HUNDRED;
private static double _direction = POSITIVE_ONE;
/**
* run: Squirrel's default behavior
*/
public void run() {
// After trying out your robot, try uncommenting the import at the top,
// and the next line:
//setColors(Color.red,Color.blue,Color.green);
do {
turnRadarRightRadians(HUNDRED);
} while(true);
}
/**
* onScannedRobot: What to do when you see another robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
double bearing;
setTurnRadarRightRadians(Utils.normalRelativeAngle(((bearing = e.getBearingRadians()) + getHeadingRadians() - getRadarHeadingRadians()) * RADAR_EXTRA));
setTurnRightRadians(bearing + RIGHT_ANGLE);
double difference;
// Voidious: this looks funky, but it really does work the same like this and is smaller.
if((difference = _energy - (_energy = e.getEnergy())) <= BULLET_POWER && difference > ONE_TENTH) {
_direction *= _moveCheck;
}
setAhead(HUNDRED * _direction);
// Voidious: don't need an extra variable here
bearing += getHeadingRadians();
setTurnGunRightRadians(Utils.normalRelativeAngle(bearing - getGunHeadingRadians() + ((_gunCheck<ZERO?((Math.random() * SIXTEEN) - EIGHT):e.getVelocity()) * Math.sin(e.getHeadingRadians() - bearing) / THIRTEEN)));
setFire(BULLET_POWER);
}
/**
* onHitByBullet: What to do when you're hit by a bullet
*/
public void onHitByBullet(HitByBulletEvent e) {
_moveCheck *= NEGATIVE_ONE;
}
/**
* onBulletHit: What to do when a bullet hits
*/
public void onBulletHit(BulletHitEvent e) {
_gunCheck -= (_gunCheck<ZERO?POSITIVE_ONE:NEGATIVE_ONE);
}
/**
* onBulletMissed: What to do when a bullet misses
*/
public void onBulletMissed(BulletMissedEvent e) {
_gunCheck += (_gunCheck<ZERO?POSITIVE_ONE:NEGATIVE_ONE);
}
/**
* onHitWall: What to do when you hit a wall
*/
public void onHitWall(HitWallEvent e) {
_direction *= NEGATIVE_ONE;
}
}
Whoah, sorry, I missed your previous update. Anyway, the second change I made could still apply, I think. Good luck. -- Voidious