[Home]Squirrel/Nano

Robo Home | Squirrel | Changes | Preferences | AllPages

Difference (from prior major revision) (no other diffs)

Removed: 12d11
//import java.awt.Color;

Changed: 15,16c14,16
* Squirrel - a robot by (your name here)
* codesize: 237
* Squirrel - a robot by Bayen
*
* Codesize Reduction Help: Voidious (Thanks!)

Changed: 20c20
//private static final double INFINITY = Double.POSITIVE_INFINITY;
//CONSTANTS:

Removed: 29d28
//private static final double THREE = 3.0;

Changed: 33c32,33


//VARIALBES:

Removed: 39,41d38
/**
* run: Squirrel's default behavior
*/

Removed: 43,45d39
// After trying out your robot, try uncommenting the import at the top,
// and the next line:
//setColors(Color.red,Color.blue,Color.green);

Removed: 51,53d44
/**
* onScannedRobot: What to do when you see another robot
*/

Changed: 61,62c52,55
if(_energy > (_energy = e.getEnergy()))
_direction *= _moveCheck;
double difference;
if((difference = _energy - (_energy = e.getEnergy())) <= BULLET_POWER && difference > ONE_TENTH) {
_direction *= _moveCheck;
}

Changed: 65,66c58,59
double absoluteBearing = getHeadingRadians() + bearing;
setTurnGunRightRadians?(Utils.normalRelativeAngle(absoluteBearing - getGunHeadingRadians?() + ((_gunCheck<ZERO?((Math.random() * SIXTEEN) - EIGHT):e.getVelocity()) * Math.sin(e.getHeadingRadians() - absoluteBearing) / THIRTEEN)));
bearing += getHeadingRadians();
setTurnGunRightRadians?(Utils.normalRelativeAngle(bearing - getGunHeadingRadians?() + ((_gunCheck<ZERO?((Math.random() * SIXTEEN) - EIGHT):e.getVelocity()) * Math.sin(e.getHeadingRadians() - bearing) / THIRTEEN)));

Changed: 68c61
setFire(BULLET_POWER);
setFire(POSITIVE_ONE);

Removed: 71,73d63
/**
* onHitByBullet?: What to do when you're hit by a bullet
*/

Removed: 78,80d67
/**
* onBulletHit?: What to do when a bullet hits
*/

Removed: 85,87d71
/**
* onBulletMissed?: What to do when a bullet misses
*/

Removed: 92,94d75
/**
* onHitWall?: What to do when you hit a wall
*/

Changed: 98,99c79,80
}
</pre>

}</pre>

Changed: 208c189,191
Whoah, sorry, I missed your previous update. Anyway, the second change I made could still apply, I think. Good luck. -- Voidious
Whoah, sorry, I missed your previous update. Anyway, the second change I made could still apply, I think. Good luck. -- Voidious

No, I prefer your changes because I don't have to sacrifice the accuracy of the Energy Drop prediction. So thanks! I replaced the code up top with the finalized version. --Bayen

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;

/**
 * Squirrel - a robot by Bayen
 *
 * Codesize Reduction Help:  Voidious (Thanks!)
 */
public class Squirrel extends AdvancedRobot
{
	//CONSTANTS:
	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 ONE_TENTH = 0.1;
	private static final double HUNDRED = 100.0;
	private static final double THIRTEEN = 13.0;

	//VARIALBES:
	private static double _gunCheck;
	private static double _moveCheck = POSITIVE_ONE;
	private static double _energy = HUNDRED;
	private static double _direction = POSITIVE_ONE;
	
	public void run() {
		do {
			turnRadarRightRadians(HUNDRED);
		} while(true);
	}

	public void onScannedRobot(ScannedRobotEvent e) {
		double bearing;
		
		setTurnRadarRightRadians(Utils.normalRelativeAngle(((bearing = e.getBearingRadians()) + getHeadingRadians() - getRadarHeadingRadians()) * RADAR_EXTRA));
		
		setTurnRightRadians(bearing + RIGHT_ANGLE);
		
		double difference;
		if((difference = _energy - (_energy = e.getEnergy())) <= BULLET_POWER && difference > ONE_TENTH) {
			_direction *= _moveCheck;
		}
		setAhead(HUNDRED * _direction);

		bearing += getHeadingRadians();
		setTurnGunRightRadians(Utils.normalRelativeAngle(bearing - getGunHeadingRadians() + ((_gunCheck<ZERO?((Math.random() * SIXTEEN) - EIGHT):e.getVelocity()) * Math.sin(e.getHeadingRadians() - bearing) / THIRTEEN)));
		
		setFire(POSITIVE_ONE);
	}

	public void onHitByBullet(HitByBulletEvent e) {
		_moveCheck *= NEGATIVE_ONE;
	}
	
	public void onBulletHit(BulletHitEvent e) {
		_gunCheck -= (_gunCheck<ZERO?POSITIVE_ONE:NEGATIVE_ONE);
	}
	
	public void onBulletMissed(BulletMissedEvent e) {
		_gunCheck += (_gunCheck<ZERO?POSITIVE_ONE:NEGATIVE_ONE);
	}
	
	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

No, I prefer your changes because I don't have to sacrifice the accuracy of the Energy Drop prediction. So thanks! I replaced the code up top with the finalized version. --Bayen


Robo Home | Squirrel | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited October 31, 2006 14:22 EST by Bayen (diff)
Search: