[Home]Squirrel/Movement

Robo Home | Squirrel | Changes | Preferences | AllPages

package bayen;
import robocode.*;
import java.util.*;
import java.awt.geom.*;

/**
 * FleetFeet - Squirrel's movement
 */
public class FleetFeet
{
	AdvancedRobot Squirrel;
	double dir = 1;
	ScannedRobotEvent lastScan;
	double iD = 225;
	
	public FleetFeet(AdvancedRobot robot) {
		Squirrel = robot;
	}
	
	public void onScannedRobot(ScannedRobotEvent e) {
		if(Squirrel.getTime()<30)
		lastScan = e;
		double dif = lastScan.getEnergy() - e.getEnergy();
		if(dif<=3 && dif>0){
		    dir=-dir;
			if(dif==3)
			iD=225;
			else if(dif>=2)
			iD=300;
			else if(dif>=1)
			iD=340;
			else if(dif>=0)
			iD=iD;
	    }
		Squirrel.setTurnRight(normalRelativeAngle(
		e.getBearing()+90-(e.getDistance()>(iD+100)?45:20)*dir*
		(e.getDistance()<(iD)?-1:1)));
		Squirrel.setAhead(100*dir);
		lastScan = e;
	}
	
	public void onHitWall(HitWallEvent e) {
		dir=-dir;
	}
	public void onHitRobot(HitRobotEvent e) {
		dir=-dir;
	}
	public void onHitByBullet(HitByBulletEvent e) {
		System.out.println("hit");
	}
	private double normalRelativeAngle(double angle) {
        angle = Math.toRadians(angle);
        return Math.toDegrees(Math.atan2(
               Math.sin(angle), Math.cos(angle))); 
    }
	
}

Robo Home | Squirrel | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited September 17, 2006 20:50 EST by Bayen (diff)
Search: