[Home]History of TeamSliNk

Robo Home | Changes | Preferences | AllPages


Revision 20 . . July 28, 2006 1:26 EST by David Alves [comment]
Revision 19 . . July 28, 2006 0:50 EST by Voidious [I doubt it]
  

Difference (from prior major revision) (no other diffs)

Added: 55a56,69

One thing you can do pretty easily to increase performance (although only by a tiny bit) is use squared distances instead of normal ones. For example, instead of

Point2D.Double me, enemy, anotherEnemy;
if(me.distance(enemy) < 100) runAway();
if(me.distance(enemy) < me.distance(anotherEnemy)) switchTargets();

you can use

Point2D.Double me, enemy;
if(me.distanceSq(enemy) < 10000) runAway();
if(me.distanceSq(enemy) < me.distanceSq(anotherEnemy)) switchTargets();

square roots are slow, so the second version is a bit faster. Probably only worth it if it's inside a loop or something though. --David Alves

Robo Home | Changes | Preferences | AllPages
Search: