[Home]Festis/Code

Robo Home | Festis | Changes | Preferences | AllPages

package strider;

import robocode.*;
import robocode.util.Utils;

/**
 * This code is released under the RoboWiki Public Code Licence (RWPCL),
 * datailed on: http://robowiki.net/?RWPCL
 *
 * Festis is a NanoBot with random targeting and random movement
 * with wallsmoothing.
 * http://robowiki.net/?Festis
 *
 * @author Strider
 * @version 1.2.1
 */
public class Festis extends AdvancedRobot {

    private static final double PI_2 = 1.5707963268;	// PI/2
    private static final double POWER = 3.0;	// fire power
    private static final double BSPEED = 20-3*POWER;
    private static final double ARENAW_2 = 400;	// Arena width / 2
    private static final double ARENAH_2 = 300; // Arena height / 2
    private static final int BOUND_X = 380;  // ARENAW_2-(botwidth+fudge)/2
    private static final int BOUND_Y = 280;  // ARENAW_2-(botheight+fudge)/2

    private static double drive = 100;		// affects wall smoothing
    private static double bullet_speed = 0;

    public void run() {
	//setColors(java.awt.Color.yellow, null, null);
	turnRadarRightRadians(Double.POSITIVE_INFINITY);
    }

    public void onScannedRobot(ScannedRobotEvent e) {
	if (Math.random() < bullet_speed / e.getDistance()) {
	    drive = -drive;
	}
	double h, d = (h = getHeadingRadians()) + e.getBearingRadians();
	int x = (int)Math.abs(getX() + drive*Math.sin(h) - ARENAW_2) - BOUND_X;
	int y = (int)Math.abs(getY() + drive*Math.cos(h) - ARENAH_2) - BOUND_Y;
	setTurnGunRightRadians(Utils.normalRelativeAngle(
	    d +
	    Math.pow(Math.random(),0.5) *
	    Math.asin(e.getVelocity()/BSPEED*Math.sin(e.getHeadingRadians()-d))
	    - getGunHeadingRadians()));
	setFire(POWER);
	setTurnRadarLeftRadians(getRadarTurnRemainingRadians());
	setTurnRightRadians((x&y) > 0
			    ? Math.tan((y>x ? PI_2 : 0) - h)
			    : e.getBearingRadians() + PI_2);
	setAhead(drive);
    }

    public void onHitWall(HitWallEvent e) {
	drive = -drive;
    }

    public void onHitByBullet(HitByBulletEvent e) {
	bullet_speed = e.getVelocity();
    }

}


Lots of room for codesize saving stuff in there! Two quick things:
bullet_speed = e.getBullet().getVelocity();
Don't need the extra call, get it directly from the event:
bullet_speed = e.getVelocity();
the setAhead in the onHitWall handler is not needed either, if you hit a wall it will be set to 0. --Pulsar

Thanks! It's in cvs now, it will be included in the next release. It saves 8 bytes, one more and Festis can have its colors back.

Increase the wall fudge factor until you don't hit walls, then remove the onHitWall?() handler. :-) --David Alves

I'll try that some day. Although I think the smoothing is too bad to avoid the walls in all cases, the corners are a big problem. -- Strider


Robo Home | Festis | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited September 16, 2004 0:40 EST by Strider (diff)
Search: