[Home]WaveSnake

Robo Home | Changes | Preferences | AllPages

Here's my attempt at a nano "surfer," although the movement is too crude to really deserve the term. It uses a simple random gun. -- Kev

package kc.nano;
import robocode.util.Utils;
import robocode.AdvancedRobot;
import robocode.ScannedRobotEvent;
import robocode.HitWallEvent;
import robocode.HitByBulletEvent;
import robocode.BulletHitEvent;

public class WaveSnake extends AdvancedRobot {
	static double moveFactor = 20;
	static double enemyEnergy;
	static int vel;
	static int lastVel;
	static int[][] hitData = new int[16][4];
		
	public void run() {
		turnRadarRightRadians(Double.POSITIVE_INFINITY);
	}

	public void onScannedRobot(ScannedRobotEvent e) {
		setTurnRightRadians(Math.cos(e.getBearingRadians()) - ((e.getDistance() - 150) * moveFactor / 30000));
		setTurnRadarLeft(getRadarTurnRemaining());

                setTurnGunRightRadians(Utils.normalRelativeAngle((1.3 * (Math.random() - 0.5)) + e.getBearingRadians() + getHeadingRadians() - getGunHeadingRadians()));
                setFire(2.4);
		
		
		if(enemyEnergy > (enemyEnergy = e.getEnergy())) {
			lastVel = vel + (4 * (int)(e.getDistance() / 267));
			int testVel = 3;
			do {
				if(hitData[lastVel][testVel] < hitData[lastVel][vel]) {
					vel = testVel;
				}
			} while(testVel-- > 0);
			if(vel < 2) {
				onHitWall(null);
			} 
		}
		setMaxVelocity(8 * (vel - 1.5));
		setAhead(moveFactor);
	}

	public void onBulletHit(BulletHitEvent e) {
		enemyEnergy -= 11.4;
	}
	
	public void onHitByBullet(HitByBulletEvent e) {
		hitData[lastVel][vel]++;
	}
	
	public void onHitWall(HitWallEvent e) {
		moveFactor = -moveFactor;
	}
}


Cool! In a strict sense, this bot surfs velocity not wave! LOL. I call it a VelocitySurfer?. -- Stelokim

Drat, I had dibs. Mine was gonna be absolute bearing based though. :P --Chase-san


Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited February 26, 2007 4:11 EST by Chase-san (diff)
Search: