[Home]UtilityClass

Robo Home | Changes | Preferences | AllPages

Showing revision 14
Pretty much every bot utilizes a set of utility functions, often compiling them in a Utility or BotMath class. There are several examples on the wiki of posted utility classes, but this pages attempts to consolidate all of these utility functions onto one page.

(Subpage each function. Within subpage provide as many examples as possible, with goal to find both a most stable function and a minimum codesize function)


What is the point of normalizing within [0, 2pi]? I don't see how it makes angles more useful. -- Jonathan

Its usually used for calculating the absolute heading of the enemy. You use normalHeading(e.getBearing() + getHeading()) and it will return the exact angle from the norm of the enemy, and then that can be used to calculate its position. In practice I have very rarely used it, but because it is such a standard in most utility classes I added it here (its even included in the Robocode utilities class). -- Jokester

But when do you need to get an angle within [0, 2pi]? -- Jonathan

Note - the reason the robocode utilities class has it is because it needs to be sure to return angles in that range to the robot sometimes. -- Kawigi

Note - I'd have used [-pi, pi] and the mathematical convention 0 rad=x, pi/2 rad=y.

How about the following?

-- Jonathan

Well what do you guys use? I havent put everything here to use, I just started listing things that are in my BotMath class (which has been compiled from most of the classes I have seen). These have just been the basic ones that I have seen every where. I plan on including some more of them. I also have a ton of game physics stuff in my botmath if anyone thinks that should be included (I can make calls to bot math to to see the maximum speed, turning etc of my or other bots). Include whichever you can think of (just list the functions if you want). I chose to do it this way because they are a page per function, but if you feel it would be better to combine similar functions on one page I can do that too. -- Jokester

Normalizing angles is something you just need if you want your bot to make sense. Here's the method I mentioned:

double normalize(double angle, double min, double max) {
	return angle - (max - min) * Math.floor((angle - min) / (max - min));
}
Try normalize(angle, -Math.PI, Math.PI), which is equivalent to:
double normalize(double angle) {
	return angle - 2 * Math.PI * Math.floor((angle + Math.PI) / (2 * Math.PI));
}
PHNRD uses it to stay perpendicular to bullets.

If you have a vector class, it makes sense to put at least cartesian<->polar conversion in there. -- Jonathan


Robo Home | Changes | Preferences | AllPages
Edit revision 14 of this page | View other revisions | View current revision
Edited March 11, 2006 15:20 EST by AvihooI (diff)
Search: