[Home]Icarus

Robo Home | Changes | Preferences | AllPages

A NanoBot by PEZ

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

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

The random movement is quite Raiko inspired. With an idiots way of doing what the MusashiTrick does for smarter bots. The gun is semi-linear. Sometimes I use blocking calls making it do some more unpredictable things. =)

Source

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

// This code is released under the RoboWiki Public Code Licence (RWPCL), datailed on:
// https://robowiki.net/?RWPCL
//
// Icarus, by PEZ. - Something small
// https://robowiki.net/?Icarus
// $Id: Icarus.java,v 1.4 2004/08/25 16:51:40 peter Exp $

public class Icarus extends AdvancedRobot {
    static int direction = 7;
    static double bulletVelocity = -3;
    static double distance;
    static int hits;

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

    public void onScannedRobot(ScannedRobotEvent e) {
	distance = e.getDistance();
	double v = 0.6 * bulletVelocity / distance;
	if (hits > 3 && Math.random() > Math.pow(v, v)) {
	    direction = -direction;
	}
	setAhead(direction * 15);
	setTurnRight(normalizeDegrees(e.getBearing() + 90 - direction));

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

	setTurnRadarLeftRadians(getRadarTurnRemaining());
    }

    public void onHitWall(HitWallEvent e) {
	if (hits < 4) {
	    turnRight(normalizeDegrees(e.getBearing() - 100)); 
	    ahead(100);
	}
	else {
	    direction = -direction;
	}
    }

    public void onHitByBullet(HitByBulletEvent e) {
	bulletVelocity = e.getVelocity();
	hits++;
    }

    double normalizeDegrees(double angle) {
	return Math.toDegrees(Utils.normalRelativeAngle(Math.toRadians(angle)));
    }
}

Comments?


Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited August 25, 2004 16:54 EST by PEZ (diff)
Search: