Difference between revisions of "Head-On Targeting"

From Robowiki
Jump to navigation Jump to search
Line 4: Line 4:
 
The simple strategy of aiming where you last saw the enemy. Works surprisingly well against surprisingly many bots, especially in [[Melee]] battles.
 
The simple strategy of aiming where you last saw the enemy. Works surprisingly well against surprisingly many bots, especially in [[Melee]] battles.
  
== Example ==
+
== Examples ==
  
 
In <code>onScannedRobot</code>, add:
 
In <code>onScannedRobot</code>, add:
Line 13: Line 13:
 
     robocode.util.Utils.normalRelativeAngle(absoluteBearing -  
 
     robocode.util.Utils.normalRelativeAngle(absoluteBearing -  
 
         getGunHeadingRadians()));
 
         getGunHeadingRadians()));
 +
</syntaxhighlight>
 +
 +
A code like this was found in <code>sample.Fire</code>.
 +
 +
<syntaxhighlight>
 +
double turnGunAmt = (getHeadingRadians() + e.getBearingRadians()) - getGunHeadingRadians();
 +
//You can make this setTurnGunRight(...) or setTurnGunRightRadians(...) with an AdvancedRobot
 +
turnGunRight(turnGunAmt);
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Revision as of 04:24, 28 September 2013

Youtube
Youtube has a video of Head-On Targeting in action: click here to watch
This article is a stub. You can help RoboWiki by expanding it.

The simple strategy of aiming where you last saw the enemy. Works surprisingly well against surprisingly many bots, especially in Melee battles.

Examples

In onScannedRobot, add:

double absoluteBearing = getHeadingRadians() + e.getBearingRadians();
setTurnGunRightRadians(
    robocode.util.Utils.normalRelativeAngle(absoluteBearing - 
        getGunHeadingRadians()));

A code like this was found in sample.Fire.

double turnGunAmt = (getHeadingRadians() + e.getBearingRadians()) - getGunHeadingRadians();
//You can make this setTurnGunRight(...) or setTurnGunRightRadians(...) with an AdvancedRobot
turnGunRight(turnGunAmt);

See also