Difference between revisions of "User:Robar/Code snippets"
Jump to navigation
Jump to search
(my interesting and silly codes - Angular Velocity gun and Maximum Escape Angle gun added) |
|||
Line 1: | Line 1: | ||
− | [[Category:Code snippets]] | + | [[Category:Code Snippets|Robar's educational code snippets]] |
= My code snippets = | = My code snippets = | ||
:During my researches in Robocode I created many educating and interesting codes, which I'd like to share with you. | :During my researches in Robocode I created many educating and interesting codes, which I'd like to share with you. |
Revision as of 18:31, 6 April 2009
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; }