[Home]History of CodeSnippets/Nano Circular Linear Predictor

Robo Home | Changes | Preferences | AllPages


Revision 11 . . December 7, 2007 23:12 EST by Chase-san [hrmmmm]
Revision 10 . . August 20, 2007 22:34 EST by Skilgannon [removed some unnecessary code stuff]
  

Difference (from prior major revision) (no other diffs)

Added: 103a104,155

Oh wow, this is gonna sound really retarded, but, couldn't you do something like this? Its probably bigger, but I dislike loops.

package chase.nano;

import static java.lang.Math.*;
import robocode.*;

public class NanoCircle extends AdvancedRobot {
public static double lastX, lastY, lastHeading;

public void run() {
lastX = lastY = 0;
while(true) {
setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
}
}

public void onScannedRobot(ScannedRobotEvent e) {
double absAngle, x, y, heading;

absAngle = e.getBearingRadians() + getHeadingRadians();
x = getX() + sin(absAngle) * e.getDistance();
y = getY() + cos(absAngle) * e.getDistance();
heading = e.getHeadingRadians();

if(lastX != 0) {
//the lines, unmutilated
//b=-tan(heading + PI/2)*x+y
//lastB=-tan(lastHeading + PI/2)*lastX+lastY
double m1,m2,b1,r, circleX;;
double circleY = (circleX = ((m2=-tan(heading + PI/2))*x+y -
(b1=(m1=-tan(lastHeading + PI/2))*lastX+lastY))
/ (m1 - m2))*m1+b1;
//the radius, fyi
r = sqrt((circleX-x)*(circleX-x)+(circleY-y)*(circleY-y));

//yay, I found the center, now to project along it
//.. I kinda got lost here, but I would think find
//where the bullet can intercept the robot
}

lastX = x;
lastY = y;
lastHeading = heading;

setTurnRadarLeftRadians(getRadarTurnRemainingRadians());
}
}


--Chase-san

Robo Home | Changes | Preferences | AllPages
Search: