User:Robar/Code snippets

From Robowiki
< User:Robar
Revision as of 07:20, 1 July 2010 by Chase-san (talk | contribs) (use <syntaxhighlight>)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

My code snippets

During my researches in Robocode I created many educating and interesting codes, which I'd like to share with you.
Many places I use variables called 'hot' and 'absB'. They are exactly what their names mean: Head-on angle and Absolute Bearing, both in radians.
The codes are not squeezed, they are supposed to be readable and obvious.

Quick Linear Targeting with Angular Velocity

This works quite well, but it's not smaller and a bit less accurate than the popular latvel-type. Otherwise, this shows very spectaculary what exactly Angular Velocity is.
public double do_Angular_Velocity_Gun(ScannedRobotEvent e){
            double av = (e.getVelocity()*Math.sin(e.getHeadingRadians()-absB))/e.getDistance();
            return hot+av*(e.getDistance()/bulletVel);
     }

Quick Linear Targeting with Maximum Escape Angle

This one is even less accurate but an interesting use of Maximum Escape Angle. ;)
 public double do_MaximumEscapeAngle_gun(ScannedRobotEvent e){
        	double lateralDir = Math.signum(e.getVelocity()*Math.sin(e.getHeadingRadians()-absB));
        	double mea = Math.asin(8.0/bulletVel);
        	return hot + mea*lateralDir;
        }