[Home]Icarus

Robo Home | Changes | Preferences | AllPages

Showing revision 2

A NanoBot by PEZ

Probably as lousy as all my other nano attempts...

Download it from http://www.robocoderepository.com/BotDetail.jsp?id=2353

Source

package pez.nano;
import robocode.*;
import robocode.util.Utils;

// This code is released under the RoboWiki Public Code Licence (RWPCL), datailed on:
// http://robowiki.net/?RWPCL
//
// Icarus, by PEZ. - Something small
// http://robowiki.net/?Icarus
// $Id: Icarus.java,v 1.3 2004/08/25 11:34:03 peter Exp $

public class Icarus extends AdvancedRobot {
    static int direction = 7;
    static int timer;
    static double[] reversies = { 0.0, 7.0, 14.0 };
    static int hits;

    public void run() {
	turnRadarRightRadians(Double.POSITIVE_INFINITY);
    }

    public void onScannedRobot(ScannedRobotEvent e) {
	int stopOrGo = 1;
	double d = e.getDistance() / 10;
	if (timer++ > d) {
	    stopOrGo = 0;
	}
	if (timer > d * 1.35) {
	    timer = 0;
	}
	if (Math.random() < reversies[hits % 3] / e.getDistance()) {
	    direction = -direction;
	}
	setAhead(direction * 20 * stopOrGo);
	setTurnRight(e.getBearing() + 90 - direction);

        double enemyAbsoluteBearing = getHeadingRadians() + e.getBearingRadians();
	setTurnGunRightRadians(Utils.normalRelativeAngle(enemyAbsoluteBearing + e.getVelocity() * Math.sin(e.getHeadingRadians() - enemyAbsoluteBearing) * (Math.random() / (8.0 + getRoundNum())) - getGunHeadingRadians()));
	setFire(e.getDistance() < 140 ? 3.0 : 1.9);

	setTurnRadarLeftRadians(getRadarTurnRemaining());
    }

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

    public void onHitByBullet(HitByBulletEvent e) {
	hits++;
    }
}

Comments?


Robo Home | Changes | Preferences | AllPages
Edit revision 2 of this page | View other revisions | View current revision
Edited August 25, 2004 13:38 EST by PEZ (diff)
Search: