[Home]Chase-san/Free Code

Robo Home | Chase-san | Changes | Preferences | AllPages

Inspired by David Alves/Free Code

Here is a 2D range based data structure: Chase-san/RangeBucket2D

Most of these are just math I threw togeather to help me out.


BellCurve?: Something I whipped up when messing around with a better way to smooth data.
	/**
	 * 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);
	}


RobotState?: Not the most useless or useful class, I find it useful as its not a all incompassing class, so your not wasting space on data you don't need. Could very easily be used in a pattern matcher.
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;
	}
}


Comments: I also made what I would like to consider a better version of David Alves/DrawingBot, but unless people want it I wont release it.

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.

--Chase-san

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

I'd like to see your improved DrawingBot, to compare to mine! One more thing, does you robot state class above right? I think the LatVel? and AdvVel? is wrong. --Nat


Robo Home | Chase-san | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited March 25, 2009 22:36 EST by labfire.ncmich.edu (diff)
Search: