little help

Jump to navigation Jump to search
Edited by another user.
Last edit: 18:00, 18 June 2012

hi i've tried radial targeting but I kepp getting a error message. Could you guys just check my code.

package argeaer;
import robocode.*;
//import java.awt.Color;

/**
 * Arg - a robot by (your name here)
 */
public class Arg extends Robot
{
	/**
	 * run: Arg's default behavior
	 */
	public void run() {
		// After trying out your robot, try uncommenting the import at the top,
		// and the next line:
		//setColors(Color.red,Color.blue,Color.green);
		while(true) {
			// Replace the next 4 lines with any behavior you would like
			ahead(100);
			turnGunRight(360);
			back(100);
			turnGunRight(360);
		}
	}

	/**
	 * onScannedRobot: What to do when you see another robot
	 */
/**This function predicts the time of the intersection between the 
bullet and the target based on a simple iteration.  It then moves 
the gun to the correct angle to fire on the target.**/
void doGun() {
    long time;
    long nextTime;
    Point2D.Double p;
    p = new Point2D.Double(target.x, target.y);
    for (int i = 0; i < 10; i++){
        nextTime = 
    (intMath.round((getRange(getX(),getY(),p.x,p.y)/(20-(3*firePower))));
        time = getTime() + nextTime;
        p = target.guessPosition(time);
    }
    /**Turn the gun to the correct angle**/
    double gunOffset = getGunHeadingRadians() - 
                  (Math.PI/2 - Math.atan2(p.y - getY(), p.x - getX()));
    setTurnGunLeftRadians(normaliseBearing(gunOffset));
}

double normaliseBearing(double ang) {
    if (ang > Math.PI)
        ang -= 2*PI;
    if (ang < -Math.PI)
        ang += 2*Math.PI;
    return ang;
}

public double getrange(double x1,double y1, double x2,double y2) {
    double x = x2-x1;
    double y = y2-y1;
    double h = Math.sqrt( x*x + y*y );
    return h;	
}


	/**
	 * onHitByBullet: What to do when you're hit by a bullet
	 */
	public void onHitByBullet(HitByBulletEvent e) {
		turnLeft(90 - e.getBearing());
	}
	
}
Rigged17:49, 18 June 2012

You do not have permission to edit this page, for the following reasons:

  • The action you have requested is limited to users in the group: Users.
  • You must confirm your email address before editing pages. Please set and validate your email address through your user preferences.

You can view and copy the source of this page.

Return to Thread:User talk:Rigged/little help/reply (9).