Here is a 2D range based data structure: Chase-san/RangeBucket2D
Most of these are just math I threw togeather to help me out.
/**
* Bell curve smoother... also know as gaussian smooth or normal distrabution
* @param x Current Position
* @param c Center (current index your adding)
* @param w Width (number of binIndexes)
* @return value of a bellcurve
*/
public static final double smoothingModifier = 30.0;
public static double bellcurve(int x, int c, int w) {
int diff = (int)Math.abs(c - x);
double binsmooth = smoothingModifier/w;
//I suppose technically you could also use Math.exp(-(binsmooth*binsmooth*diff*diff)/2.0);
return Math.pow(Math.E, -(binsmooth*binsmooth*diff*diff)/2.0);
}
package chase.g;
import robocode.AdvancedRobot;
import robocode.ScannedRobotEvent;
public class RobotState {
public double x, xDelta;
public double y, yDelta;
public double distance, distanceDelta;
public double heading, headingDelta;
public double bearing, bearingDelta;
public double velocity, velocityDelta;
public double latVelocity, latVelocityDelta;
public double advVelocity, advVelocityDelta;
public void setRobotState(AdvancedRobot b, ScannedRobotEvent e) {
x = b.getX();
y = b.getY();
distance = e.getDistance();
heading = b.getHeadingRadians();
bearing = e.getBearingRadians() + heading;
velocity = b.getVelocity();
latVelocity = velocity*Math.sin(heading-bearing);
advVelocity = velocity*Math.cos(heading-bearing);
}
public void setEnemyState(AdvancedRobot b, ScannedRobotEvent e) {
bearing = e.getBearingRadians() + heading;
distance = e.getDistance();
x = b.getX() + Math.sin(bearing) * distance;
y = b.getY() + Math.cos(bearing) * distance;
velocity = e.getVelocity();
heading = e.getHeadingRadians();
latVelocity = velocity*Math.sin(heading-bearing);
advVelocity = velocity*Math.cos(heading-bearing);
bearing += Math.PI; //bearing from the enemy to us of course
}
public void setDelta(RobotState rs) {
xDelta = x - rs.x;
yDelta = y - rs.y;
distanceDelta = distance - rs.distance;
headingDelta = heading - rs.heading;
bearingDelta = bearing - rs.bearing;
velocityDelta = velocity - rs.velocity;
latVelocityDelta = latVelocity - rs.latVelocity;
advVelocityDelta = advVelocity - rs.advVelocity;
}
}
It works more like Graphics2D does, it can draw, fill and stroke shapes and draw points. It even has a method that will draw a image from the data folder to the screen. Its also smaller then DrawingBot, but thats because it uses the built-in Shape method.
Your bell curve smoother, why does it take doubles as arguments? Shouldn't it take ints? -- Skilgannon
I would definatly like to see how you improved DrawingBot, i made some update for yoda aswell, storing Renerables in a stack and poping them off when drawing, still not a fast as i would like. -- Gorded