Random Targeting
A method of targeting that simply chooses a random angle among the angles that could possibly hit the opponent. Some successful NanoBots use this firing method. Its implementation is very small and for unpredictable movements, it will give a consistent hit percentage.
Contents 
Example
public void onScannedRobot(ScannedRobotEvent e) { // ... double targetAngle = getHeadingRadians() + e.getBearingRadians(); double bulletPower = Math.max(0.1,Math.random() * 3.0); double escapeAngle = Math.asin(8 / Rules.getBulletSpeed(bulletPower)); double randomAimOffset = escapeAngle + Math.random() * 2 * escapeAngle; double headOnTargeting = targetAngle  getGunHeadingRadians(); setTurnGunRightRadians(Utils.normalRelativeAngle(headOnTargeting + randomAimOffset)); setFire(bulletPower); // ... }
A simpler solution
A simpler method is to assume that the enemy is traveling in a circle around you (see Musashi Trick), which is often true among NanoBots and 1vs1 bots. If the enemy is traveling in a circle around you, the maximum distance it can cover before a bullet reaches it is enemy velocity / bullet velocity
(in radians). For example, a power 3.0 bullet fired at an enemy going at full speed should be fired at a bearing offset between 8/11 and +8/11.
Selecting firepower
The advantage of a random gun is that it should have a roughly equal hit rate against all types of Movement. This makes ideal firepower selection pretty easy to precalculate. In the following equations x is the choice of firepower. It is assumed that damage output per tick is the quantity you're interested in maximizing, it may not be.
Bullet damage, assuming firepower > 1:
The smallest size of a robot, in radians:
, where is the distance to the other bot.
The total escape area, in radians:
Probability of a hit, assuming uniform spread of bullets over :
The expected damage from a shot:
The heat created by a shot:
The firing frequency:
Expected damage per tick of combat:
Optimization of is left as an exercise for the coder.
See also
